-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspm-text-editor.html
More file actions
505 lines (462 loc) · 18.6 KB
/
spm-text-editor.html
File metadata and controls
505 lines (462 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="Super Paper Mario, SPM, Super Paper Mario formatting, Super Paper Mario hacking, Super Paper Mario modding, Super Paper Mario text editor, Super Paper Mario text preview, SPM text editor, SPM text preview, SPM hacking, SPM modding, SPM formatting, text editor, Wii">
<title>SPM Text Preview</title>
<link rel="stylesheet" href="spm-stylesheet.css">
<style>
/* Font */
@font-face { font-family: 'SPMText'; src: url('PopJoyStd-B.ttf') format('truetype'); }
/* Base styles */
body, #output { font-family: 'SPMText', sans-serif; }
body { display: flex; flex-direction: column; align-items: center; padding: 2rem; background: #f4f4f4; }
textarea { width: 80%; height: 200px; margin-bottom: 1rem; font-family: monospace; font-size: 1rem; white-space: pre-wrap; word-wrap: break-word; resize: both; }
#output { width: 80%; background: white; padding: 1rem; white-space: pre-wrap; cursor: pointer; resize: both; overflow: auto; box-sizing: border-box; border: 4px solid black; }
/* Animations */
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes dynamicShrink { from { transform: scale(var(--dyn-factor)); } to { transform: scale(1); } }
@keyframes shake { 0%{transform:translate(0,0)rotate(0);}20%{transform:translate(-0.5px,-0.5px)rotate(-1deg);}40%{transform:translate(-0.5px,0.5px)rotate(1deg);}60%{transform:translate(0.5px,0.5px)rotate(0);}80%{transform:translate(0.5px,-0.5px)rotate(1deg);}100%{transform:translate(0,0)rotate(-1deg);} }
@keyframes wave {
from { transform: rotate(0deg) translateX(2px) rotate(0deg); }
to { transform: rotate(360deg) translateX(2px) rotate(-360deg); }
}
@keyframes rainbow { 0%{border-color:hotpink;}12.5%{border-color:orange;}25%{border-color:yellow;}37.5%{border-color:lawngreen;}50%{border-color:cyan;}62.5%{border-color:lawngreen;}75%{border-color:yellow;}87.5%{border-color:orange;}100%{border-color:hotpink;} }
/* Letter effects */
.shake-letter { display:inline-block; animation: shake 0.1s infinite; }
.wave-letter { display:inline-block; animation: wave 0.9s linear infinite; transform-origin: center; }
.dynamic-letter { display:inline-block; transform: scale(var(--dyn-factor)); animation: dynamicShrink 0.05s forwards; }
/* Page container styles */
#output.fairy-border { border:4px solid; animation: rainbow 5s linear infinite; }
#output.kanban-border { border:4px solid brown; }
#output.system-style { background: darkblue; border:4px solid gray; color:white; }
#output.diary-style { background: lightgoldenrodyellow; }
#output.clear-style { background: black; color: white; }
#output.majo-style { background: #4a3867; color: #ffddddff; }
</style>
</head>
<body>
<h1>Super Paper Mario Text Preview</h1>
<textarea id="input" placeholder="Use tags from Super Paper Mario's text files! This editor supports <shake>, <wave>, <scale [size]>, <dynamic 3>, <wait [ms]>, <col [hex]>, <fairy>, <fairy2>, <kanban>, <system>, <diary>, <clear>, <majo>, and <icon [button]>."></textarea>
<div id="output" title="Click to advance"></div>
<script>
const inputArea=document.getElementById('input'), outputDiv=document.getElementById('output');
let pages=[], fairyFlags=[], kanbanFlags=[], systemFlags=[], diaryFlags=[], clearFlags=[], majoFlags=[], currentPage=0;
function createSpan(char, effects, scale, dyn, delay) {
let node=document.createTextNode(char===' ' ? '\u00A0':char);
if(effects.includes('shake')){ const s=document.createElement('span');s.className='shake-letter';s.style.animationDelay=delay+'ms';s.appendChild(node);node=s; }
if(effects.includes('wave')){ const w=document.createElement('span');w.className='wave-letter';w.style.animationDelay=delay+'ms';w.appendChild(node);node=w; }
if(scale!==1){ const sc=document.createElement('span');sc.style.display='inline-block';sc.style.fontSize=scale+'em';sc.appendChild(node);node=sc; }
if(dyn!==1){ const d=document.createElement('span');d.className='dynamic-letter';d.style.setProperty('--dyn-factor',dyn);d.style.animationDelay=delay+'ms';d.appendChild(node);node=d; }
const f=document.createElement('span');f.style.display='inline-block';f.style.opacity='0';f.style.animation=`fadeIn 0s forwards ${delay}ms`;f.appendChild(node);
return f;
}
function parseCustomTags(text) {
const frag = document.createDocumentFragment();
const stack = [];
const flags = { fairy:false, kanban:false, system:false, diary:false, clear:false, majo:false, ph:false };
let d = 0, i = 0;
// A stack of “containers” where new nodes should be appended.
// Start with the root fragment.
const containerStack = [{ type: 'root', node: frag }];
function currentContainer() {
return containerStack[containerStack.length - 1].node;
}
while (i < text.length) {
let c = text[i];
if (c === 'Þ') c = '☆';
if (c === '®') c = '←';
if (c === '©') c = '→';
if (c === 'Ø') c = '♪';
if (c === '³') c = '↓';
if (c === '²') c = '↑';
// 1) Newline → <br>
if (c === '\n') {
currentContainer().appendChild(document.createElement('br'));
i++;
continue;
}
// ICON handler (inside parseCustomTags, at top of the while loop)
const iconMatch = text.slice(i).match(/^<\s*icon\s+([^\s>]+)[^>]*>/i);
if (iconMatch) {
const arg = iconMatch[1].toUpperCase();
// CRYSTAL → image
if (arg === 'CRYSTAL') {
const img = document.createElement('img');
img.src = 'images/Merlumina.png';
img.alt = 'Merlumina';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'AC_STAR') {
const img = document.createElement('img');
img.src = 'images/Star.png';
img.alt = 'Shooting Star';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'AC_KOURA') {
const img = document.createElement('img');
img.src = 'images/Shell.png';
img.alt = 'Shell';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'AC_ON') {
const img = document.createElement('img');
img.src = 'images/Circle.png';
img.alt = 'Circle with star';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'AC_KINOKO') {
const img = document.createElement('img');
img.src = 'images/Mushroom.png';
img.alt = 'Mushroom';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'PAD_PLUS') {
const img = document.createElement('img');
img.src = 'images/Plus.png';
img.alt = 'Plus button';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'PAD_MINUS') {
const img = document.createElement('img');
img.src = 'images/Minus.png';
img.alt = 'Minus button';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'STICK') {
const img = document.createElement('img');
img.src = 'images/Dpad.png';
img.alt = 'D-Pad';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'PAD') {
const img = document.createElement('img');
img.src = 'images/Wiimote.png';
img.alt = 'Wii remote';
img.style.width = '4em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'PAD_1') {
const img = document.createElement('img');
img.src = 'images/1.png';
img.alt = '1 button';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'PAD_2') {
const img = document.createElement('img');
img.src = 'images/2.png';
img.alt = '2 button';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else if (arg === 'PAD_A') {
const img = document.createElement('img');
img.src = 'images/A.png';
img.alt = 'A button';
img.style.width = '1em';
img.style.height = '1em';
currentContainer().appendChild(img);
} else {
let displayText;
if (arg.startsWith('STICK'))
displayText = '✚';
else if (arg === 'AC_STAR')
displayText = 'Star';
else if (arg === 'PAD_PLUS')
displayText = '⊕';
else if (arg === 'PAD_MINUS')
displayText = '⊖';
else if (arg === 'PAD_1')
displayText = '①';
else if (arg === 'PAD_2')
displayText = '②';
else if (arg === 'PAD_A')
displayText = 'Ⓐ';
else if (arg.startsWith('AC_KOURA'))
displayText = 'Shell';
else if (arg.startsWith('AC_ON'))
displayText = 'Circle';
else if (arg === 'HM')
displayText = '♡';
else if (arg.startsWith('AC_KINOKO'))
displayText = 'Mushroom';
else {
displayText = arg.charAt(0);
}
for (const ch of displayText) {
currentContainer().appendChild(
createSpan(
ch,
stack.filter(e => ['shake','wave'].includes(e.type)).map(e => e.type),
stack.filter(e => e.type === 'scale').reduce((s,e) => s * e.factor, 1),
stack.filter(e => e.type === 'dynamic').reduce((s,e) => s * e.factor, 1),
d * 25
)
);
d++;
}
}
// advance past the <icon…> tag and resume parsing
i += iconMatch[0].length;
continue;
}
// 3) Open‐tag (including <ph>)
const openMatch = text.slice(i).match(
/^<\s*(shake|wave|scale|dynamic|wait|fairy|kanban|system|diary|clear|majo|col|ph)\s*([^>]*)>/i
);
if (openMatch) {
const t = openMatch[1].toLowerCase();
const arg = openMatch[2].trim();
if (t === 'ph') {
// Create a wrapper <div> with zero height for <ph> ... </ph>
const wrapper = document.createElement('div');
wrapper.style.height = '0';
wrapper.style.overflow = 'hidden';
currentContainer().appendChild(wrapper);
// Push the wrapper onto the containerStack so subsequent content goes inside it
containerStack.push({ type: 'ph', node: wrapper });
flags.ph = true;
} else {
// All other open‐tags behave as before
switch (t) {
case 'wait':
d += Math.ceil(parseFloat(arg) / 25) || 0;
break;
case 'col':
stack.push({ type:'col', value:arg });
break;
case 'scale': {
const existing = stack.find(e => e.type === 'scale');
const nf = parseFloat(arg) || 1;
if (existing) existing.factor = nf;
else stack.push({ type:'scale', factor:nf });
break;
}
case 'dynamic':
if (!stack.some(e => e.type === 'dynamic'))
stack.push({ type:'dynamic', factor:parseFloat(arg)||1 });
break;
case 'shake':
if (!stack.some(e => e.type === 'shake'))
stack.push({ type:'shake' });
break;
case 'wave':
if (!stack.some(e => e.type === 'wave'))
stack.push({ type:'wave' });
break;
case 'fairy':
flags.fairy = true;
break;
case 'kanban':
flags.kanban = true;
break;
case 'system':
flags.system = true;
break;
case 'diary':
flags.diary = true;
break;
case 'clear':
flags.clear = true;
break;
case 'majo':
flags.majo = true;
break;
}
}
i += openMatch[0].length;
continue;
}
// 4) Close‐tag (including </ph>)
const closeMatch = text.slice(i).match(
/^<\s*\/\s*(shake|wave|scale|dynamic|fairy|kanban|system|diary|clear|majo|col|ph)\s*>/i
);
if (closeMatch) {
const t = closeMatch[1].toLowerCase();
if (t === 'ph') {
// Pop the <ph> wrapper from the containerStack
if (containerStack[containerStack.length - 1].type === 'ph') {
containerStack.pop();
}
flags.ph = false;
} else {
if (t === 'fairy') flags.fairy = false;
if (t === 'kanban') flags.kanban = false;
if (t === 'system') flags.system = false;
if (t === 'diary') flags.diary = false;
if (t === 'clear') flags.clear = false;
if (t === 'majo') flags.majo = false;
for (let j = stack.length - 1; j >= 0; j--) {
if (stack[j].type === t) {
stack.splice(j, 1);
break;
}
}
}
i += closeMatch[0].length;
continue;
}
// 5) Strip any other junk tags
const junkTag = text.slice(i).match(/^<[^>]+>/);
if (junkTag) {
i += junkTag[0].length;
continue;
}
// 6) Regular character
const effects = stack.filter(e => ['shake','wave'].includes(e.type)).map(e => e.type);
const scaleVal = stack.filter(e => e.type === 'scale').reduce((s,e) => s * e.factor, 1);
const dynVal = stack.filter(e => e.type === 'dynamic').reduce((s,e) => s * e.factor, 1);
const colorEntry = stack.find(e => e.type === 'col');
const color = colorEntry ? '#' + colorEntry.value : null;
const delay = d * 25;
let node = createSpan(c, effects, scaleVal, dynVal, delay);
if (color) {
const sp = document.createElement('span');
sp.style.color = color;
sp.appendChild(node);
node = sp;
}
currentContainer().appendChild(node);
d++;
i++;
}
return { fragment: frag, ...flags };
}
function generatePages(text) {
// Add this at the top of generatePages(text), right after the "{"
{
// Automatically wrap consecutive blocks of only‐tag lines with <ph>…</ph>
let lines = text.split('\n');
for (let i = 0; i < lines.length; i++) {
// If we find a line that’s “only tags,” start of a potential block:
if (/^(\s*<\s*\/?\s*(?:shake|wave|scale|dynamic|wait|col|fairy|kanban|system|diary|clear|majo|icon)\b[^>]*>\s*)+$/i.test(lines[i])) {
// Determine the end of this consecutive block of only‐tag lines
let start = i;
let end = i;
while (
end + 1 < lines.length &&
/^(\s*<\s*\/?\s*(?:shake|wave|scale|dynamic|wait|col|fairy|kanban|system|diary|clear|majo|icon)\b[^>]*>\s*)+$/i.test(lines[end + 1])
) {
end++;
}
// Append <ph> onto the line *before* this block (if it exists)
if (start > 0) {
lines[start - 1] = lines[start - 1] + '<ph>';
}
// Prepend </ph> onto the line *after* this block (if it exists)
if (end + 1 < lines.length) {
lines[end + 1] = '</ph>' + lines[end + 1];
}
// Advance i to skip over the rest of this block
i = end;
}
}
// Re‐join so the rest of generatePages sees the inserted <ph>…</ph>
text = lines.join('\n');
// Insert newline before other text whenever an underscore‐word is followed by non‐space
text = text
.split('\n')
.map(line => {
// Apply only if there’s at least one underscore‐word
if (/\b\w+_\w+\b/.test(line)) {
// Remove tags to check plain text
const stripped = line.replace(/<[^>]+>/g, '');
// Insert “\n” after the spaces that follow every underscore‐word
return line.replace(
/(\b\w+_\w+\b)(\s+)(?=\S)/g,
'$1$2\n'
);
}
return line;
})
.join('\n');
/*
// Resolve all <icon …> tags into text so their underscores won’t split pages
text = text.replace(/<\s*icon\s+([^\s>]+)[^>]*>/gi, (match, arg) => {
const upper = arg.toUpperCase();
let displayText;
if (upper.startsWith('STICK')) {
displayText = '✚';
} else if (upper.startsWith('AC_STAR')) {
displayText = 'Star';
} else if (upper === 'PAD_PLUS') {
displayText = '⊕';
} else if (upper === 'PAD_MINUS') {
displayText = '⊖';
} else if (upper === 'PAD_1') {
displayText = '①';
} else if (upper === 'PAD_2') {
displayText = '②';
} else if (upper === 'PAD_A') {
displayText = 'Ⓐ';
} else if (upper.startsWith('AC_KOURA')) {
displayText = 'Shell';
} else if (upper.startsWith('AC_ON')) {
displayText = 'Circle';
} else if (upper === 'HM') {
displayText = '♡';
} else if (upper.startsWith('AC_KINOKO')) {
displayText = 'Mushroom';
} else if (upper.startsWith('CRYSTAL')) {
displayText = ' [Merlumina\'s face]';
} else if (upper.startsWith('PAD_') && upper.length > 4) {
return upper.charAt(4);
} else if (upper === 'PAD') {
displayText = 'Wii Remote';
} else {
return upper.charAt(0);
}
return displayText;
});
*/
// Now split only on “real” underscore-words (icons have already been removed)
const parts = text.split(/(?=(?!PAD_|AC_)\b\w+_\w*\b)/);
// Reset pages & flags
pages = [];
fairyFlags = [];
kanbanFlags = [];
systemFlags = [];
diaryFlags = [];
clearFlags = [];
majoFlags = [];
// Process each segment, collapsing <ph> lines to zero height
parts.forEach(raw => {
const trimmed = raw.trim();
const { fragment, fairy, kanban, system, diary, clear, majo, ph } = parseCustomTags(trimmed);
if (ph) {
// Wrap the placeholder-only content so it takes zero height
const wrapper = document.createElement('div');
wrapper.style.height = '0';
wrapper.style.overflow = 'hidden';
wrapper.appendChild(fragment);
pages.push(wrapper);
} else {
// Normal line: keep the parsed fragment as-is
pages.push(fragment);
}
// Push flags (keep flags.ph if needed later, though it's only for collapsing)
fairyFlags.push(fairy);
kanbanFlags.push(kanban);
systemFlags.push(system);
diaryFlags.push(diary);
clearFlags.push(clear);
majoFlags.push(majo);
});
// Start at the first page
currentPage = 0;
}}
function showPage(idx){if(!pages[idx])return;outputDiv.innerHTML='';outputDiv.className='';if(fairyFlags[idx])outputDiv.classList.add('fairy-border');if(kanbanFlags[idx])outputDiv.classList.add('kanban-border');if(systemFlags[idx])outputDiv.classList.add('system-style');if(diaryFlags[idx])outputDiv.classList.add('diary-style');if(clearFlags[idx])outputDiv.classList.add('clear-style');if(majoFlags[idx])outputDiv.classList.add('majo-style');outputDiv.appendChild(pages[idx].cloneNode(true));}
function updatePreview(){generatePages(inputArea.value);showPage(0);}inputArea.addEventListener('input',updatePreview);outputDiv.addEventListener('click',()=>{if(currentPage<pages.length-1)showPage(++currentPage);});updatePreview();
</script>
</body>
</html>