@jjlmoya/utils-games-development 1.51.0 → 1.52.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 (31) hide show
  1. package/package.json +1 -1
  2. package/src/category/index.ts +2 -1
  3. package/src/entries.ts +4 -1
  4. package/src/tests/locale_completeness.test.ts +2 -2
  5. package/src/tests/tool_validation.test.ts +2 -2
  6. package/src/tool/saveFileEditor/bibliography.astro +6 -0
  7. package/src/tool/saveFileEditor/bibliography.ts +12 -0
  8. package/src/tool/saveFileEditor/component.astro +351 -0
  9. package/src/tool/saveFileEditor/entry.ts +28 -0
  10. package/src/tool/saveFileEditor/game-save-file-editor.css +250 -0
  11. package/src/tool/saveFileEditor/i18n/de.ts +182 -0
  12. package/src/tool/saveFileEditor/i18n/en.ts +182 -0
  13. package/src/tool/saveFileEditor/i18n/es.ts +182 -0
  14. package/src/tool/saveFileEditor/i18n/fr.ts +182 -0
  15. package/src/tool/saveFileEditor/i18n/id.ts +182 -0
  16. package/src/tool/saveFileEditor/i18n/it.ts +182 -0
  17. package/src/tool/saveFileEditor/i18n/ja.ts +182 -0
  18. package/src/tool/saveFileEditor/i18n/ko.ts +182 -0
  19. package/src/tool/saveFileEditor/i18n/nl.ts +182 -0
  20. package/src/tool/saveFileEditor/i18n/pl.ts +182 -0
  21. package/src/tool/saveFileEditor/i18n/pt.ts +182 -0
  22. package/src/tool/saveFileEditor/i18n/ru.ts +182 -0
  23. package/src/tool/saveFileEditor/i18n/sv.ts +182 -0
  24. package/src/tool/saveFileEditor/i18n/tr.ts +182 -0
  25. package/src/tool/saveFileEditor/i18n/zh.ts +182 -0
  26. package/src/tool/saveFileEditor/index.ts +11 -0
  27. package/src/tool/saveFileEditor/logic.test.ts +69 -0
  28. package/src/tool/saveFileEditor/logic.ts +139 -0
  29. package/src/tool/saveFileEditor/seo.astro +15 -0
  30. package/src/tool/saveFileEditor/ui.ts +24 -0
  31. package/src/tools.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jjlmoya/utils-games-development",
3
- "version": "1.51.0",
3
+ "version": "1.52.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -2,10 +2,11 @@ import type { GamesCategoryEntry } from '../types';
2
2
  import { steamCapsuleGenerator } from '../tool/steamCapsuleGenerator/entry';
3
3
  import { spriteSheetPacker } from '../tool/spriteSheetPacker/entry';
4
4
  import { audioLoopPointFinder } from '../tool/audioLoopPointFinder/entry';
5
+ import { saveFileEditor } from '../tool/saveFileEditor/entry';
5
6
 
