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.
Files changed (210) hide show
  1. package/CHANGELOG.md +92 -1
  2. package/README.md +15 -6
  3. package/dist/1681-engine.js +588 -465
  4. package/dist/ai/behaviorTree.js +198 -0
  5. package/dist/ai/buildTree.js +54 -0
  6. package/dist/ambient/life/Birds.js +73 -0
  7. package/dist/ambient/life/Butterflies.js +43 -0
  8. package/dist/ambient/life/ChimneySmoke.js +50 -0
  9. package/dist/ambient/life/Drift.js +75 -0
  10. package/dist/ambient/life/Fireflies.js +52 -0
  11. package/dist/ambient/life/lifeMotion.js +49 -0
  12. package/dist/assets/AssetLoader.js +115 -70
  13. package/dist/assets/Prepainter.js +61 -0
  14. package/dist/assets/workerPainter.js +39 -0
  15. package/dist/audio/spatial.js +118 -0
  16. package/dist/cjs/electron/electronLike.d.ts +55 -0
  17. package/dist/cjs/electron/electronLike.js +7 -0
  18. package/dist/cjs/electron/index.d.ts +14 -0
  19. package/dist/cjs/electron/index.js +20 -0
  20. package/dist/cjs/electron/lockdown.d.ts +33 -0
  21. package/dist/cjs/electron/lockdown.js +69 -0
  22. package/dist/cjs/electron/lockdownRules.d.ts +28 -0
  23. package/dist/cjs/electron/lockdownRules.js +61 -0
  24. package/dist/cjs/electron/sessionStore.d.ts +40 -0
  25. package/dist/cjs/electron/sessionStore.js +77 -0
  26. package/dist/cjs/electron/shellId.d.ts +22 -0
  27. package/dist/cjs/electron/shellId.js +31 -0
  28. package/dist/cjs/electron/webFiles.d.ts +13 -0
  29. package/dist/cjs/electron/webFiles.js +52 -0
  30. package/dist/cjs/electron/webPatcher.d.ts +83 -0
  31. package/dist/cjs/electron/webPatcher.js +223 -0
  32. package/dist/cjs/electron/webPointers.d.ts +19 -0
  33. package/dist/cjs/electron/webPointers.js +35 -0
  34. package/dist/cjs/package.json +1 -0
  35. package/dist/cjs/updates/index.d.ts +8 -0
  36. package/dist/cjs/updates/index.js +21 -0
  37. package/dist/cjs/updates/manifest.d.ts +73 -0
  38. package/dist/cjs/updates/manifest.js +67 -0
  39. package/dist/cjs/updates/pickUpdate.d.ts +42 -0
  40. package/dist/cjs/updates/pickUpdate.js +52 -0
  41. package/dist/cjs/updates/webPlan.d.ts +20 -0
  42. package/dist/cjs/updates/webPlan.js +34 -0
  43. package/dist/dialogue/DialogueRunner.js +173 -0
  44. package/dist/dialogue/expr.js +137 -0
  45. package/dist/dialogue/validateDialogue.js +52 -0
  46. package/dist/ecs/prefab.js +94 -0
  47. package/dist/electron/lockdown.js +31 -0
  48. package/dist/electron/lockdownRules.js +42 -0
  49. package/dist/electron/sessionStore.js +48 -0
  50. package/dist/electron/shellId.js +18 -0
  51. package/dist/electron/webFiles.js +36 -0
  52. package/dist/electron/webPatcher.js +153 -0
  53. package/dist/electron/webPointers.js +25 -0
  54. package/dist/electron.js +19 -0
  55. package/dist/input/Actions.js +58 -27
  56. package/dist/input/InputCapture.js +98 -0
  57. package/dist/input/Keymap.js +32 -26
  58. package/dist/input/haptics.js +50 -0
  59. package/dist/input/inputTape.js +68 -0
  60. package/dist/mobile/backButton.js +40 -0
  61. package/dist/mobile/capacitor.js +48 -0
  62. package/dist/mobile/screen.js +31 -0
  63. package/dist/mobile.js +12 -0
  64. package/dist/nav/flowField.js +58 -0
  65. package/dist/nav/steering.js +77 -0
  66. package/dist/net/ApiClient.js +96 -0
  67. package/dist/net/InterpolationBuffer.js +30 -23
  68. package/dist/net/LagCompensator.js +100 -0
  69. package/dist/net/Room.js +122 -43
  70. package/dist/net/RoomHost.js +13 -4
  71. package/dist/net/SpatialHash.js +66 -0
  72. package/dist/pixel/lifeArt.js +83 -0
  73. package/dist/pixel.js +63 -58
  74. package/dist/react/ConfirmButton.js +24 -0
  75. package/dist/react/baseCss.js +1 -0
  76. package/dist/react/labels.js +7 -6
  77. package/dist/react/useJsonSelector.js +13 -0
  78. package/dist/react.js +73 -68
  79. package/dist/tilemap/TilemapView.js +57 -32
  80. package/dist/tilemap/autotile.js +103 -0
  81. package/dist/tilemap/collision.js +29 -18
  82. package/dist/tilemap/ldtk.js +21 -0
  83. package/dist/tilemap/ldtkParse.js +191 -0
  84. package/dist/types/ai/behaviorTree.d.ts +133 -0
  85. package/dist/types/ai/behaviorTree.d.ts.map +1 -0
  86. package/dist/types/ai/buildTree.d.ts +55 -0
  87. package/dist/types/ai/buildTree.d.ts.map +1 -0
  88. package/dist/types/ambient/life/Birds.d.ts +50 -0
  89. package/dist/types/ambient/life/Birds.d.ts.map +1 -0
  90. package/dist/types/ambient/life/Butterflies.d.ts +32 -0
  91. package/dist/types/ambient/life/Butterflies.d.ts.map +1 -0
  92. package/dist/types/ambient/life/ChimneySmoke.d.ts +37 -0
  93. package/dist/types/ambient/life/ChimneySmoke.d.ts.map +1 -0
  94. package/dist/types/ambient/life/Drift.d.ts +58 -0
  95. package/dist/types/ambient/life/Drift.d.ts.map +1 -0
  96. package/dist/types/ambient/life/Fireflies.d.ts +43 -0
  97. package/dist/types/ambient/life/Fireflies.d.ts.map +1 -0
  98. package/dist/types/ambient/life/lifeMotion.d.ts +63 -0
  99. package/dist/types/ambient/life/lifeMotion.d.ts.map +1 -0
  100. package/dist/types/assets/AssetLoader.d.ts +20 -0
  101. package/dist/types/assets/AssetLoader.d.ts.map +1 -1
  102. package/dist/types/assets/Prepainter.d.ts +64 -0
  103. package/dist/types/assets/Prepainter.d.ts.map +1 -0
  104. package/dist/types/assets/workerPainter.d.ts +21 -0
  105. package/dist/types/assets/workerPainter.d.ts.map +1 -0
  106. package/dist/types/audio/spatial.d.ts +107 -0
  107. package/dist/types/audio/spatial.d.ts.map +1 -0
  108. package/dist/types/dialogue/DialogueRunner.d.ts +78 -0
  109. package/dist/types/dialogue/DialogueRunner.d.ts.map +1 -0
  110. package/dist/types/dialogue/expr.d.ts +12 -0
  111. package/dist/types/dialogue/expr.d.ts.map +1 -0
  112. package/dist/types/dialogue/script.d.ts +78 -0
  113. package/dist/types/dialogue/script.d.ts.map +1 -0
  114. package/dist/types/dialogue/validateDialogue.d.ts +21 -0
  115. package/dist/types/dialogue/validateDialogue.d.ts.map +1 -0
  116. package/dist/types/ecs/prefab.d.ts +84 -0
  117. package/dist/types/ecs/prefab.d.ts.map +1 -0
  118. package/dist/types/electron/electronLike.d.ts +56 -0
  119. package/dist/types/electron/electronLike.d.ts.map +1 -0
  120. package/dist/types/electron/index.d.ts +15 -0
  121. package/dist/types/electron/index.d.ts.map +1 -0
  122. package/dist/types/electron/lockdown.d.ts +34 -0
  123. package/dist/types/electron/lockdown.d.ts.map +1 -0
  124. package/dist/types/electron/lockdownRules.d.ts +29 -0
  125. package/dist/types/electron/lockdownRules.d.ts.map +1 -0
  126. package/dist/types/electron/sessionStore.d.ts +41 -0
  127. package/dist/types/electron/sessionStore.d.ts.map +1 -0
  128. package/dist/types/electron/shellId.d.ts +23 -0
  129. package/dist/types/electron/shellId.d.ts.map +1 -0
  130. package/dist/types/electron/webFiles.d.ts +14 -0
  131. package/dist/types/electron/webFiles.d.ts.map +1 -0
  132. package/dist/types/electron/webPatcher.d.ts +84 -0
  133. package/dist/types/electron/webPatcher.d.ts.map +1 -0
  134. package/dist/types/electron/webPointers.d.ts +20 -0
  135. package/dist/types/electron/webPointers.d.ts.map +1 -0
  136. package/dist/types/index.d.ts +30 -3
  137. package/dist/types/index.d.ts.map +1 -1
  138. package/dist/types/input/Actions.d.ts +14 -0
  139. package/dist/types/input/Actions.d.ts.map +1 -1
  140. package/dist/types/input/InputCapture.d.ts +53 -0
  141. package/dist/types/input/InputCapture.d.ts.map +1 -0
  142. package/dist/types/input/Keymap.d.ts +12 -6
  143. package/dist/types/input/Keymap.d.ts.map +1 -1
  144. package/dist/types/input/haptics.d.ts +42 -0
  145. package/dist/types/input/haptics.d.ts.map +1 -0
  146. package/dist/types/input/inputTape.d.ts +66 -0
  147. package/dist/types/input/inputTape.d.ts.map +1 -0
  148. package/dist/types/mobile/backButton.d.ts +30 -0
  149. package/dist/types/mobile/backButton.d.ts.map +1 -0
  150. package/dist/types/mobile/capacitor.d.ts +62 -0
  151. package/dist/types/mobile/capacitor.d.ts.map +1 -0
  152. package/dist/types/mobile/index.d.ts +4 -0
  153. package/dist/types/mobile/index.d.ts.map +1 -0
  154. package/dist/types/mobile/screen.d.ts +27 -0
  155. package/dist/types/mobile/screen.d.ts.map +1 -0
  156. package/dist/types/nav/flowField.d.ts +31 -0
  157. package/dist/types/nav/flowField.d.ts.map +1 -0
  158. package/dist/types/nav/steering.d.ts +47 -0
  159. package/dist/types/nav/steering.d.ts.map +1 -0
  160. package/dist/types/net/ApiClient.d.ts +74 -0
  161. package/dist/types/net/ApiClient.d.ts.map +1 -0
  162. package/dist/types/net/InterpolationBuffer.d.ts +5 -0
  163. package/dist/types/net/InterpolationBuffer.d.ts.map +1 -1
  164. package/dist/types/net/LagCompensator.d.ts +70 -0
  165. package/dist/types/net/LagCompensator.d.ts.map +1 -0
  166. package/dist/types/net/Room.d.ts +72 -3
  167. package/dist/types/net/Room.d.ts.map +1 -1
  168. package/dist/types/net/RoomHost.d.ts +8 -3
  169. package/dist/types/net/RoomHost.d.ts.map +1 -1
  170. package/dist/types/net/SpatialHash.d.ts +25 -0
  171. package/dist/types/net/SpatialHash.d.ts.map +1 -0
  172. package/dist/types/pixel/index.d.ts +1 -0
  173. package/dist/types/pixel/index.d.ts.map +1 -1
  174. package/dist/types/pixel/lifeArt.d.ts +63 -0
  175. package/dist/types/pixel/lifeArt.d.ts.map +1 -0
  176. package/dist/types/react/ConfirmButton.d.ts +26 -0
  177. package/dist/types/react/ConfirmButton.d.ts.map +1 -0
  178. package/dist/types/react/baseCss.d.ts +1 -1
  179. package/dist/types/react/baseCss.d.ts.map +1 -1
  180. package/dist/types/react/index.d.ts +2 -0
  181. package/dist/types/react/index.d.ts.map +1 -1
  182. package/dist/types/react/labels.d.ts +2 -0
  183. package/dist/types/react/labels.d.ts.map +1 -1
  184. package/dist/types/react/useJsonSelector.d.ts +13 -0
  185. package/dist/types/react/useJsonSelector.d.ts.map +1 -0
  186. package/dist/types/tilemap/TilemapView.d.ts +17 -0
  187. package/dist/types/tilemap/TilemapView.d.ts.map +1 -1
  188. package/dist/types/tilemap/autotile.d.ts +95 -0
  189. package/dist/types/tilemap/autotile.d.ts.map +1 -0
  190. package/dist/types/tilemap/collision.d.ts +8 -0
  191. package/dist/types/tilemap/collision.d.ts.map +1 -1
  192. package/dist/types/tilemap/ldtk.d.ts +97 -0
  193. package/dist/types/tilemap/ldtk.d.ts.map +1 -0
  194. package/dist/types/tilemap/ldtkParse.d.ts +26 -0
  195. package/dist/types/tilemap/ldtkParse.d.ts.map +1 -0
  196. package/dist/types/ui/ScrollView.d.ts.map +1 -1
  197. package/dist/types/updates/index.d.ts +9 -0
  198. package/dist/types/updates/index.d.ts.map +1 -0
  199. package/dist/types/updates/manifest.d.ts +74 -0
  200. package/dist/types/updates/manifest.d.ts.map +1 -0
  201. package/dist/types/updates/pickUpdate.d.ts +43 -0
  202. package/dist/types/updates/pickUpdate.d.ts.map +1 -0
  203. package/dist/types/updates/webPlan.d.ts +21 -0
  204. package/dist/types/updates/webPlan.d.ts.map +1 -0
  205. package/dist/ui/ScrollView.js +10 -8
  206. package/dist/updates/manifest.js +35 -0
  207. package/dist/updates/pickUpdate.js +27 -0
  208. package/dist/updates/webPlan.js +14 -0
  209. package/dist/updates.js +15 -0
  210. 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 l } from "./react/classNames.js";
