1681-engine 0.5.9 → 0.6.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/CHANGELOG.md +92 -1
- package/README.md +15 -6
- package/dist/1681-engine.js +588 -465
- package/dist/ai/behaviorTree.js +198 -0
- package/dist/ai/buildTree.js +54 -0
- package/dist/ambient/life/Birds.js +73 -0
- package/dist/ambient/life/Butterflies.js +43 -0
- package/dist/ambient/life/ChimneySmoke.js +50 -0
- package/dist/ambient/life/Drift.js +75 -0
- package/dist/ambient/life/Fireflies.js +52 -0
- package/dist/ambient/life/lifeMotion.js +49 -0
- package/dist/assets/AssetLoader.js +115 -70
- package/dist/assets/Prepainter.js +61 -0
- package/dist/assets/workerPainter.js +39 -0
- package/dist/audio/spatial.js +118 -0
- package/dist/cjs/electron/electronLike.d.ts +55 -0
- package/dist/cjs/electron/electronLike.js +7 -0
- package/dist/cjs/electron/index.d.ts +14 -0
- package/dist/cjs/electron/index.js +20 -0
- package/dist/cjs/electron/lockdown.d.ts +33 -0
- package/dist/cjs/electron/lockdown.js +69 -0
- package/dist/cjs/electron/lockdownRules.d.ts +28 -0
- package/dist/cjs/electron/lockdownRules.js +61 -0
- package/dist/cjs/electron/sessionStore.d.ts +40 -0
- package/dist/cjs/electron/sessionStore.js +77 -0
- package/dist/cjs/electron/shellId.d.ts +22 -0
- package/dist/cjs/electron/shellId.js +31 -0
- package/dist/cjs/electron/webFiles.d.ts +13 -0
- package/dist/cjs/electron/webFiles.js +52 -0
- package/dist/cjs/electron/webPatcher.d.ts +83 -0
- package/dist/cjs/electron/webPatcher.js +223 -0
- package/dist/cjs/electron/webPointers.d.ts +19 -0
- package/dist/cjs/electron/webPointers.js +35 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/updates/index.d.ts +8 -0
- package/dist/cjs/updates/index.js +21 -0
- package/dist/cjs/updates/manifest.d.ts +73 -0
- package/dist/cjs/updates/manifest.js +67 -0
- package/dist/cjs/updates/pickUpdate.d.ts +42 -0
- package/dist/cjs/updates/pickUpdate.js +52 -0
- package/dist/cjs/updates/webPlan.d.ts +20 -0
- package/dist/cjs/updates/webPlan.js +34 -0
- package/dist/dialogue/DialogueRunner.js +173 -0
- package/dist/dialogue/expr.js +137 -0
- package/dist/dialogue/validateDialogue.js +52 -0
- package/dist/ecs/prefab.js +94 -0
- package/dist/electron/lockdown.js +31 -0
- package/dist/electron/lockdownRules.js +42 -0
- package/dist/electron/sessionStore.js +48 -0
- package/dist/electron/shellId.js +18 -0
- package/dist/electron/webFiles.js +36 -0
- package/dist/electron/webPatcher.js +153 -0
- package/dist/electron/webPointers.js +25 -0
- package/dist/electron.js +19 -0
- package/dist/input/Actions.js +58 -27
- package/dist/input/InputCapture.js +98 -0
- package/dist/input/Keymap.js +32 -26
- package/dist/input/haptics.js +50 -0
- package/dist/input/inputTape.js +68 -0
- package/dist/mobile/backButton.js +40 -0
- package/dist/mobile/capacitor.js +48 -0
- package/dist/mobile/screen.js +31 -0
- package/dist/mobile.js +12 -0
- package/dist/nav/flowField.js +58 -0
- package/dist/nav/steering.js +77 -0
- package/dist/net/ApiClient.js +96 -0
- package/dist/net/InterpolationBuffer.js +30 -23
- package/dist/net/LagCompensator.js +100 -0
- package/dist/net/Room.js +122 -43
- package/dist/net/RoomHost.js +13 -4
- package/dist/net/SpatialHash.js +66 -0
- package/dist/pixel/lifeArt.js +83 -0
- package/dist/pixel.js +63 -58
- package/dist/react/ConfirmButton.js +24 -0
- package/dist/react/baseCss.js +1 -0
- package/dist/react/labels.js +7 -6
- package/dist/react/useJsonSelector.js +13 -0
- package/dist/react.js +73 -68
- package/dist/tilemap/TilemapView.js +57 -32
- package/dist/tilemap/autotile.js +103 -0
- package/dist/tilemap/collision.js +29 -18
- package/dist/tilemap/ldtk.js +21 -0
- package/dist/tilemap/ldtkParse.js +191 -0
- package/dist/types/ai/behaviorTree.d.ts +133 -0
- package/dist/types/ai/behaviorTree.d.ts.map +1 -0
- package/dist/types/ai/buildTree.d.ts +55 -0
- package/dist/types/ai/buildTree.d.ts.map +1 -0
- package/dist/types/ambient/life/Birds.d.ts +50 -0
- package/dist/types/ambient/life/Birds.d.ts.map +1 -0
- package/dist/types/ambient/life/Butterflies.d.ts +32 -0
- package/dist/types/ambient/life/Butterflies.d.ts.map +1 -0
- package/dist/types/ambient/life/ChimneySmoke.d.ts +37 -0
- package/dist/types/ambient/life/ChimneySmoke.d.ts.map +1 -0
- package/dist/types/ambient/life/Drift.d.ts +58 -0
- package/dist/types/ambient/life/Drift.d.ts.map +1 -0
- package/dist/types/ambient/life/Fireflies.d.ts +43 -0
- package/dist/types/ambient/life/Fireflies.d.ts.map +1 -0
- package/dist/types/ambient/life/lifeMotion.d.ts +63 -0
- package/dist/types/ambient/life/lifeMotion.d.ts.map +1 -0
- package/dist/types/assets/AssetLoader.d.ts +20 -0
- package/dist/types/assets/AssetLoader.d.ts.map +1 -1
- package/dist/types/assets/Prepainter.d.ts +64 -0
- package/dist/types/assets/Prepainter.d.ts.map +1 -0
- package/dist/types/assets/workerPainter.d.ts +21 -0
- package/dist/types/assets/workerPainter.d.ts.map +1 -0
- package/dist/types/audio/spatial.d.ts +107 -0
- package/dist/types/audio/spatial.d.ts.map +1 -0
- package/dist/types/dialogue/DialogueRunner.d.ts +78 -0
- package/dist/types/dialogue/DialogueRunner.d.ts.map +1 -0
- package/dist/types/dialogue/expr.d.ts +12 -0
- package/dist/types/dialogue/expr.d.ts.map +1 -0
- package/dist/types/dialogue/script.d.ts +78 -0
- package/dist/types/dialogue/script.d.ts.map +1 -0
- package/dist/types/dialogue/validateDialogue.d.ts +21 -0
- package/dist/types/dialogue/validateDialogue.d.ts.map +1 -0
- package/dist/types/ecs/prefab.d.ts +84 -0
- package/dist/types/ecs/prefab.d.ts.map +1 -0
- package/dist/types/electron/electronLike.d.ts +56 -0
- package/dist/types/electron/electronLike.d.ts.map +1 -0
- package/dist/types/electron/index.d.ts +15 -0
- package/dist/types/electron/index.d.ts.map +1 -0
- package/dist/types/electron/lockdown.d.ts +34 -0
- package/dist/types/electron/lockdown.d.ts.map +1 -0
- package/dist/types/electron/lockdownRules.d.ts +29 -0
- package/dist/types/electron/lockdownRules.d.ts.map +1 -0
- package/dist/types/electron/sessionStore.d.ts +41 -0
- package/dist/types/electron/sessionStore.d.ts.map +1 -0
- package/dist/types/electron/shellId.d.ts +23 -0
- package/dist/types/electron/shellId.d.ts.map +1 -0
- package/dist/types/electron/webFiles.d.ts +14 -0
- package/dist/types/electron/webFiles.d.ts.map +1 -0
- package/dist/types/electron/webPatcher.d.ts +84 -0
- package/dist/types/electron/webPatcher.d.ts.map +1 -0
- package/dist/types/electron/webPointers.d.ts +20 -0
- package/dist/types/electron/webPointers.d.ts.map +1 -0
- package/dist/types/index.d.ts +30 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/input/Actions.d.ts +14 -0
- package/dist/types/input/Actions.d.ts.map +1 -1
- package/dist/types/input/InputCapture.d.ts +53 -0
- package/dist/types/input/InputCapture.d.ts.map +1 -0
- package/dist/types/input/Keymap.d.ts +12 -6
- package/dist/types/input/Keymap.d.ts.map +1 -1
- package/dist/types/input/haptics.d.ts +42 -0
- package/dist/types/input/haptics.d.ts.map +1 -0
- package/dist/types/input/inputTape.d.ts +66 -0
- package/dist/types/input/inputTape.d.ts.map +1 -0
- package/dist/types/mobile/backButton.d.ts +30 -0
- package/dist/types/mobile/backButton.d.ts.map +1 -0
- package/dist/types/mobile/capacitor.d.ts +62 -0
- package/dist/types/mobile/capacitor.d.ts.map +1 -0
- package/dist/types/mobile/index.d.ts +4 -0
- package/dist/types/mobile/index.d.ts.map +1 -0
- package/dist/types/mobile/screen.d.ts +27 -0
- package/dist/types/mobile/screen.d.ts.map +1 -0
- package/dist/types/nav/flowField.d.ts +31 -0
- package/dist/types/nav/flowField.d.ts.map +1 -0
- package/dist/types/nav/steering.d.ts +47 -0
- package/dist/types/nav/steering.d.ts.map +1 -0
- package/dist/types/net/ApiClient.d.ts +74 -0
- package/dist/types/net/ApiClient.d.ts.map +1 -0
- package/dist/types/net/InterpolationBuffer.d.ts +5 -0
- package/dist/types/net/InterpolationBuffer.d.ts.map +1 -1
- package/dist/types/net/LagCompensator.d.ts +70 -0
- package/dist/types/net/LagCompensator.d.ts.map +1 -0
- package/dist/types/net/Room.d.ts +72 -3
- package/dist/types/net/Room.d.ts.map +1 -1
- package/dist/types/net/RoomHost.d.ts +8 -3
- package/dist/types/net/RoomHost.d.ts.map +1 -1
- package/dist/types/net/SpatialHash.d.ts +25 -0
- package/dist/types/net/SpatialHash.d.ts.map +1 -0
- package/dist/types/pixel/index.d.ts +1 -0
- package/dist/types/pixel/index.d.ts.map +1 -1
- package/dist/types/pixel/lifeArt.d.ts +63 -0
- package/dist/types/pixel/lifeArt.d.ts.map +1 -0
- package/dist/types/react/ConfirmButton.d.ts +26 -0
- package/dist/types/react/ConfirmButton.d.ts.map +1 -0
- package/dist/types/react/baseCss.d.ts +1 -1
- package/dist/types/react/baseCss.d.ts.map +1 -1
- package/dist/types/react/index.d.ts +2 -0
- package/dist/types/react/index.d.ts.map +1 -1
- package/dist/types/react/labels.d.ts +2 -0
- package/dist/types/react/labels.d.ts.map +1 -1
- package/dist/types/react/useJsonSelector.d.ts +13 -0
- package/dist/types/react/useJsonSelector.d.ts.map +1 -0
- package/dist/types/tilemap/TilemapView.d.ts +17 -0
- package/dist/types/tilemap/TilemapView.d.ts.map +1 -1
- package/dist/types/tilemap/autotile.d.ts +95 -0
- package/dist/types/tilemap/autotile.d.ts.map +1 -0
- package/dist/types/tilemap/collision.d.ts +8 -0
- package/dist/types/tilemap/collision.d.ts.map +1 -1
- package/dist/types/tilemap/ldtk.d.ts +97 -0
- package/dist/types/tilemap/ldtk.d.ts.map +1 -0
- package/dist/types/tilemap/ldtkParse.d.ts +26 -0
- package/dist/types/tilemap/ldtkParse.d.ts.map +1 -0
- package/dist/types/ui/ScrollView.d.ts.map +1 -1
- package/dist/types/updates/index.d.ts +9 -0
- package/dist/types/updates/index.d.ts.map +1 -0
- package/dist/types/updates/manifest.d.ts +74 -0
- package/dist/types/updates/manifest.d.ts.map +1 -0
- package/dist/types/updates/pickUpdate.d.ts +43 -0
- package/dist/types/updates/pickUpdate.d.ts.map +1 -0
- package/dist/types/updates/webPlan.d.ts +21 -0
- package/dist/types/updates/webPlan.d.ts.map +1 -0
- package/dist/ui/ScrollView.js +10 -8
- package/dist/updates/manifest.js +35 -0
- package/dist/updates/pickUpdate.js +27 -0
- package/dist/updates/webPlan.js +14 -0
- package/dist/updates.js +15 -0
- package/package.json +35 -3
package/dist/react.js
CHANGED
|
@@ -1,77 +1,82 @@
|
|
|
1
1
|
import { UiProvider as r, defaultUiSettings as t, useCx as i, useUi as p } from "./react/UiProvider.js";
|
|
2
|
-
import { classJoiner as
|
|
3
|
-
import { DEFAULT_LABELS as
|
|
4
|
-
import { baseCss as
|
|
2
|
+
import { classJoiner as f } from "./react/classNames.js";
|
|
3
|
+
import { DEFAULT_LABELS as l, fillLabel as x } from "./react/labels.js";
|
|
4
|
+
import { baseCss as n, injectBaseCss as c } from "./react/baseCss.js";
|
|
5
5
|
import { useStore as C } from "./react/useStore.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
6
|
+
import { useJsonSelector as h, useStoreJson as y } from "./react/useJsonSelector.js";
|
|
7
|
+
import { useViewport as L } from "./react/useViewport.js";
|
|
8
|
+
import { SCROLL_CLASS as P, useFitToViewport as g } from "./react/useFitToViewport.js";
|
|
9
|
+
import { useFillSheet as k } from "./react/useFillSheet.js";
|
|
10
|
+
import { SPLIT_STACK_BELOW as A, cursorTip as B, listPlacement as E, pixelFit as U, sheetScaleStyle as _, splitModeFor as b, windowStyle as D } from "./react/placement.js";
|
|
11
|
+
import { Panel as J } from "./react/Panel.js";
|
|
12
|
+
import { TabStrip as V } from "./react/TabStrip.js";
|
|
13
|
+
import { SplitPane as K } from "./react/SplitPane.js";
|
|
14
|
+
import { pickedEntry as Q, usePicked as j } from "./react/usePicked.js";
|
|
15
|
+
import { Select as R, stepOption as W } from "./react/Select.js";
|
|
16
|
+
import { Tooltip as z } from "./react/Tooltip.js";
|
|
17
|
+
import { TitleTips as N } from "./react/TitleTips.js";
|
|
18
|
+
import { Modal as Y } from "./react/Modal.js";
|
|
19
|
+
import { ConfirmDialog as $ } from "./react/ConfirmDialog.js";
|
|
20
|
+
import { ConfirmButton as oe } from "./react/ConfirmButton.js";
|
|
21
|
+
import { answerConfirm as te, askConfirm as ie, askQuantity as pe, cancelConfirm as se, confirmStore as fe, parseQuantity as me } from "./react/confirmStore.js";
|
|
22
|
+
import { ChoiceDialog as xe } from "./react/ChoiceDialog.js";
|
|
23
|
+
import { answerChoice as ne, askChoice as ce, cancelChoice as Se, choiceStore as Ce, firstChoice as ue } from "./react/choiceStore.js";
|
|
24
|
+
import { Slider as ye, sliderKeyValue as de } from "./react/Slider.js";
|
|
25
|
+
import { PixelImage as Te } from "./react/PixelImage.js";
|
|
26
|
+
import { Glyph as ge, glyphPath as we, hasGlyph as ke, registerGlyph as Fe } from "./react/Glyph.js";
|
|
25
27
|
export {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
xe as ChoiceDialog,
|
|
29
|
+
oe as ConfirmButton,
|
|
30
|
+
$ as ConfirmDialog,
|
|
31
|
+
l as DEFAULT_LABELS,
|
|
32
|
+
ge as Glyph,
|
|
33
|
+
Y as Modal,
|
|
34
|
+
J as Panel,
|
|
35
|
+
Te as PixelImage,
|
|
36
|
+
P as SCROLL_CLASS,
|
|
37
|
+
A as SPLIT_STACK_BELOW,
|
|
38
|
+
R as Select,
|
|
39
|
+
ye as Slider,
|
|
40
|
+
K as SplitPane,
|
|
41
|
+
V as TabStrip,
|
|
42
|
+
N as TitleTips,
|
|
43
|
+
z as Tooltip,
|
|
41
44
|
r as UiProvider,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
ne as answerChoice,
|
|
46
|
+
te as answerConfirm,
|
|
47
|
+
ce as askChoice,
|
|
48
|
+
ie as askConfirm,
|
|
49
|
+
pe as askQuantity,
|
|
50
|
+
n as baseCss,
|
|
51
|
+
Se as cancelChoice,
|
|
52
|
+
se as cancelConfirm,
|
|
53
|
+
Ce as choiceStore,
|
|
54
|
+
f as classJoiner,
|
|
55
|
+
fe as confirmStore,
|
|
56
|
+
B as cursorTip,
|
|
54
57
|
t as defaultUiSettings,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
x as fillLabel,
|
|
59
|
+
ue as firstChoice,
|
|
60
|
+
we as glyphPath,
|
|
61
|
+
ke as hasGlyph,
|
|
62
|
+
c as injectBaseCss,
|
|
63
|
+
E as listPlacement,
|
|
64
|
+
me as parseQuantity,
|
|
65
|
+
Q as pickedEntry,
|
|
66
|
+
U as pixelFit,
|
|
67
|
+
Fe as registerGlyph,
|
|
68
|
+
_ as sheetScaleStyle,
|
|
69
|
+
de as sliderKeyValue,
|
|
70
|
+
b as splitModeFor,
|
|
71
|
+
W as stepOption,
|
|
69
72
|
i as useCx,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
k as useFillSheet,
|
|
74
|
+
g as useFitToViewport,
|
|
75
|
+
h as useJsonSelector,
|
|
76
|
+
j as usePicked,
|
|
73
77
|
C as useStore,
|
|
78
|
+
y as useStoreJson,
|
|
74
79
|
p as useUi,
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
L as useViewport,
|
|
81
|
+
D as windowStyle
|
|
77
82
|
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Container as
|
|
2
|
-
import { tileAt as
|
|
3
|
-
let
|
|
4
|
-
class
|
|
1
|
+
import { Container as C, Sprite as F } from "pixi.js";
|
|
2
|
+
import { tileAt as I, tileRect as T, FLIP_D as P, FLIP_H as H, FLIP_V as S } from "./tiled.js";
|
|
3
|
+
let V = 0;
|
|
4
|
+
class _ {
|
|
5
5
|
constructor(s, i, e = {}) {
|
|
6
6
|
this.stage = s, this.map = i;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
for (let
|
|
12
|
-
for (let
|
|
13
|
-
const
|
|
14
|
-
this.paintChunk(t,
|
|
7
|
+
const l = this.textureFor = e.textureFor ?? ((t) => t.name), h = this.chunkTiles = Math.max(1, e.chunkTiles ?? 32), o = e.baseDepth ?? -1e6, f = e.layers ? new Set(e.layers) : null, n = i.layers.filter((t) => t.kind === "tiles" && (f ? f.has(t.name) : t.visible)), c = e.parent ?? s.world;
|
|
8
|
+
this.originX = e.x ?? 0, this.originY = e.y ?? 0, n.forEach((t, x) => {
|
|
9
|
+
const w = typeof t.properties.depth == "number" ? t.properties.depth : o + x, r = new C();
|
|
10
|
+
r.zIndex = w, r.sortableChildren = !0, r.alpha = t.opacity, r.position.set(this.originX + t.offsetX, this.originY + t.offsetY), this.layers.set(t.name, r), this.drawn.set(t.name, t), c.addChild(r);
|
|
11
|
+
for (let d = 0; d < i.height; d += h)
|
|
12
|
+
for (let p = 0; p < i.width; p += h) {
|
|
13
|
+
const u = Math.min(h, i.width - p), m = Math.min(h, i.height - d);
|
|
14
|
+
this.paintChunk(t, r, p, d, u, m, l);
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
}
|
|
@@ -20,13 +20,38 @@ class T {
|
|
|
20
20
|
/** One container per drawn tile layer, by name, each at its own depth among the bodies. */
|
|
21
21
|
layers = /* @__PURE__ */ new Map();
|
|
22
22
|
chunks = [];
|
|
23
|
-
id =
|
|
23
|
+
id = V++;
|
|
24
|
+
chunkTiles;
|
|
25
|
+
textureFor;
|
|
26
|
+
drawn = /* @__PURE__ */ new Map();
|
|
27
|
+
originX;
|
|
28
|
+
originY;
|
|
24
29
|
/** Shows only the chunks in the camera's view (plus a margin in world px). Call once a frame. */
|
|
25
30
|
update(s = 32) {
|
|
26
31
|
const i = this.stage.cameras.main.worldView;
|
|
27
32
|
for (const e of this.chunks)
|
|
28
33
|
e.sprite.visible = e.x < i.right + s && e.x + e.w > i.x - s && e.y < i.bottom + s && e.y + e.h > i.y - s;
|
|
29
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Repaints the chunks holding these cells (row-major indices) of a drawn layer, after its `data` changed: a door
|
|
37
|
+
* opening, a wall dug out, a cell autotiled again (`updateAutotile` returns exactly the indices to pass). Costs one
|
|
38
|
+
* chunk's painting per chunk touched, so keep it out of every frame.
|
|
39
|
+
*/
|
|
40
|
+
refreshTiles(s, i) {
|
|
41
|
+
const e = this.drawn.get(s), l = this.layers.get(s);
|
|
42
|
+
if (!e || !l) return;
|
|
43
|
+
const { map: h, chunkTiles: o } = this, f = /* @__PURE__ */ new Set();
|
|
44
|
+
for (const n of i)
|
|
45
|
+
n < 0 || n >= h.width * h.height || f.add(`${Math.floor(n % h.width / o) * o},${Math.floor(Math.floor(n / h.width) / o) * o}`);
|
|
46
|
+
for (const n of f) {
|
|
47
|
+
const [c, t] = n.split(",").map(Number), x = `tilemap:${this.id}:${e.name}:${c},${t}`, w = this.chunks.findIndex((r) => r.key === x);
|
|
48
|
+
if (w >= 0) {
|
|
49
|
+
const [r] = this.chunks.splice(w, 1);
|
|
50
|
+
r.sprite.destroy(), this.stage.textures.remove(x);
|
|
51
|
+
}
|
|
52
|
+
this.paintChunk(e, l, c, t, Math.min(o, h.width - c), Math.min(o, h.height - t), this.textureFor);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
30
55
|
/** World size of the map in px. */
|
|
31
56
|
get widthPx() {
|
|
32
57
|
return this.map.width * this.map.tileWidth;
|
|
@@ -40,29 +65,29 @@ class T {
|
|
|
40
65
|
for (const s of this.layers.values()) s.destroy({ children: !0 });
|
|
41
66
|
this.layers.clear();
|
|
42
67
|
}
|
|
43
|
-
paintChunk(s, i, e,
|
|
44
|
-
const { map:
|
|
45
|
-
let
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
for (let
|
|
49
|
-
for (let
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
const
|
|
55
|
-
|
|
68
|
+
paintChunk(s, i, e, l, h, o, f) {
|
|
69
|
+
const { map: n } = this, c = n.tileWidth, t = n.tileHeight;
|
|
70
|
+
let x = !1;
|
|
71
|
+
const w = `tilemap:${this.id}:${s.name}:${e},${l}`, d = Math.max(t, ...n.tilesets.map((g) => g.tileHeight)) - t, p = this.stage.textures.createCanvas(w, h * c, o * t + d), u = p.context;
|
|
72
|
+
u.imageSmoothingEnabled = !1;
|
|
73
|
+
for (let g = 0; g < o; g++)
|
|
74
|
+
for (let y = 0; y < h; y++) {
|
|
75
|
+
const M = s.data[(l + g) * n.width + (e + y)], k = I(n, M);
|
|
76
|
+
if (!k) continue;
|
|
77
|
+
const $ = this.stage.textures.exists(f(k.tileset)) ? this.stage.textures.get(f(k.tileset)).source.resource : null;
|
|
78
|
+
if (!$) continue;
|
|
79
|
+
const a = T(k.tileset, k.local), b = y * c, v = d + (g + 1) * t - a.h;
|
|
80
|
+
u.save(), u.translate(b + a.w / 2, v + a.h / 2), M & P && u.transform(0, 1, 1, 0, 0, 0), u.scale(M & H ? -1 : 1, M & S ? -1 : 1), u.drawImage($, a.x, a.y, a.w, a.h, -a.w / 2, -a.h / 2, a.w, a.h), u.restore(), x = !0;
|
|
56
81
|
}
|
|
57
|
-
if (!
|
|
58
|
-
this.stage.textures.remove(
|
|
82
|
+
if (!x) {
|
|
83
|
+
this.stage.textures.remove(w);
|
|
59
84
|
return;
|
|
60
85
|
}
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
86
|
+
p.refresh();
|
|
87
|
+
const m = new F(p.whole);
|
|
88
|
+
m.position.set(e * c, l * t - d), m.zIndex = l * n.width + e, i.addChild(m), this.chunks.push({ sprite: m, x: m.x + i.x, y: m.y + i.y, w: h * c, h: o * t + d, key: w });
|
|
64
89
|
}
|
|
65
90
|
}
|
|
66
91
|
export {
|
|
67
|
-
|
|
92
|
+
_ as TilemapView
|
|
68
93
|
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const G = 1, d = 2, m = 4, A = 8, j = 1, T = 2, U = 4, v = 8, I = 16, F = 32, H = 64, K = 128;
|
|
2
|
+
function f(t) {
|
|
3
|
+
let n = t & 85;
|
|
4
|
+
return t & 2 && t & 1 && t & 4 && (n |= 2), t & 8 && t & 16 && t & 4 && (n |= 8), t & 32 && t & 16 && t & 64 && (n |= 32), t & 128 && t & 1 && t & 64 && (n |= 128), n;
|
|
5
|
+
}
|
|
6
|
+
const S = (() => {
|
|
7
|
+
const t = /* @__PURE__ */ new Set();
|
|
8
|
+
for (let n = 0; n < 256; n++) t.add(f(n));
|
|
9
|
+
return [...t].sort((n, e) => n - e);
|
|
10
|
+
})(), w = new Map(S.map((t, n) => [t, n]));
|
|
11
|
+
function R(t) {
|
|
12
|
+
return w.get(f(t));
|
|
13
|
+
}
|
|
14
|
+
const N = [
|
|
15
|
+
[0, -1, 1],
|
|
16
|
+
[1, -1, 2],
|
|
17
|
+
[1, 0, 4],
|
|
18
|
+
[1, 1, 8],
|
|
19
|
+
[0, 1, 16],
|
|
20
|
+
[-1, 1, 32],
|
|
21
|
+
[-1, 0, 64],
|
|
22
|
+
[-1, -1, 128]
|
|
23
|
+
];
|
|
24
|
+
function _(t, n, e, o, B) {
|
|
25
|
+
if (e < 0 || o < 0 || e >= t.width || o >= t.height) return (B.edge ?? "same") === "same";
|
|
26
|
+
const c = t.cells[o * t.width + e];
|
|
27
|
+
return B.joins ? B.joins(n, c) : c === n;
|
|
28
|
+
}
|
|
29
|
+
function a(t, n, e, o = {}) {
|
|
30
|
+
const B = t.cells[e * t.width + n];
|
|
31
|
+
return (_(t, B, n, e - 1, o) ? 1 : 0) | (_(t, B, n + 1, e, o) ? 2 : 0) | (_(t, B, n, e + 1, o) ? 4 : 0) | (_(t, B, n - 1, e, o) ? 8 : 0);
|
|
32
|
+
}
|
|
33
|
+
function W(t, n, e, o = {}) {
|
|
34
|
+
const B = t.cells[e * t.width + n];
|
|
35
|
+
let c = 0;
|
|
36
|
+
for (const [l, u, s] of N) _(t, B, n + l, e + u, o) && (c |= s);
|
|
37
|
+
return f(c);
|
|
38
|
+
}
|
|
39
|
+
function b(t, n) {
|
|
40
|
+
let e = Math.imul(t, 668265261) ^ Math.imul(n, 374761393);
|
|
41
|
+
return e ^= e >>> 15, e = Math.imul(e, 739982445), (e ^ e >>> 12) >>> 0;
|
|
42
|
+
}
|
|
43
|
+
const p = { edges: 15, blob: 255 }, h = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
function D(t) {
|
|
45
|
+
let n = h.get(t);
|
|
46
|
+
if (n) return n;
|
|
47
|
+
n = /* @__PURE__ */ new Map();
|
|
48
|
+
for (const e of t.rules) {
|
|
49
|
+
const o = e.connectsTo ? new Set(e.connectsTo) : null, B = { edge: t.edge ?? "same" };
|
|
50
|
+
o && (B.joins = (c, l) => l === c || o.has(l)), n.set(e.terrain, { rule: e, options: B });
|
|
51
|
+
}
|
|
52
|
+
return h.set(t, n), n;
|
|
53
|
+
}
|
|
54
|
+
function E(t, n, e) {
|
|
55
|
+
return t === void 0 || typeof t == "number" ? t : t.length ? t[b(n, e) % t.length] : void 0;
|
|
56
|
+
}
|
|
57
|
+
function r(t, n, e, o) {
|
|
58
|
+
const B = D(n).get(t.cells[o * t.width + e]);
|
|
59
|
+
if (!B) return n.empty ?? 0;
|
|
60
|
+
const c = B.rule.mode ?? "blob", l = c === "blob" ? W(t, e, o, B.options) : a(t, e, o, B.options), { tiles: u } = B.rule;
|
|
61
|
+
return typeof u == "function" ? u(l, e, o) : E(u[l], e, o) ?? B.rule.fallback ?? E(u[p[c]], e, o) ?? n.empty ?? 0;
|
|
62
|
+
}
|
|
63
|
+
function X(t, n, e = new Uint32Array(t.width * t.height)) {
|
|
64
|
+
for (let o = 0; o < t.height; o++) for (let B = 0; B < t.width; B++) e[o * t.width + B] = r(t, n, B, o);
|
|
65
|
+
return e;
|
|
66
|
+
}
|
|
67
|
+
function M(t, n, e, o, B) {
|
|
68
|
+
const c = [];
|
|
69
|
+
for (let l = -1; l <= 1; l++)
|
|
70
|
+
for (let u = -1; u <= 1; u++) {
|
|
71
|
+
const s = o + u, i = B + l;
|
|
72
|
+
if (s < 0 || i < 0 || s >= t.width || i >= t.height) continue;
|
|
73
|
+
const L = i * t.width + s, O = r(t, n, s, i);
|
|
74
|
+
e[L] !== O && (e[L] = O, c.push(L));
|
|
75
|
+
}
|
|
76
|
+
return c;
|
|
77
|
+
}
|
|
78
|
+
function q(t, n, e, o, B, c) {
|
|
79
|
+
return o < 0 || B < 0 || o >= t.width || B >= t.height ? [] : (t.cells[B * t.width + o] = c, M(t, n, e, o, B));
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
S as BLOB47_MASKS,
|
|
83
|
+
U as BLOB_E,
|
|
84
|
+
j as BLOB_N,
|
|
85
|
+
T as BLOB_NE,
|
|
86
|
+
K as BLOB_NW,
|
|
87
|
+
I as BLOB_S,
|
|
88
|
+
v as BLOB_SE,
|
|
89
|
+
F as BLOB_SW,
|
|
90
|
+
H as BLOB_W,
|
|
91
|
+
d as EDGE_E,
|
|
92
|
+
G as EDGE_N,
|
|
93
|
+
m as EDGE_S,
|
|
94
|
+
A as EDGE_W,
|
|
95
|
+
X as autotile,
|
|
96
|
+
r as autotileAt,
|
|
97
|
+
R as blob47Index,
|
|
98
|
+
W as blobMask,
|
|
99
|
+
a as edgeMask,
|
|
100
|
+
q as paintTerrain,
|
|
101
|
+
f as reduceBlobMask,
|
|
102
|
+
M as updateAutotile
|
|
103
|
+
};
|
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
import { createCollisionGrid as
|
|
2
|
-
import { gidOf as
|
|
3
|
-
function
|
|
4
|
-
if (
|
|
5
|
-
const
|
|
6
|
-
if (typeof
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
9
|
-
for (let
|
|
1
|
+
import { createCollisionGrid as h } from "../net/movement.js";
|
|
2
|
+
import { gidOf as u, tileAt as a } from "./tiled.js";
|
|
3
|
+
function g(e, l = {}) {
|
|
4
|
+
if (e.tileWidth !== e.tileHeight) throw new Error(`Tiled map: collision needs square tiles, not ${e.tileWidth}x${e.tileHeight}`);
|
|
5
|
+
const n = l.solid ?? (e.layers.some((t) => t.kind === "tiles" && t.name === "collision") ? "collision" : { property: "solid" }), r = e.width * e.height, s = new Uint8Array(r);
|
|
6
|
+
if (typeof n == "string") {
|
|
7
|
+
const t = e.layers.find((i) => i.kind === "tiles" && i.name === n);
|
|
8
|
+
if (!t || t.kind !== "tiles") throw new Error(`Tiled map: no tile layer named "${n}"`);
|
|
9
|
+
for (let i = 0; i < r; i++) u(t.data[i]) !== 0 && (s[i] = 1);
|
|
10
10
|
} else
|
|
11
|
-
for (const
|
|
12
|
-
if (
|
|
13
|
-
for (let
|
|
14
|
-
const
|
|
15
|
-
|
|
11
|
+
for (const t of e.layers)
|
|
12
|
+
if (t.kind === "tiles")
|
|
13
|
+
for (let i = 0; i < r; i++) {
|
|
14
|
+
const f = a(e, t.data[i]);
|
|
15
|
+
f && f.tileset.tileProperties.get(f.local)?.[n.property] === !0 && (s[i] = 1);
|
|
16
16
|
}
|
|
17
17
|
let d = "";
|
|
18
|
-
for (let
|
|
19
|
-
const { solid:
|
|
20
|
-
return
|
|
18
|
+
for (let t = 0; t < r; t++) d += s[t] ? "1" : "0";
|
|
19
|
+
const { solid: c, ...o } = l;
|
|
20
|
+
return h(e.width, e.height, e.tileWidth, d, o);
|
|
21
|
+
}
|
|
22
|
+
function k(e, l, n = {}) {
|
|
23
|
+
const r = typeof l == "function" ? l : (c) => l.includes(c), s = /* @__PURE__ */ new Map();
|
|
24
|
+
let d = "";
|
|
25
|
+
for (let c = 0; c < e.values.length; c++) {
|
|
26
|
+
const o = e.values[c];
|
|
27
|
+
let t = s.get(o);
|
|
28
|
+
t === void 0 && s.set(o, t = o !== 0 && r(o, e.names.get(o))), d += t ? "1" : "0";
|
|
29
|
+
}
|
|
30
|
+
return h(e.width, e.height, e.gridSize, d, n);
|
|
21
31
|
}
|
|
22
32
|
export {
|
|
23
|
-
|
|
33
|
+
k as collisionFromIntGrid,
|
|
34
|
+
g as collisionFromTiled
|
|
24
35
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function o(i, t) {
|
|
2
|
+
return i.levels.find((e) => e.identifier === t || e.iid === t);
|
|
3
|
+
}
|
|
4
|
+
function l(i, t, e, r) {
|
|
5
|
+
for (const n of i)
|
|
6
|
+
if (!(r !== void 0 && n.worldDepth !== r) && t >= n.worldX && e >= n.worldY && t < n.worldX + n.pxWidth && e < n.worldY + n.pxHeight)
|
|
7
|
+
return n;
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
function u(i, t, e) {
|
|
11
|
+
return t < 0 || e < 0 || t >= i.width || e >= i.height ? 0 : i.values[e * i.width + t];
|
|
12
|
+
}
|
|
13
|
+
function f(i, t) {
|
|
14
|
+
return t === void 0 ? i.entities : i.entities.filter((e) => e.identifier === t);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
f as entitiesOf,
|
|
18
|
+
u as intGridAt,
|
|
19
|
+
l as levelAt,
|
|
20
|
+
o as levelByName
|
|
21
|
+
};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { FLIP_H as z, FLIP_V as M } from "./tiled.js";
|
|
2
|
+
class G extends Error {
|
|
3
|
+
constructor(n) {
|
|
4
|
+
super(`LDtk project: ${n}`);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function c(e, n) {
|
|
8
|
+
if (typeof e != "number" || !Number.isFinite(e)) throw new G(`${n} must be a number`);
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
function L(e) {
|
|
12
|
+
const n = {};
|
|
13
|
+
if (Array.isArray(e))
|
|
14
|
+
for (const r of e) r && typeof r.__identifier == "string" && (n[r.__identifier] = r.__value ?? null);
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
function N(e) {
|
|
18
|
+
const n = {};
|
|
19
|
+
for (const [r, o] of Object.entries(e)) (typeof o == "string" || typeof o == "number" || typeof o == "boolean") && (n[r] = o);
|
|
20
|
+
return n;
|
|
21
|
+
}
|
|
22
|
+
function W(e) {
|
|
23
|
+
return Array.isArray(e.worlds) && e.worlds.length ? e.worlds : [{ identifier: "World", iid: "", worldLayout: e.worldLayout, worldGridWidth: e.worldGridWidth, worldGridHeight: e.worldGridHeight, levels: e.levels ?? [] }];
|
|
24
|
+
}
|
|
25
|
+
function R(e) {
|
|
26
|
+
const n = e;
|
|
27
|
+
if (!n || typeof n != "object") return [];
|
|
28
|
+
const r = [];
|
|
29
|
+
for (const o of W(n)) for (const t of o.levels ?? []) typeof t.externalRelPath == "string" && !Array.isArray(t.layerInstances) && r.push(t.externalRelPath);
|
|
30
|
+
return r;
|
|
31
|
+
}
|
|
32
|
+
function A(e) {
|
|
33
|
+
const n = [], r = /* @__PURE__ */ new Map();
|
|
34
|
+
let o = 1;
|
|
35
|
+
for (const t of e?.tilesets ?? []) {
|
|
36
|
+
if (typeof t.relPath != "string") continue;
|
|
37
|
+
const a = c(t.tileGridSize, `tileset "${t.identifier}" tileGridSize`), d = c(t.__cWid, `tileset "${t.identifier}" __cWid`), s = d * c(t.__cHei, `tileset "${t.identifier}" __cHei`), l = /* @__PURE__ */ new Map(), p = (i) => l.get(i) ?? (l.set(i, {}), l.get(i));
|
|
38
|
+
for (const i of t.customData ?? []) typeof i.tileId == "number" && typeof i.data == "string" && (p(i.tileId).data = i.data);
|
|
39
|
+
for (const i of t.enumTags ?? []) for (const g of i.tileIds ?? []) typeof i.enumValueId == "string" && (p(g)[i.enumValueId] = !0);
|
|
40
|
+
const u = {
|
|
41
|
+
name: String(t.identifier ?? `tileset${t.uid}`),
|
|
42
|
+
firstGid: o,
|
|
43
|
+
image: t.relPath,
|
|
44
|
+
imageWidth: c(t.pxWid, `tileset "${t.identifier}" pxWid`),
|
|
45
|
+
imageHeight: c(t.pxHei, `tileset "${t.identifier}" pxHei`),
|
|
46
|
+
tileWidth: a,
|
|
47
|
+
tileHeight: a,
|
|
48
|
+
columns: d,
|
|
49
|
+
tileCount: s,
|
|
50
|
+
margin: Number(t.padding ?? 0),
|
|
51
|
+
spacing: Number(t.spacing ?? 0),
|
|
52
|
+
tileProperties: l,
|
|
53
|
+
animations: /* @__PURE__ */ new Map(),
|
|
54
|
+
properties: {}
|
|
55
|
+
};
|
|
56
|
+
n.push(u), r.set(c(t.uid, "tileset uid"), u), o += s;
|
|
57
|
+
}
|
|
58
|
+
return { tilesets: n, byUid: r };
|
|
59
|
+
}
|
|
60
|
+
function T(e, n, r, o, t, a, d) {
|
|
61
|
+
const s = [], l = (u) => {
|
|
62
|
+
for (; s.length <= u; )
|
|
63
|
+
s.push({
|
|
64
|
+
kind: "tiles",
|
|
65
|
+
name: s.length ? `${n}#${s.length}` : n,
|
|
66
|
+
data: new Uint32Array(t * a),
|
|
67
|
+
visible: e.visible !== !1,
|
|
68
|
+
opacity: typeof e.__opacity == "number" ? e.__opacity : 1,
|
|
69
|
+
offsetX: Number(e.__pxTotalOffsetX ?? 0),
|
|
70
|
+
offsetY: Number(e.__pxTotalOffsetY ?? 0),
|
|
71
|
+
properties: {}
|
|
72
|
+
});
|
|
73
|
+
return s[u];
|
|
74
|
+
}, p = new Uint8Array(t * a);
|
|
75
|
+
for (const u of r) {
|
|
76
|
+
const i = Math.floor(c(u.px?.[0], `layer "${n}" tile px`) / d), g = Math.floor(c(u.px?.[1], `layer "${n}" tile px`) / d);
|
|
77
|
+
if (i < 0 || g < 0 || i >= t || g >= a) continue;
|
|
78
|
+
const h = c(u.t, `layer "${n}" tile id`);
|
|
79
|
+
if (h < 0 || h >= o.tileCount) continue;
|
|
80
|
+
const m = g * t + i, b = Number(u.f ?? 0), y = (o.firstGid + h | (b & 1 ? z : 0) | (b & 2 ? M : 0)) >>> 0;
|
|
81
|
+
l(p[m]).data[m] = y, p[m] = Math.min(255, p[m] + 1);
|
|
82
|
+
}
|
|
83
|
+
return s.length || l(0), s;
|
|
84
|
+
}
|
|
85
|
+
function X(e, n) {
|
|
86
|
+
const r = /* @__PURE__ */ new Map(), o = (e?.layers ?? []).find((t) => t.uid === n);
|
|
87
|
+
for (const t of o?.intGridValues ?? []) typeof t.value == "number" && typeof t.identifier == "string" && t.identifier && r.set(t.value, t.identifier);
|
|
88
|
+
return r;
|
|
89
|
+
}
|
|
90
|
+
function Y(e, n, r, o, t) {
|
|
91
|
+
const a = n.filter((i) => i.__type !== "Entities"), d = a.length ? c(a[0].__gridSize, "layer __gridSize") : t;
|
|
92
|
+
for (const i of a)
|
|
93
|
+
if (i.__gridSize !== d) throw new G(`level "${e.identifier}" layer "${i.__identifier}" has a ${i.__gridSize} px grid, not ${d}: every tile and IntGrid layer of a level must share one grid`);
|
|
94
|
+
const s = a.length ? Math.max(...a.map((i) => c(i.__cWid, "layer __cWid"))) : Math.ceil(e.pxWidth / d), l = a.length ? Math.max(...a.map((i) => c(i.__cHei, "layer __cHei"))) : Math.ceil(e.pxHeight / d), p = [];
|
|
95
|
+
let u = 1;
|
|
96
|
+
for (const i of [...n].reverse()) {
|
|
97
|
+
const g = String(i.__identifier ?? ""), h = i.__type, m = Number(i.__pxTotalOffsetX ?? 0), b = Number(i.__pxTotalOffsetY ?? 0);
|
|
98
|
+
if (h === "IntGrid") {
|
|
99
|
+
const y = c(i.__cWid, "layer __cWid"), f = c(i.__cHei, "layer __cHei"), _ = i.intGridCsv;
|
|
100
|
+
if (!Array.isArray(_) || _.length !== y * f) throw new G(`layer "${g}" must hold ${y * f} IntGrid cells`);
|
|
101
|
+
const w = { name: g, width: y, height: f, gridSize: d, values: Int32Array.from(_), names: X(r, i.layerDefUid), offsetX: m, offsetY: b };
|
|
102
|
+
e.intGrids.set(g, w);
|
|
103
|
+
}
|
|
104
|
+
if (h === "IntGrid" || h === "AutoLayer" || h === "Tiles") {
|
|
105
|
+
const y = h === "Tiles" ? i.gridTiles ?? [] : i.autoLayerTiles ?? [], f = i.overrideTilesetUid ?? i.__tilesetDefUid, _ = typeof f == "number" ? o.get(f) : void 0;
|
|
106
|
+
_ && (h !== "IntGrid" || y.length) && p.push(...T(i, g, y, _, s, l, d));
|
|
107
|
+
} else if (h === "Entities") {
|
|
108
|
+
const y = [];
|
|
109
|
+
for (const f of i.entityInstances ?? []) {
|
|
110
|
+
const _ = L(f.fieldInstances), w = Number(f.width ?? 0), x = Number(f.height ?? 0), $ = Number(f.__pivot?.[0] ?? 0), I = Number(f.__pivot?.[1] ?? 0), v = c(f.px?.[0], `entity "${f.__identifier}" px`) + m, H = c(f.px?.[1], `entity "${f.__identifier}" px`) + b, S = {
|
|
111
|
+
iid: String(f.iid ?? ""),
|
|
112
|
+
identifier: String(f.__identifier ?? ""),
|
|
113
|
+
x: v,
|
|
114
|
+
y: H,
|
|
115
|
+
width: w,
|
|
116
|
+
height: x,
|
|
117
|
+
pivotX: $,
|
|
118
|
+
pivotY: I,
|
|
119
|
+
cx: Number(f.__grid?.[0] ?? Math.floor(v / d)),
|
|
120
|
+
cy: Number(f.__grid?.[1] ?? Math.floor(H / d)),
|
|
121
|
+
tags: Array.isArray(f.__tags) ? f.__tags.map(String) : [],
|
|
122
|
+
fields: _,
|
|
123
|
+
layer: g
|
|
124
|
+
};
|
|
125
|
+
e.entities.push(S), y.push({ id: u++, name: S.identifier, type: S.identifier, x: v - $ * w, y: H - I * x, width: w, height: x, rotation: 0, point: w === 0 && x === 0, ellipse: !1, properties: N(_) });
|
|
126
|
+
}
|
|
127
|
+
p.push({ kind: "objects", name: g, objects: y, visible: i.visible !== !1, properties: {} });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
e.map.width = s, e.map.height = l, e.map.tileWidth = d, e.map.tileHeight = d, e.map.layers = p;
|
|
131
|
+
}
|
|
132
|
+
function P(e, n, r, o, t) {
|
|
133
|
+
const a = String(e.identifier ?? ""), d = String(e.__bgColor ?? e.bgColor ?? n.bgColor), s = {
|
|
134
|
+
identifier: a,
|
|
135
|
+
iid: String(e.iid ?? ""),
|
|
136
|
+
uid: Number(e.uid ?? 0),
|
|
137
|
+
worldX: Number(e.worldX ?? 0),
|
|
138
|
+
worldY: Number(e.worldY ?? 0),
|
|
139
|
+
worldDepth: Number(e.worldDepth ?? 0),
|
|
140
|
+
pxWidth: c(e.pxWid, `level "${a}" pxWid`),
|
|
141
|
+
pxHeight: c(e.pxHei, `level "${a}" pxHei`),
|
|
142
|
+
bgColor: d,
|
|
143
|
+
fields: L(e.fieldInstances),
|
|
144
|
+
map: { width: 0, height: 0, tileWidth: n.defaultGridSize, tileHeight: n.defaultGridSize, layers: [], tilesets: n.tilesets, properties: {}, backgroundColor: d },
|
|
145
|
+
intGrids: /* @__PURE__ */ new Map(),
|
|
146
|
+
entities: [],
|
|
147
|
+
loaded: !1
|
|
148
|
+
};
|
|
149
|
+
typeof e.externalRelPath == "string" && (s.externalRelPath = e.externalRelPath);
|
|
150
|
+
let l = e;
|
|
151
|
+
return !Array.isArray(e.layerInstances) && s.externalRelPath && (l = t(s.externalRelPath)), l && Array.isArray(l.layerInstances) && (s.fields = { ...s.fields, ...L(l.fieldInstances) }, s.map.properties = N(s.fields), Y(s, l.layerInstances, r, o, n.defaultGridSize), s.loaded = !0), s;
|
|
152
|
+
}
|
|
153
|
+
function k(e, n) {
|
|
154
|
+
let r = 0;
|
|
155
|
+
for (const o of e)
|
|
156
|
+
n === "LinearHorizontal" ? (o.worldX = r, o.worldY = 0, r += o.pxWidth) : (o.worldX = 0, o.worldY = r, r += o.pxHeight);
|
|
157
|
+
}
|
|
158
|
+
function j(e, n = {}) {
|
|
159
|
+
const r = e;
|
|
160
|
+
if (!r || typeof r != "object" || !r.defs) throw new G('not an LDtk project (no "defs")');
|
|
161
|
+
const o = n.levels, t = typeof o == "function" ? o : (l) => o?.[l], { tilesets: a, byUid: d } = A(r.defs), s = {
|
|
162
|
+
jsonVersion: String(r.jsonVersion ?? ""),
|
|
163
|
+
defaultGridSize: Number(r.defaultGridSize ?? 16),
|
|
164
|
+
bgColor: String(r.bgColor ?? "#000000"),
|
|
165
|
+
tilesets: a,
|
|
166
|
+
worlds: [],
|
|
167
|
+
levels: []
|
|
168
|
+
};
|
|
169
|
+
for (const l of W(r)) {
|
|
170
|
+
const p = l.worldLayout ?? "Free", u = {
|
|
171
|
+
identifier: String(l.identifier ?? ""),
|
|
172
|
+
iid: String(l.iid ?? ""),
|
|
173
|
+
layout: p,
|
|
174
|
+
gridWidth: Number(l.worldGridWidth ?? 0),
|
|
175
|
+
gridHeight: Number(l.worldGridHeight ?? 0),
|
|
176
|
+
levels: (l.levels ?? []).map((i) => P(i, s, r.defs, d, t))
|
|
177
|
+
};
|
|
178
|
+
(p === "LinearHorizontal" || p === "LinearVertical") && k(u.levels, p), s.worlds.push(u), s.levels.push(...u.levels);
|
|
179
|
+
}
|
|
180
|
+
return s;
|
|
181
|
+
}
|
|
182
|
+
function O(e, n, r, o) {
|
|
183
|
+
const t = n, { byUid: a } = A(t?.defs), d = P({ ...o, worldX: r.worldX, worldY: r.worldY, externalRelPath: r.externalRelPath }, e, t?.defs, a, () => {
|
|
184
|
+
});
|
|
185
|
+
return Object.assign(r, { map: d.map, intGrids: d.intGrids, entities: d.entities, fields: d.fields, loaded: d.loaded }), r;
|
|
186
|
+
}
|
|
187
|
+
export {
|
|
188
|
+
R as ldtkExternalLevels,
|
|
189
|
+
O as loadLdtkLevel,
|
|
190
|
+
j as parseLdtk
|
|
191
|
+
};
|