@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.
- package/package.json +67 -67
- package/scripts/postinstall.mjs +27 -27
- package/src/category/GamesCategorySEO.astro +19 -19
- package/src/category/i18n/de.ts +15 -15
- package/src/category/i18n/en.ts +15 -15
- package/src/category/i18n/es.ts +15 -15
- package/src/category/i18n/fr.ts +15 -15
- package/src/category/i18n/id.ts +10 -10
- package/src/category/i18n/it.ts +10 -10
- package/src/category/i18n/ja.ts +10 -10
- package/src/category/i18n/ko.ts +10 -10
- package/src/category/i18n/nl.ts +10 -10
- package/src/category/i18n/pl.ts +10 -10
- package/src/category/i18n/pt.ts +10 -10
- package/src/category/i18n/ru.ts +10 -10
- package/src/category/i18n/sv.ts +10 -10
- package/src/category/i18n/tr.ts +10 -10
- package/src/category/i18n/zh.ts +10 -10
- package/src/category/seo.astro +15 -15
- package/src/components/PreviewNavSidebar.astro +116 -116
- package/src/components/PreviewToolbar.astro +143 -143
- package/src/data.ts +11 -11
- package/src/env.d.ts +5 -5
- package/src/index.ts +20 -20
- package/src/layouts/PreviewLayout.astro +122 -122
- package/src/pages/[locale]/[slug].astro +165 -165
- package/src/pages/[locale].astro +250 -250
- package/src/pages/index.astro +4 -4
- package/src/tests/category_seo_quality.test.ts +74 -0
- package/src/tests/diacritics_density.test.ts +118 -118
- package/src/tests/faq_count.test.ts +19 -19
- package/src/tests/i18n_coverage.test.ts +36 -36
- package/src/tests/inverted_punctuation.test.ts +84 -84
- package/src/tests/mocks/astro_mock.js +2 -2
- package/src/tests/no_en_dash.test.ts +70 -70
- package/src/tests/no_h1_in_components.test.ts +48 -48
- package/src/tests/pagespeed_best_practices.test.ts +198 -198
- package/src/tests/qa-test-helpers.ts +32 -32
- package/src/tests/qa_bibliography_links.test.ts +41 -41
- package/src/tests/qa_claim_evidence.test.ts +69 -69
- package/src/tests/qa_logic_reference_coverage.test.ts +46 -46
- package/src/tests/qa_runtime_i18n.test.ts +100 -100
- package/src/tests/schemas_fulfillment.test.ts +23 -23
- package/src/tests/script_density.test.ts +94 -94
- package/src/tests/seo_length.test.ts +23 -23
- package/src/tests/slug_language_code_format.test.ts +23 -23
- package/src/tests/slug_uniqueness.test.ts +80 -80
- package/src/tests/title_quality.test.ts +56 -56
- package/src/tool/audioLoopPointFinder/audio-loop-point-finder.css +322 -322
- package/src/tool/audioLoopPointFinder/client.ts +262 -262
- package/src/tool/hitboxHurtboxAnimator/hitbox-hurtbox-animator.css +614 -614
- package/src/tool/saveFileEditor/component.astro +351 -351
- package/src/tool/saveFileEditor/game-save-file-editor.css +250 -250
- package/src/tool/spriteSheetPacker/app-client.ts +248 -248
- package/src/tool/spriteSheetPacker/bibliography.ts +12 -12
- package/src/tool/spriteSheetPacker/component.astro +229 -229
- package/src/tool/spriteSheetPacker/dropzone-client.ts +55 -55
- package/src/tool/spriteSheetPacker/entry.ts +28 -28
- package/src/tool/spriteSheetPacker/exporter.ts +116 -116
- package/src/tool/spriteSheetPacker/extractor-client.ts +127 -127
- package/src/tool/spriteSheetPacker/flipbook-client.ts +60 -60
- package/src/tool/spriteSheetPacker/logic.test.ts +155 -155
- package/src/tool/spriteSheetPacker/logic.ts +32 -32
- package/src/tool/spriteSheetPacker/packer-core.ts +121 -121
- package/src/tool/spriteSheetPacker/packer-ui.ts +86 -86
- package/src/tool/spriteSheetPacker/sprite-sheet-packer.css +578 -578
- package/src/tool/spriteSheetPacker/types.ts +89 -89
- package/src/tool/spriteSheetPacker/ui.ts +42 -42
- package/src/tool/steamCapsuleGenerator/index.ts +9 -9
- package/src/tool/steamCapsuleGenerator/validation.ts +14 -14
- package/src/types.ts +72 -72
|
@@ -1,248 +1,248 @@
|
|
|
1
|
-
import JSZip from 'jszip';
|
|
2
|
-
import { bindDropzone } from './dropzone-client';
|
|
3
|
-
import { initExtractor, updateExtractor } from './extractor-client';
|
|
4
|
-
import { bindFlipbook, startFlipbookLoop } from './flipbook-client';
|
|
5
|
-
import { calculateBinPacking, type ExportFormat, type SpriteFrameInput } from './logic';
|
|
6
|
-
import { drawEmptyCanvasMessage, setupStepper, spawnParticle, triggerButtonFeedback, type LoadedImageItem } from './packer-ui';
|
|
7
|
-
|
|
8
|
-
let loadedImages: LoadedImageItem[] = [];
|
|
9
|
-
let currentAtlasData: ReturnType<typeof calculateBinPacking> | null = null;
|
|
10
|
-
|
|
11
|
-
function parseInputValue(id: string, fallback: string): number {
|
|
12
|
-
const el = document.getElementById(id) as HTMLInputElement | null;
|
|
13
|
-
return parseInt(el?.value || fallback, 10);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function renderAtlasCanvas(): void {
|
|
17
|
-
const canvas = document.getElementById('ssp-atlas-canvas') as HTMLCanvasElement | null;
|
|
18
|
-
if (!canvas) return;
|
|
19
|
-
|
|
20
|
-
if (!currentAtlasData || loadedImages.length === 0) {
|
|
21
|
-
drawEmptyCanvasMessage(canvas, 'Upload PNG frames to preview packed texture atlas');
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
canvas.width = currentAtlasData.textureWidth;
|
|
26
|
-
canvas.height = currentAtlasData.textureHeight;
|
|
27
|
-
|
|
28
|
-
const ctx = canvas.getContext('2d');
|
|
29
|
-
if (!ctx) return;
|
|
30
|
-
|
|
31
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
32
|
-
for (const frame of currentAtlasData.frames) {
|
|
33
|
-
const found = loadedImages.find((img) => img.id === frame.id);
|
|
34
|
-
if (found) {
|
|
35
|
-
ctx.drawImage(found.img, frame.x, frame.y, frame.width, frame.height);
|
|
36
|
-
ctx.strokeStyle = 'rgba(99, 102, 241, 0.4)';
|
|
37
|
-
ctx.lineWidth = 1;
|
|
38
|
-
ctx.strokeRect(frame.x, frame.y, frame.width, frame.height);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function updateStatsUI(): void {
|
|
44
|
-
if (!currentAtlasData) return;
|
|
45
|
-
|
|
46
|
-
const effEl = document.getElementById('ssp-stat-efficiency');
|
|
47
|
-
const dcEl = document.getElementById('ssp-stat-drawcalls');
|
|
48
|
-
const framesEl = document.getElementById('ssp-stat-frames');
|
|
49
|
-
const sizeEl = document.getElementById('ssp-stat-size');
|
|
50
|
-
const codeEl = document.getElementById('ssp-code-snippet');
|
|
51
|
-
|
|
52
|
-
if (effEl) effEl.textContent = `${currentAtlasData.efficiency}%`;
|
|
53
|
-
if (dcEl) dcEl.textContent = `${currentAtlasData.drawCallsBefore} -> ${currentAtlasData.drawCallsAfter}`;
|
|
54
|
-
if (framesEl) framesEl.textContent = currentAtlasData.totalFrames.toString();
|
|
55
|
-
if (sizeEl) sizeEl.textContent = `${currentAtlasData.textureWidth}x${currentAtlasData.textureHeight}`;
|
|
56
|
-
if (codeEl) codeEl.textContent = currentAtlasData.codeSnippet;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getPackerSettings() {
|
|
60
|
-
const pad = parseInputValue('ssp-padding', '2');
|
|
61
|
-
const ext = parseInputValue('ssp-extrusion', '0');
|
|
62
|
-
const max = parseInputValue('ssp-max-size', '2048');
|
|
63
|
-
const fmt = ((document.getElementById('ssp-export-format') as HTMLSelectElement)?.value || 'generic-json-hash') as ExportFormat;
|
|
64
|
-
const pot = (document.getElementById('ssp-power-two') as HTMLInputElement)?.checked ?? true;
|
|
65
|
-
return { padding: pad, borderExtrusion: ext, format: fmt, maxTextureWidth: max, forcePowerOfTwo: pot };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function updatePacker(): void {
|
|
69
|
-
const { padding, borderExtrusion, format, maxTextureWidth, forcePowerOfTwo } = getPackerSettings();
|
|
70
|
-
|
|
71
|
-
const frameInputs: SpriteFrameInput[] = loadedImages.map((item) => ({
|
|
72
|
-
id: item.id,
|
|
73
|
-
name: item.name,
|
|
74
|
-
width: item.img.width,
|
|
75
|
-
height: item.img.height,
|
|
76
|
-
}));
|
|
77
|
-
|
|
78
|
-
currentAtlasData = calculateBinPacking(frameInputs, {
|
|
79
|
-
padding,
|
|
80
|
-
borderExtrusion,
|
|
81
|
-
forcePowerOfTwo,
|
|
82
|
-
maxTextureWidth,
|
|
83
|
-
maxTextureHeight: maxTextureWidth,
|
|
84
|
-
allowRotation: false,
|
|
85
|
-
trimTransparency: false,
|
|
86
|
-
format,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
renderAtlasCanvas();
|
|
90
|
-
updateStatsUI();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function setPresetValues(padding: number, extrusion: number, maxSize: string, pot: boolean): void {
|
|
94
|
-
const padInput = document.getElementById('ssp-padding') as HTMLInputElement | null;
|
|
95
|
-
const extInput = document.getElementById('ssp-extrusion') as HTMLInputElement | null;
|
|
96
|
-
const maxSelect = document.getElementById('ssp-max-size') as HTMLSelectElement | null;
|
|
97
|
-
const potCheck = document.getElementById('ssp-power-two') as HTMLInputElement | null;
|
|
98
|
-
|
|
99
|
-
if (padInput) {
|
|
100
|
-
padInput.value = padding.toString();
|
|
101
|
-
const valEl = document.getElementById('ssp-padding-val');
|
|
102
|
-
if (valEl) valEl.textContent = padding.toString();
|
|
103
|
-
}
|
|
104
|
-
if (extInput) {
|
|
105
|
-
extInput.value = extrusion.toString();
|
|
106
|
-
const valEl = document.getElementById('ssp-extrusion-val');
|
|
107
|
-
if (valEl) valEl.textContent = extrusion.toString();
|
|
108
|
-
}
|
|
109
|
-
if (maxSelect) maxSelect.value = maxSize;
|
|
110
|
-
if (potCheck) potCheck.checked = pot;
|
|
111
|
-
|
|
112
|
-
updatePacker();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function downloadZipPackage(e: MouseEvent): void {
|
|
116
|
-
if (!currentAtlasData || currentAtlasData.frames.length === 0) return;
|
|
117
|
-
const canvas = document.getElementById('ssp-atlas-canvas') as HTMLCanvasElement | null;
|
|
118
|
-
if (!canvas) return;
|
|
119
|
-
|
|
120
|
-
triggerButtonFeedback(document.getElementById('ssp-btn-download-zip'), 'ZIP Generated!', e);
|
|
121
|
-
|
|
122
|
-
const zip = new JSZip();
|
|
123
|
-
canvas.toBlob((blob) => {
|
|
124
|
-
if (!blob) return;
|
|
125
|
-
zip.file('spritesheet.png', blob);
|
|
126
|
-
zip.file('spritesheet.json', currentAtlasData!.atlasJson);
|
|
127
|
-
zip.generateAsync({ type: 'blob' }).then((content) => {
|
|
128
|
-
const link = document.createElement('a');
|
|
129
|
-
link.href = URL.createObjectURL(content);
|
|
130
|
-
link.download = 'sprite-sheet-package.zip';
|
|
131
|
-
link.click();
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function bindTabs(): void {
|
|
137
|
-
const tabPacker = document.getElementById('ssp-tab-packer');
|
|
138
|
-
const tabExtractor = document.getElementById('ssp-tab-extractor');
|
|
139
|
-
const panelPacker = document.getElementById('ssp-packer-panel');
|
|
140
|
-
const panelExtractor = document.getElementById('ssp-extractor-panel');
|
|
141
|
-
|
|
142
|
-
tabPacker?.addEventListener('click', () => {
|
|
143
|
-
tabPacker.classList.add('active');
|
|
144
|
-
tabExtractor?.classList.remove('active');
|
|
145
|
-
if (panelPacker) panelPacker.style.display = 'grid';
|
|
146
|
-
if (panelExtractor) panelExtractor.style.display = 'none';
|
|
147
|
-
renderAtlasCanvas();
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
tabExtractor?.addEventListener('click', () => {
|
|
151
|
-
tabExtractor.classList.add('active');
|
|
152
|
-
tabPacker?.classList.remove('active');
|
|
153
|
-
if (panelPacker) panelPacker.style.display = 'none';
|
|
154
|
-
if (panelExtractor) panelExtractor.style.display = 'grid';
|
|
155
|
-
updateExtractor();
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function bindPresets(): void {
|
|
160
|
-
const setActivePreset = (target: HTMLElement) => {
|
|
161
|
-
document.querySelectorAll('.ssp-chip-btn').forEach((el) => el.classList.remove('active'));
|
|
162
|
-
target.classList.add('active');
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
document.getElementById('ssp-preset-pixel')?.addEventListener('click', (e) => {
|
|
166
|
-
setActivePreset(e.target as HTMLElement);
|
|
167
|
-
setPresetValues(2, 0, '512', true);
|
|
168
|
-
spawnParticle(e.clientX, e.clientY, 'PIXEL 16x16');
|
|
169
|
-
});
|
|
170
|
-
document.getElementById('ssp-preset-hd')?.addEventListener('click', (e) => {
|
|
171
|
-
setActivePreset(e.target as HTMLElement);
|
|
172
|
-
setPresetValues(4, 1, '1024', true);
|
|
173
|
-
spawnParticle(e.clientX, e.clientY, 'HD 1024');
|
|
174
|
-
});
|
|
175
|
-
document.getElementById('ssp-preset-mobile')?.addEventListener('click', (e) => {
|
|
176
|
-
setActivePreset(e.target as HTMLElement);
|
|
177
|
-
setPresetValues(2, 0, '2048', true);
|
|
178
|
-
spawnParticle(e.clientX, e.clientY, 'MOBILE 2048');
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function bindSliders(): void {
|
|
183
|
-
const paddingSlider = document.getElementById('ssp-padding') as HTMLInputElement | null;
|
|
184
|
-
const extrusionSlider = document.getElementById('ssp-extrusion') as HTMLInputElement | null;
|
|
185
|
-
|
|
186
|
-
paddingSlider?.addEventListener('input', () => {
|
|
187
|
-
const valEl = document.getElementById('ssp-padding-val');
|
|
188
|
-
if (valEl) valEl.textContent = paddingSlider.value;
|
|
189
|
-
updatePacker();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
extrusionSlider?.addEventListener('input', () => {
|
|
193
|
-
const valEl = document.getElementById('ssp-extrusion-val');
|
|
194
|
-
if (valEl) valEl.textContent = extrusionSlider.value;
|
|
195
|
-
updatePacker();
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function bindExportCopies(): void {
|
|
200
|
-
document.getElementById('ssp-btn-copy-json')?.addEventListener('click', (e) => {
|
|
201
|
-
if (!currentAtlasData) return;
|
|
202
|
-
triggerButtonFeedback(document.getElementById('ssp-btn-copy-json'), 'Copied!', e);
|
|
203
|
-
navigator.clipboard.writeText(currentAtlasData.atlasJson);
|
|
204
|
-
});
|
|
205
|
-
document.getElementById('ssp-btn-download-png')?.addEventListener('click', (e) => {
|
|
206
|
-
const canvas = document.getElementById('ssp-atlas-canvas') as HTMLCanvasElement | null;
|
|
207
|
-
if (!canvas) return;
|
|
208
|
-
triggerButtonFeedback(document.getElementById('ssp-btn-download-png'), 'Downloaded!', e);
|
|
209
|
-
const link = document.createElement('a');
|
|
210
|
-
link.href = canvas.toDataURL('image/png');
|
|
211
|
-
link.download = 'spritesheet.png';
|
|
212
|
-
link.click();
|
|
213
|
-
});
|
|
214
|
-
document.getElementById('ssp-btn-copy-code')?.addEventListener('click', (e) => {
|
|
215
|
-
if (!currentAtlasData) return;
|
|
216
|
-
triggerButtonFeedback(document.getElementById('ssp-btn-copy-code'), 'Copied Code!', e);
|
|
217
|
-
navigator.clipboard.writeText(currentAtlasData.codeSnippet);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function bindActionButtons(): void {
|
|
222
|
-
setupStepper('ssp-pad-dec', 'ssp-pad-inc', 'ssp-padding', updatePacker);
|
|
223
|
-
setupStepper('ssp-ext-dec', 'ssp-ext-inc', 'ssp-extrusion', updatePacker);
|
|
224
|
-
bindSliders();
|
|
225
|
-
bindExportCopies();
|
|
226
|
-
|
|
227
|
-
document.getElementById('ssp-export-format')?.addEventListener('change', updatePacker);
|
|
228
|
-
document.getElementById('ssp-max-size')?.addEventListener('change', updatePacker);
|
|
229
|
-
document.getElementById('ssp-power-two')?.addEventListener('change', updatePacker);
|
|
230
|
-
document.getElementById('ssp-btn-download-zip')?.addEventListener('click', (e) => downloadZipPackage(e));
|
|
231
|
-
document.getElementById('ssp-btn-clear')?.addEventListener('click', (e) => {
|
|
232
|
-
loadedImages = [];
|
|
233
|
-
updatePacker();
|
|
234
|
-
spawnParticle(e.clientX, e.clientY, 'CLEARED!');
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export function initSpriteSheetPackerApp(): void {
|
|
239
|
-
bindTabs();
|
|
240
|
-
bindPresets();
|
|
241
|
-
bindDropzone(loadedImages, updatePacker);
|
|
242
|
-
bindActionButtons();
|
|
243
|
-
bindFlipbook();
|
|
244
|
-
initExtractor();
|
|
245
|
-
startFlipbookLoop(loadedImages);
|
|
246
|
-
renderAtlasCanvas();
|
|
247
|
-
updateExtractor();
|
|
248
|
-
}
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
import { bindDropzone } from './dropzone-client';
|
|
3
|
+
import { initExtractor, updateExtractor } from './extractor-client';
|
|
4
|
+
import { bindFlipbook, startFlipbookLoop } from './flipbook-client';
|
|
5
|
+
import { calculateBinPacking, type ExportFormat, type SpriteFrameInput } from './logic';
|
|
6
|
+
import { drawEmptyCanvasMessage, setupStepper, spawnParticle, triggerButtonFeedback, type LoadedImageItem } from './packer-ui';
|
|
7
|
+
|
|
8
|
+
let loadedImages: LoadedImageItem[] = [];
|
|
9
|
+
let currentAtlasData: ReturnType<typeof calculateBinPacking> | null = null;
|
|
10
|
+
|
|
11
|
+
function parseInputValue(id: string, fallback: string): number {
|
|
12
|
+
const el = document.getElementById(id) as HTMLInputElement | null;
|
|
13
|
+
return parseInt(el?.value || fallback, 10);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function renderAtlasCanvas(): void {
|
|
17
|
+
const canvas = document.getElementById('ssp-atlas-canvas') as HTMLCanvasElement | null;
|
|
18
|
+
if (!canvas) return;
|
|
19
|
+
|
|
20
|
+
if (!currentAtlasData || loadedImages.length === 0) {
|
|
21
|
+
drawEmptyCanvasMessage(canvas, 'Upload PNG frames to preview packed texture atlas');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
canvas.width = currentAtlasData.textureWidth;
|
|
26
|
+
canvas.height = currentAtlasData.textureHeight;
|
|
27
|
+
|
|
28
|
+
const ctx = canvas.getContext('2d');
|
|
29
|
+
if (!ctx) return;
|
|
30
|
+
|
|
31
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
32
|
+
for (const frame of currentAtlasData.frames) {
|
|
33
|
+
const found = loadedImages.find((img) => img.id === frame.id);
|
|
34
|
+
if (found) {
|
|
35
|
+
ctx.drawImage(found.img, frame.x, frame.y, frame.width, frame.height);
|
|
36
|
+
ctx.strokeStyle = 'rgba(99, 102, 241, 0.4)';
|
|
37
|
+
ctx.lineWidth = 1;
|
|
38
|
+
ctx.strokeRect(frame.x, frame.y, frame.width, frame.height);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function updateStatsUI(): void {
|
|
44
|
+
if (!currentAtlasData) return;
|
|
45
|
+
|
|
46
|
+
const effEl = document.getElementById('ssp-stat-efficiency');
|
|
47
|
+
const dcEl = document.getElementById('ssp-stat-drawcalls');
|
|
48
|
+
const framesEl = document.getElementById('ssp-stat-frames');
|
|
49
|
+
const sizeEl = document.getElementById('ssp-stat-size');
|
|
50
|
+
const codeEl = document.getElementById('ssp-code-snippet');
|
|
51
|
+
|
|
52
|
+
if (effEl) effEl.textContent = `${currentAtlasData.efficiency}%`;
|
|
53
|
+
if (dcEl) dcEl.textContent = `${currentAtlasData.drawCallsBefore} -> ${currentAtlasData.drawCallsAfter}`;
|
|
54
|
+
if (framesEl) framesEl.textContent = currentAtlasData.totalFrames.toString();
|
|
55
|
+
if (sizeEl) sizeEl.textContent = `${currentAtlasData.textureWidth}x${currentAtlasData.textureHeight}`;
|
|
56
|
+
if (codeEl) codeEl.textContent = currentAtlasData.codeSnippet;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getPackerSettings() {
|
|
60
|
+
const pad = parseInputValue('ssp-padding', '2');
|
|
61
|
+
const ext = parseInputValue('ssp-extrusion', '0');
|
|
62
|
+
const max = parseInputValue('ssp-max-size', '2048');
|
|
63
|
+
const fmt = ((document.getElementById('ssp-export-format') as HTMLSelectElement)?.value || 'generic-json-hash') as ExportFormat;
|
|
64
|
+
const pot = (document.getElementById('ssp-power-two') as HTMLInputElement)?.checked ?? true;
|
|
65
|
+
return { padding: pad, borderExtrusion: ext, format: fmt, maxTextureWidth: max, forcePowerOfTwo: pot };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function updatePacker(): void {
|
|
69
|
+
const { padding, borderExtrusion, format, maxTextureWidth, forcePowerOfTwo } = getPackerSettings();
|
|
70
|
+
|
|
71
|
+
const frameInputs: SpriteFrameInput[] = loadedImages.map((item) => ({
|
|
72
|
+
id: item.id,
|
|
73
|
+
name: item.name,
|
|
74
|
+
width: item.img.width,
|
|
75
|
+
height: item.img.height,
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
currentAtlasData = calculateBinPacking(frameInputs, {
|
|
79
|
+
padding,
|
|
80
|
+
borderExtrusion,
|
|
81
|
+
forcePowerOfTwo,
|
|
82
|
+
maxTextureWidth,
|
|
83
|
+
maxTextureHeight: maxTextureWidth,
|
|
84
|
+
allowRotation: false,
|
|
85
|
+
trimTransparency: false,
|
|
86
|
+
format,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
renderAtlasCanvas();
|
|
90
|
+
updateStatsUI();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function setPresetValues(padding: number, extrusion: number, maxSize: string, pot: boolean): void {
|
|
94
|
+
const padInput = document.getElementById('ssp-padding') as HTMLInputElement | null;
|
|
95
|
+
const extInput = document.getElementById('ssp-extrusion') as HTMLInputElement | null;
|
|
96
|
+
const maxSelect = document.getElementById('ssp-max-size') as HTMLSelectElement | null;
|
|
97
|
+
const potCheck = document.getElementById('ssp-power-two') as HTMLInputElement | null;
|
|
98
|
+
|
|
99
|
+
if (padInput) {
|
|
100
|
+
padInput.value = padding.toString();
|
|
101
|
+
const valEl = document.getElementById('ssp-padding-val');
|
|
102
|
+
if (valEl) valEl.textContent = padding.toString();
|
|
103
|
+
}
|
|
104
|
+
if (extInput) {
|
|
105
|
+
extInput.value = extrusion.toString();
|
|
106
|
+
const valEl = document.getElementById('ssp-extrusion-val');
|
|
107
|
+
if (valEl) valEl.textContent = extrusion.toString();
|
|
108
|
+
}
|
|
109
|
+
if (maxSelect) maxSelect.value = maxSize;
|
|
110
|
+
if (potCheck) potCheck.checked = pot;
|
|
111
|
+
|
|
112
|
+
updatePacker();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function downloadZipPackage(e: MouseEvent): void {
|
|
116
|
+
if (!currentAtlasData || currentAtlasData.frames.length === 0) return;
|
|
117
|
+
const canvas = document.getElementById('ssp-atlas-canvas') as HTMLCanvasElement | null;
|
|
118
|
+
if (!canvas) return;
|
|
119
|
+
|
|
120
|
+
triggerButtonFeedback(document.getElementById('ssp-btn-download-zip'), 'ZIP Generated!', e);
|
|
121
|
+
|
|
122
|
+
const zip = new JSZip();
|
|
123
|
+
canvas.toBlob((blob) => {
|
|
124
|
+
if (!blob) return;
|
|
125
|
+
zip.file('spritesheet.png', blob);
|
|
126
|
+
zip.file('spritesheet.json', currentAtlasData!.atlasJson);
|
|
127
|
+
zip.generateAsync({ type: 'blob' }).then((content) => {
|
|
128
|
+
const link = document.createElement('a');
|
|
129
|
+
link.href = URL.createObjectURL(content);
|
|
130
|
+
link.download = 'sprite-sheet-package.zip';
|
|
131
|
+
link.click();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function bindTabs(): void {
|
|
137
|
+
const tabPacker = document.getElementById('ssp-tab-packer');
|
|
138
|
+
const tabExtractor = document.getElementById('ssp-tab-extractor');
|
|
139
|
+
const panelPacker = document.getElementById('ssp-packer-panel');
|
|
140
|
+
const panelExtractor = document.getElementById('ssp-extractor-panel');
|
|
141
|
+
|
|
142
|
+
tabPacker?.addEventListener('click', () => {
|
|
143
|
+
tabPacker.classList.add('active');
|
|
144
|
+
tabExtractor?.classList.remove('active');
|
|
145
|
+
if (panelPacker) panelPacker.style.display = 'grid';
|
|
146
|
+
if (panelExtractor) panelExtractor.style.display = 'none';
|
|
147
|
+
renderAtlasCanvas();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
tabExtractor?.addEventListener('click', () => {
|
|
151
|
+
tabExtractor.classList.add('active');
|
|
152
|
+
tabPacker?.classList.remove('active');
|
|
153
|
+
if (panelPacker) panelPacker.style.display = 'none';
|
|
154
|
+
if (panelExtractor) panelExtractor.style.display = 'grid';
|
|
155
|
+
updateExtractor();
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function bindPresets(): void {
|
|
160
|
+
const setActivePreset = (target: HTMLElement) => {
|
|
161
|
+
document.querySelectorAll('.ssp-chip-btn').forEach((el) => el.classList.remove('active'));
|
|
162
|
+
target.classList.add('active');
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
document.getElementById('ssp-preset-pixel')?.addEventListener('click', (e) => {
|
|
166
|
+
setActivePreset(e.target as HTMLElement);
|
|
167
|
+
setPresetValues(2, 0, '512', true);
|
|
168
|
+
spawnParticle(e.clientX, e.clientY, 'PIXEL 16x16');
|
|
169
|
+
});
|
|
170
|
+
document.getElementById('ssp-preset-hd')?.addEventListener('click', (e) => {
|
|
171
|
+
setActivePreset(e.target as HTMLElement);
|
|
172
|
+
setPresetValues(4, 1, '1024', true);
|
|
173
|
+
spawnParticle(e.clientX, e.clientY, 'HD 1024');
|
|
174
|
+
});
|
|
175
|
+
document.getElementById('ssp-preset-mobile')?.addEventListener('click', (e) => {
|
|
176
|
+
setActivePreset(e.target as HTMLElement);
|
|
177
|
+
setPresetValues(2, 0, '2048', true);
|
|
178
|
+
spawnParticle(e.clientX, e.clientY, 'MOBILE 2048');
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function bindSliders(): void {
|
|
183
|
+
const paddingSlider = document.getElementById('ssp-padding') as HTMLInputElement | null;
|
|
184
|
+
const extrusionSlider = document.getElementById('ssp-extrusion') as HTMLInputElement | null;
|
|
185
|
+
|
|
186
|
+
paddingSlider?.addEventListener('input', () => {
|
|
187
|
+
const valEl = document.getElementById('ssp-padding-val');
|
|
188
|
+
if (valEl) valEl.textContent = paddingSlider.value;
|
|
189
|
+
updatePacker();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
extrusionSlider?.addEventListener('input', () => {
|
|
193
|
+
const valEl = document.getElementById('ssp-extrusion-val');
|
|
194
|
+
if (valEl) valEl.textContent = extrusionSlider.value;
|
|
195
|
+
updatePacker();
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function bindExportCopies(): void {
|
|
200
|
+
document.getElementById('ssp-btn-copy-json')?.addEventListener('click', (e) => {
|
|
201
|
+
if (!currentAtlasData) return;
|
|
202
|
+
triggerButtonFeedback(document.getElementById('ssp-btn-copy-json'), 'Copied!', e);
|
|
203
|
+
navigator.clipboard.writeText(currentAtlasData.atlasJson);
|
|
204
|
+
});
|
|
205
|
+
document.getElementById('ssp-btn-download-png')?.addEventListener('click', (e) => {
|
|
206
|
+
const canvas = document.getElementById('ssp-atlas-canvas') as HTMLCanvasElement | null;
|
|
207
|
+
if (!canvas) return;
|
|
208
|
+
triggerButtonFeedback(document.getElementById('ssp-btn-download-png'), 'Downloaded!', e);
|
|
209
|
+
const link = document.createElement('a');
|
|
210
|
+
link.href = canvas.toDataURL('image/png');
|
|
211
|
+
link.download = 'spritesheet.png';
|
|
212
|
+
link.click();
|
|
213
|
+
});
|
|
214
|
+
document.getElementById('ssp-btn-copy-code')?.addEventListener('click', (e) => {
|
|
215
|
+
if (!currentAtlasData) return;
|
|
216
|
+
triggerButtonFeedback(document.getElementById('ssp-btn-copy-code'), 'Copied Code!', e);
|
|
217
|
+
navigator.clipboard.writeText(currentAtlasData.codeSnippet);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function bindActionButtons(): void {
|
|
222
|
+
setupStepper('ssp-pad-dec', 'ssp-pad-inc', 'ssp-padding', updatePacker);
|
|
223
|
+
setupStepper('ssp-ext-dec', 'ssp-ext-inc', 'ssp-extrusion', updatePacker);
|
|
224
|
+
bindSliders();
|
|
225
|
+
bindExportCopies();
|
|
226
|
+
|
|
227
|
+
document.getElementById('ssp-export-format')?.addEventListener('change', updatePacker);
|
|
228
|
+
document.getElementById('ssp-max-size')?.addEventListener('change', updatePacker);
|
|
229
|
+
document.getElementById('ssp-power-two')?.addEventListener('change', updatePacker);
|
|
230
|
+
document.getElementById('ssp-btn-download-zip')?.addEventListener('click', (e) => downloadZipPackage(e));
|
|
231
|
+
document.getElementById('ssp-btn-clear')?.addEventListener('click', (e) => {
|
|
232
|
+
loadedImages = [];
|
|
233
|
+
updatePacker();
|
|
234
|
+
spawnParticle(e.clientX, e.clientY, 'CLEARED!');
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function initSpriteSheetPackerApp(): void {
|
|
239
|
+
bindTabs();
|
|
240
|
+
bindPresets();
|
|
241
|
+
bindDropzone(loadedImages, updatePacker);
|
|
242
|
+
bindActionButtons();
|
|
243
|
+
bindFlipbook();
|
|
244
|
+
initExtractor();
|
|
245
|
+
startFlipbookLoop(loadedImages);
|
|
246
|
+
renderAtlasCanvas();
|
|
247
|
+
updateExtractor();
|
|
248
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { BibliographyEntry } from '../../types';
|
|
2
|
-
|
|
3
|
-
export const bibliographyEntries: BibliographyEntry[] = [
|
|
4
|
-
{
|
|
5
|
-
name: 'Godot Engine 2D Sprite Sheets Documentation',
|
|
6
|
-
url: 'https://docs.godotengine.org/en/stable/tutorials/2d/2d_sprite_animation.html',
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
name: 'Unity Sprite Atlas Manual',
|
|
10
|
-
url: 'https://docs.unity3d.com/Manual/class-SpriteAtlas.html',
|
|
11
|
-
},
|
|
12
|
-
];
|
|
1
|
+
import type { BibliographyEntry } from '../../types';
|
|
2
|
+
|
|
3
|
+
export const bibliographyEntries: BibliographyEntry[] = [
|
|
4
|
+
{
|
|
5
|
+
name: 'Godot Engine 2D Sprite Sheets Documentation',
|
|
6
|
+
url: 'https://docs.godotengine.org/en/stable/tutorials/2d/2d_sprite_animation.html',
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: 'Unity Sprite Atlas Manual',
|
|
10
|
+
url: 'https://docs.unity3d.com/Manual/class-SpriteAtlas.html',
|
|
11
|
+
},
|
|
12
|
+
];
|