6
7
  export const gamesCategory: GamesCategoryEntry = {
7
8
  icon: 'mdi:gamepad-variant',
8
- tools: [steamCapsuleGenerator, spriteSheetPacker, audioLoopPointFinder],
9
+ tools: [steamCapsuleGenerator, spriteSheetPacker, audioLoopPointFinder, saveFileEditor],
9
10
  i18n: {
10
11
  de: () => import('./i18n/de').then((m) => m.content),
11
12
  en: () => import('./i18n/en').then((m) => m.content),
package/src/entries.ts CHANGED
@@ -6,11 +6,14 @@ export { spriteSheetPacker } from './tool/spriteSheetPacker/entry';
6
6
  export type { SpriteSheetPackerUI, SpriteSheetPackerLocaleContent } from './tool/spriteSheetPacker/entry';
7
7
  export { audioLoopPointFinder } from './tool/audioLoopPointFinder/entry';
8
8
  export type { AudioLoopPointFinderUI, AudioLoopPointFinderLocaleContent } from './tool/audioLoopPointFinder/entry';
9
+ export { saveFileEditor } from './tool/saveFileEditor/entry';
10
+ export type { SaveFileEditorUI, SaveFileEditorLocaleContent } from './tool/saveFileEditor/entry';
9
11
  export { gamesCategory } from './category';
10
12
  import { steamCapsuleGenerator } from './tool/steamCapsuleGenerator/entry';
11
13
  import { itchioGameTester } from './tool/itchioGameTester/entry';
12
14
  import { spriteSheetPacker } from './tool/spriteSheetPacker/entry';
13
15
  import { audioLoopPointFinder } from './tool/audioLoopPointFinder/entry';
16
+ import { saveFileEditor } from './tool/saveFileEditor/entry';
14
17
 
15
- export const ALL_ENTRIES = [steamCapsuleGenerator, itchioGameTester, spriteSheetPacker, audioLoopPointFinder];
18
+ export const ALL_ENTRIES = [steamCapsuleGenerator, itchioGameTester, spriteSheetPacker, audioLoopPointFinder, saveFileEditor];
16
19
 
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
2
2
  import { ALL_TOOLS } from '../tools';
3
3
 
4
4
  describe('Locale Completeness Validation', () => {
5
- it('one tool is registered', () => {
6
- expect(ALL_TOOLS.length).toBe(4);
5
+ it('five tools are registered', () => {
6
+ expect(ALL_TOOLS.length).toBe(5);
7
7
  });
8
8
  });
@@ -4,8 +4,8 @@ import { gamesCategory } from '../data';
4
4
 
5
5
  describe('Tool Validation Suite', () => {
6
6
  describe('Library Registration', () => {
7
- it('should have 4 tools in ALL_TOOLS', () => {
8
- expect(ALL_TOOLS.length).toBe(4);
7
+ it('should have 5 tools in ALL_TOOLS', () => {
8
+ expect(ALL_TOOLS.length).toBe(5);
9
9
  });
10
10
 
11
11
  it('gamesCategory should be defined', () => {
@@ -0,0 +1,6 @@
1
+ ---
2
+ import { Bibliography as SharedBibliography } from '@jjlmoya/utils-shared';
3
+ import { bibliographyEntries } from './bibliography';
4
+ ---
5
+
6
+ <SharedBibliography links={bibliographyEntries} />
@@ -0,0 +1,12 @@
1
+ import type { BibliographyEntry } from '../../types';
2
+
3
+ export const bibliographyEntries: BibliographyEntry[] = [
4
+ {
5
+ name: 'Game Save Data Architecture (Game Developer Article)',
6
+ url: 'https://www.gamedeveloper.com/programming/game-save-data-architecture',
7
+ },
8
+ {
9
+ name: 'RFC 4648 - The Base16, Base32, and Base64 Data Encodings',
10
+ url: 'https://datatracker.ietf.org/doc/html/rfc4648',
11
+ },
12
+ ];
@@ -0,0 +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>
@@ -0,0 +1,28 @@
1
+ import type { GamesToolEntry, ToolLocaleContent } from '../../types';
2
+ import type { SaveFileEditorUI } from './ui';
3
+
4
+ export type { SaveFileEditorUI };
5
+
6
+ export type SaveFileEditorLocaleContent = ToolLocaleContent<SaveFileEditorUI>;
7
+
8
+ export const saveFileEditor: GamesToolEntry<SaveFileEditorUI> = {
9
+ id: 'save-file-editor',
10
+ icons: { bg: 'mdi:gamepad-variant', fg: 'mdi:file-lock-outline' },
11
+ i18n: {
12
+ de: () => import('./i18n/de').then((m) => m.content),
13
+ en: () => import('./i18n/en').then((m) => m.content),
14
+ es: () => import('./i18n/es').then((m) => m.content),
15
+ fr: () => import('./i18n/fr').then((m) => m.content),
16
+ id: () => import('./i18n/id').then((m) => m.content),
17
+ it: () => import('./i18n/it').then((m) => m.content),
18
+ ja: () => import('./i18n/ja').then((m) => m.content),
19
+ ko: () => import('./i18n/ko').then((m) => m.content),
20
+ nl: () => import('./i18n/nl').then((m) => m.content),
21
+ pl: () => import('./i18n/pl').then((m) => m.content),
22
+ pt: () => import('./i18n/pt').then((m) => m.content),
23
+ ru: () => import('./i18n/ru').then((m) => m.content),
24
+ sv: () => import('./i18n/sv').then((m) => m.content),
25
+ tr: () => import('./i18n/tr').then((m) => m.content),
26
+ zh: () => import('./i18n/zh').then((m) => m.content),
27
+ },
28
+ };