3
- import { DEFAULT_LABELS as m, fillLabel as a } from "./react/labels.js";
4
- import { baseCss as c, injectBaseCss as n } from "./react/baseCss.js";
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 { useViewport as u } from "./react/useViewport.js";
7
- import { SCROLL_CLASS as d, useFitToViewport as L } from "./react/useFitToViewport.js";
8
- import { useFillSheet as P } from "./react/useFillSheet.js";
9
- import { SPLIT_STACK_BELOW as w, cursorTip as k, listPlacement as F, pixelFit as A, sheetScaleStyle as E, splitModeFor as U, windowStyle as _ } from "./react/placement.js";
10
- import { Panel as B } from "./react/Panel.js";
11
- import { TabStrip as G } from "./react/TabStrip.js";
12
- import { SplitPane as V } from "./react/SplitPane.js";
13
- import { pickedEntry as K, usePicked as M } from "./react/usePicked.js";
14
- import { Select as j, stepOption as v } from "./react/Select.js";
15
- import { Tooltip as R } from "./react/Tooltip.js";
16
- import { TitleTips as q } from "./react/TitleTips.js";
17
- import { Modal as H } from "./react/Modal.js";
18
- import { ConfirmDialog as X } from "./react/ConfirmDialog.js";
19
- import { answerConfirm as Z, askConfirm as $, askQuantity as ee, cancelConfirm as oe, confirmStore as re, parseQuantity as te } from "./react/confirmStore.js";
20
- import { ChoiceDialog as pe } from "./react/ChoiceDialog.js";
21
- import { answerChoice as le, askChoice as se, cancelChoice as me, choiceStore as ae, firstChoice as xe } from "./react/choiceStore.js";
22
- import { Slider as ne, sliderKeyValue as Se } from "./react/Slider.js";
23
- import { PixelImage as he } from "./react/PixelImage.js";
24
- import { Glyph as ye, glyphPath as de, hasGlyph as Le, registerGlyph as Te } from "./react/Glyph.js";
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
- pe as ChoiceDialog,
27
- X as ConfirmDialog,
28
- m as DEFAULT_LABELS,
29
- ye as Glyph,
30
- H as Modal,
31
- B as Panel,
32
- he as PixelImage,
33
- d as SCROLL_CLASS,
34
- w as SPLIT_STACK_BELOW,
35
- j as Select,
36
- ne as Slider,
37
- V as SplitPane,
38
- G as TabStrip,
39
- q as TitleTips,
40
- R as Tooltip,
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
- le as answerChoice,
43
- Z as answerConfirm,
44
- se as askChoice,
45
- $ as askConfirm,
46
- ee as askQuantity,
47
- c as baseCss,
48
- me as cancelChoice,
49
- oe as cancelConfirm,
50
- ae as choiceStore,
51
- l as classJoiner,
52
- re as confirmStore,
53
- k as cursorTip,
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
- a as fillLabel,
56
- xe as firstChoice,
57
- de as glyphPath,
58
- Le as hasGlyph,
59
- n as injectBaseCss,
60
- F as listPlacement,
61
- te as parseQuantity,
62
- K as pickedEntry,
63
- A as pixelFit,
64
- Te as registerGlyph,
65
- E as sheetScaleStyle,
66
- Se as sliderKeyValue,
67
- U as splitModeFor,
68
- v as stepOption,
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
- P as useFillSheet,
71
- L as useFitToViewport,
72
- M as usePicked,
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
- u as useViewport,
76
- _ as windowStyle
80
+ L as useViewport,
81
+ D as windowStyle
77
82
  };
