@jjlmoya/utils-games-development 1.65.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/bibliography_wellformed_export.test.ts +46 -0
- 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/seo_wellformed_export.test.ts +65 -0
- 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/damageFormulaLab/bibliography.astro +3 -21
- package/src/tool/damageFormulaLab/seo.astro +7 -5
- package/src/tool/gameDeltaTimeFixedTimestepLab/bibliography.astro +3 -19
- package/src/tool/hitboxHurtboxAnimator/hitbox-hurtbox-animator.css +614 -614
- package/src/tool/hitboxHurtboxAnimator/seo.astro +7 -5
- 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,116 +1,116 @@
|
|
|
1
|
-
import type { ExportFormat, PackedFrame } from './types';
|
|
2
|
-
|
|
3
|
-
function buildGenericHashJson(frames: PackedFrame[], width: number, height: number): string {
|
|
4
|
-
const frameHash: Record<string, unknown> = {};
|
|
5
|
-
for (const f of frames) {
|
|
6
|
-
frameHash[f.name] = {
|
|
7
|
-
frame: { x: f.x, y: f.y, w: f.width, h: f.height },
|
|
8
|
-
rotated: f.rotated,
|
|
9
|
-
trimmed: f.trimmed,
|
|
10
|
-
spriteSourceSize: f.spriteSourceSize,
|
|
11
|
-
sourceSize: f.sourceSize,
|
|
12
|
-
pivot: f.pivot,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
return JSON.stringify(
|
|
16
|
-
{
|
|
17
|
-
frames: frameHash,
|
|
18
|
-
meta: { app: 'GameBob Sprite Sheet Packer', version: '1.0', size: { w: width, h: height }, scale: 1 },
|
|
19
|
-
},
|
|
20
|
-
null,
|
|
21
|
-
2
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function buildGenericArrayJson(frames: PackedFrame[], width: number, height: number): string {
|
|
26
|
-
const frameArray = frames.map((f) => ({
|
|
27
|
-
filename: f.name,
|
|
28
|
-
frame: { x: f.x, y: f.y, w: f.width, h: f.height },
|
|
29
|
-
rotated: f.rotated,
|
|
30
|
-
trimmed: f.trimmed,
|
|
31
|
-
spriteSourceSize: f.spriteSourceSize,
|
|
32
|
-
sourceSize: f.sourceSize,
|
|
33
|
-
pivot: f.pivot,
|
|
34
|
-
}));
|
|
35
|
-
return JSON.stringify(
|
|
36
|
-
{
|
|
37
|
-
frames: frameArray,
|
|
38
|
-
meta: { app: 'GameBob Sprite Sheet Packer', version: '1.0', size: { w: width, h: height }, scale: 1 },
|
|
39
|
-
},
|
|
40
|
-
null,
|
|
41
|
-
2
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function buildGodotJson(frames: PackedFrame[], width: number, height: number): string {
|
|
46
|
-
const godotData = {
|
|
47
|
-
textures: [
|
|
48
|
-
{
|
|
49
|
-
image: 'spritesheet.png',
|
|
50
|
-
size: { w: width, h: height },
|
|
51
|
-
sprites: frames.map((f) => ({
|
|
52
|
-
name: f.name,
|
|
53
|
-
region: [f.x, f.y, f.width, f.height],
|
|
54
|
-
margin: [f.spriteSourceSize.x, f.spriteSourceSize.y, f.sourceSize.w, f.sourceSize.h],
|
|
55
|
-
})),
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
};
|
|
59
|
-
return JSON.stringify(godotData, null, 2);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function buildUnityJson(frames: PackedFrame[], width: number, height: number): string {
|
|
63
|
-
const unityFrames = frames.map((f) => ({
|
|
64
|
-
name: f.name,
|
|
65
|
-
x: f.x,
|
|
66
|
-
y: f.y,
|
|
67
|
-
width: f.width,
|
|
68
|
-
height: f.height,
|
|
69
|
-
pivotX: f.pivot.x,
|
|
70
|
-
pivotY: f.pivot.y,
|
|
71
|
-
}));
|
|
72
|
-
return JSON.stringify({ sprites: unityFrames, meta: { width, height } }, null, 2);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function generateAtlasJson(
|
|
76
|
-
frames: PackedFrame[],
|
|
77
|
-
width: number,
|
|
78
|
-
height: number,
|
|
79
|
-
format: ExportFormat
|
|
80
|
-
): string {
|
|
81
|
-
if (format === 'generic-json-hash' || format === 'phaser') {
|
|
82
|
-
return buildGenericHashJson(frames, width, height);
|
|
83
|
-
}
|
|
84
|
-
if (format === 'generic-json-array') {
|
|
85
|
-
return buildGenericArrayJson(frames, width, height);
|
|
86
|
-
}
|
|
87
|
-
if (format === 'godot') {
|
|
88
|
-
return buildGodotJson(frames, width, height);
|
|
89
|
-
}
|
|
90
|
-
if (format === 'unity') {
|
|
91
|
-
return buildUnityJson(frames, width, height);
|
|
92
|
-
}
|
|
93
|
-
return JSON.stringify({ frames, meta: { width, height } }, null, 2);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function generateCssSnippet(frames: PackedFrame[]): string {
|
|
97
|
-
return frames
|
|
98
|
-
.map(
|
|
99
|
-
(f) =>
|
|
100
|
-
`.sprite-${f.name.replace(/[^a-zA-Z0-9_-]/g, '_')} {\n width: ${f.width}px;\n height: ${f.height}px;\n background-position: -${f.x}px -${f.y}px;\n}`
|
|
101
|
-
)
|
|
102
|
-
.join('\n\n');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function generateEngineCodeSnippet(format: ExportFormat): string {
|
|
106
|
-
if (format === 'unity') {
|
|
107
|
-
return `// Unity C# Load Example\nSprite[] sprites = Resources.LoadAll<Sprite>("spritesheet");\nSprite myFrame = System.Array.Find(sprites, s => s.name == "frame_0");`;
|
|
108
|
-
}
|
|
109
|
-
if (format === 'godot') {
|
|
110
|
-
return `# Godot GDScript Load Example\nvar atlas_texture = AtlasTexture.new()\natlas_texture.atlas = load("res://spritesheet.png")\natlas_texture.region = Rect2(0, 0, 32, 32)`;
|
|
111
|
-
}
|
|
112
|
-
if (format === 'phaser') {
|
|
113
|
-
return `// Phaser 3 Load Example\nthis.load.atlas('sheetKey', 'spritesheet.png', 'spritesheet.json');\nconst sprite = this.add.sprite(400, 300, 'sheetKey', 'frame_0');`;
|
|
114
|
-
}
|
|
115
|
-
return `// HTML / JS Load Example\nconst image = new Image();\nimage.src = 'spritesheet.png';`;
|
|
116
|
-
}
|
|
1
|
+
import type { ExportFormat, PackedFrame } from './types';
|
|
2
|
+
|
|
3
|
+
function buildGenericHashJson(frames: PackedFrame[], width: number, height: number): string {
|
|
4
|
+
const frameHash: Record<string, unknown> = {};
|
|
5
|
+
for (const f of frames) {
|
|
6
|
+
frameHash[f.name] = {
|
|
7
|
+
frame: { x: f.x, y: f.y, w: f.width, h: f.height },
|
|
8
|
+
rotated: f.rotated,
|
|
9
|
+
trimmed: f.trimmed,
|
|
10
|
+
spriteSourceSize: f.spriteSourceSize,
|
|
11
|
+
sourceSize: f.sourceSize,
|
|
12
|
+
pivot: f.pivot,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return JSON.stringify(
|
|
16
|
+
{
|
|
17
|
+
frames: frameHash,
|
|
18
|
+
meta: { app: 'GameBob Sprite Sheet Packer', version: '1.0', size: { w: width, h: height }, scale: 1 },
|
|
19
|
+
},
|
|
20
|
+
null,
|
|
21
|
+
2
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function buildGenericArrayJson(frames: PackedFrame[], width: number, height: number): string {
|
|
26
|
+
const frameArray = frames.map((f) => ({
|
|
27
|
+
filename: f.name,
|
|
28
|
+
frame: { x: f.x, y: f.y, w: f.width, h: f.height },
|
|
29
|
+
rotated: f.rotated,
|
|
30
|
+
trimmed: f.trimmed,
|
|
31
|
+
spriteSourceSize: f.spriteSourceSize,
|
|
32
|
+
sourceSize: f.sourceSize,
|
|
33
|
+
pivot: f.pivot,
|
|
34
|
+
}));
|
|
35
|
+
return JSON.stringify(
|
|
36
|
+
{
|
|
37
|
+
frames: frameArray,
|
|
38
|
+
meta: { app: 'GameBob Sprite Sheet Packer', version: '1.0', size: { w: width, h: height }, scale: 1 },
|
|
39
|
+
},
|
|
40
|
+
null,
|
|
41
|
+
2
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function buildGodotJson(frames: PackedFrame[], width: number, height: number): string {
|
|
46
|
+
const godotData = {
|
|
47
|
+
textures: [
|
|
48
|
+
{
|
|
49
|
+
image: 'spritesheet.png',
|
|
50
|
+
size: { w: width, h: height },
|
|
51
|
+
sprites: frames.map((f) => ({
|
|
52
|
+
name: f.name,
|
|
53
|
+
region: [f.x, f.y, f.width, f.height],
|
|
54
|
+
margin: [f.spriteSourceSize.x, f.spriteSourceSize.y, f.sourceSize.w, f.sourceSize.h],
|
|
55
|
+
})),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
return JSON.stringify(godotData, null, 2);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function buildUnityJson(frames: PackedFrame[], width: number, height: number): string {
|
|
63
|
+
const unityFrames = frames.map((f) => ({
|
|
64
|
+
name: f.name,
|
|
65
|
+
x: f.x,
|
|
66
|
+
y: f.y,
|
|
67
|
+
width: f.width,
|
|
68
|
+
height: f.height,
|
|
69
|
+
pivotX: f.pivot.x,
|
|
70
|
+
pivotY: f.pivot.y,
|
|
71
|
+
}));
|
|
72
|
+
return JSON.stringify({ sprites: unityFrames, meta: { width, height } }, null, 2);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function generateAtlasJson(
|
|
76
|
+
frames: PackedFrame[],
|
|
77
|
+
width: number,
|
|
78
|
+
height: number,
|
|
79
|
+
format: ExportFormat
|
|
80
|
+
): string {
|
|
81
|
+
if (format === 'generic-json-hash' || format === 'phaser') {
|
|
82
|
+
return buildGenericHashJson(frames, width, height);
|
|
83
|
+
}
|
|
84
|
+
if (format === 'generic-json-array') {
|
|
85
|
+
return buildGenericArrayJson(frames, width, height);
|
|
86
|
+
}
|
|
87
|
+
if (format === 'godot') {
|
|
88
|
+
return buildGodotJson(frames, width, height);
|
|
89
|
+
}
|
|
90
|
+
if (format === 'unity') {
|
|
91
|
+
return buildUnityJson(frames, width, height);
|
|
92
|
+
}
|
|
93
|
+
return JSON.stringify({ frames, meta: { width, height } }, null, 2);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function generateCssSnippet(frames: PackedFrame[]): string {
|
|
97
|
+
return frames
|
|
98
|
+
.map(
|
|
99
|
+
(f) =>
|
|
100
|
+
`.sprite-${f.name.replace(/[^a-zA-Z0-9_-]/g, '_')} {\n width: ${f.width}px;\n height: ${f.height}px;\n background-position: -${f.x}px -${f.y}px;\n}`
|
|
101
|
+
)
|
|
102
|
+
.join('\n\n');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function generateEngineCodeSnippet(format: ExportFormat): string {
|
|
106
|
+
if (format === 'unity') {
|
|
107
|
+
return `// Unity C# Load Example\nSprite[] sprites = Resources.LoadAll<Sprite>("spritesheet");\nSprite myFrame = System.Array.Find(sprites, s => s.name == "frame_0");`;
|
|
108
|
+
}
|
|
109
|
+
if (format === 'godot') {
|
|
110
|
+
return `# Godot GDScript Load Example\nvar atlas_texture = AtlasTexture.new()\natlas_texture.atlas = load("res://spritesheet.png")\natlas_texture.region = Rect2(0, 0, 32, 32)`;
|
|
111
|
+
}
|
|
112
|
+
if (format === 'phaser') {
|
|
113
|
+
return `// Phaser 3 Load Example\nthis.load.atlas('sheetKey', 'spritesheet.png', 'spritesheet.json');\nconst sprite = this.add.sprite(400, 300, 'sheetKey', 'frame_0');`;
|
|
114
|
+
}
|
|
115
|
+
return `// HTML / JS Load Example\nconst image = new Image();\nimage.src = 'spritesheet.png';`;
|
|
116
|
+
}
|
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import JSZip from 'jszip';
|
|
2
|
-
import { calculateGridSlices } from './logic';
|
|
3
|
-
import { drawEmptyCanvasMessage, setupStepper, triggerButtonFeedback } from './packer-ui';
|
|
4
|
-
|
|
5
|
-
let extImage: HTMLImageElement | null = null;
|
|
6
|
-
|
|
7
|
-
function parseInputValue(id: string, fallback: string): number {
|
|
8
|
-
const el = document.getElementById(id) as HTMLInputElement | null;
|
|
9
|
-
return parseInt(el?.value || fallback, 10);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function getExtractorInputs() {
|
|
13
|
-
return {
|
|
14
|
-
fw: parseInputValue('ssp-ext-width', '32'),
|
|
15
|
-
fh: parseInputValue('ssp-ext-height', '32'),
|
|
16
|
-
margin: parseInputValue('ssp-ext-margin', '0'),
|
|
17
|
-
spacing: parseInputValue('ssp-ext-spacing', '0'),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function updateExtractor(): void {
|
|
22
|
-
const canvas = document.getElementById('ssp-ext-canvas') as HTMLCanvasElement | null;
|
|
23
|
-
if (!canvas) return;
|
|
24
|
-
|
|
25
|
-
if (!extImage) {
|
|
26
|
-
drawEmptyCanvasMessage(canvas, 'Upload sprite sheet to slice frames');
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
canvas.width = extImage.width;
|
|
31
|
-
canvas.height = extImage.height;
|
|
32
|
-
|
|
33
|
-
const ctx = canvas.getContext('2d');
|
|
34
|
-
if (!ctx) return;
|
|
35
|
-
|
|
36
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
37
|
-
ctx.drawImage(extImage, 0, 0);
|
|
38
|
-
|
|
39
|
-
const { fw, fh, margin, spacing } = getExtractorInputs();
|
|
40
|
-
const slices = calculateGridSlices({
|
|
41
|
-
imageWidth: extImage.width,
|
|
42
|
-
imageHeight: extImage.height,
|
|
43
|
-
frameWidth: fw,
|
|
44
|
-
frameHeight: fh,
|
|
45
|
-
margin,
|
|
46
|
-
spacing,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const countEl = document.getElementById('ssp-ext-count');
|
|
50
|
-
if (countEl) countEl.textContent = slices.length.toString();
|
|
51
|
-
|
|
52
|
-
ctx.strokeStyle = '#38bdf8';
|
|
53
|
-
ctx.lineWidth = 1;
|
|
54
|
-
for (const slice of slices) {
|
|
55
|
-
ctx.strokeRect(slice.x, slice.y, slice.width, slice.height);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function processExtractedZip(e: MouseEvent, fw: number, fh: number, slices: ReturnType<typeof calculateGridSlices>) {
|
|
60
|
-
triggerButtonFeedback(document.getElementById('ssp-btn-extract-zip'), 'SPLIT ZIP!', e);
|
|
61
|
-
|
|
62
|
-
const zip = new JSZip();
|
|
63
|
-
const tempCanvas = document.createElement('canvas');
|
|
64
|
-
tempCanvas.width = fw;
|
|
65
|
-
tempCanvas.height = fh;
|
|
66
|
-
const tempCtx = tempCanvas.getContext('2d');
|
|
67
|
-
if (!tempCtx || !extImage) return;
|
|
68
|
-
|
|
69
|
-
slices.forEach((slice) => {
|
|
70
|
-
tempCtx.clearRect(0, 0, fw, fh);
|
|
71
|
-
tempCtx.drawImage(extImage!, slice.x, slice.y, slice.width, slice.height, 0, 0, fw, fh);
|
|
72
|
-
const dataUrl = tempCanvas.toDataURL('image/png').split(',')[1] ?? '';
|
|
73
|
-
zip.file(`frame_${slice.index}.png`, dataUrl, { base64: true });
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
zip.generateAsync({ type: 'blob' }).then((content) => {
|
|
77
|
-
const link = document.createElement('a');
|
|
78
|
-
link.href = URL.createObjectURL(content);
|
|
79
|
-
link.download = 'extracted-sprites.zip';
|
|
80
|
-
link.click();
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function downloadExtractedZip(e: MouseEvent): void {
|
|
85
|
-
if (!extImage) return;
|
|
86
|
-
const { fw, fh, margin, spacing } = getExtractorInputs();
|
|
87
|
-
const slices = calculateGridSlices({
|
|
88
|
-
imageWidth: extImage.width,
|
|
89
|
-
imageHeight: extImage.height,
|
|
90
|
-
frameWidth: fw,
|
|
91
|
-
frameHeight: fh,
|
|
92
|
-
margin,
|
|
93
|
-
spacing,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
if (slices.length === 0) return;
|
|
97
|
-
processExtractedZip(e, fw, fh, slices);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function initExtractor(): void {
|
|
101
|
-
const extDrop = document.getElementById('ssp-ext-dropzone');
|
|
102
|
-
const extInput = document.getElementById('ssp-ext-file-input') as HTMLInputElement | null;
|
|
103
|
-
|
|
104
|
-
extDrop?.addEventListener('click', () => extInput?.click());
|
|
105
|
-
extInput?.addEventListener('change', () => {
|
|
106
|
-
if (extInput.files && extInput.files[0]) {
|
|
107
|
-
const file = extInput.files[0];
|
|
108
|
-
const img = new Image();
|
|
109
|
-
img.onload = () => {
|
|
110
|
-
extImage = img;
|
|
111
|
-
updateExtractor();
|
|
112
|
-
};
|
|
113
|
-
img.src = URL.createObjectURL(file);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
setupStepper('ssp-fw-dec', 'ssp-fw-inc', 'ssp-ext-width', updateExtractor);
|
|
118
|
-
setupStepper('ssp-fh-dec', 'ssp-fh-inc', 'ssp-ext-height', updateExtractor);
|
|
119
|
-
setupStepper('ssp-mar-dec', 'ssp-mar-inc', 'ssp-ext-margin', updateExtractor);
|
|
120
|
-
setupStepper('ssp-spc-dec', 'ssp-spc-inc', 'ssp-ext-spacing', updateExtractor);
|
|
121
|
-
|
|
122
|
-
['ssp-ext-width', 'ssp-ext-height', 'ssp-ext-margin', 'ssp-ext-spacing'].forEach((id) => {
|
|
123
|
-
document.getElementById(id)?.addEventListener('input', updateExtractor);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
document.getElementById('ssp-btn-extract-zip')?.addEventListener('click', (e) => downloadExtractedZip(e));
|
|
127
|
-
}
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
import { calculateGridSlices } from './logic';
|
|
3
|
+
import { drawEmptyCanvasMessage, setupStepper, triggerButtonFeedback } from './packer-ui';
|
|
4
|
+
|
|
5
|
+
let extImage: HTMLImageElement | null = null;
|
|
6
|
+
|
|
7
|
+
function parseInputValue(id: string, fallback: string): number {
|
|
8
|
+
const el = document.getElementById(id) as HTMLInputElement | null;
|
|
9
|
+
return parseInt(el?.value || fallback, 10);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getExtractorInputs() {
|
|
13
|
+
return {
|
|
14
|
+
fw: parseInputValue('ssp-ext-width', '32'),
|
|
15
|
+
fh: parseInputValue('ssp-ext-height', '32'),
|
|
16
|
+
margin: parseInputValue('ssp-ext-margin', '0'),
|
|
17
|
+
spacing: parseInputValue('ssp-ext-spacing', '0'),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function updateExtractor(): void {
|
|
22
|
+
const canvas = document.getElementById('ssp-ext-canvas') as HTMLCanvasElement | null;
|
|
23
|
+
if (!canvas) return;
|
|
24
|
+
|
|
25
|
+
if (!extImage) {
|
|
26
|
+
drawEmptyCanvasMessage(canvas, 'Upload sprite sheet to slice frames');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
canvas.width = extImage.width;
|
|
31
|
+
canvas.height = extImage.height;
|
|
32
|
+
|
|
33
|
+
const ctx = canvas.getContext('2d');
|
|
34
|
+
if (!ctx) return;
|
|
35
|
+
|
|
36
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
37
|
+
ctx.drawImage(extImage, 0, 0);
|
|
38
|
+
|
|
39
|
+
const { fw, fh, margin, spacing } = getExtractorInputs();
|
|
40
|
+
const slices = calculateGridSlices({
|
|
41
|
+
imageWidth: extImage.width,
|
|
42
|
+
imageHeight: extImage.height,
|
|
43
|
+
frameWidth: fw,
|
|
44
|
+
frameHeight: fh,
|
|
45
|
+
margin,
|
|
46
|
+
spacing,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const countEl = document.getElementById('ssp-ext-count');
|
|
50
|
+
if (countEl) countEl.textContent = slices.length.toString();
|
|
51
|
+
|
|
52
|
+
ctx.strokeStyle = '#38bdf8';
|
|
53
|
+
ctx.lineWidth = 1;
|
|
54
|
+
for (const slice of slices) {
|
|
55
|
+
ctx.strokeRect(slice.x, slice.y, slice.width, slice.height);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function processExtractedZip(e: MouseEvent, fw: number, fh: number, slices: ReturnType<typeof calculateGridSlices>) {
|
|
60
|
+
triggerButtonFeedback(document.getElementById('ssp-btn-extract-zip'), 'SPLIT ZIP!', e);
|
|
61
|
+
|
|
62
|
+
const zip = new JSZip();
|
|
63
|
+
const tempCanvas = document.createElement('canvas');
|
|
64
|
+
tempCanvas.width = fw;
|
|
65
|
+
tempCanvas.height = fh;
|
|
66
|
+
const tempCtx = tempCanvas.getContext('2d');
|
|
67
|
+
if (!tempCtx || !extImage) return;
|
|
68
|
+
|
|
69
|
+
slices.forEach((slice) => {
|
|
70
|
+
tempCtx.clearRect(0, 0, fw, fh);
|
|
71
|
+
tempCtx.drawImage(extImage!, slice.x, slice.y, slice.width, slice.height, 0, 0, fw, fh);
|
|
72
|
+
const dataUrl = tempCanvas.toDataURL('image/png').split(',')[1] ?? '';
|
|
73
|
+
zip.file(`frame_${slice.index}.png`, dataUrl, { base64: true });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
zip.generateAsync({ type: 'blob' }).then((content) => {
|
|
77
|
+
const link = document.createElement('a');
|
|
78
|
+
link.href = URL.createObjectURL(content);
|
|
79
|
+
link.download = 'extracted-sprites.zip';
|
|
80
|
+
link.click();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function downloadExtractedZip(e: MouseEvent): void {
|
|
85
|
+
if (!extImage) return;
|
|
86
|
+
const { fw, fh, margin, spacing } = getExtractorInputs();
|
|
87
|
+
const slices = calculateGridSlices({
|
|
88
|
+
imageWidth: extImage.width,
|
|
89
|
+
imageHeight: extImage.height,
|
|
90
|
+
frameWidth: fw,
|
|
91
|
+
frameHeight: fh,
|
|
92
|
+
margin,
|
|
93
|
+
spacing,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (slices.length === 0) return;
|
|
97
|
+
processExtractedZip(e, fw, fh, slices);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function initExtractor(): void {
|
|
101
|
+
const extDrop = document.getElementById('ssp-ext-dropzone');
|
|
102
|
+
const extInput = document.getElementById('ssp-ext-file-input') as HTMLInputElement | null;
|
|
103
|
+
|
|
104
|
+
extDrop?.addEventListener('click', () => extInput?.click());
|
|
105
|
+
extInput?.addEventListener('change', () => {
|
|
106
|
+
if (extInput.files && extInput.files[0]) {
|
|
107
|
+
const file = extInput.files[0];
|
|
108
|
+
const img = new Image();
|
|
109
|
+
img.onload = () => {
|
|
110
|
+
extImage = img;
|
|
111
|
+
updateExtractor();
|
|
112
|
+
};
|
|
113
|
+
img.src = URL.createObjectURL(file);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
setupStepper('ssp-fw-dec', 'ssp-fw-inc', 'ssp-ext-width', updateExtractor);
|
|
118
|
+
setupStepper('ssp-fh-dec', 'ssp-fh-inc', 'ssp-ext-height', updateExtractor);
|
|
119
|
+
setupStepper('ssp-mar-dec', 'ssp-mar-inc', 'ssp-ext-margin', updateExtractor);
|
|
120
|
+
setupStepper('ssp-spc-dec', 'ssp-spc-inc', 'ssp-ext-spacing', updateExtractor);
|
|
121
|
+
|
|
122
|
+
['ssp-ext-width', 'ssp-ext-height', 'ssp-ext-margin', 'ssp-ext-spacing'].forEach((id) => {
|
|
123
|
+
document.getElementById(id)?.addEventListener('input', updateExtractor);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
document.getElementById('ssp-btn-extract-zip')?.addEventListener('click', (e) => downloadExtractedZip(e));
|
|
127
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { spawnParticle, type LoadedImageItem } from './packer-ui';
|
|
2
|
-
|
|
3
|
-
let currentAnimFrameIndex = 0;
|
|
4
|
-
let animFps = 12;
|
|
5
|
-
let isPlayingAnim = true;
|
|
6
|
-
let lastFrameTime = 0;
|
|
7
|
-
|
|
8
|
-
export function renderFlipbookFrame(loadedImages: LoadedImageItem[]): void {
|
|
9
|
-
const canvas = document.getElementById('ssp-flipbook-canvas') as HTMLCanvasElement | null;
|
|
10
|
-
if (!canvas || loadedImages.length === 0) return;
|
|
11
|
-
|
|
12
|
-
const ctx = canvas.getContext('2d');
|
|
13
|
-
if (!ctx) return;
|
|
14
|
-
|
|
15
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
16
|
-
const item = loadedImages[currentAnimFrameIndex % loadedImages.length];
|
|
17
|
-
|
|
18
|
-
if (item && item.img) {
|
|
19
|
-
const scale = Math.min(canvas.width / item.img.width, canvas.height / item.img.height);
|
|
20
|
-
const drawW = item.img.width * scale;
|
|
21
|
-
const drawH = item.img.height * scale;
|
|
22
|
-
const drawX = (canvas.width - drawW) / 2;
|
|
23
|
-
const drawY = (canvas.height - drawH) / 2;
|
|
24
|
-
ctx.drawImage(item.img, drawX, drawY, drawW, drawH);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function startFlipbookLoop(loadedImages: LoadedImageItem[]): void {
|
|
29
|
-
function loop(timestamp: number) {
|
|
30
|
-
if (isPlayingAnim && loadedImages.length > 0) {
|
|
31
|
-
const interval = 1000 / animFps;
|
|
32
|
-
if (timestamp - lastFrameTime > interval) {
|
|
33
|
-
currentAnimFrameIndex = (currentAnimFrameIndex + 1) % loadedImages.length;
|
|
34
|
-
lastFrameTime = timestamp;
|
|
35
|
-
renderFlipbookFrame(loadedImages);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
requestAnimationFrame(loop);
|
|
39
|
-
}
|
|
40
|
-
requestAnimationFrame(loop);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function bindFlipbook(): void {
|
|
44
|
-
const fpsSlider = document.getElementById('ssp-fps-slider') as HTMLInputElement | null;
|
|
45
|
-
fpsSlider?.addEventListener('input', () => {
|
|
46
|
-
animFps = parseInt(fpsSlider.value, 10);
|
|
47
|
-
const valEl = document.getElementById('ssp-fps-val');
|
|
48
|
-
if (valEl) valEl.textContent = `${animFps} FPS`;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
document.getElementById('ssp-btn-play')?.addEventListener('click', (e) => {
|
|
52
|
-
isPlayingAnim = true;
|
|
53
|
-
spawnParticle(e.clientX, e.clientY, 'PLAYING');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
document.getElementById('ssp-btn-pause')?.addEventListener('click', (e) => {
|
|
57
|
-
isPlayingAnim = false;
|
|
58
|
-
spawnParticle(e.clientX, e.clientY, 'PAUSED');
|
|
59
|
-
});
|
|
60
|
-
}
|
|
1
|
+
import { spawnParticle, type LoadedImageItem } from './packer-ui';
|
|
2
|
+
|
|
3
|
+
let currentAnimFrameIndex = 0;
|
|
4
|
+
let animFps = 12;
|
|
5
|
+
let isPlayingAnim = true;
|
|
6
|
+
let lastFrameTime = 0;
|
|
7
|
+
|
|
8
|
+
export function renderFlipbookFrame(loadedImages: LoadedImageItem[]): void {
|
|
9
|
+
const canvas = document.getElementById('ssp-flipbook-canvas') as HTMLCanvasElement | null;
|
|
10
|
+
if (!canvas || loadedImages.length === 0) return;
|
|
11
|
+
|
|
12
|
+
const ctx = canvas.getContext('2d');
|
|
13
|
+
if (!ctx) return;
|
|
14
|
+
|
|
15
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
16
|
+
const item = loadedImages[currentAnimFrameIndex % loadedImages.length];
|
|
17
|
+
|
|
18
|
+
if (item && item.img) {
|
|
19
|
+
const scale = Math.min(canvas.width / item.img.width, canvas.height / item.img.height);
|
|
20
|
+
const drawW = item.img.width * scale;
|
|
21
|
+
const drawH = item.img.height * scale;
|
|
22
|
+
const drawX = (canvas.width - drawW) / 2;
|
|
23
|
+
const drawY = (canvas.height - drawH) / 2;
|
|
24
|
+
ctx.drawImage(item.img, drawX, drawY, drawW, drawH);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function startFlipbookLoop(loadedImages: LoadedImageItem[]): void {
|
|
29
|
+
function loop(timestamp: number) {
|
|
30
|
+
if (isPlayingAnim && loadedImages.length > 0) {
|
|
31
|
+
const interval = 1000 / animFps;
|
|
32
|
+
if (timestamp - lastFrameTime > interval) {
|
|
33
|
+
currentAnimFrameIndex = (currentAnimFrameIndex + 1) % loadedImages.length;
|
|
34
|
+
lastFrameTime = timestamp;
|
|
35
|
+
renderFlipbookFrame(loadedImages);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
requestAnimationFrame(loop);
|
|
39
|
+
}
|
|
40
|
+
requestAnimationFrame(loop);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function bindFlipbook(): void {
|
|
44
|
+
const fpsSlider = document.getElementById('ssp-fps-slider') as HTMLInputElement | null;
|
|
45
|
+
fpsSlider?.addEventListener('input', () => {
|
|
46
|
+
animFps = parseInt(fpsSlider.value, 10);
|
|
47
|
+
const valEl = document.getElementById('ssp-fps-val');
|
|
48
|
+
if (valEl) valEl.textContent = `${animFps} FPS`;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
document.getElementById('ssp-btn-play')?.addEventListener('click', (e) => {
|
|
52
|
+
isPlayingAnim = true;
|
|
53
|
+
spawnParticle(e.clientX, e.clientY, 'PLAYING');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
document.getElementById('ssp-btn-pause')?.addEventListener('click', (e) => {
|
|
57
|
+
isPlayingAnim = false;
|
|
58
|
+
spawnParticle(e.clientX, e.clientY, 'PAUSED');
|
|
59
|
+
});
|
|
60
|
+
}
|