@jjlmoya/utils-games-development 1.66.0 → 1.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/package.json +67 -67
  2. package/scripts/postinstall.mjs +27 -27
  3. package/src/category/GamesCategorySEO.astro +19 -19
  4. package/src/category/i18n/de.ts +15 -15
  5. package/src/category/i18n/en.ts +15 -15
  6. package/src/category/i18n/es.ts +15 -15
  7. package/src/category/i18n/fr.ts +15 -15
  8. package/src/category/i18n/id.ts +10 -10
  9. package/src/category/i18n/it.ts +10 -10
  10. package/src/category/i18n/ja.ts +10 -10
  11. package/src/category/i18n/ko.ts +10 -10
  12. package/src/category/i18n/nl.ts +10 -10
  13. package/src/category/i18n/pl.ts +10 -10
  14. package/src/category/i18n/pt.ts +10 -10
  15. package/src/category/i18n/ru.ts +10 -10
  16. package/src/category/i18n/sv.ts +10 -10
  17. package/src/category/i18n/tr.ts +10 -10
  18. package/src/category/i18n/zh.ts +10 -10
  19. package/src/category/seo.astro +15 -15
  20. package/src/components/PreviewNavSidebar.astro +116 -116
  21. package/src/components/PreviewToolbar.astro +143 -143
  22. package/src/data.ts +11 -11
  23. package/src/env.d.ts +5 -5
  24. package/src/index.ts +20 -20
  25. package/src/layouts/PreviewLayout.astro +122 -122
  26. package/src/pages/[locale]/[slug].astro +165 -165
  27. package/src/pages/[locale].astro +250 -250
  28. package/src/pages/index.astro +4 -4
  29. package/src/tests/category_seo_quality.test.ts +74 -0
  30. package/src/tests/diacritics_density.test.ts +118 -118
  31. package/src/tests/faq_count.test.ts +19 -19
  32. package/src/tests/i18n_coverage.test.ts +36 -36
  33. package/src/tests/inverted_punctuation.test.ts +84 -84
  34. package/src/tests/mocks/astro_mock.js +2 -2
  35. package/src/tests/no_en_dash.test.ts +70 -70
  36. package/src/tests/no_h1_in_components.test.ts +48 -48
  37. package/src/tests/pagespeed_best_practices.test.ts +198 -198
  38. package/src/tests/qa-test-helpers.ts +32 -32
  39. package/src/tests/qa_bibliography_links.test.ts +41 -41
  40. package/src/tests/qa_claim_evidence.test.ts +69 -69
  41. package/src/tests/qa_logic_reference_coverage.test.ts +46 -46
  42. package/src/tests/qa_runtime_i18n.test.ts +100 -100
  43. package/src/tests/schemas_fulfillment.test.ts +23 -23
  44. package/src/tests/script_density.test.ts +94 -94
  45. package/src/tests/seo_length.test.ts +23 -23
  46. package/src/tests/slug_language_code_format.test.ts +23 -23
  47. package/src/tests/slug_uniqueness.test.ts +80 -80
  48. package/src/tests/title_quality.test.ts +56 -56
  49. package/src/tool/audioLoopPointFinder/audio-loop-point-finder.css +322 -322
  50. package/src/tool/audioLoopPointFinder/client.ts +262 -262
  51. package/src/tool/hitboxHurtboxAnimator/hitbox-hurtbox-animator.css +614 -614
  52. package/src/tool/saveFileEditor/component.astro +351 -351
  53. package/src/tool/saveFileEditor/game-save-file-editor.css +250 -250
  54. package/src/tool/spriteSheetPacker/app-client.ts +248 -248
  55. package/src/tool/spriteSheetPacker/bibliography.ts +12 -12
  56. package/src/tool/spriteSheetPacker/component.astro +229 -229
  57. package/src/tool/spriteSheetPacker/dropzone-client.ts +55 -55
  58. package/src/tool/spriteSheetPacker/entry.ts +28 -28
  59. package/src/tool/spriteSheetPacker/exporter.ts +116 -116
  60. package/src/tool/spriteSheetPacker/extractor-client.ts +127 -127
  61. package/src/tool/spriteSheetPacker/flipbook-client.ts +60 -60
  62. package/src/tool/spriteSheetPacker/logic.test.ts +155 -155
  63. package/src/tool/spriteSheetPacker/logic.ts +32 -32
  64. package/src/tool/spriteSheetPacker/packer-core.ts +121 -121
  65. package/src/tool/spriteSheetPacker/packer-ui.ts +86 -86
  66. package/src/tool/spriteSheetPacker/sprite-sheet-packer.css +578 -578
  67. package/src/tool/spriteSheetPacker/types.ts +89 -89
  68. package/src/tool/spriteSheetPacker/ui.ts +42 -42
  69. package/src/tool/steamCapsuleGenerator/index.ts +9 -9
  70. package/src/tool/steamCapsuleGenerator/validation.ts +14 -14
  71. package/src/types.ts +72 -72