@@ -1,17 +1,17 @@
1
- import { Container as M, Sprite as P } from "pixi.js";
2
- import { tileAt as F, tileRect as H, FLIP_D as V, FLIP_H as $, FLIP_V as L } from "./tiled.js";
3
- let S = 0;
4
- class T {
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 p = e.textureFor ?? ((t) => t.name), r = Math.max(1, e.chunkTiles ?? 32), m = e.baseDepth ?? -1e6, w = e.layers ? new Set(e.layers) : null, c = i.layers.filter((t) => t.kind === "tiles" && (w ? w.has(t.name) : t.visible)), f = e.parent ?? s.world;
8
- c.forEach((t, y) => {
9
- const x = typeof t.properties.depth == "number" ? t.properties.depth : m + y, l = new M();
10
- l.zIndex = x, l.alpha = t.opacity, l.position.set(t.offsetX, t.offsetY), this.layers.set(t.name, l), f.addChild(l);
11
- for (let n = 0; n < i.height; n += r)
12
- for (let a = 0; a < i.width; a += r) {
13
- const o = Math.min(r, i.width - a), d = Math.min(r, i.height - n);
14
- this.paintChunk(t, l, a, n, o, d, p);
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 = S++;
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, p, r, m, w) {
44
- const { map: c } = this, f = c.tileWidth, t = c.tileHeight;
45
- let y = !1;
46
- const x = `tilemap:${this.id}:${s.name}:${e},${p}`, n = Math.max(t, ...c.tilesets.map((u) => u.tileHeight)) - t, a = this.stage.textures.createCanvas(x, r * f, m * t + n), o = a.context;
47
- o.imageSmoothingEnabled = !1;
48
- for (let u = 0; u < m; u++)
49
- for (let k = 0; k < r; k++) {
50
- const v = s.data[(p + u) * c.width + (e + k)], g = F(c, v);
51
- if (!g) continue;
52
- const b = this.stage.textures.exists(w(g.tileset)) ? this.stage.textures.get(w(g.tileset)).source.resource : null;
53
- if (!b) continue;
54
- const h = H(g.tileset, g.local), C = k * f, I = n + (u + 1) * t - h.h;
55
- o.save(), o.translate(C + h.w / 2, I + h.h / 2), v & V && o.transform(0, 1, 1, 0, 0, 0), o.scale(v & $ ? -1 : 1, v & L ? -1 : 1), o.drawImage(b, h.x, h.y, h.w, h.h, -h.w / 2, -h.h / 2, h.w, h.h), o.restore(), y = !0;
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 (!y) {
58
- this.stage.textures.remove(x);
82
+ if (!x) {
83
+ this.stage.textures.remove(w);
59
84
  return;
60
85
  }
61
- a.refresh();
62
- const d = new P(a.whole);
63
- d.position.set(e * f, p * t - n), i.addChild(d), this.chunks.push({ sprite: d, x: d.x + s.offsetX, y: d.y + s.offsetY, w: r * f, h: m * t + n, key: x });
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
- T as TilemapView
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 c } from "../net/movement.js";
2
- import { gidOf as h, tileAt as y } from "./tiled.js";
3
- function w(i, s = {}) {
4
- if (i.tileWidth !== i.tileHeight) throw new Error(`Tiled map: collision needs square tiles, not ${i.tileWidth}x${i.tileHeight}`);
5
- const l = s.solid ?? (i.layers.some((e) => e.kind === "tiles" && e.name === "collision") ? "collision" : { property: "solid" }), o = i.width * i.height, r = new Uint8Array(o);
6
- if (typeof l == "string") {
7
- const e = i.layers.find((t) => t.kind === "tiles" && t.name === l);
8
- if (!e || e.kind !== "tiles") throw new Error(`Tiled map: no tile layer named "${l}"`);
9
- for (let t = 0; t < o; t++) h(e.data[t]) !== 0 && (r[t] = 1);
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 e of i.layers)
12
- if (e.kind === "tiles")
13
- for (let t = 0; t < o; t++) {
14
- const n = y(i, e.data[t]);
15
- n && n.tileset.tileProperties.get(n.local)?.[l.property] === !0 && (r[t] = 1);
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 e = 0; e < o; e++) d += r[e] ? "1" : "0";
19
- const { solid: g, ...f } = s;
20
- return c(i.width, i.height, i.tileWidth, d, f);
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
- w as collisionFromTiled
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
+ };