@nice2dev/ui-graphics 1.3.15 → 1.3.16
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/CHANGELOG.md +9 -0
- package/dist/cjs/animation/AnimatedPerson.js +470 -143
- package/dist/cjs/animation/AnimationEditor.js +289 -101
- package/dist/cjs/animation/Audience.js +83 -61
- package/dist/cjs/animation/BodyRenderer.js +69 -28
- package/dist/cjs/animation/animationHelper.js +281 -288
- package/dist/cjs/animation/characterTypes.js +200 -203
- package/dist/cjs/animation/choreoDSL.js +205 -219
- package/dist/cjs/animation/choreography.js +4 -32
- package/dist/cjs/animation/karaokeIntegration.js +68 -77
- package/dist/cjs/animation/lottieExport.js +108 -114
- package/dist/cjs/animation/motionPath.js +225 -248
- package/dist/cjs/animation/physics.js +227 -254
- package/dist/cjs/animation/rig/RigPlayer.js +53 -56
- package/dist/cjs/animation/rig/RiggedBody.js +71 -26
- package/dist/cjs/animation/rig/choreoRigBridge.js +72 -77
- package/dist/cjs/animation/rig/ik.js +13 -18
- package/dist/cjs/animation/rig/poseOps.js +34 -41
- package/dist/cjs/animation/rig/presets.js +64 -72
- package/dist/cjs/animation/rig/rigMath.js +25 -32
- package/dist/cjs/animation/rig/rigTypes.js +59 -63
- package/dist/cjs/animation/shapes/arms.js +31 -13
- package/dist/cjs/animation/shapes/eyes.js +129 -47
- package/dist/cjs/animation/shapes/hair.js +72 -45
- package/dist/cjs/animation/shapes/heads.js +131 -57
- package/dist/cjs/animation/shapes/headwear.js +47 -38
- package/dist/cjs/animation/shapes/legs.js +31 -13
- package/dist/cjs/animation/shapes/mouths.js +120 -44
- package/dist/cjs/animation/shapes/noses.js +80 -25
- package/dist/cjs/animation/shapes/outfits.js +101 -39
- package/dist/cjs/animation/shapes/torsos.js +15 -11
- package/dist/cjs/animation/spineExport.js +103 -121
- package/dist/cjs/core/LocalUI.js +108 -43
- package/dist/cjs/core/NiceBrushEngine.js +758 -552
- package/dist/cjs/core/collaboration.js +249 -251
- package/dist/cjs/core/colorBlindness.js +100 -115
- package/dist/cjs/core/dragDrop.js +155 -158
- package/dist/cjs/core/editorAsk.js +51 -41
- package/dist/cjs/core/fixes.js +140 -171
- package/dist/cjs/core/gridGuides.js +166 -201
- package/dist/cjs/core/historyVisual.js +156 -135
- package/dist/cjs/core/i18n.js +13 -14
- package/dist/cjs/core/integrations.js +238 -249
- package/dist/cjs/core/minimap.js +149 -151
- package/dist/cjs/core/plugins.js +98 -113
- package/dist/cjs/core/rtl.js +71 -83
- package/dist/cjs/core/shortcuts.js +196 -225
- package/dist/cjs/core/theme.js +142 -149
- package/dist/cjs/core/yjsCollaboration.js +232 -293
- package/dist/cjs/design/design-tools.js +12 -22
- package/dist/cjs/font/NiceFontEditor.js +877 -316
- package/dist/cjs/font/fontFormatUtils.js +388 -448
- package/dist/cjs/game/GameAsset2dEditor.js +1201 -392
- package/dist/cjs/game/GameAsset2dEditor.module.css.js +146 -5
- package/dist/cjs/game/gameAssetTypes.js +7 -16
- package/dist/cjs/game/gameAssetUtils.js +390 -413
- package/dist/cjs/game/useGameAssetEditor.js +820 -763
- package/dist/cjs/index.js +81 -84
- package/dist/cjs/nice2dev-ui-graphics.css +1 -1
- package/dist/cjs/node_modules/lib0/array.js +8 -70
- package/dist/cjs/node_modules/lib0/binary.js +3 -20
- package/dist/cjs/node_modules/lib0/broadcastchannel.js +24 -86
- package/dist/cjs/node_modules/lib0/buffer.js +15 -82
- package/dist/cjs/node_modules/lib0/conditions.js +3 -16
- package/dist/cjs/node_modules/lib0/decoding.js +108 -287
- package/dist/cjs/node_modules/lib0/dom.js +14 -44
- package/dist/cjs/node_modules/lib0/encoding.js +68 -418
- package/dist/cjs/node_modules/lib0/environment.js +26 -92
- package/dist/cjs/node_modules/lib0/error.js +5 -29
- package/dist/cjs/node_modules/lib0/function.js +27 -66
- package/dist/cjs/node_modules/lib0/iterator.js +8 -33
- package/dist/cjs/node_modules/lib0/logging.common.js +12 -22
- package/dist/cjs/node_modules/lib0/logging.js +32 -71
- package/dist/cjs/node_modules/lib0/map.js +16 -86
- package/dist/cjs/node_modules/lib0/math.js +3 -32
- package/dist/cjs/node_modules/lib0/number.js +4 -15
- package/dist/cjs/node_modules/lib0/object.js +14 -88
- package/dist/cjs/node_modules/lib0/observable.js +38 -78
- package/dist/cjs/node_modules/lib0/pair.js +3 -20
- package/dist/cjs/node_modules/lib0/prng.js +8 -77
- package/dist/cjs/node_modules/lib0/promise.js +6 -30
- package/dist/cjs/node_modules/lib0/random.js +8 -23
- package/dist/cjs/node_modules/lib0/schema.js +313 -687
- package/dist/cjs/node_modules/lib0/set.js +3 -10
- package/dist/cjs/node_modules/lib0/storage.js +20 -55
- package/dist/cjs/node_modules/lib0/string.js +17 -72
- package/dist/cjs/node_modules/lib0/symbol.js +2 -12
- package/dist/cjs/node_modules/lib0/time.js +2 -15
- package/dist/cjs/node_modules/lib0/trait/equality.js +3 -28
- package/dist/cjs/node_modules/lib0/url.js +4 -18
- package/dist/cjs/node_modules/lib0/webcrypto.js +2 -5
- package/dist/cjs/node_modules/y-protocols/auth.js +5 -19
- package/dist/cjs/node_modules/y-protocols/awareness.js +53 -116
- package/dist/cjs/node_modules/y-protocols/sync.js +16 -103
- package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +77 -219
- package/dist/cjs/node_modules/yjs/dist/yjs.js +2128 -4868
- package/dist/cjs/photo/FilterThumb.js +37 -25
- package/dist/cjs/photo/NiceAITools.js +679 -467
- package/dist/cjs/photo/PhotoEditor.js +34 -20
- package/dist/cjs/photo/PhotoEditor.module.css.js +296 -5
- package/dist/cjs/photo/PhotoEditorCanvas.js +250 -91
- package/dist/cjs/photo/PhotoEditorLeftPanel.js +1086 -224
- package/dist/cjs/photo/PhotoEditorToolbar.js +135 -19
- package/dist/cjs/photo/photoEditorActions.js +89 -72
- package/dist/cjs/photo/photoEditorTypes.js +29 -32
- package/dist/cjs/photo/photoFilters.js +959 -985
- package/dist/cjs/photo/photoOverlays.js +899 -945
- package/dist/cjs/photo/photoSelection.js +427 -499
- package/dist/cjs/photo/usePhotoEditor.js +739 -741
- package/dist/cjs/pixel/HSVPicker.js +191 -175
- package/dist/cjs/pixel/PixelEditor.js +159 -48
- package/dist/cjs/pixel/PixelEditor.module.css.js +209 -5
- package/dist/cjs/pixel/PixelEditorCanvas.js +29 -16
- package/dist/cjs/pixel/PixelEditorMenuBar.js +160 -162
- package/dist/cjs/pixel/PixelEditorRightPanel.js +377 -45
- package/dist/cjs/pixel/PixelEditorStatusBar.js +47 -20
- package/dist/cjs/pixel/PixelEditorTimeline.js +106 -23
- package/dist/cjs/pixel/PixelEditorToolbar.js +99 -21
- package/dist/cjs/pixel/SpriteGeneratorPanel.js +483 -303
- package/dist/cjs/pixel/animalGeneratorPresets.js +776 -601
- package/dist/cjs/pixel/asepriteFormat.js +511 -560
- package/dist/cjs/pixel/buildingGeneratorPresets.js +693 -520
- package/dist/cjs/pixel/characterGeneratorPresets.js +644 -544
- package/dist/cjs/pixel/pixel-pro.js +52 -63
- package/dist/cjs/pixel/pixelEditorExports.js +388 -428
- package/dist/cjs/pixel/pixelEditorTypes.js +91 -108
- package/dist/cjs/pixel/pixelEditorUtils.js +519 -561
- package/dist/cjs/pixel/spriteGeneratorCore.js +206 -257
- package/dist/cjs/pixel/usePixelEditor.js +1321 -1343
- package/dist/cjs/texture/Nice3DTexturePainter.js +707 -440
- package/dist/cjs/ui/NiceUIDesigner.js +954 -527
- package/dist/cjs/vector/NiceSvgToCode.js +586 -446
- package/dist/cjs/vector/VectorEditor.js +290 -117
- package/dist/cjs/vector/VectorEditor.module.css.js +86 -5
- package/dist/cjs/vector/VectorEditorMenuBar.js +333 -275
- package/dist/cjs/vector/VectorEditorRightPanel.js +1094 -371
- package/dist/cjs/vector/VectorEditorShapeRenderer.js +198 -60
- package/dist/cjs/vector/VectorEditorStatusBar.js +39 -13
- package/dist/cjs/vector/useVectorEditor.js +848 -889
- package/dist/cjs/vector/vectorAnimation.js +110 -137
- package/dist/cjs/vector/vectorBooleanOps.js +398 -485
- package/dist/cjs/vector/vectorEditorExport.js +201 -203
- package/dist/cjs/vector/vectorEditorImport.js +173 -189
- package/dist/cjs/vector/vectorEditorTypes.js +42 -49
- package/dist/cjs/vector/vectorGradients.js +151 -174
- package/dist/cjs/vector/vectorIconExport.js +52 -59
- package/dist/cjs/vector/vectorIconImport.js +169 -219
- package/dist/esm/animation/AnimatedPerson.js +470 -141
- package/dist/esm/animation/AnimationEditor.js +290 -100
- package/dist/esm/animation/Audience.js +83 -59
- package/dist/esm/animation/BodyRenderer.js +71 -25
- package/dist/esm/animation/animationHelper.js +284 -287
- package/dist/esm/animation/characterTypes.js +204 -202
- package/dist/esm/animation/choreoDSL.js +212 -218
- package/dist/esm/animation/choreography.js +8 -31
- package/dist/esm/animation/karaokeIntegration.js +74 -76
- package/dist/esm/animation/lottieExport.js +112 -113
- package/dist/esm/animation/motionPath.js +235 -247
- package/dist/esm/animation/physics.js +235 -253
- package/dist/esm/animation/rig/RigPlayer.js +53 -54
- package/dist/esm/animation/rig/RiggedBody.js +71 -24
- package/dist/esm/animation/rig/choreoRigBridge.js +74 -76
- package/dist/esm/animation/rig/ik.js +14 -17
- package/dist/esm/animation/rig/poseOps.js +37 -40
- package/dist/esm/animation/rig/presets.js +70 -71
- package/dist/esm/animation/rig/rigMath.js +28 -31
- package/dist/esm/animation/rig/rigTypes.js +62 -62
- package/dist/esm/animation/shapes/arms.js +32 -12
- package/dist/esm/animation/shapes/eyes.js +135 -46
- package/dist/esm/animation/shapes/hair.js +80 -44
- package/dist/esm/animation/shapes/heads.js +140 -56
- package/dist/esm/animation/shapes/headwear.js +54 -37
- package/dist/esm/animation/shapes/legs.js +32 -12
- package/dist/esm/animation/shapes/mouths.js +127 -43
- package/dist/esm/animation/shapes/noses.js +87 -24
- package/dist/esm/animation/shapes/outfits.js +106 -38
- package/dist/esm/animation/shapes/torsos.js +16 -10
- package/dist/esm/animation/spineExport.js +106 -120
- package/dist/esm/core/LocalUI.js +111 -42
- package/dist/esm/core/NiceBrushEngine.js +761 -551
- package/dist/esm/core/collaboration.js +255 -250
- package/dist/esm/core/colorBlindness.js +106 -114
- package/dist/esm/core/dragDrop.js +157 -157
- package/dist/esm/core/editorAsk.js +53 -40
- package/dist/esm/core/fixes.js +145 -170
- package/dist/esm/core/gridGuides.js +178 -200
- package/dist/esm/core/historyVisual.js +158 -134
- package/dist/esm/core/i18n.js +15 -13
- package/dist/esm/core/integrations.js +244 -248
- package/dist/esm/core/minimap.js +151 -150
- package/dist/esm/core/plugins.js +102 -112
- package/dist/esm/core/rtl.js +77 -82
- package/dist/esm/core/shortcuts.js +200 -224
- package/dist/esm/core/theme.js +150 -148
- package/dist/esm/core/yjsCollaboration.js +240 -292
- package/dist/esm/design/design-tools.js +13 -21
- package/dist/esm/font/NiceFontEditor.js +880 -315
- package/dist/esm/font/fontFormatUtils.js +394 -447
- package/dist/esm/game/GameAsset2dEditor.js +1202 -391
- package/dist/esm/game/GameAsset2dEditor.module.css.js +146 -3
- package/dist/esm/game/gameAssetTypes.js +8 -15
- package/dist/esm/game/gameAssetUtils.js +408 -412
- package/dist/esm/game/useGameAssetEditor.js +821 -762
- package/dist/esm/index.js +332 -69
- package/dist/esm/nice2dev-ui-graphics.css +1 -1
- package/dist/esm/node_modules/lib0/array.js +15 -69
- package/dist/esm/node_modules/lib0/binary.js +14 -19
- package/dist/esm/node_modules/lib0/broadcastchannel.js +27 -85
- package/dist/esm/node_modules/lib0/buffer.js +20 -80
- package/dist/esm/node_modules/lib0/conditions.js +4 -15
- package/dist/esm/node_modules/lib0/decoding.js +128 -286
- package/dist/esm/node_modules/lib0/dom.js +20 -43
- package/dist/esm/node_modules/lib0/encoding.js +90 -415
- package/dist/esm/node_modules/lib0/environment.js +33 -91
- package/dist/esm/node_modules/lib0/error.js +8 -28
- package/dist/esm/node_modules/lib0/function.js +31 -65
- package/dist/esm/node_modules/lib0/iterator.js +11 -32
- package/dist/esm/node_modules/lib0/logging.common.js +22 -21
- package/dist/esm/node_modules/lib0/logging.js +44 -70
- package/dist/esm/node_modules/lib0/map.js +21 -85
- package/dist/esm/node_modules/lib0/math.js +9 -31
- package/dist/esm/node_modules/lib0/number.js +7 -14
- package/dist/esm/node_modules/lib0/object.js +26 -87
- package/dist/esm/node_modules/lib0/observable.js +40 -77
- package/dist/esm/node_modules/lib0/pair.js +5 -19
- package/dist/esm/node_modules/lib0/prng.js +15 -76
- package/dist/esm/node_modules/lib0/promise.js +7 -29
- package/dist/esm/node_modules/lib0/random.js +10 -22
- package/dist/esm/node_modules/lib0/schema.js +367 -686
- package/dist/esm/node_modules/lib0/set.js +4 -9
- package/dist/esm/node_modules/lib0/storage.js +23 -54
- package/dist/esm/node_modules/lib0/string.js +26 -71
- package/dist/esm/node_modules/lib0/symbol.js +3 -11
- package/dist/esm/node_modules/lib0/time.js +3 -14
- package/dist/esm/node_modules/lib0/trait/equality.js +5 -27
- package/dist/esm/node_modules/lib0/url.js +5 -17
- package/dist/esm/node_modules/lib0/webcrypto.js +3 -4
- package/dist/esm/node_modules/y-protocols/auth.js +7 -18
- package/dist/esm/node_modules/y-protocols/awareness.js +58 -115
- package/dist/esm/node_modules/y-protocols/sync.js +26 -102
- package/dist/esm/node_modules/y-websocket/src/y-websocket.js +82 -218
- package/dist/esm/node_modules/yjs/dist/yjs.js +2263 -4899
- package/dist/esm/photo/FilterThumb.js +37 -23
- package/dist/esm/photo/NiceAITools.js +685 -466
- package/dist/esm/photo/PhotoEditor.js +34 -18
- package/dist/esm/photo/PhotoEditor.module.css.js +296 -3
- package/dist/esm/photo/PhotoEditorCanvas.js +250 -89
- package/dist/esm/photo/PhotoEditorLeftPanel.js +1086 -222
- package/dist/esm/photo/PhotoEditorToolbar.js +135 -17
- package/dist/esm/photo/photoEditorActions.js +93 -71
- package/dist/esm/photo/photoEditorTypes.js +32 -31
- package/dist/esm/photo/photoFilters.js +967 -984
- package/dist/esm/photo/photoOverlays.js +913 -944
- package/dist/esm/photo/photoSelection.js +438 -498
- package/dist/esm/photo/usePhotoEditor.js +740 -740
- package/dist/esm/pixel/HSVPicker.js +192 -174
- package/dist/esm/pixel/PixelEditor.js +160 -47
- package/dist/esm/pixel/PixelEditor.module.css.js +209 -3
- package/dist/esm/pixel/PixelEditorCanvas.js +29 -14
- package/dist/esm/pixel/PixelEditorMenuBar.js +160 -160
- package/dist/esm/pixel/PixelEditorRightPanel.js +377 -43
- package/dist/esm/pixel/PixelEditorStatusBar.js +47 -18
- package/dist/esm/pixel/PixelEditorTimeline.js +106 -21
- package/dist/esm/pixel/PixelEditorToolbar.js +99 -19
- package/dist/esm/pixel/SpriteGeneratorPanel.js +483 -301
- package/dist/esm/pixel/animalGeneratorPresets.js +782 -600
- package/dist/esm/pixel/asepriteFormat.js +517 -559
- package/dist/esm/pixel/buildingGeneratorPresets.js +699 -519
- package/dist/esm/pixel/characterGeneratorPresets.js +650 -543
- package/dist/esm/pixel/pixel-pro.js +53 -62
- package/dist/esm/pixel/pixelEditorExports.js +397 -427
- package/dist/esm/pixel/pixelEditorTypes.js +103 -107
- package/dist/esm/pixel/pixelEditorUtils.js +551 -560
- package/dist/esm/pixel/spriteGeneratorCore.js +223 -256
- package/dist/esm/pixel/usePixelEditor.js +1322 -1342
- package/dist/esm/texture/Nice3DTexturePainter.js +709 -439
- package/dist/esm/ui/NiceUIDesigner.js +957 -526
- package/dist/esm/vector/NiceSvgToCode.js +589 -445
- package/dist/esm/vector/VectorEditor.js +291 -116
- package/dist/esm/vector/VectorEditor.module.css.js +86 -3
- package/dist/esm/vector/VectorEditorMenuBar.js +333 -273
- package/dist/esm/vector/VectorEditorRightPanel.js +1094 -369
- package/dist/esm/vector/VectorEditorShapeRenderer.js +199 -59
- package/dist/esm/vector/VectorEditorStatusBar.js +39 -11
- package/dist/esm/vector/useVectorEditor.js +849 -888
- package/dist/esm/vector/vectorAnimation.js +115 -136
- package/dist/esm/vector/vectorBooleanOps.js +401 -484
- package/dist/esm/vector/vectorEditorExport.js +207 -202
- package/dist/esm/vector/vectorEditorImport.js +174 -188
- package/dist/esm/vector/vectorEditorTypes.js +50 -48
- package/dist/esm/vector/vectorGradients.js +158 -173
- package/dist/esm/vector/vectorIconExport.js +53 -58
- package/dist/esm/vector/vectorIconImport.js +171 -218
- package/package.json +9 -15
|
@@ -1,466 +1,443 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* gameAssetUtils.ts — Utilities for GameAsset2dEditor
|
|
7
|
-
*/
|
|
8
|
-
/* ────────────────────────────────────────────────────────────────
|
|
9
|
-
ID GENERATION
|
|
10
|
-
──────────────────────────────────────────────────────────────── */
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const gameAssetTypes = require("./gameAssetTypes.js");
|
|
11
4
|
let idCounter = 0;
|
|
12
|
-
const generateId = (prefix =
|
|
13
|
-
/* ────────────────────────────────────────────────────────────────
|
|
14
|
-
IMAGE UTILITIES
|
|
15
|
-
──────────────────────────────────────────────────────────────── */
|
|
5
|
+
const generateId = (prefix = "id") => `${prefix}_${++idCounter}_${Date.now().toString(36)}`;
|
|
16
6
|
const imageDataToDataUrl = (imageData) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
const canvas = document.createElement("canvas");
|
|
8
|
+
canvas.width = imageData.width;
|
|
9
|
+
canvas.height = imageData.height;
|
|
10
|
+
const ctx = canvas.getContext("2d");
|
|
11
|
+
ctx.putImageData(imageData, 0, 0);
|
|
12
|
+
return canvas.toDataURL("image/png");
|
|
23
13
|
};
|
|
24
14
|
const dataUrlToImageData = async (dataUrl) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const img = new Image();
|
|
17
|
+
img.onload = () => {
|
|
18
|
+
const canvas = document.createElement("canvas");
|
|
19
|
+
canvas.width = img.width;
|
|
20
|
+
canvas.height = img.height;
|
|
21
|
+
const ctx = canvas.getContext("2d");
|
|
22
|
+
ctx.drawImage(img, 0, 0);
|
|
23
|
+
resolve(ctx.getImageData(0, 0, img.width, img.height));
|
|
24
|
+
};
|
|
25
|
+
img.onerror = reject;
|
|
26
|
+
img.src = dataUrl;
|
|
27
|
+
});
|
|
38
28
|
};
|
|
39
29
|
const loadImage = (src) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const img = new Image();
|
|
32
|
+
img.onload = () => resolve(img);
|
|
33
|
+
img.onerror = reject;
|
|
34
|
+
img.src = src;
|
|
35
|
+
});
|
|
46
36
|
};
|
|
47
|
-
/* ────────────────────────────────────────────────────────────────
|
|
48
|
-
TILE UTILITIES
|
|
49
|
-
──────────────────────────────────────────────────────────────── */
|
|
50
37
|
const createTileFromImage = (imageData, name) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
38
|
+
return {
|
|
39
|
+
id: generateId("tile"),
|
|
40
|
+
name,
|
|
41
|
+
image: imageData,
|
|
42
|
+
thumbnail: imageDataToDataUrl(imageData),
|
|
43
|
+
width: imageData.width,
|
|
44
|
+
height: imageData.height,
|
|
45
|
+
properties: {}
|
|
46
|
+
};
|
|
60
47
|
};
|
|
61
48
|
const createEmptyTileLayer = (name, mapWidth, mapHeight) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
49
|
+
const tiles = [];
|
|
50
|
+
for (let y = 0; y < mapHeight; y++) {
|
|
51
|
+
tiles.push(new Array(mapWidth).fill(null));
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
id: generateId("layer"),
|
|
55
|
+
name,
|
|
56
|
+
visible: true,
|
|
57
|
+
locked: false,
|
|
58
|
+
opacity: 1,
|
|
59
|
+
tiles,
|
|
60
|
+
parallaxX: 1,
|
|
61
|
+
parallaxY: 1,
|
|
62
|
+
offsetX: 0,
|
|
63
|
+
offsetY: 0,
|
|
64
|
+
zIndex: 0
|
|
65
|
+
};
|
|
79
66
|
};
|
|
80
|
-
const createEmptyTileMap = (name, width, height, tileWidth, tileHeight, mode =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
67
|
+
const createEmptyTileMap = (name, width, height, tileWidth, tileHeight, mode = "2d") => {
|
|
68
|
+
const mapMode = mode === "tilemap" ? "2d" : mode;
|
|
69
|
+
return {
|
|
70
|
+
id: generateId("map"),
|
|
71
|
+
name,
|
|
72
|
+
mode: mapMode,
|
|
73
|
+
width,
|
|
74
|
+
height,
|
|
75
|
+
tileWidth,
|
|
76
|
+
tileHeight,
|
|
77
|
+
layers: [createEmptyTileLayer("Layer 1", width, height)],
|
|
78
|
+
properties: {},
|
|
79
|
+
// Document data (saved with the tile map). audit-allow: literal-color
|
|
80
|
+
backgroundColor: "#1a1a2e"
|
|
81
|
+
};
|
|
95
82
|
};
|
|
96
|
-
/* ────────────────────────────────────────────────────────────────
|
|
97
|
-
SPRITE SHEET UTILITIES
|
|
98
|
-
──────────────────────────────────────────────────────────────── */
|
|
99
83
|
const autoSliceSpriteSheet = (imageData, frameWidth, frameHeight, padding = 0) => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
84
|
+
const frames = [];
|
|
85
|
+
const cols = Math.floor((imageData.width + padding) / (frameWidth + padding));
|
|
86
|
+
const rows = Math.floor((imageData.height + padding) / (frameHeight + padding));
|
|
87
|
+
for (let row = 0; row < rows; row++) {
|
|
88
|
+
for (let col = 0; col < cols; col++) {
|
|
89
|
+
frames.push({
|
|
90
|
+
id: generateId("frame"),
|
|
91
|
+
name: `frame_${row}_${col}`,
|
|
92
|
+
x: col * (frameWidth + padding),
|
|
93
|
+
y: row * (frameHeight + padding),
|
|
94
|
+
width: frameWidth,
|
|
95
|
+
height: frameHeight,
|
|
96
|
+
pivotX: 0.5,
|
|
97
|
+
pivotY: 0.5
|
|
98
|
+
});
|
|
116
99
|
}
|
|
117
|
-
|
|
100
|
+
}
|
|
101
|
+
return frames;
|
|
118
102
|
};
|
|
119
103
|
const detectFrames = (imageData) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
for (let
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
}
|
|
104
|
+
const frames = [];
|
|
105
|
+
const visited = /* @__PURE__ */ new Set();
|
|
106
|
+
const { data, width, height } = imageData;
|
|
107
|
+
const isTransparent = (x, y) => {
|
|
108
|
+
if (x < 0 || y < 0 || x >= width || y >= height) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
const idx = (y * width + x) * 4;
|
|
112
|
+
return data[idx + 3] < 10;
|
|
113
|
+
};
|
|
114
|
+
const floodFillBounds = (startX, startY) => {
|
|
115
|
+
let minX = startX, maxX = startX, minY = startY, maxY = startY;
|
|
116
|
+
const stack = [[startX, startY]];
|
|
117
|
+
while (stack.length > 0) {
|
|
118
|
+
const [x, y] = stack.pop();
|
|
119
|
+
const key = `${x},${y}`;
|
|
120
|
+
if (visited.has(key) || isTransparent(x, y)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
visited.add(key);
|
|
124
|
+
minX = Math.min(minX, x);
|
|
125
|
+
maxX = Math.max(maxX, x);
|
|
126
|
+
minY = Math.min(minY, y);
|
|
127
|
+
maxY = Math.max(maxY, y);
|
|
128
|
+
stack.push([x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]);
|
|
129
|
+
}
|
|
130
|
+
return { minX, maxX, minY, maxY };
|
|
131
|
+
};
|
|
132
|
+
for (let y = 0; y < height; y++) {
|
|
133
|
+
for (let x = 0; x < width; x++) {
|
|
134
|
+
const key = `${x},${y}`;
|
|
135
|
+
if (!visited.has(key) && !isTransparent(x, y)) {
|
|
136
|
+
const bounds = floodFillBounds(x, y);
|
|
137
|
+
const frameWidth = bounds.maxX - bounds.minX + 1;
|
|
138
|
+
const frameHeight = bounds.maxY - bounds.minY + 1;
|
|
139
|
+
if (frameWidth > 1 && frameHeight > 1) {
|
|
140
|
+
frames.push({
|
|
141
|
+
id: generateId("frame"),
|
|
142
|
+
name: `sprite_${frames.length}`,
|
|
143
|
+
x: bounds.minX,
|
|
144
|
+
y: bounds.minY,
|
|
145
|
+
width: frameWidth,
|
|
146
|
+
height: frameHeight,
|
|
147
|
+
pivotX: 0.5,
|
|
148
|
+
pivotY: 1
|
|
149
|
+
// bottom center for most sprites
|
|
150
|
+
});
|
|
169
151
|
}
|
|
152
|
+
}
|
|
170
153
|
}
|
|
171
|
-
|
|
154
|
+
}
|
|
155
|
+
return frames;
|
|
172
156
|
};
|
|
173
157
|
const createSpriteAnimation = (name, frameIds, frameDelay = 100) => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
158
|
+
return {
|
|
159
|
+
id: generateId("anim"),
|
|
160
|
+
name,
|
|
161
|
+
frameIds,
|
|
162
|
+
frameDurations: frameIds.map(() => frameDelay),
|
|
163
|
+
loop: true,
|
|
164
|
+
pingPong: false
|
|
165
|
+
};
|
|
182
166
|
};
|
|
183
|
-
/* ────────────────────────────────────────────────────────────────
|
|
184
|
-
EFFECTS PROCESSING
|
|
185
|
-
──────────────────────────────────────────────────────────────── */
|
|
186
167
|
const applyEffect = (imageData, effect) => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
168
|
+
const canvas = document.createElement("canvas");
|
|
169
|
+
canvas.width = imageData.width;
|
|
170
|
+
canvas.height = imageData.height;
|
|
171
|
+
const ctx = canvas.getContext("2d");
|
|
172
|
+
ctx.putImageData(imageData, 0, 0);
|
|
173
|
+
const data = imageData.data.slice();
|
|
174
|
+
const result = new ImageData(new Uint8ClampedArray(data), imageData.width, imageData.height);
|
|
175
|
+
switch (effect.type) {
|
|
176
|
+
case "brightness": {
|
|
177
|
+
const value = effect.params.value || 0;
|
|
178
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
179
|
+
result.data[i] = Math.min(255, Math.max(0, data[i] + value));
|
|
180
|
+
result.data[i + 1] = Math.min(255, Math.max(0, data[i + 1] + value));
|
|
181
|
+
result.data[i + 2] = Math.min(255, Math.max(0, data[i + 2] + value));
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case "contrast": {
|
|
186
|
+
const factor = 259 * (effect.params.value + 255) / (255 * (259 - effect.params.value));
|
|
187
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
188
|
+
result.data[i] = Math.min(255, Math.max(0, factor * (data[i] - 128) + 128));
|
|
189
|
+
result.data[i + 1] = Math.min(255, Math.max(0, factor * (data[i + 1] - 128) + 128));
|
|
190
|
+
result.data[i + 2] = Math.min(255, Math.max(0, factor * (data[i + 2] - 128) + 128));
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case "invert": {
|
|
195
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
196
|
+
result.data[i] = 255 - data[i];
|
|
197
|
+
result.data[i + 1] = 255 - data[i + 1];
|
|
198
|
+
result.data[i + 2] = 255 - data[i + 2];
|
|
199
|
+
}
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case "saturation": {
|
|
203
|
+
const value = (effect.params.value + 100) / 100;
|
|
204
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
205
|
+
const r = data[i], g = data[i + 1], b = data[i + 2];
|
|
206
|
+
const gray = 0.2989 * r + 0.587 * g + 0.114 * b;
|
|
207
|
+
result.data[i] = Math.min(255, Math.max(0, gray + (r - gray) * value));
|
|
208
|
+
result.data[i + 1] = Math.min(255, Math.max(0, gray + (g - gray) * value));
|
|
209
|
+
result.data[i + 2] = Math.min(255, Math.max(0, gray + (b - gray) * value));
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "hue-shift": {
|
|
214
|
+
const degrees = effect.params.degrees || 0;
|
|
215
|
+
const cos = Math.cos(degrees * Math.PI / 180);
|
|
216
|
+
const sin = Math.sin(degrees * Math.PI / 180);
|
|
217
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
218
|
+
const r = data[i], g = data[i + 1], b = data[i + 2];
|
|
219
|
+
result.data[i] = Math.min(
|
|
220
|
+
255,
|
|
221
|
+
Math.max(
|
|
222
|
+
0,
|
|
223
|
+
(0.213 + cos * 0.787 - sin * 0.213) * r + (0.715 - cos * 0.715 - sin * 0.715) * g + (0.072 - cos * 0.072 + sin * 0.928) * b
|
|
224
|
+
)
|
|
225
|
+
);
|
|
226
|
+
result.data[i + 1] = Math.min(
|
|
227
|
+
255,
|
|
228
|
+
Math.max(
|
|
229
|
+
0,
|
|
230
|
+
(0.213 - cos * 0.213 + sin * 0.143) * r + (0.715 + cos * 0.285 + sin * 0.14) * g + (0.072 - cos * 0.072 - sin * 0.283) * b
|
|
231
|
+
)
|
|
232
|
+
);
|
|
233
|
+
result.data[i + 2] = Math.min(
|
|
234
|
+
255,
|
|
235
|
+
Math.max(
|
|
236
|
+
0,
|
|
237
|
+
(0.213 - cos * 0.213 - sin * 0.787) * r + (0.715 - cos * 0.715 + sin * 0.715) * g + (0.072 + cos * 0.928 + sin * 0.072) * b
|
|
238
|
+
)
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case "tint": {
|
|
244
|
+
const color = effect.params.color || "#ffffff";
|
|
245
|
+
const amount = effect.params.amount || 0.5;
|
|
246
|
+
const tr = parseInt(color.slice(1, 3), 16);
|
|
247
|
+
const tg = parseInt(color.slice(3, 5), 16);
|
|
248
|
+
const tb = parseInt(color.slice(5, 7), 16);
|
|
249
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
250
|
+
result.data[i] = Math.round(data[i] * (1 - amount) + tr * amount);
|
|
251
|
+
result.data[i + 1] = Math.round(data[i + 1] * (1 - amount) + tg * amount);
|
|
252
|
+
result.data[i + 2] = Math.round(data[i + 2] * (1 - amount) + tb * amount);
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
case "pixelate": {
|
|
257
|
+
const size = effect.params.size || 4;
|
|
258
|
+
const { width, height } = imageData;
|
|
259
|
+
for (let y = 0; y < height; y += size) {
|
|
260
|
+
for (let x = 0; x < width; x += size) {
|
|
261
|
+
let r = 0, g = 0, b = 0, a = 0, count = 0;
|
|
262
|
+
for (let dy = 0; dy < size && y + dy < height; dy++) {
|
|
263
|
+
for (let dx = 0; dx < size && x + dx < width; dx++) {
|
|
264
|
+
const idx = ((y + dy) * width + (x + dx)) * 4;
|
|
265
|
+
r += data[idx];
|
|
266
|
+
g += data[idx + 1];
|
|
267
|
+
b += data[idx + 2];
|
|
268
|
+
a += data[idx + 3];
|
|
269
|
+
count++;
|
|
248
270
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
result.data[i + 2] = Math.round(data[i + 2] * (1 - amount) + tb * amount);
|
|
271
|
+
}
|
|
272
|
+
r = Math.round(r / count);
|
|
273
|
+
g = Math.round(g / count);
|
|
274
|
+
b = Math.round(b / count);
|
|
275
|
+
a = Math.round(a / count);
|
|
276
|
+
for (let dy = 0; dy < size && y + dy < height; dy++) {
|
|
277
|
+
for (let dx = 0; dx < size && x + dx < width; dx++) {
|
|
278
|
+
const idx = ((y + dy) * width + (x + dx)) * 4;
|
|
279
|
+
result.data[idx] = r;
|
|
280
|
+
result.data[idx + 1] = g;
|
|
281
|
+
result.data[idx + 2] = b;
|
|
282
|
+
result.data[idx + 3] = a;
|
|
262
283
|
}
|
|
263
|
-
|
|
284
|
+
}
|
|
264
285
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
a = Math.round(a / count);
|
|
285
|
-
for (let dy = 0; dy < size && y + dy < height; dy++) {
|
|
286
|
-
for (let dx = 0; dx < size && x + dx < width; dx++) {
|
|
287
|
-
const idx = ((y + dy) * width + (x + dx)) * 4;
|
|
288
|
-
result.data[idx] = r;
|
|
289
|
-
result.data[idx + 1] = g;
|
|
290
|
-
result.data[idx + 2] = b;
|
|
291
|
-
result.data[idx + 3] = a;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
286
|
+
}
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case "outline": {
|
|
290
|
+
const color = effect.params.color || "#000000";
|
|
291
|
+
const thickness = effect.params.thickness || 1;
|
|
292
|
+
const or = parseInt(color.slice(1, 3), 16);
|
|
293
|
+
const og = parseInt(color.slice(3, 5), 16);
|
|
294
|
+
const ob = parseInt(color.slice(5, 7), 16);
|
|
295
|
+
const { width, height } = imageData;
|
|
296
|
+
for (let y = 0; y < height; y++) {
|
|
297
|
+
for (let x = 0; x < width; x++) {
|
|
298
|
+
const idx = (y * width + x) * 4;
|
|
299
|
+
if (data[idx + 3] < 128) {
|
|
300
|
+
let hasOpaqueNeighbor = false;
|
|
301
|
+
for (let dy = -thickness; dy <= thickness && !hasOpaqueNeighbor; dy++) {
|
|
302
|
+
for (let dx = -thickness; dx <= thickness && !hasOpaqueNeighbor; dx++) {
|
|
303
|
+
if (dx === 0 && dy === 0) {
|
|
304
|
+
continue;
|
|
294
305
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const or = parseInt(color.slice(1, 3), 16);
|
|
302
|
-
const og = parseInt(color.slice(3, 5), 16);
|
|
303
|
-
const ob = parseInt(color.slice(5, 7), 16);
|
|
304
|
-
const { width, height } = imageData;
|
|
305
|
-
for (let y = 0; y < height; y++) {
|
|
306
|
-
for (let x = 0; x < width; x++) {
|
|
307
|
-
const idx = (y * width + x) * 4;
|
|
308
|
-
if (data[idx + 3] < 128) {
|
|
309
|
-
// Check neighbors for opaque pixels
|
|
310
|
-
let hasOpaqueNeighbor = false;
|
|
311
|
-
for (let dy = -thickness; dy <= thickness && !hasOpaqueNeighbor; dy++) {
|
|
312
|
-
for (let dx = -thickness; dx <= thickness && !hasOpaqueNeighbor; dx++) {
|
|
313
|
-
if (dx === 0 && dy === 0) {
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
const nx = x + dx, ny = y + dy;
|
|
317
|
-
if (nx >= 0 && nx < width && ny >= 0 && ny < height) {
|
|
318
|
-
const nidx = (ny * width + nx) * 4;
|
|
319
|
-
if (data[nidx + 3] >= 128) {
|
|
320
|
-
hasOpaqueNeighbor = true;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
if (hasOpaqueNeighbor) {
|
|
326
|
-
result.data[idx] = or;
|
|
327
|
-
result.data[idx + 1] = og;
|
|
328
|
-
result.data[idx + 2] = ob;
|
|
329
|
-
result.data[idx + 3] = 255;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
306
|
+
const nx = x + dx, ny = y + dy;
|
|
307
|
+
if (nx >= 0 && nx < width && ny >= 0 && ny < height) {
|
|
308
|
+
const nidx = (ny * width + nx) * 4;
|
|
309
|
+
if (data[nidx + 3] >= 128) {
|
|
310
|
+
hasOpaqueNeighbor = true;
|
|
311
|
+
}
|
|
332
312
|
}
|
|
313
|
+
}
|
|
333
314
|
}
|
|
334
|
-
|
|
315
|
+
if (hasOpaqueNeighbor) {
|
|
316
|
+
result.data[idx] = or;
|
|
317
|
+
result.data[idx + 1] = og;
|
|
318
|
+
result.data[idx + 2] = ob;
|
|
319
|
+
result.data[idx + 3] = 255;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
335
322
|
}
|
|
336
|
-
|
|
323
|
+
}
|
|
324
|
+
break;
|
|
337
325
|
}
|
|
338
|
-
|
|
326
|
+
}
|
|
327
|
+
return result;
|
|
339
328
|
};
|
|
340
329
|
const applyEffects = (imageData, effects) => {
|
|
341
|
-
|
|
342
|
-
.filter((e) => e.enabled)
|
|
343
|
-
.reduce((img, effect) => applyEffect(img, effect), imageData);
|
|
330
|
+
return effects.filter((e) => e.enabled).reduce((img, effect) => applyEffect(img, effect), imageData);
|
|
344
331
|
};
|
|
345
|
-
/* ────────────────────────────────────────────────────────────────
|
|
346
|
-
EXPORT UTILITIES
|
|
347
|
-
──────────────────────────────────────────────────────────────── */
|
|
348
332
|
const exportToTiledJson = (tileMap, tileSets) => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
else {
|
|
373
|
-
data.push(0);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
333
|
+
const tilesetData = tileSets.map((tile, index) => ({
|
|
334
|
+
firstgid: index + 1,
|
|
335
|
+
columns: 1,
|
|
336
|
+
image: tile.thumbnail,
|
|
337
|
+
imageheight: tile.height,
|
|
338
|
+
imagewidth: tile.width,
|
|
339
|
+
margin: 0,
|
|
340
|
+
name: tile.name,
|
|
341
|
+
spacing: 0,
|
|
342
|
+
tilecount: 1,
|
|
343
|
+
tileheight: tile.height,
|
|
344
|
+
tilewidth: tile.width
|
|
345
|
+
}));
|
|
346
|
+
const layerData = tileMap.layers.map((layer) => {
|
|
347
|
+
const data = [];
|
|
348
|
+
for (let y = 0; y < tileMap.height; y++) {
|
|
349
|
+
for (let x = 0; x < tileMap.width; x++) {
|
|
350
|
+
const tileId = layer.tiles[y]?.[x];
|
|
351
|
+
if (tileId) {
|
|
352
|
+
const tileIndex = tileSets.findIndex((t) => t.id === tileId);
|
|
353
|
+
data.push(tileIndex >= 0 ? tileIndex + 1 : 0);
|
|
354
|
+
} else {
|
|
355
|
+
data.push(0);
|
|
376
356
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
height: tileMap.height,
|
|
380
|
-
id: 1,
|
|
381
|
-
name: layer.name,
|
|
382
|
-
opacity: layer.opacity,
|
|
383
|
-
type: 'tilelayer',
|
|
384
|
-
visible: layer.visible,
|
|
385
|
-
width: tileMap.width,
|
|
386
|
-
x: 0,
|
|
387
|
-
y: 0,
|
|
388
|
-
};
|
|
389
|
-
});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
390
359
|
return {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
360
|
+
data,
|
|
361
|
+
height: tileMap.height,
|
|
362
|
+
id: 1,
|
|
363
|
+
name: layer.name,
|
|
364
|
+
opacity: layer.opacity,
|
|
365
|
+
type: "tilelayer",
|
|
366
|
+
visible: layer.visible,
|
|
367
|
+
width: tileMap.width,
|
|
368
|
+
x: 0,
|
|
369
|
+
y: 0
|
|
400
370
|
};
|
|
371
|
+
});
|
|
372
|
+
return {
|
|
373
|
+
type: "map",
|
|
374
|
+
version: "1.10",
|
|
375
|
+
tiledversion: "1.10.2",
|
|
376
|
+
width: tileMap.width,
|
|
377
|
+
height: tileMap.height,
|
|
378
|
+
tilewidth: tileMap.tileWidth,
|
|
379
|
+
tileheight: tileMap.tileHeight,
|
|
380
|
+
layers: layerData,
|
|
381
|
+
tilesets: tilesetData
|
|
382
|
+
};
|
|
401
383
|
};
|
|
402
384
|
const downloadJson = (data, filename) => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
385
|
+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
|
|
386
|
+
const url = URL.createObjectURL(blob);
|
|
387
|
+
const a = document.createElement("a");
|
|
388
|
+
a.href = url;
|
|
389
|
+
a.download = filename;
|
|
390
|
+
a.click();
|
|
391
|
+
URL.revokeObjectURL(url);
|
|
410
392
|
};
|
|
411
393
|
const downloadPng = (canvas, filename) => {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
394
|
+
const url = canvas.toDataURL("image/png");
|
|
395
|
+
const a = document.createElement("a");
|
|
396
|
+
a.href = url;
|
|
397
|
+
a.download = filename;
|
|
398
|
+
a.click();
|
|
417
399
|
};
|
|
418
|
-
/* ────────────────────────────────────────────────────────────────
|
|
419
|
-
PROJECT UTILITIES
|
|
420
|
-
──────────────────────────────────────────────────────────────── */
|
|
421
400
|
const createEmptyProject = (name) => ({
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
401
|
+
id: generateId("project"),
|
|
402
|
+
name,
|
|
403
|
+
tileSets: [],
|
|
404
|
+
tileMaps: [],
|
|
405
|
+
spriteSheets: [],
|
|
406
|
+
stateMachines: [],
|
|
407
|
+
effectPresets: [],
|
|
408
|
+
settings: { ...gameAssetTypes.DEFAULT_PROJECT_SETTINGS }
|
|
430
409
|
});
|
|
431
410
|
const serializeProject = (project) => {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
411
|
+
const serializable = {
|
|
412
|
+
...project,
|
|
413
|
+
tileSets: project.tileSets.map((tile) => ({
|
|
414
|
+
...tile,
|
|
415
|
+
image: null
|
|
416
|
+
// Skip ImageData, use thumbnail
|
|
417
|
+
})),
|
|
418
|
+
spriteSheets: project.spriteSheets.map((sheet) => ({
|
|
419
|
+
...sheet,
|
|
420
|
+
image: null,
|
|
421
|
+
imageData: null
|
|
422
|
+
}))
|
|
423
|
+
};
|
|
424
|
+
return JSON.stringify(serializable, null, 2);
|
|
446
425
|
};
|
|
447
426
|
const deserializeProject = async (json) => {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
tile.image = await dataUrlToImageData(tile.thumbnail);
|
|
453
|
-
}
|
|
427
|
+
const data = JSON.parse(json);
|
|
428
|
+
for (const tile of data.tileSets) {
|
|
429
|
+
if (tile.thumbnail) {
|
|
430
|
+
tile.image = await dataUrlToImageData(tile.thumbnail);
|
|
454
431
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
432
|
+
}
|
|
433
|
+
for (const sheet of data.spriteSheets) {
|
|
434
|
+
if (sheet.dataUrl) {
|
|
435
|
+
sheet.image = await loadImage(sheet.dataUrl);
|
|
436
|
+
sheet.imageData = await dataUrlToImageData(sheet.dataUrl);
|
|
460
437
|
}
|
|
461
|
-
|
|
438
|
+
}
|
|
439
|
+
return data;
|
|
462
440
|
};
|
|
463
|
-
|
|
464
441
|
exports.applyEffect = applyEffect;
|
|
465
442
|
exports.applyEffects = applyEffects;
|
|
466
443
|
exports.autoSliceSpriteSheet = autoSliceSpriteSheet;
|