@@ -1,351 +1,351 @@
1
- ---
2
- import type { SaveFileEditorUI } from './ui';
3
- import './game-save-file-editor.css';
4
-
5
- interface Props {
6
- ui: SaveFileEditorUI;
7
- }
8
-
9
- const { ui: t } = Astro.props;
10
- ---
11
-
12
- <div
13
- class="save-editor-main-card"
14
- id="save-editor-root"
15
- data-decode-error={t.decodeError}
16
- data-bytes-unit={t.bytesUnit}
17
- >
18
- <div style="display: none;">
19
- <span>{t.title}</span>
20
- <span>{t.subtitle}</span>
21
- </div>
22
-
23
- <div class="form-group">
24
- <label for="save-file-input" class="form-label">{t.dropSaveFile}</label>
25
- <div class="dropzone" id="drop-zone">
26
- <input type="file" id="save-file-input" style="display: none;" accept=".json,.sav,.txt,.dat" />
27
- <p>{t.dropSaveFile}</p>
28
- <button type="button" class="btn-secondary" id="browse-btn">{t.orSelectFile}</button>
29
- </div>
30
- </div>
31
-
32
- <div class="editor-unified-layout">
33
- <div class="control-panel">
34
- <h3 class="panel-section-title">{t.decodePanelTitle}</h3>
35
-
36
- <div class="options-row">
37
- <div class="form-group">
38
- <label class="form-label">{t.encryptionMethod}</label>
39
- <div class="method-chip-group" id="enc-method-group">
40
- <button type="button" class="chip-btn active" data-value="base64">{t.methodBase64}</button>
41
- <button type="button" class="chip-btn" data-value="xor">{t.methodXor}</button>
42
- <button type="button" class="chip-btn" data-value="raw">{t.methodRaw}</button>
43
- </div>
44
- </div>
45
-
46
- <div class="form-group" id="xor-key-group">
47
- <label for="xor-key-input" class="form-label">{t.xorKeyLabel}</label>
48
- <input type="text" id="xor-key-input" class="input-text" placeholder={t.xorKeyPlaceholder} />
49
- </div>
50
- </div>
51
-
52
- <div id="decode-error" class="error-banner" style="display: none;"></div>
53
-
54
- <div class="form-group" style="flex: 1; display: flex; flex-direction: column;">
55
- <label for="json-code-input" class="form-label">{t.jsonRawTitle}</label>
56
- <textarea id="json-code-input" class="textarea-code" spellcheck="false" style="flex: 1; min-height: 340px;"></textarea>
57
- </div>
58
- </div>
59
-
60
- <div class="control-panel">
61
- <h3 class="panel-section-title">{t.exportPanelTitle}</h3>
62
-
63
- <div class="stats-grid">
64
- <div class="stat-item">
65
- <span class="stat-val" id="stat-format">BASE64</span>
66
- <span class="stat-lbl">{t.detectedFormat}</span>
67
- </div>
68
- <div class="stat-item">
69
- <span class="stat-val" id="stat-keys">0</span>
70
- <span class="stat-lbl">{t.decodedKeysCount}</span>
71
- </div>
72
- <div class="stat-item">
73
- <span class="stat-val" id="stat-size">0 B</span>
74
- <span class="stat-lbl">{t.dataSize}</span>
75
- </div>
76
- </div>
77
-
78
- <div class="form-group" style="flex: 1; display: flex; flex-direction: column;">
79
- <label for="export-preview" class="form-label">{t.exportPreviewLabel}</label>
80
- <textarea id="export-preview" class="textarea-code" readonly style="flex: 1; min-height: 340px;"></textarea>
81
- </div>
82
-
83
- <div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
84
- <button type="button" class="btn-primary" id="export-download-btn" style="flex: 1;">{t.encodeAndDownload}</button>
85
- <button type="button" class="btn-secondary" id="export-copy-btn">{t.copyEncoded}</button>
86
- </div>
87
- <span id="copied-notice" class="copied-notice" style="display: none;">{t.copiedNotice}</span>
88
- </div>
89
- </div>
90
- </div>
91
-
92
- <script>
93
- import { decodeSaveData, encodeSaveData, detectFormat, bytesToBase64, applyXor, strToUtf8Bytes } from './logic';
94
-
95
- const STORAGE_KEY_RAW = 'save_editor_last_raw';
96
- const STORAGE_KEY_METHOD = 'save_editor_last_method';
97
- const STORAGE_KEY_KEY = 'save_editor_last_key';
98
-
99
- const DEFAULT_SAMPLE = {
100
- player: { name: 'ShadowKnight', level: 45, gold: 12500, health: 100, mana: 80 },
101
- inventory: ['Legendary Sword', 'Health Potion x5', 'Dragon Armor'],
102
- unlockedLevels: [1, 2, 3, 4, 5],
103
- settings: { difficulty: 'hard', sound: true }
104
- };
105
-
106
- let currentJsonData: unknown = DEFAULT_SAMPLE;
107
- let rawSourceContent: string = '';
108
- let selectedMethod: 'base64' | 'xor' | 'raw' = 'base64';
109
-
110
- const rootCard = document.getElementById('save-editor-root');
111
- const defaultDecodeErrorMsg = rootCard?.dataset.decodeError || '';
112
- const bytesUnit = rootCard?.dataset.bytesUnit || 'B';
113
-
114
- const encMethodGroup = document.getElementById('enc-method-group');
115
- const xorKeyInput = document.getElementById('xor-key-input') as HTMLInputElement;
116
- const decodeError = document.getElementById('decode-error');
117
-
118
- const jsonCodeInput = document.getElementById('json-code-input') as HTMLTextAreaElement;
119
- const exportPreview = document.getElementById('export-preview') as HTMLTextAreaElement;
120
- const exportDownloadBtn = document.getElementById('export-download-btn');
121
- const exportCopyBtn = document.getElementById('export-copy-btn');
122
- const copiedNotice = document.getElementById('copied-notice');
123
-
124
- const statFormat = document.getElementById('stat-format');
125
- const statKeys = document.getElementById('stat-keys');
126
- const statSize = document.getElementById('stat-size');
127
-
128
- const dropZone = document.getElementById('drop-zone');
129
- const fileInput = document.getElementById('save-file-input') as HTMLInputElement;
130
- const browseBtn = document.getElementById('browse-btn');
131
-
132
- function updateChipGroupActiveState(selectedValue: string) {
133
- if (!encMethodGroup) return;
134
- const chips = encMethodGroup.querySelectorAll<HTMLButtonElement>('.chip-btn');
135
- chips.forEach((chip) => {
136
- chip.classList.toggle('active', chip.dataset.value === selectedValue);
137
- });
138
- }
139
-
140
- function setMethod(method: 'base64' | 'xor' | 'raw') {
141
- selectedMethod = method;
142
- updateChipGroupActiveState(method);
143
- saveStateToLocalStorage();
144
- performDecode();
145
- }
146
-
147
- encMethodGroup?.querySelectorAll<HTMLButtonElement>('.chip-btn').forEach((btn) => {
148
- btn.addEventListener('click', () => {
149
- const val = btn.dataset.value as 'base64' | 'xor' | 'raw';
150
- setMethod(val);
151
- });
152
- });
153
-
154
- function saveStateToLocalStorage() {
155
- try {
156
- localStorage.setItem(STORAGE_KEY_RAW, rawSourceContent);
157
- localStorage.setItem(STORAGE_KEY_METHOD, selectedMethod);
158
- if (xorKeyInput) localStorage.setItem(STORAGE_KEY_KEY, xorKeyInput.value);
159
- } catch {
160
- void 0;
161
- }
162
- }
163
-
164
- function updateEditorWithData(data: unknown, format: string) {
165
- currentJsonData = data;
166
- const jsonStr = JSON.stringify(data, null, 2);
167
- if (jsonCodeInput && document.activeElement !== jsonCodeInput) {
168
- jsonCodeInput.value = jsonStr;
169
- }
170
-
171
- if (statFormat) statFormat.textContent = format.toUpperCase();
172
- if (statKeys && typeof data === 'object' && data !== null) {
173
- statKeys.textContent = String(Object.keys(data as object).length);
174
- }
175
- if (statSize) {
176
- statSize.textContent = `${jsonStr.length} ${bytesUnit}`;
177
- }
178
-
179
- updateExportPreview();
180
- }
181
-
182
- function updateExportPreview() {
183
- if (!exportPreview) return;
184
- const key = xorKeyInput?.value || '';
185
- const encoded = encodeSaveData(currentJsonData, { method: selectedMethod, xorKey: key });
186
- exportPreview.value = encoded;
187
- }
188
-
189
- function renderDecodeError(errorMsg?: string) {
190
- if (!decodeError) return;
191
- if (errorMsg) {
192
- decodeError.textContent = errorMsg;
193
- decodeError.style.display = 'block';
194
- } else {
195
- decodeError.style.display = 'none';
196
- }
197
- }
198
-
199
- function performDecode() {
200
- if (!rawSourceContent) return;
201
- const key = xorKeyInput?.value || '';
202
- const res = decodeSaveData(rawSourceContent, { method: selectedMethod, xorKey: key });
203
-
204
- if (res.success && res.data) {
205
- renderDecodeError();
206
- updateEditorWithData(res.data, selectedMethod);
207
- saveStateToLocalStorage();
208
- return;
209
- }
210
-
211
- renderDecodeError(res.error || defaultDecodeErrorMsg);
212
- }
213
-
214
- function encodeRawStringFallback(val: string): string {
215
- const key = xorKeyInput?.value || '';
216
- const utf8 = strToUtf8Bytes(val);
217
-
218
- if (selectedMethod === 'base64') {
219
- return bytesToBase64(utf8);
220
- }
221
- if (selectedMethod === 'xor' && key) {
222
- return bytesToBase64(applyXor(utf8, key));
223
- }
224
- return val;
225
- }
226
-
227
- function updateUnparsedPreview() {
228
- if (exportPreview && jsonCodeInput?.value.trim()) {
229
- exportPreview.value = encodeRawStringFallback(jsonCodeInput.value);
230
- }
231
- }
232
-
233
- function updateJsonStats(val: string, parsed: object) {
234
- if (statKeys) {
235
- statKeys.textContent = String(Object.keys(parsed).length);
236
- }
237
- if (statSize) {
238
- statSize.textContent = `${val.length} ${bytesUnit}`;
239
- }
240
- }
241
-
242
- function handleJsonInputChange() {
243
- if (!jsonCodeInput) return;
244
- try {
245
- const parsed = JSON.parse(jsonCodeInput.value);
246
- currentJsonData = parsed;
247
- if (typeof parsed === 'object' && parsed !== null) {
248
- updateJsonStats(jsonCodeInput.value, parsed as object);
249
- }
250
- updateExportPreview();
251
- } catch {
252
- updateUnparsedPreview();
253
- }
254
- }
255
-
256
- jsonCodeInput?.addEventListener('input', handleJsonInputChange);
257
- jsonCodeInput?.addEventListener('keyup', handleJsonInputChange);
258
- jsonCodeInput?.addEventListener('change', handleJsonInputChange);
259
-
260
- xorKeyInput?.addEventListener('input', () => {
261
- saveStateToLocalStorage();
262
- performDecode();
263
- });
264
-
265
- exportCopyBtn?.addEventListener('click', () => {
266
- if (!exportPreview) return;
267
- navigator.clipboard.writeText(exportPreview.value);
268
- if (copiedNotice) {
269
- copiedNotice.style.display = 'inline';
270
- setTimeout(() => {
271
- copiedNotice.style.display = 'none';
272
- }, 2000);
273
- }
274
- });
275
-
276
- exportDownloadBtn?.addEventListener('click', () => {
277
- if (!exportPreview) return;
278
- const blob = new Blob([exportPreview.value], { type: 'text/plain;charset=utf-8' });
279
- const url = URL.createObjectURL(blob);
280
- const a = document.createElement('a');
281
- a.href = url;
282
- a.download = 'save_data.sav';
283
- a.click();
284
- URL.revokeObjectURL(url);
285
- });
286
-
287
- function processFileContent(content: string) {
288
- rawSourceContent = content.trim();
289
- const autoDetected = detectFormat(rawSourceContent, xorKeyInput?.value || '');
290
- setMethod(autoDetected);
291
- }
292
-
293
- function readFileAndProcess(file: File) {
294
- const reader = new FileReader();
295
- reader.onload = (evt) => {
296
- if (evt.target?.result) {
297
- processFileContent(evt.target.result as string);
298
- }
299
- };
300
- reader.readAsText(file);
301
- }
302
-
303
- browseBtn?.addEventListener('click', () => fileInput?.click());
304
- fileInput?.addEventListener('change', (e) => {
305
- const file = (e.target as HTMLInputElement).files?.[0];
306
- if (file) readFileAndProcess(file);
307
- });
308
-
309
- if (dropZone) {
310
- dropZone.addEventListener('dragover', (e) => e.preventDefault());
311
- dropZone.addEventListener('drop', (e) => {
312
- e.preventDefault();
313
- const file = e.dataTransfer?.files?.[0];
314
- if (file) readFileAndProcess(file);
315
- });
316
- }
317
-
318
- function getLocalStorageValue(key: string): string {
319
- try {
320
- return localStorage.getItem(key) || '';
321
- } catch {
322
- return '';
323
- }
324
- }
325
-
326
- function restoreSavedState(): boolean {
327
- const savedRaw = getLocalStorageValue(STORAGE_KEY_RAW);
328
- if (!savedRaw) return false;
329
-
330
- rawSourceContent = savedRaw;
331
- const savedMethod = getLocalStorageValue(STORAGE_KEY_METHOD);
332
- if (savedMethod === 'base64' || savedMethod === 'xor' || savedMethod === 'raw') {
333
- selectedMethod = savedMethod;
334
- updateChipGroupActiveState(savedMethod);
335
- }
336
- const savedKey = getLocalStorageValue(STORAGE_KEY_KEY);
337
- if (xorKeyInput && savedKey) xorKeyInput.value = savedKey;
338
-
339
- performDecode();
340
- return true;
341
- }
342
-
343
- function initTool() {
344
- if (restoreSavedState()) return;
345
-
346
- rawSourceContent = encodeSaveData(DEFAULT_SAMPLE, { method: 'base64', xorKey: '' });
347
- setMethod('base64');
348
- }
349
-
350
- initTool();
351
- </script>
1
+ ---
2
+ import type { SaveFileEditorUI } from './ui';
3
+ import './game-save-file-editor.css';
4
+
5
+ interface Props {
6
+ ui: SaveFileEditorUI;
7
+ }
8
+
9
+ const { ui: t } = Astro.props;
10
+ ---
11
+
12
+ <div
13
+ class="save-editor-main-card"
14
+ id="save-editor-root"
15
+ data-decode-error={t.decodeError}
16
+ data-bytes-unit={t.bytesUnit}
17
+ >
18
+ <div style="display: none;">
19
+ <span>{t.title}</span>
20
+ <span>{t.subtitle}</span>
21
+ </div>
22
+
23
+ <div class="form-group">
24
+ <label for="save-file-input" class="form-label">{t.dropSaveFile}</label>
25
+ <div class="dropzone" id="drop-zone">
26
+ <input type="file" id="save-file-input" style="display: none;" accept=".json,.sav,.txt,.dat" />
27
+ <p>{t.dropSaveFile}</p>
28
+ <button type="button" class="btn-secondary" id="browse-btn">{t.orSelectFile}</button>
29
+ </div>
30
+ </div>
31
+
32
+ <div class="editor-unified-layout">
33
+ <div class="control-panel">
34
+ <h3 class="panel-section-title">{t.decodePanelTitle}</h3>
35
+
36
+ <div class="options-row">
37
+ <div class="form-group">
38
+ <label class="form-label">{t.encryptionMethod}</label>
39
+ <div class="method-chip-group" id="enc-method-group">
40
+ <button type="button" class="chip-btn active" data-value="base64">{t.methodBase64}</button>
41
+ <button type="button" class="chip-btn" data-value="xor">{t.methodXor}</button>
42
+ <button type="button" class="chip-btn" data-value="raw">{t.methodRaw}</button>
43
+ </div>
44
+ </div>
45
+
46
+ <div class="form-group" id="xor-key-group">
47
+ <label for="xor-key-input" class="form-label">{t.xorKeyLabel}</label>
48
+ <input type="text" id="xor-key-input" class="input-text" placeholder={t.xorKeyPlaceholder} />
49
+ </div>
50
+ </div>
51
+
52
+ <div id="decode-error" class="error-banner" style="display: none;"></div>
53
+
54
+ <div class="form-group" style="flex: 1; display: flex; flex-direction: column;">
55
+ <label for="json-code-input" class="form-label">{t.jsonRawTitle}</label>
56
+ <textarea id="json-code-input" class="textarea-code" spellcheck="false" style="flex: 1; min-height: 340px;"></textarea>
57
+ </div>
58
+ </div>
59
+
60
+ <div class="control-panel">
61
+ <h3 class="panel-section-title">{t.exportPanelTitle}</h3>
62
+
63
+ <div class="stats-grid">
64
+ <div class="stat-item">
65
+ <span class="stat-val" id="stat-format">BASE64</span>
66
+ <span class="stat-lbl">{t.detectedFormat}</span>
67
+ </div>
68
+ <div class="stat-item">
69
+ <span class="stat-val" id="stat-keys">0</span>
70
+ <span class="stat-lbl">{t.decodedKeysCount}</span>
71
+ </div>
72
+ <div class="stat-item">
73
+ <span class="stat-val" id="stat-size">0 B</span>
74
+ <span class="stat-lbl">{t.dataSize}</span>
75
+ </div>
76
+ </div>
77
+
78
+ <div class="form-group" style="flex: 1; display: flex; flex-direction: column;">
79
+ <label for="export-preview" class="form-label">{t.exportPreviewLabel}</label>
80
+ <textarea id="export-preview" class="textarea-code" readonly style="flex: 1; min-height: 340px;"></textarea>
81
+ </div>
82
+
83
+ <div style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
84
+ <button type="button" class="btn-primary" id="export-download-btn" style="flex: 1;">{t.encodeAndDownload}</button>
85
+ <button type="button" class="btn-secondary" id="export-copy-btn">{t.copyEncoded}</button>
86
+ </div>
87
+ <span id="copied-notice" class="copied-notice" style="display: none;">{t.copiedNotice}</span>
88
+ </div>
89
+ </div>
90
+ </div>
91
+
92
+ <script>
93
+ import { decodeSaveData, encodeSaveData, detectFormat, bytesToBase64, applyXor, strToUtf8Bytes } from './logic';
94
+
95
+ const STORAGE_KEY_RAW = 'save_editor_last_raw';
96
+ const STORAGE_KEY_METHOD = 'save_editor_last_method';
97
+ const STORAGE_KEY_KEY = 'save_editor_last_key';
98
+
99
+ const DEFAULT_SAMPLE = {
100
+ player: { name: 'ShadowKnight', level: 45, gold: 12500, health: 100, mana: 80 },
101
+ inventory: ['Legendary Sword', 'Health Potion x5', 'Dragon Armor'],
102
+ unlockedLevels: [1, 2, 3, 4, 5],
103
+ settings: { difficulty: 'hard', sound: true }
104
+ };
105
+
106
+ let currentJsonData: unknown = DEFAULT_SAMPLE;
107
+ let rawSourceContent: string = '';
108
+ let selectedMethod: 'base64' | 'xor' | 'raw' = 'base64';
109
+
110
+ const rootCard = document.getElementById('save-editor-root');
111
+ const defaultDecodeErrorMsg = rootCard?.dataset.decodeError || '';
112
+ const bytesUnit = rootCard?.dataset.bytesUnit || 'B';
113
+
114
+ const encMethodGroup = document.getElementById('enc-method-group');
115
+ const xorKeyInput = document.getElementById('xor-key-input') as HTMLInputElement;
116
+ const decodeError = document.getElementById('decode-error');
117
+
118
+ const jsonCodeInput = document.getElementById('json-code-input') as HTMLTextAreaElement;
119
+ const exportPreview = document.getElementById('export-preview') as HTMLTextAreaElement;
120
+ const exportDownloadBtn = document.getElementById('export-download-btn');
121
+ const exportCopyBtn = document.getElementById('export-copy-btn');
122
+ const copiedNotice = document.getElementById('copied-notice');
123
+
124
+ const statFormat = document.getElementById('stat-format');
125
+ const statKeys = document.getElementById('stat-keys');
126
+ const statSize = document.getElementById('stat-size');
127
+
128
+ const dropZone = document.getElementById('drop-zone');
129
+ const fileInput = document.getElementById('save-file-input') as HTMLInputElement;
130
+ const browseBtn = document.getElementById('browse-btn');
131
+
132
+ function updateChipGroupActiveState(selectedValue: string) {
133
+ if (!encMethodGroup) return;
134
+ const chips = encMethodGroup.querySelectorAll<HTMLButtonElement>('.chip-btn');
135
+ chips.forEach((chip) => {
136
+ chip.classList.toggle('active', chip.dataset.value === selectedValue);
137
+ });
138
+ }
139
+
140
+ function setMethod(method: 'base64' | 'xor' | 'raw') {
141
+ selectedMethod = method;
142
+ updateChipGroupActiveState(method);
143
+ saveStateToLocalStorage();
144
+ performDecode();
145
+ }
146
+
147
+ encMethodGroup?.querySelectorAll<HTMLButtonElement>('.chip-btn').forEach((btn) => {
148
+ btn.addEventListener('click', () => {
149
+ const val = btn.dataset.value as 'base64' | 'xor' | 'raw';
150
+ setMethod(val);
151
+ });
152
+ });
153
+
154
+ function saveStateToLocalStorage() {
155
+ try {
156
+ localStorage.setItem(STORAGE_KEY_RAW, rawSourceContent);
157
+ localStorage.setItem(STORAGE_KEY_METHOD, selectedMethod);
158
+ if (xorKeyInput) localStorage.setItem(STORAGE_KEY_KEY, xorKeyInput.value);
159
+ } catch {
160
+ void 0;
161
+ }
162
+ }
163
+
164
+ function updateEditorWithData(data: unknown, format: string) {
165
+ currentJsonData = data;
166
+ const jsonStr = JSON.stringify(data, null, 2);
167
+ if (jsonCodeInput && document.activeElement !== jsonCodeInput) {
168
+ jsonCodeInput.value = jsonStr;
169
+ }
170
+
171
+ if (statFormat) statFormat.textContent = format.toUpperCase();
172
+ if (statKeys && typeof data === 'object' && data !== null) {
173
+ statKeys.textContent = String(Object.keys(data as object).length);
174
+ }
175
+ if (statSize) {
176
+ statSize.textContent = `${jsonStr.length} ${bytesUnit}`;
177
+ }
178
+
179
+ updateExportPreview();
180
+ }
181
+
182
+ function updateExportPreview() {
183
+ if (!exportPreview) return;
184
+ const key = xorKeyInput?.value || '';
185
+ const encoded = encodeSaveData(currentJsonData, { method: selectedMethod, xorKey: key });
186
+ exportPreview.value = encoded;
187
+ }
188
+
189
+ function renderDecodeError(errorMsg?: string) {
190
+ if (!decodeError) return;
191
+ if (errorMsg) {
192
+ decodeError.textContent = errorMsg;
193
+ decodeError.style.display = 'block';
194
+ } else {
195
+ decodeError.style.display = 'none';
196
+ }
197
+ }
198
+
199
+ function performDecode() {
200
+ if (!rawSourceContent) return;
201
+ const key = xorKeyInput?.value || '';
202
+ const res = decodeSaveData(rawSourceContent, { method: selectedMethod, xorKey: key });
203
+
204
+ if (res.success && res.data) {
205
+ renderDecodeError();
206
+ updateEditorWithData(res.data, selectedMethod);
207
+ saveStateToLocalStorage();
208
+ return;
209
+ }
210
+
211
+ renderDecodeError(res.error || defaultDecodeErrorMsg);
212
+ }
213
+
214
+ function encodeRawStringFallback(val: string): string {
215
+ const key = xorKeyInput?.value || '';
216
+ const utf8 = strToUtf8Bytes(val);
217
+
218
+ if (selectedMethod === 'base64') {
219
+ return bytesToBase64(utf8);
220
+ }
221
+ if (selectedMethod === 'xor' && key) {
222
+ return bytesToBase64(applyXor(utf8, key));
223
+ }
224
+ return val;
225
+ }
226
+
227
+ function updateUnparsedPreview() {
228
+ if (exportPreview && jsonCodeInput?.value.trim()) {
229
+ exportPreview.value = encodeRawStringFallback(jsonCodeInput.value);
230
+ }
231
+ }
232
+
233
+ function updateJsonStats(val: string, parsed: object) {
234
+ if (statKeys) {
235
+ statKeys.textContent = String(Object.keys(parsed).length);
236
+ }
237
+ if (statSize) {
238
+ statSize.textContent = `${val.length} ${bytesUnit}`;
239
+ }
240
+ }
241
+
242
+ function handleJsonInputChange() {
243
+ if (!jsonCodeInput) return;
244
+ try {
245
+ const parsed = JSON.parse(jsonCodeInput.value);
246
+ currentJsonData = parsed;
247
+ if (typeof parsed === 'object' && parsed !== null) {
248
+ updateJsonStats(jsonCodeInput.value, parsed as object);
249
+ }
250
+ updateExportPreview();
251
+ } catch {
252
+ updateUnparsedPreview();
253
+ }
254
+ }
255
+
256
+ jsonCodeInput?.addEventListener('input', handleJsonInputChange);
257
+ jsonCodeInput?.addEventListener('keyup', handleJsonInputChange);
258
+ jsonCodeInput?.addEventListener('change', handleJsonInputChange);
259
+
260
+ xorKeyInput?.addEventListener('input', () => {
261
+ saveStateToLocalStorage();
262
+ performDecode();
263
+ });
264
+
265
+ exportCopyBtn?.addEventListener('click', () => {
266
+ if (!exportPreview) return;
267
+ navigator.clipboard.writeText(exportPreview.value);
268
+ if (copiedNotice) {
269
+ copiedNotice.style.display = 'inline';
270
+ setTimeout(() => {
271
+ copiedNotice.style.display = 'none';
272
+ }, 2000);
273
+ }
274
+ });
275
+
276
+ exportDownloadBtn?.addEventListener('click', () => {
277
+ if (!exportPreview) return;
278
+ const blob = new Blob([exportPreview.value], { type: 'text/plain;charset=utf-8' });
279
+ const url = URL.createObjectURL(blob);
280
+ const a = document.createElement('a');
281
+ a.href = url;
282
+ a.download = 'save_data.sav';
283
+ a.click();
284
+ URL.revokeObjectURL(url);
285
+ });
286
+
287
+ function processFileContent(content: string) {
288
+ rawSourceContent = content.trim();
289
+ const autoDetected = detectFormat(rawSourceContent, xorKeyInput?.value || '');
290
+ setMethod(autoDetected);
291
+ }
292
+
293
+ function readFileAndProcess(file: File) {
294
+ const reader = new FileReader();
295
+ reader.onload = (evt) => {
296
+ if (evt.target?.result) {
297
+ processFileContent(evt.target.result as string);
298
+ }
299
+ };
300
+ reader.readAsText(file);
301
+ }
302
+
303
+ browseBtn?.addEventListener('click', () => fileInput?.click());
304
+ fileInput?.addEventListener('change', (e) => {
305
+ const file = (e.target as HTMLInputElement).files?.[0];
306
+ if (file) readFileAndProcess(file);
307
+ });
308
+
309
+ if (dropZone) {
310
+ dropZone.addEventListener('dragover', (e) => e.preventDefault());
311
+ dropZone.addEventListener('drop', (e) => {
312
+ e.preventDefault();
313
+ const file = e.dataTransfer?.files?.[0];
314
+ if (file) readFileAndProcess(file);
315
+ });
316
+ }
317
+
318
+ function getLocalStorageValue(key: string): string {
319
+ try {
320
+ return localStorage.getItem(key) || '';
321
+ } catch {
322
+ return '';
323
+ }
324
+ }
325
+
326
+ function restoreSavedState(): boolean {
327
+ const savedRaw = getLocalStorageValue(STORAGE_KEY_RAW);
328
+ if (!savedRaw) return false;
329
+
330
+ rawSourceContent = savedRaw;
331
+ const savedMethod = getLocalStorageValue(STORAGE_KEY_METHOD);
332
+ if (savedMethod === 'base64' || savedMethod === 'xor' || savedMethod === 'raw') {
333
+ selectedMethod = savedMethod;
334
+ updateChipGroupActiveState(savedMethod);
335
+ }
336
+ const savedKey = getLocalStorageValue(STORAGE_KEY_KEY);
337
+ if (xorKeyInput && savedKey) xorKeyInput.value = savedKey;
338
+
339
+ performDecode();
340
+ return true;
341
+ }
342
+
343
+ function initTool() {
344
+ if (restoreSavedState()) return;
345
+
346
+ rawSourceContent = encodeSaveData(DEFAULT_SAMPLE, { method: 'base64', xorKey: '' });
347
+ setMethod('base64');
348
+ }
349
+
350
+ initTool();
351
+ </script>