@rpgjs/client 5.0.0-alpha.9 → 5.0.0-beta.10
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 +37 -0
- package/LICENSE +19 -0
- package/dist/Game/AnimationManager.d.ts +8 -0
- package/dist/Game/AnimationManager.js +35 -0
- package/dist/Game/AnimationManager.js.map +1 -0
- package/dist/Game/AnimationManager.spec.d.ts +1 -0
- package/dist/Game/Event.d.ts +1 -1
- package/dist/Game/Event.js +12 -0
- package/dist/Game/Event.js.map +1 -0
- package/dist/Game/Map.d.ts +31 -2
- package/dist/Game/Map.js +138 -0
- package/dist/Game/Map.js.map +1 -0
- package/dist/Game/Object.d.ts +189 -0
- package/dist/Game/Object.js +255 -0
- package/dist/Game/Object.js.map +1 -0
- package/dist/Game/Player.d.ts +1 -1
- package/dist/Game/Player.js +12 -0
- package/dist/Game/Player.js.map +1 -0
- package/dist/Gui/Gui.d.ts +192 -7
- package/dist/Gui/Gui.js +475 -0
- package/dist/Gui/Gui.js.map +1 -0
- package/dist/Gui/Gui.spec.d.ts +1 -0
- package/dist/Gui/NotificationManager.d.ts +23 -0
- package/dist/Gui/NotificationManager.js +49 -0
- package/dist/Gui/NotificationManager.js.map +1 -0
- package/dist/Resource.d.ts +97 -0
- package/dist/Resource.js +133 -0
- package/dist/Resource.js.map +1 -0
- package/dist/RpgClient.d.ts +295 -13
- package/dist/RpgClientEngine.d.ts +671 -15
- package/dist/RpgClientEngine.js +1442 -0
- package/dist/RpgClientEngine.js.map +1 -0
- package/dist/Sound.d.ts +199 -0
- package/dist/Sound.js +167 -0
- package/dist/Sound.js.map +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.130.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/animations/animation.ce.js +23 -0
- package/dist/components/animations/animation.ce.js.map +1 -0
- package/dist/components/animations/hit.ce.js +64 -0
- package/dist/components/animations/hit.ce.js.map +1 -0
- package/dist/components/animations/index.d.ts +4 -0
- package/dist/components/animations/index.js +11 -0
- package/dist/components/animations/index.js.map +1 -0
- package/dist/components/character.ce.js +572 -0
- package/dist/components/character.ce.js.map +1 -0
- package/dist/components/dynamics/bar.ce.js +96 -0
- package/dist/components/dynamics/bar.ce.js.map +1 -0
- package/dist/components/dynamics/image.ce.js +23 -0
- package/dist/components/dynamics/image.ce.js.map +1 -0
- package/dist/components/dynamics/parse-value.d.ts +4 -0
- package/dist/components/dynamics/parse-value.js +63 -0
- package/dist/components/dynamics/parse-value.js.map +1 -0
- package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
- package/dist/components/dynamics/shape-utils.d.ts +16 -0
- package/dist/components/dynamics/shape-utils.js +73 -0
- package/dist/components/dynamics/shape-utils.js.map +1 -0
- package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
- package/dist/components/dynamics/shape.ce.js +83 -0
- package/dist/components/dynamics/shape.ce.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +50 -0
- package/dist/components/dynamics/text.ce.js.map +1 -0
- package/dist/components/gui/box.ce.js +26 -0
- package/dist/components/gui/box.ce.js.map +1 -0
- package/dist/components/gui/dialogbox/index.ce.js +198 -0
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
- package/dist/components/gui/gameover.ce.js +169 -0
- package/dist/components/gui/gameover.ce.js.map +1 -0
- package/dist/components/gui/hud/hud.ce.js +83 -0
- package/dist/components/gui/hud/hud.ce.js.map +1 -0
- package/dist/components/gui/index.d.ts +15 -3
- package/dist/components/gui/index.js +14 -0
- package/dist/components/gui/menu/equip-menu.ce.js +427 -0
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/exit-menu.ce.js +55 -0
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/items-menu.ce.js +326 -0
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/main-menu.ce.js +399 -0
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/options-menu.ce.js +49 -0
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/skills-menu.ce.js +102 -0
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
- package/dist/components/gui/mobile/index.d.ts +8 -0
- package/dist/components/gui/mobile/index.js +21 -0
- package/dist/components/gui/mobile/index.js.map +1 -0
- package/dist/components/gui/mobile/mobile.ce.js +79 -0
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
- package/dist/components/gui/notification/notification.ce.js +62 -0
- package/dist/components/gui/notification/notification.ce.js.map +1 -0
- package/dist/components/gui/save-load.ce.js +211 -0
- package/dist/components/gui/save-load.ce.js.map +1 -0
- package/dist/components/gui/shop/shop.ce.js +614 -0
- package/dist/components/gui/shop/shop.ce.js.map +1 -0
- package/dist/components/gui/title-screen.ce.js +164 -0
- package/dist/components/gui/title-screen.ce.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/player-components-utils.d.ts +67 -0
- package/dist/components/player-components-utils.js +162 -0
- package/dist/components/player-components-utils.js.map +1 -0
- package/dist/components/player-components-utils.spec.d.ts +1 -0
- package/dist/components/player-components.ce.js +188 -0
- package/dist/components/player-components.ce.js.map +1 -0
- package/dist/components/prebuilt/hp-bar.ce.js +113 -0
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
- package/dist/components/prebuilt/index.d.ts +19 -0
- package/dist/components/prebuilt/index.js +2 -0
- package/dist/components/prebuilt/light-halo.ce.js +70 -0
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
- package/dist/components/scenes/canvas.ce.js +196 -0
- package/dist/components/scenes/canvas.ce.js.map +1 -0
- package/dist/components/scenes/draw-map.ce.js +79 -0
- package/dist/components/scenes/draw-map.ce.js.map +1 -0
- package/dist/components/scenes/event-layer.ce.js +29 -0
- package/dist/components/scenes/event-layer.ce.js.map +1 -0
- package/dist/core/inject.js +18 -0
- package/dist/core/inject.js.map +1 -0
- package/dist/core/setup.js +16 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/decorators/spritesheet.d.ts +1 -0
- package/dist/decorators/spritesheet.js +11 -0
- package/dist/decorators/spritesheet.js.map +1 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +45 -14
- package/dist/module.d.ts +43 -4
- package/dist/module.js +179 -0
- package/dist/module.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js +167 -0
- package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js +239 -0
- package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js +13 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js +696 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js +44 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js +241 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +115 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +401 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3756 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
- package/dist/presets/animation.d.ts +31 -0
- package/dist/presets/animation.js +39 -0
- package/dist/presets/animation.js.map +1 -0
- package/dist/presets/faceset.d.ts +30 -0
- package/dist/presets/faceset.js +51 -0
- package/dist/presets/faceset.js.map +1 -0
- package/dist/presets/icon.d.ts +20 -0
- package/dist/presets/icon.js +15 -0
- package/dist/presets/icon.js.map +1 -0
- package/dist/presets/index.d.ts +123 -0
- package/dist/presets/index.js +17 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/lpc.d.ts +89 -0
- package/dist/presets/lpc.js +98 -0
- package/dist/presets/lpc.js.map +1 -0
- package/dist/presets/rmspritesheet.js +42 -0
- package/dist/presets/rmspritesheet.js.map +1 -0
- package/dist/services/AbstractSocket.d.ts +9 -5
- package/dist/services/AbstractSocket.js +11 -0
- package/dist/services/AbstractSocket.js.map +1 -0
- package/dist/services/keyboardControls.d.ts +15 -0
- package/dist/services/keyboardControls.js +23 -0
- package/dist/services/keyboardControls.js.map +1 -0
- package/dist/services/loadMap.d.ts +6 -0
- package/dist/services/loadMap.js +123 -0
- package/dist/services/loadMap.js.map +1 -0
- package/dist/services/mmorpg.d.ts +21 -9
- package/dist/services/mmorpg.js +136 -0
- package/dist/services/mmorpg.js.map +1 -0
- package/dist/services/save.d.ts +19 -0
- package/dist/services/save.js +77 -0
- package/dist/services/save.js.map +1 -0
- package/dist/services/save.spec.d.ts +1 -0
- package/dist/services/standalone.d.ts +67 -7
- package/dist/services/standalone.js +168 -0
- package/dist/services/standalone.js.map +1 -0
- package/dist/utils/getEntityProp.d.ts +39 -0
- package/dist/utils/getEntityProp.js +53 -0
- package/dist/utils/getEntityProp.js.map +1 -0
- package/dist/utils/getEntityProp.spec.d.ts +1 -0
- package/dist/utils/readPropValue.d.ts +2 -0
- package/dist/utils/readPropValue.js +13 -0
- package/dist/utils/readPropValue.js.map +1 -0
- package/package.json +14 -11
- package/src/Game/AnimationManager.spec.ts +30 -0
- package/src/Game/AnimationManager.ts +33 -0
- package/src/Game/Event.ts +1 -1
- package/src/Game/Map.ts +184 -3
- package/src/Game/Object.ts +409 -14
- package/src/Game/Player.ts +1 -1
- package/src/Gui/Gui.spec.ts +273 -0
- package/src/Gui/Gui.ts +566 -23
- package/src/Gui/NotificationManager.ts +69 -0
- package/src/Resource.ts +149 -0
- package/src/RpgClient.ts +309 -14
- package/src/RpgClientEngine.ts +1790 -63
- package/src/Sound.ts +253 -0
- package/src/components/{effects → animations}/animation.ce +3 -6
- package/src/components/{effects → animations}/index.ts +1 -1
- package/src/components/character.ce +801 -59
- package/src/components/dynamics/bar.ce +87 -0
- package/src/components/dynamics/image.ce +20 -0
- package/src/components/dynamics/parse-value.spec.ts +83 -0
- package/src/components/dynamics/parse-value.ts +154 -0
- package/src/components/dynamics/shape-utils.spec.ts +46 -0
- package/src/components/dynamics/shape-utils.ts +61 -0
- package/src/components/dynamics/shape.ce +89 -0
- package/src/components/dynamics/text.ce +68 -0
- package/src/components/gui/box.ce +17 -0
- package/src/components/gui/dialogbox/index.ce +213 -187
- package/src/components/gui/gameover.ce +158 -0
- package/src/components/gui/hud/hud.ce +61 -0
- package/src/components/gui/index.ts +30 -4
- package/src/components/gui/menu/equip-menu.ce +410 -0
- package/src/components/gui/menu/exit-menu.ce +41 -0
- package/src/components/gui/menu/items-menu.ce +317 -0
- package/src/components/gui/menu/main-menu.ce +294 -0
- package/src/components/gui/menu/options-menu.ce +35 -0
- package/src/components/gui/menu/skills-menu.ce +83 -0
- package/src/components/gui/mobile/index.ts +24 -0
- package/src/components/gui/mobile/mobile.ce +80 -0
- package/src/components/gui/notification/notification.ce +51 -0
- package/src/components/gui/save-load.ce +208 -0
- package/src/components/gui/shop/shop.ce +493 -0
- package/src/components/gui/title-screen.ce +163 -0
- package/src/components/index.ts +3 -0
- package/src/components/player-components-utils.spec.ts +109 -0
- package/src/components/player-components-utils.ts +205 -0
- package/src/components/player-components.ce +221 -0
- package/src/components/prebuilt/hp-bar.ce +255 -0
- package/src/components/prebuilt/index.ts +24 -0
- package/src/components/prebuilt/light-halo.ce +148 -0
- package/src/components/scenes/canvas.ce +185 -21
- package/src/components/scenes/draw-map.ce +55 -21
- package/src/components/scenes/event-layer.ce +8 -2
- package/src/components/scenes/transition.ce +60 -0
- package/src/core/setup.ts +2 -2
- package/src/decorators/spritesheet.ts +8 -0
- package/src/index.ts +17 -2
- package/src/module.ts +132 -10
- package/src/presets/animation.ts +46 -0
- package/src/presets/faceset.ts +60 -0
- package/src/presets/icon.ts +17 -0
- package/src/presets/index.ts +9 -1
- package/src/presets/lpc.ts +108 -0
- package/src/services/AbstractSocket.ts +10 -2
- package/src/services/keyboardControls.ts +20 -0
- package/src/services/loadMap.ts +3 -1
- package/src/services/mmorpg.ts +106 -12
- package/src/services/save.spec.ts +127 -0
- package/src/services/save.ts +103 -0
- package/src/services/standalone.ts +110 -18
- package/src/utils/getEntityProp.spec.ts +96 -0
- package/src/utils/getEntityProp.ts +88 -0
- package/src/utils/readPropValue.ts +16 -0
- package/vite.config.ts +4 -2
- package/dist/Game/EffectManager.d.ts +0 -5
- package/dist/components/effects/index.d.ts +0 -4
- package/dist/index.js.map +0 -1
- package/dist/index10.js +0 -8
- package/dist/index10.js.map +0 -1
- package/dist/index11.js +0 -10
- package/dist/index11.js.map +0 -1
- package/dist/index12.js +0 -8
- package/dist/index12.js.map +0 -1
- package/dist/index13.js +0 -17
- package/dist/index13.js.map +0 -1
- package/dist/index14.js +0 -107
- package/dist/index14.js.map +0 -1
- package/dist/index15.js +0 -50
- package/dist/index15.js.map +0 -1
- package/dist/index16.js +0 -191
- package/dist/index16.js.map +0 -1
- package/dist/index17.js +0 -9
- package/dist/index17.js.map +0 -1
- package/dist/index18.js +0 -387
- package/dist/index18.js.map +0 -1
- package/dist/index19.js +0 -31
- package/dist/index19.js.map +0 -1
- package/dist/index2.js +0 -181
- package/dist/index2.js.map +0 -1
- package/dist/index20.js +0 -24
- package/dist/index20.js.map +0 -1
- package/dist/index21.js +0 -2421
- package/dist/index21.js.map +0 -1
- package/dist/index22.js +0 -114
- package/dist/index22.js.map +0 -1
- package/dist/index23.js +0 -109
- package/dist/index23.js.map +0 -1
- package/dist/index24.js +0 -71
- package/dist/index24.js.map +0 -1
- package/dist/index25.js +0 -21
- package/dist/index25.js.map +0 -1
- package/dist/index26.js +0 -41
- package/dist/index26.js.map +0 -1
- package/dist/index27.js +0 -5
- package/dist/index27.js.map +0 -1
- package/dist/index28.js +0 -322
- package/dist/index28.js.map +0 -1
- package/dist/index29.js +0 -27
- package/dist/index29.js.map +0 -1
- package/dist/index3.js +0 -87
- package/dist/index3.js.map +0 -1
- package/dist/index30.js +0 -11
- package/dist/index30.js.map +0 -1
- package/dist/index31.js +0 -11
- package/dist/index31.js.map +0 -1
- package/dist/index32.js +0 -174
- package/dist/index32.js.map +0 -1
- package/dist/index33.js +0 -501
- package/dist/index33.js.map +0 -1
- package/dist/index34.js +0 -12
- package/dist/index34.js.map +0 -1
- package/dist/index35.js +0 -4403
- package/dist/index35.js.map +0 -1
- package/dist/index36.js +0 -316
- package/dist/index36.js.map +0 -1
- package/dist/index37.js +0 -61
- package/dist/index37.js.map +0 -1
- package/dist/index38.js +0 -20
- package/dist/index38.js.map +0 -1
- package/dist/index39.js +0 -20
- package/dist/index39.js.map +0 -1
- package/dist/index4.js +0 -67
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -16
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -17
- package/dist/index6.js.map +0 -1
- package/dist/index7.js +0 -39
- package/dist/index7.js.map +0 -1
- package/dist/index8.js +0 -108
- package/dist/index8.js.map +0 -1
- package/dist/index9.js +0 -76
- package/dist/index9.js.map +0 -1
- package/src/Game/EffectManager.ts +0 -20
- package/src/components/gui/dialogbox/itemMenu.ce +0 -23
- package/src/components/gui/dialogbox/selection.ce +0 -67
- /package/src/components/{effects → animations}/hit.ce +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { inject } from "../../core/inject.js";
|
|
2
|
+
import { RpgGui } from "../../Gui/Gui.js";
|
|
3
|
+
import { RpgClientEngine } from "../../RpgClientEngine.js";
|
|
4
|
+
import { DOMContainer, DOMElement, Navigation, computed, cond, effect, h, loop, signal, useDefineProps, useProps } from "canvasengine";
|
|
5
|
+
import { PrebuiltGui } from "@rpgjs/common";
|
|
6
|
+
//#region src/components/gui/title-screen.ce
|
|
7
|
+
function component($$props) {
|
|
8
|
+
useProps($$props);
|
|
9
|
+
const defineProps = useDefineProps($$props);
|
|
10
|
+
const engine = inject(RpgClientEngine);
|
|
11
|
+
const guiService = inject(RpgGui);
|
|
12
|
+
const keyboardControls = engine.globalConfig.keyboardControls;
|
|
13
|
+
const { data, onInteraction } = defineProps({
|
|
14
|
+
entries: { default: () => [] },
|
|
15
|
+
saveLoad: { default: () => ({}) },
|
|
16
|
+
localActions: { default: false }
|
|
17
|
+
});
|
|
18
|
+
const { entries, title, subtitle, version, saveLoad, localActions } = data();
|
|
19
|
+
const defaultEntries = [{
|
|
20
|
+
id: "start",
|
|
21
|
+
label: "Start"
|
|
22
|
+
}, {
|
|
23
|
+
id: "load",
|
|
24
|
+
label: "Load"
|
|
25
|
+
}];
|
|
26
|
+
const resolveProp = (value) => typeof value === "function" ? value() : value;
|
|
27
|
+
const titleText = computed(() => resolveProp(title) || "RPG");
|
|
28
|
+
const subtitleText = computed(() => resolveProp(subtitle) || "");
|
|
29
|
+
const versionText = computed(() => resolveProp(version) || "");
|
|
30
|
+
const localActionsEnabled = computed(() => resolveProp(localActions) === true);
|
|
31
|
+
const entryList = computed(() => {
|
|
32
|
+
const list = resolveProp(entries);
|
|
33
|
+
if (Array.isArray(list) && list.length) return list;
|
|
34
|
+
return defaultEntries;
|
|
35
|
+
});
|
|
36
|
+
const isEntryDisabled = (entry) => {
|
|
37
|
+
if (!entry) return true;
|
|
38
|
+
if (entry.disabled) return true;
|
|
39
|
+
if (entry.enabled === false) return true;
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
const selectedEntry = signal(0);
|
|
43
|
+
const selectableIndexes = computed(() => {
|
|
44
|
+
return entryList().map((entry, index) => isEntryDisabled(entry) ? null : index).filter((value) => value !== null);
|
|
45
|
+
});
|
|
46
|
+
effect(() => {
|
|
47
|
+
const available = selectableIndexes();
|
|
48
|
+
if (!available.length) return;
|
|
49
|
+
const current = selectedEntry();
|
|
50
|
+
if (!available.includes(current)) selectedEntry.set(available[0]);
|
|
51
|
+
});
|
|
52
|
+
const moveSelection = (delta) => {
|
|
53
|
+
const available = selectableIndexes();
|
|
54
|
+
if (!available.length) return;
|
|
55
|
+
const current = selectedEntry();
|
|
56
|
+
const nextIndex = (Math.max(0, available.indexOf(current)) + delta + available.length) % available.length;
|
|
57
|
+
selectedEntry.set(available[nextIndex]);
|
|
58
|
+
};
|
|
59
|
+
const triggerSelect = (index) => {
|
|
60
|
+
const entry = entryList()[index];
|
|
61
|
+
if (!entry || isEntryDisabled(entry)) return;
|
|
62
|
+
if (localActionsEnabled()) {
|
|
63
|
+
if (entry.id === "start") guiService.hide(PrebuiltGui.TitleScreen);
|
|
64
|
+
if (entry.id === "load") {
|
|
65
|
+
const config = resolveProp(saveLoad) || {};
|
|
66
|
+
const slots = Array.isArray(config.slots) ? config.slots : [
|
|
67
|
+
null,
|
|
68
|
+
null,
|
|
69
|
+
null
|
|
70
|
+
];
|
|
71
|
+
guiService.display(PrebuiltGui.Save, {
|
|
72
|
+
...config,
|
|
73
|
+
mode: config.mode || "load",
|
|
74
|
+
slots
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (onInteraction) onInteraction("select", {
|
|
79
|
+
id: entry.id,
|
|
80
|
+
index,
|
|
81
|
+
entry
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
function selectEntry(index) {
|
|
85
|
+
return function() {
|
|
86
|
+
selectedEntry.set(index);
|
|
87
|
+
triggerSelect(index);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const controls = signal({
|
|
91
|
+
up: {
|
|
92
|
+
repeat: true,
|
|
93
|
+
bind: keyboardControls.up,
|
|
94
|
+
throttle: 150,
|
|
95
|
+
keyDown() {
|
|
96
|
+
if (guiService.isDisplaying(PrebuiltGui.Save)) return;
|
|
97
|
+
moveSelection(-1);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
down: {
|
|
101
|
+
repeat: true,
|
|
102
|
+
bind: keyboardControls.down,
|
|
103
|
+
throttle: 150,
|
|
104
|
+
keyDown() {
|
|
105
|
+
if (guiService.isDisplaying(PrebuiltGui.Save)) return;
|
|
106
|
+
moveSelection(1);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
action: {
|
|
110
|
+
bind: keyboardControls.action,
|
|
111
|
+
keyDown() {
|
|
112
|
+
if (guiService.isDisplaying(PrebuiltGui.Save)) return;
|
|
113
|
+
triggerSelect(selectedEntry());
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
gamepad: { enabled: true }
|
|
117
|
+
});
|
|
118
|
+
return h(DOMContainer, {
|
|
119
|
+
width: "100%",
|
|
120
|
+
height: "100%"
|
|
121
|
+
}, h(DOMElement, {
|
|
122
|
+
element: "div",
|
|
123
|
+
attrs: { class: "rpg-ui-title-screen rpg-anim-fade-in" }
|
|
124
|
+
}, [
|
|
125
|
+
h(DOMElement, {
|
|
126
|
+
element: "div",
|
|
127
|
+
attrs: { class: "rpg-ui-title-screen-header rpg-anim-float" }
|
|
128
|
+
}, [h(DOMElement, {
|
|
129
|
+
element: "div",
|
|
130
|
+
attrs: { class: "rpg-ui-title-screen-title" },
|
|
131
|
+
textContent: computed(() => titleText())
|
|
132
|
+
}), cond(computed(() => subtitleText()), () => h(DOMElement, {
|
|
133
|
+
element: "div",
|
|
134
|
+
attrs: { class: "rpg-ui-title-screen-subtitle" },
|
|
135
|
+
textContent: computed(() => subtitleText())
|
|
136
|
+
}))]),
|
|
137
|
+
h(Navigation, {
|
|
138
|
+
tabindex: selectedEntry,
|
|
139
|
+
controls
|
|
140
|
+
}, h(DOMElement, {
|
|
141
|
+
element: "div",
|
|
142
|
+
attrs: { class: "rpg-ui-menu rpg-ui-title-screen-menu rpg-anim-slide-up" }
|
|
143
|
+
}, loop(entryList(), (entry, index) => h(DOMElement, {
|
|
144
|
+
element: "div",
|
|
145
|
+
attrs: {
|
|
146
|
+
class: ["rpg-ui-menu-item", computed(() => ({ disabled: isEntryDisabled(entry) }))],
|
|
147
|
+
"data-selected": computed(() => selectedEntry() === index ? "true" : "false"),
|
|
148
|
+
tabindex: index,
|
|
149
|
+
click: selectEntry(index)
|
|
150
|
+
},
|
|
151
|
+
textContent: entry.label
|
|
152
|
+
})))),
|
|
153
|
+
cond(computed(() => versionText()), () => h(DOMElement, {
|
|
154
|
+
element: "div",
|
|
155
|
+
attrs: { class: "rpg-ui-title-screen-version" },
|
|
156
|
+
textContent: computed(() => versionText())
|
|
157
|
+
}))
|
|
158
|
+
]));
|
|
159
|
+
}
|
|
160
|
+
var __ce_component = component;
|
|
161
|
+
//#endregion
|
|
162
|
+
export { __ce_component as default };
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=title-screen.ce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"title-screen.ce.js","names":[],"sources":["../../../src/components/gui/title-screen.ce"],"sourcesContent":["<DOMContainer width=\"100%\" height=\"100%\">\n <div class=\"rpg-ui-title-screen rpg-anim-fade-in\">\n <div class=\"rpg-ui-title-screen-header rpg-anim-float\">\n <div class=\"rpg-ui-title-screen-title\">{titleText()}</div>\n @if (subtitleText()) {\n <div class=\"rpg-ui-title-screen-subtitle\">{subtitleText()}</div>\n }\n </div>\n <Navigation tabindex={selectedEntry} controls={controls}>\n <div class=\"rpg-ui-menu rpg-ui-title-screen-menu rpg-anim-slide-up\">\n @for ((entry,index) of entryList()) {\n <div\n class=\"rpg-ui-menu-item\"\n class={{disabled: isEntryDisabled(entry)}}\n data-selected={selectedEntry() === index ? \"true\" : \"false\"}\n tabindex={index}\n click={selectEntry(index)}\n >{entry.label}</div>\n }\n </div>\n </Navigation>\n @if (versionText()) {\n <div class=\"rpg-ui-title-screen-version\">{versionText()}</div>\n }\n </div>\n</DOMContainer>\n\n<script>\n import { signal, computed, effect } from \"canvasengine\";\n import { PrebuiltGui } from \"@rpgjs/common\";\n import { inject } from \"../../core/inject\";\n import { RpgClientEngine } from \"../../RpgClientEngine\";\n import { RpgGui } from \"../../Gui/Gui\";\n\n const engine = inject(RpgClientEngine);\n const guiService = inject(RpgGui);\n const keyboardControls = engine.globalConfig.keyboardControls;\n\n const { data, onInteraction } = defineProps({\n entries: {\n default: () => []\n },\n saveLoad: {\n default: () => ({})\n },\n localActions: {\n default: false\n }\n });\n\n const { entries, title, subtitle, version, saveLoad, localActions } = data();\n\n const defaultEntries = [\n { id: \"start\", label: \"Start\" },\n { id: \"load\", label: \"Load\" }\n ];\n\n const resolveProp = (value) => typeof value === \"function\" ? value() : value;\n const titleText = computed(() => resolveProp(title) || \"RPG\");\n const subtitleText = computed(() => resolveProp(subtitle) || \"\");\n const versionText = computed(() => resolveProp(version) || \"\");\n const localActionsEnabled = computed(() => resolveProp(localActions) === true);\n\n const entryList = computed(() => {\n const list = resolveProp(entries);\n if (Array.isArray(list) && list.length) return list;\n return defaultEntries;\n });\n\n const isEntryDisabled = (entry) => {\n if (!entry) return true;\n if (entry.disabled) return true;\n if (entry.enabled === false) return true;\n return false;\n };\n\n const selectedEntry = signal(0);\n const selectableIndexes = computed(() => {\n const list = entryList();\n return list\n .map((entry, index) => (isEntryDisabled(entry) ? null : index))\n .filter((value) => value !== null);\n });\n\n effect(() => {\n const available = selectableIndexes();\n if (!available.length) return;\n const current = selectedEntry();\n if (!available.includes(current)) {\n selectedEntry.set(available[0]);\n }\n });\n\n const moveSelection = (delta) => {\n const available = selectableIndexes();\n if (!available.length) return;\n const current = selectedEntry();\n const currentIndex = Math.max(0, available.indexOf(current));\n const nextIndex = (currentIndex + delta + available.length) % available.length;\n selectedEntry.set(available[nextIndex]);\n };\n\n const triggerSelect = (index) => {\n const list = entryList();\n const entry = list[index];\n if (!entry || isEntryDisabled(entry)) return;\n if (localActionsEnabled()) {\n if (entry.id === \"start\") {\n guiService.hide(PrebuiltGui.TitleScreen);\n }\n if (entry.id === \"load\") {\n const config = resolveProp(saveLoad) || {};\n const slots = Array.isArray(config.slots) ? config.slots : [null, null, null];\n guiService.display(PrebuiltGui.Save, {\n ...config,\n mode: config.mode || \"load\",\n slots\n });\n }\n }\n if (onInteraction) {\n onInteraction(\"select\", { id: entry.id, index, entry });\n }\n };\n\n function selectEntry(index) {\n return function() {\n selectedEntry.set(index);\n triggerSelect(index);\n };\n }\n\n const controls = signal({\n up: {\n repeat: true,\n bind: keyboardControls.up,\n throttle: 150,\n keyDown() {\n if (guiService.isDisplaying(PrebuiltGui.Save)) return;\n moveSelection(-1);\n }\n },\n down: {\n repeat: true,\n bind: keyboardControls.down,\n throttle: 150,\n keyDown() {\n if (guiService.isDisplaying(PrebuiltGui.Save)) return;\n moveSelection(1);\n }\n },\n action: {\n bind: keyboardControls.action,\n keyDown() {\n if (guiService.isDisplaying(PrebuiltGui.Save)) return;\n triggerSelect(selectedEntry());\n }\n },\n gamepad: {\n enabled: true\n }\n });\n</script>\n"],"mappings":";;;;;;AAYM,SAAS,UAAS,SAAU;CACX,SAAS,OAAA;CACxB,MAAM,cAAc,eAAW,OAAA;CAC/B,MAAM,SAAS,OA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AAA,GAAA,EAAA,YAAA;EAAA,SAAA;EAAA,OAAA,EAAA,OAAA,uCAAA;CAAA,GAAA;EAAA,EAAA,YAAA;GAAA,SAAA;GAAA,OAAA,EAAA,OAAA,4CAAA;EAAA,GAAA,CAAA,EAAA,YAAA;GAAA,SAAA;GAAA,OAAA,EAAA,OAAA,4BAAA;GAAA,aAAA,eAAA,UAAA,CAAA;EAAA,CAAA,GAAA,KAAA,eAAA,aAAA,CAAA,SAAA,EAAA,YAAA;GAAA,SAAA;GAAA,OAAA,EAAA,OAAA,+BAAA;GAAA,aAAA,eAAA,aAAA,CAAA;EAAA,CAAA,CAAA,CAAA,CAAA;EAAA,EAAA,YAAA;GAAA,UAAA;GAAA;EAAA,GAAA,EAAA,YAAA;GAAA,SAAA;GAAA,OAAA,EAAA,OAAA,yDAAA;EAAA,GAAA,KAAA,UAAA,IAAA,OAAA,UAAA,EAAA,YAAA;GAAA,SAAA;GAAA,OAAA;IAAA,OAAA,CAAA,oBAAA,gBAAA,EAAA,UAAA,gBAAA,KAAA,EAAA,EAAA,CAAA;IAAA,iBAAA,eAAA,cAAA,MAAA,QAAA,SAAA,OAAA;IAAA,UAAA;IAAA,OAAA,YAAA,KAAA;GAAA;GAAA,aAAA,MAAA;EAAA,CAAA,CAAA,CAAA,CAAA;EAAA,KAAA,eAAA,YAAA,CAAA,SAAA,EAAA,YAAA;GAAA,SAAA;GAAA,OAAA,EAAA,OAAA,8BAAA;GAAA,aAAA,eAAA,YAAA,CAAA;EAAA,CAAA,CAAA;CAAA,CAAA,CACK;AACR;AAEA,IAAM,iBAEF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export declare const DEFAULT_HP_BAR_STYLE: {
|
|
2
|
+
fillColor: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const DEFAULT_SP_BAR_STYLE: {
|
|
5
|
+
fillColor: string;
|
|
6
|
+
};
|
|
7
|
+
type NumberResolver = (value: any, fallback?: number) => number;
|
|
8
|
+
export declare function getPointBounds(points?: any[], toNumber?: NumberResolver): {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function getComponentId(definition: any): any;
|
|
13
|
+
export declare function getComponentProps(definition: any): any;
|
|
14
|
+
export declare function estimateComponentSize(definition: any, { toNumber, estimateTextWidth }?: {
|
|
15
|
+
toNumber?: NumberResolver;
|
|
16
|
+
estimateTextWidth?: (value: any, style?: any) => number;
|
|
17
|
+
}): {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
export declare function computeBlockSize({ position, layout, rowMetrics, gap, graphic, hitbox }: {
|
|
22
|
+
position: string;
|
|
23
|
+
layout?: any;
|
|
24
|
+
rowMetrics: Array<{
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
cells: any[];
|
|
28
|
+
}>;
|
|
29
|
+
gap?: {
|
|
30
|
+
row: number;
|
|
31
|
+
column: number;
|
|
32
|
+
};
|
|
33
|
+
graphic: {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
};
|
|
37
|
+
hitbox: {
|
|
38
|
+
w: number;
|
|
39
|
+
h: number;
|
|
40
|
+
};
|
|
41
|
+
}): {
|
|
42
|
+
width: any;
|
|
43
|
+
height: any;
|
|
44
|
+
};
|
|
45
|
+
export declare function computeBlockPosition({ position, size, layout, graphic, hitbox }: {
|
|
46
|
+
position: string;
|
|
47
|
+
size: {
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
};
|
|
51
|
+
layout?: any;
|
|
52
|
+
graphic: {
|
|
53
|
+
left: number;
|
|
54
|
+
top: number;
|
|
55
|
+
right: number;
|
|
56
|
+
centerX: number;
|
|
57
|
+
centerY: number;
|
|
58
|
+
};
|
|
59
|
+
hitbox: {
|
|
60
|
+
w: number;
|
|
61
|
+
h: number;
|
|
62
|
+
};
|
|
63
|
+
}): {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
};
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
//#region src/components/player-components-utils.ts
|
|
2
|
+
var DEFAULT_HP_BAR_STYLE = { fillColor: "#ef4444" };
|
|
3
|
+
var DEFAULT_SP_BAR_STYLE = { fillColor: "#3b82f6" };
|
|
4
|
+
var DEFAULT_CELL_HEIGHT = 16;
|
|
5
|
+
var DEFAULT_CELL_WIDTH = 32;
|
|
6
|
+
var defaultToNumber = (value, fallback = 0) => {
|
|
7
|
+
const num = typeof value === "number" ? value : parseFloat(value);
|
|
8
|
+
return Number.isFinite(num) ? num : fallback;
|
|
9
|
+
};
|
|
10
|
+
function getPointBounds(points = [], toNumber = defaultToNumber) {
|
|
11
|
+
if (!Array.isArray(points) || points.length < 2) return {
|
|
12
|
+
width: 1,
|
|
13
|
+
height: 1
|
|
14
|
+
};
|
|
15
|
+
let minX = Infinity;
|
|
16
|
+
let minY = Infinity;
|
|
17
|
+
let maxX = -Infinity;
|
|
18
|
+
let maxY = -Infinity;
|
|
19
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
20
|
+
const x = toNumber(points[i], 0);
|
|
21
|
+
const y = toNumber(points[i + 1], 0);
|
|
22
|
+
minX = Math.min(minX, x);
|
|
23
|
+
minY = Math.min(minY, y);
|
|
24
|
+
maxX = Math.max(maxX, x);
|
|
25
|
+
maxY = Math.max(maxY, y);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
width: Math.max(1, maxX - minX),
|
|
29
|
+
height: Math.max(1, maxY - minY)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function getComponentId(definition) {
|
|
33
|
+
if (!definition) return void 0;
|
|
34
|
+
if (definition.id) return definition.id;
|
|
35
|
+
if (definition.type === "text") return "rpg:text";
|
|
36
|
+
if (definition.type === "hpBar") return "rpg:hpBar";
|
|
37
|
+
if (definition.type === "spBar") return "rpg:spBar";
|
|
38
|
+
if (definition.type === "bar") return "rpg:bar";
|
|
39
|
+
if (definition.type === "shape") return "rpg:shape";
|
|
40
|
+
if (definition.type === "image") return "rpg:image";
|
|
41
|
+
if (definition.type === "tile") return "rpg:tile";
|
|
42
|
+
return definition.type;
|
|
43
|
+
}
|
|
44
|
+
function getComponentProps(definition) {
|
|
45
|
+
if (definition.props) return definition.props;
|
|
46
|
+
if (definition.type === "text") return {
|
|
47
|
+
value: definition.value,
|
|
48
|
+
style: definition.style
|
|
49
|
+
};
|
|
50
|
+
if (definition.type === "hpBar") return {
|
|
51
|
+
current: "{hp}",
|
|
52
|
+
max: "{param.maxHp}",
|
|
53
|
+
style: {
|
|
54
|
+
...DEFAULT_HP_BAR_STYLE,
|
|
55
|
+
...definition.style
|
|
56
|
+
},
|
|
57
|
+
text: definition.text
|
|
58
|
+
};
|
|
59
|
+
if (definition.type === "spBar") return {
|
|
60
|
+
current: "{sp}",
|
|
61
|
+
max: "{param.maxSp}",
|
|
62
|
+
style: {
|
|
63
|
+
...DEFAULT_SP_BAR_STYLE,
|
|
64
|
+
...definition.style
|
|
65
|
+
},
|
|
66
|
+
text: definition.text
|
|
67
|
+
};
|
|
68
|
+
if (definition.type === "bar") return {
|
|
69
|
+
current: `{${definition.current}}`,
|
|
70
|
+
max: `{${definition.max}}`,
|
|
71
|
+
style: definition.style,
|
|
72
|
+
text: definition.text
|
|
73
|
+
};
|
|
74
|
+
if (definition.type === "shape") return definition.value;
|
|
75
|
+
if (definition.type === "image" || definition.type === "tile") return { value: definition.value };
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
function estimateComponentSize(definition, { toNumber = defaultToNumber, estimateTextWidth = (value) => String(value ?? "").length * 8 } = {}) {
|
|
79
|
+
const props = getComponentProps(definition);
|
|
80
|
+
const style = props?.style ?? definition?.style ?? {};
|
|
81
|
+
if (definition?.type === "text" || definition?.id === "rpg:text") return {
|
|
82
|
+
width: estimateTextWidth(props.value ?? definition.value, style),
|
|
83
|
+
height: toNumber(style.fontSize, 12)
|
|
84
|
+
};
|
|
85
|
+
if (definition?.type === "hpBar" || definition?.type === "spBar" || definition?.type === "bar" || definition?.id === "rpg:hpBar" || definition?.id === "rpg:spBar" || definition?.id === "rpg:bar") {
|
|
86
|
+
const barHeight = toNumber(style.height, 8);
|
|
87
|
+
const labelHeight = props.text != null && props.text !== "" ? toNumber(style.fontSize, 10) + 2 : 0;
|
|
88
|
+
return {
|
|
89
|
+
width: toNumber(style.width, 50),
|
|
90
|
+
height: barHeight + labelHeight
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (definition?.type === "shape" || definition?.id === "rpg:shape") {
|
|
94
|
+
const shape = props ?? {};
|
|
95
|
+
if (shape.type === "circle") {
|
|
96
|
+
const radius = toNumber(shape.radius, 8);
|
|
97
|
+
return {
|
|
98
|
+
width: radius * 2,
|
|
99
|
+
height: radius * 2
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (shape.type === "line") return {
|
|
103
|
+
width: Math.max(1, Math.abs(toNumber(shape.x2, 16) - toNumber(shape.x1, 0))),
|
|
104
|
+
height: Math.max(1, Math.abs(toNumber(shape.y2, 0) - toNumber(shape.y1, 0)))
|
|
105
|
+
};
|
|
106
|
+
if (shape.type === "polygon") return getPointBounds(shape.points, toNumber);
|
|
107
|
+
return {
|
|
108
|
+
width: toNumber(shape.width, 16),
|
|
109
|
+
height: toNumber(shape.height, 16)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
width: toNumber(definition?.props?.width, DEFAULT_CELL_WIDTH),
|
|
114
|
+
height: toNumber(definition?.props?.height, DEFAULT_CELL_HEIGHT)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function computeBlockSize({ position, layout = {}, rowMetrics, gap = {
|
|
118
|
+
row: 0,
|
|
119
|
+
column: 0
|
|
120
|
+
}, graphic, hitbox }) {
|
|
121
|
+
const rowGapTotal = Math.max(0, rowMetrics.length - 1) * gap.row;
|
|
122
|
+
const maxColumns = rowMetrics.reduce((max, row) => Math.max(max, row.cells.length), 0);
|
|
123
|
+
const columnGapTotal = Math.max(0, maxColumns - 1) * gap.column;
|
|
124
|
+
const contentWidth = rowMetrics.reduce((max, row) => Math.max(max, row.width), 0) + columnGapTotal;
|
|
125
|
+
const contentHeight = rowMetrics.reduce((sum, row) => sum + row.height, 0) + rowGapTotal;
|
|
126
|
+
return {
|
|
127
|
+
width: layout.width ?? Math.max(contentWidth, position === "bottom" ? hitbox.w : position === "top" || position === "center" ? graphic.width : contentWidth),
|
|
128
|
+
height: layout.height ?? Math.max(contentHeight, position === "bottom" ? hitbox.h : position === "left" || position === "right" || position === "center" ? graphic.height : contentHeight)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function computeBlockPosition({ position, size, layout = {}, graphic, hitbox }) {
|
|
132
|
+
const marginLeft = layout.marginLeft ?? 0;
|
|
133
|
+
const marginRight = layout.marginRight ?? 0;
|
|
134
|
+
const marginTop = layout.marginTop ?? 0;
|
|
135
|
+
const marginBottom = layout.marginBottom ?? 0;
|
|
136
|
+
switch (position) {
|
|
137
|
+
case "bottom": return {
|
|
138
|
+
x: hitbox.w / 2 - size.width / 2 + marginLeft - marginRight,
|
|
139
|
+
y: hitbox.h / 2 - size.height / 2 + marginBottom - marginTop
|
|
140
|
+
};
|
|
141
|
+
case "center": return {
|
|
142
|
+
x: graphic.centerX - size.width / 2 + marginLeft - marginRight,
|
|
143
|
+
y: graphic.centerY - size.height / 2 + marginTop - marginBottom
|
|
144
|
+
};
|
|
145
|
+
case "left": return {
|
|
146
|
+
x: graphic.left - size.width + marginLeft - marginRight,
|
|
147
|
+
y: graphic.centerY - size.height / 2 + marginTop - marginBottom
|
|
148
|
+
};
|
|
149
|
+
case "right": return {
|
|
150
|
+
x: graphic.right + marginLeft - marginRight,
|
|
151
|
+
y: graphic.centerY - size.height / 2 + marginTop - marginBottom
|
|
152
|
+
};
|
|
153
|
+
default: return {
|
|
154
|
+
x: graphic.centerX - size.width / 2 + marginLeft - marginRight,
|
|
155
|
+
y: graphic.top - size.height + marginTop - marginBottom
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
export { computeBlockPosition, computeBlockSize, estimateComponentSize, getComponentId, getComponentProps };
|
|
161
|
+
|
|
162
|
+
//# sourceMappingURL=player-components-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"player-components-utils.js","names":[],"sources":["../../src/components/player-components-utils.ts"],"sourcesContent":["export const DEFAULT_HP_BAR_STYLE = { fillColor: '#ef4444' };\nexport const DEFAULT_SP_BAR_STYLE = { fillColor: '#3b82f6' };\n\nconst DEFAULT_CELL_HEIGHT = 16;\nconst DEFAULT_CELL_WIDTH = 32;\n\ntype NumberResolver = (value: any, fallback?: number) => number;\n\nconst defaultToNumber: NumberResolver = (value, fallback = 0) => {\n const num = typeof value === 'number' ? value : parseFloat(value);\n return Number.isFinite(num) ? num : fallback;\n};\n\nexport function getPointBounds(points: any[] = [], toNumber: NumberResolver = defaultToNumber) {\n if (!Array.isArray(points) || points.length < 2) {\n return { width: 1, height: 1 };\n }\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < points.length; i += 2) {\n const x = toNumber(points[i], 0);\n const y = toNumber(points[i + 1], 0);\n minX = Math.min(minX, x);\n minY = Math.min(minY, y);\n maxX = Math.max(maxX, x);\n maxY = Math.max(maxY, y);\n }\n\n return {\n width: Math.max(1, maxX - minX),\n height: Math.max(1, maxY - minY)\n };\n}\n\nexport function getComponentId(definition: any) {\n if (!definition) return undefined;\n if (definition.id) return definition.id;\n if (definition.type === 'text') return 'rpg:text';\n if (definition.type === 'hpBar') return 'rpg:hpBar';\n if (definition.type === 'spBar') return 'rpg:spBar';\n if (definition.type === 'bar') return 'rpg:bar';\n if (definition.type === 'shape') return 'rpg:shape';\n if (definition.type === 'image') return 'rpg:image';\n if (definition.type === 'tile') return 'rpg:tile';\n return definition.type;\n}\n\nexport function getComponentProps(definition: any) {\n if (definition.props) return definition.props;\n\n if (definition.type === 'text') {\n return { value: definition.value, style: definition.style };\n }\n if (definition.type === 'hpBar') {\n return { current: '{hp}', max: '{param.maxHp}', style: { ...DEFAULT_HP_BAR_STYLE, ...definition.style }, text: definition.text };\n }\n if (definition.type === 'spBar') {\n return { current: '{sp}', max: '{param.maxSp}', style: { ...DEFAULT_SP_BAR_STYLE, ...definition.style }, text: definition.text };\n }\n if (definition.type === 'bar') {\n return { current: `{${definition.current}}`, max: `{${definition.max}}`, style: definition.style, text: definition.text };\n }\n if (definition.type === 'shape') {\n return definition.value;\n }\n if (definition.type === 'image' || definition.type === 'tile') {\n return { value: definition.value };\n }\n\n return {};\n}\n\nexport function estimateComponentSize(\n definition: any,\n {\n toNumber = defaultToNumber,\n estimateTextWidth = (value: any) => String(value ?? '').length * 8\n }: {\n toNumber?: NumberResolver;\n estimateTextWidth?: (value: any, style?: any) => number;\n } = {}\n) {\n const props = getComponentProps(definition);\n const style = props?.style ?? definition?.style ?? {};\n\n if (definition?.type === 'text' || definition?.id === 'rpg:text') {\n return {\n width: estimateTextWidth(props.value ?? definition.value, style),\n height: toNumber(style.fontSize, 12)\n };\n }\n\n if (definition?.type === 'hpBar' || definition?.type === 'spBar' || definition?.type === 'bar' || definition?.id === 'rpg:hpBar' || definition?.id === 'rpg:spBar' || definition?.id === 'rpg:bar') {\n const barHeight = toNumber(style.height, 8);\n const labelHeight = props.text != null && props.text !== '' ? toNumber(style.fontSize, 10) + 2 : 0;\n return {\n width: toNumber(style.width, 50),\n height: barHeight + labelHeight\n };\n }\n\n if (definition?.type === 'shape' || definition?.id === 'rpg:shape') {\n const shape = props ?? {};\n if (shape.type === 'circle') {\n const radius = toNumber(shape.radius, 8);\n return { width: radius * 2, height: radius * 2 };\n }\n if (shape.type === 'line') {\n return {\n width: Math.max(1, Math.abs(toNumber(shape.x2, 16) - toNumber(shape.x1, 0))),\n height: Math.max(1, Math.abs(toNumber(shape.y2, 0) - toNumber(shape.y1, 0)))\n };\n }\n if (shape.type === 'polygon') {\n return getPointBounds(shape.points, toNumber);\n }\n return {\n width: toNumber(shape.width, 16),\n height: toNumber(shape.height, 16)\n };\n }\n\n return {\n width: toNumber(definition?.props?.width, DEFAULT_CELL_WIDTH),\n height: toNumber(definition?.props?.height, DEFAULT_CELL_HEIGHT)\n };\n}\n\nexport function computeBlockSize({\n position,\n layout = {},\n rowMetrics,\n gap = { row: 0, column: 0 },\n graphic,\n hitbox\n}: {\n position: string;\n layout?: any;\n rowMetrics: Array<{ width: number; height: number; cells: any[] }>;\n gap?: { row: number; column: number };\n graphic: { width: number; height: number };\n hitbox: { w: number; h: number };\n}) {\n const rowGapTotal = Math.max(0, rowMetrics.length - 1) * gap.row;\n const maxColumns = rowMetrics.reduce((max, row) => Math.max(max, row.cells.length), 0);\n const columnGapTotal = Math.max(0, maxColumns - 1) * gap.column;\n const contentWidth = rowMetrics.reduce((max, row) => Math.max(max, row.width), 0) + columnGapTotal;\n const contentHeight = rowMetrics.reduce((sum, row) => sum + row.height, 0) + rowGapTotal;\n const width = layout.width ?? Math.max(contentWidth, position === 'bottom' ? hitbox.w : position === 'top' || position === 'center' ? graphic.width : contentWidth);\n const height = layout.height ?? Math.max(contentHeight, position === 'bottom' ? hitbox.h : position === 'left' || position === 'right' || position === 'center' ? graphic.height : contentHeight);\n\n return { width, height };\n}\n\nexport function computeBlockPosition({\n position,\n size,\n layout = {},\n graphic,\n hitbox\n}: {\n position: string;\n size: { width: number; height: number };\n layout?: any;\n graphic: { left: number; top: number; right: number; centerX: number; centerY: number };\n hitbox: { w: number; h: number };\n}) {\n const marginLeft = layout.marginLeft ?? 0;\n const marginRight = layout.marginRight ?? 0;\n const marginTop = layout.marginTop ?? 0;\n const marginBottom = layout.marginBottom ?? 0;\n\n switch (position) {\n case 'bottom':\n return {\n x: (hitbox.w / 2) - (size.width / 2) + marginLeft - marginRight,\n y: (hitbox.h / 2) - (size.height / 2) + marginBottom - marginTop\n };\n case 'center':\n return {\n x: graphic.centerX - (size.width / 2) + marginLeft - marginRight,\n y: graphic.centerY - (size.height / 2) + marginTop - marginBottom\n };\n case 'left':\n return {\n x: graphic.left - size.width + marginLeft - marginRight,\n y: graphic.centerY - (size.height / 2) + marginTop - marginBottom\n };\n case 'right':\n return {\n x: graphic.right + marginLeft - marginRight,\n y: graphic.centerY - (size.height / 2) + marginTop - marginBottom\n };\n case 'top':\n default:\n return {\n x: graphic.centerX - (size.width / 2) + marginLeft - marginRight,\n y: graphic.top - size.height + marginTop - marginBottom\n };\n }\n}\n"],"mappings":";AAAA,IAAa,uBAAuB,EAAE,WAAW,UAAU;AAC3D,IAAa,uBAAuB,EAAE,WAAW,UAAU;AAE3D,IAAM,sBAAsB;AAC5B,IAAM,qBAAqB;AAI3B,IAAM,mBAAmC,OAAO,WAAW,MAAM;CAC/D,MAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,WAAW,KAAK;CAChE,OAAO,OAAO,SAAS,GAAG,IAAI,MAAM;AACtC;AAEA,SAAgB,eAAe,SAAgB,CAAC,GAAG,WAA2B,iBAAiB;CAC7F,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,GAC5C,OAAO;EAAE,OAAO;EAAG,QAAQ;CAAE;CAG/B,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CAEX,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;EACzC,MAAM,IAAI,SAAS,OAAO,IAAI,CAAC;EAC/B,MAAM,IAAI,SAAS,OAAO,IAAI,IAAI,CAAC;EACnC,OAAO,KAAK,IAAI,MAAM,CAAC;EACvB,OAAO,KAAK,IAAI,MAAM,CAAC;EACvB,OAAO,KAAK,IAAI,MAAM,CAAC;EACvB,OAAO,KAAK,IAAI,MAAM,CAAC;CACzB;CAEA,OAAO;EACL,OAAO,KAAK,IAAI,GAAG,OAAO,IAAI;EAC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G,QAAQ,UAAW,KAAK,QAAQ,IAAK,aAAa;GACrD,GAAG,QAAQ,UAAW,KAAK,SAAS,IAAK,YAAY;EACvD;EACF,KAAK,QACH,OAAO;GACL,GAAG,QAAQ,OAAO,KAAK,QAAQ,aAAa;GAC5C,GAAG,QAAQ,UAAW,KAAK,SAAS,IAAK,YAAY;EACvD;EACF,KAAK,SACH,OAAO;GACL,GAAG,QAAQ,QAAQ,aAAa;GAChC,GAAG,QAAQ,UAAW,KAAK,SAAS,IAAK,YAAY;EACvD;EAEF,SACE,OAAO;GACL,GAAG,QAAQ,UAAW,KAAK,QAAQ,IAAK,aAAa;GACrD,GAAG,QAAQ,MAAM,KAAK,SAAS,YAAY;EAC7C;CACJ;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { inject } from "../core/inject.js";
|
|
2
|
+
import { resolveDynamicProps, resolveDynamicValue } from "./dynamics/parse-value.js";
|
|
3
|
+
import { RpgClientEngine } from "../RpgClientEngine.js";
|
|
4
|
+
import { computeBlockPosition, computeBlockSize, estimateComponentSize, getComponentId, getComponentProps } from "./player-components-utils.js";
|
|
5
|
+
import { Container, computed, h, loop, useDefineProps, useProps } from "canvasengine";
|
|
6
|
+
//#region src/components/player-components.ce
|
|
7
|
+
function component($$props) {
|
|
8
|
+
useProps($$props);
|
|
9
|
+
const { object, position, graphicBounds } = useDefineProps($$props)({ position: { default: "top" } });
|
|
10
|
+
const client = inject(RpgClientEngine);
|
|
11
|
+
const warnedComponents = /* @__PURE__ */ new Set();
|
|
12
|
+
const readPosition = computed(() => position?.() ?? "top");
|
|
13
|
+
const componentSource = computed(() => {
|
|
14
|
+
switch (readPosition()) {
|
|
15
|
+
case "bottom": return object.componentsBottom?.();
|
|
16
|
+
case "center": return object.componentsCenter?.();
|
|
17
|
+
case "left": return object.componentsLeft?.();
|
|
18
|
+
case "right": return object.componentsRight?.();
|
|
19
|
+
default: return object.componentsTop?.();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const componentData = computed(() => {
|
|
23
|
+
const value = componentSource();
|
|
24
|
+
if (!value) return {
|
|
25
|
+
components: [],
|
|
26
|
+
layout: {}
|
|
27
|
+
};
|
|
28
|
+
if (typeof value !== "string") return value;
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(value);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "production") console.warn("[RPGJS] Invalid server sprite component payload", error);
|
|
33
|
+
return {
|
|
34
|
+
components: [],
|
|
35
|
+
layout: {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const layout = computed(() => componentData()?.layout ?? {});
|
|
40
|
+
const rows = computed(() => componentData()?.components ?? []);
|
|
41
|
+
const hitbox = object.hitbox;
|
|
42
|
+
const toNumber = (value, fallback = 0) => {
|
|
43
|
+
const resolved = resolveDynamicValue(value, object);
|
|
44
|
+
const num = typeof resolved === "number" ? resolved : parseFloat(resolved);
|
|
45
|
+
return Number.isFinite(num) ? num : fallback;
|
|
46
|
+
};
|
|
47
|
+
const estimateTextWidth = (value, style = {}) => {
|
|
48
|
+
const text = String(resolveDynamicValue(value ?? "", object) ?? "");
|
|
49
|
+
const fontSize = toNumber(style.fontSize, 12);
|
|
50
|
+
return Math.max(1, Math.ceil(text.length * fontSize * .6));
|
|
51
|
+
};
|
|
52
|
+
const rowMetrics = computed(() => {
|
|
53
|
+
return rows().map((row) => {
|
|
54
|
+
const cells = row.map((definition) => {
|
|
55
|
+
const intrinsic = estimateComponentSize(definition, {
|
|
56
|
+
toNumber,
|
|
57
|
+
estimateTextWidth
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
definition,
|
|
61
|
+
width: intrinsic.width,
|
|
62
|
+
height: intrinsic.height
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
cells,
|
|
67
|
+
width: cells.reduce((sum, cell) => sum + cell.width, 0),
|
|
68
|
+
height: cells.reduce((max, cell) => Math.max(max, cell.height), 0)
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
const gap = computed(() => ({
|
|
73
|
+
row: toNumber(layout().rowGap ?? layout().gap, 0),
|
|
74
|
+
column: toNumber(layout().columnGap ?? layout().gap, 0)
|
|
75
|
+
}));
|
|
76
|
+
const fallbackBounds = computed(() => {
|
|
77
|
+
const box = hitbox();
|
|
78
|
+
const width = box?.w ?? 0;
|
|
79
|
+
const height = box?.h ?? 0;
|
|
80
|
+
return {
|
|
81
|
+
left: 0,
|
|
82
|
+
top: 0,
|
|
83
|
+
right: width,
|
|
84
|
+
bottom: height,
|
|
85
|
+
width,
|
|
86
|
+
height,
|
|
87
|
+
centerX: width / 2,
|
|
88
|
+
centerY: height / 2
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
const bounds = computed(() => {
|
|
92
|
+
return (typeof graphicBounds === "function" ? graphicBounds() : void 0) ?? fallbackBounds();
|
|
93
|
+
});
|
|
94
|
+
const blockSize = computed(() => {
|
|
95
|
+
const box = hitbox() ?? {
|
|
96
|
+
w: 0,
|
|
97
|
+
h: 0
|
|
98
|
+
};
|
|
99
|
+
const graphic = bounds();
|
|
100
|
+
return computeBlockSize({
|
|
101
|
+
position: readPosition(),
|
|
102
|
+
layout: layout(),
|
|
103
|
+
rowMetrics: rowMetrics(),
|
|
104
|
+
gap: gap(),
|
|
105
|
+
graphic,
|
|
106
|
+
hitbox: box
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
const blockPosition = computed(() => {
|
|
110
|
+
const box = hitbox() ?? {
|
|
111
|
+
w: 0,
|
|
112
|
+
h: 0
|
|
113
|
+
};
|
|
114
|
+
const graphic = bounds();
|
|
115
|
+
return computeBlockPosition({
|
|
116
|
+
position: readPosition(),
|
|
117
|
+
size: blockSize(),
|
|
118
|
+
layout: layout(),
|
|
119
|
+
graphic,
|
|
120
|
+
hitbox: box
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
const warnMissingComponent = (id) => {
|
|
124
|
+
if (!id || warnedComponents.has(id)) return;
|
|
125
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") return;
|
|
126
|
+
warnedComponents.add(id);
|
|
127
|
+
console.warn(`[RPGJS] Server sprite component "${id}" is not registered on the client.`);
|
|
128
|
+
};
|
|
129
|
+
const renderedRows = computed(() => {
|
|
130
|
+
return rowMetrics().map((row) => {
|
|
131
|
+
const entries = [];
|
|
132
|
+
row.cells.forEach((cell) => {
|
|
133
|
+
const definition = cell.definition;
|
|
134
|
+
const id = getComponentId(definition);
|
|
135
|
+
const component = client.getSpriteComponent(id);
|
|
136
|
+
if (!component) {
|
|
137
|
+
warnMissingComponent(id);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
entries.push({
|
|
141
|
+
component,
|
|
142
|
+
props: resolveDynamicProps(getComponentProps(definition), object),
|
|
143
|
+
width: cell.width,
|
|
144
|
+
height: cell.height
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
height: row.height,
|
|
149
|
+
entries
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
return h(Container, {
|
|
154
|
+
x: computed(() => blockPosition().x),
|
|
155
|
+
y: computed(() => blockPosition().y),
|
|
156
|
+
width: computed(() => blockSize().width),
|
|
157
|
+
height: computed(() => blockSize().height),
|
|
158
|
+
minWidth: computed(() => blockSize().width),
|
|
159
|
+
minHeight: computed(() => blockSize().height),
|
|
160
|
+
display: "flex",
|
|
161
|
+
flexDirection: "column",
|
|
162
|
+
justifyContent: "center",
|
|
163
|
+
alignItems: "center",
|
|
164
|
+
rowGap: computed(() => gap().row)
|
|
165
|
+
}, loop(renderedRows, (row) => h(Container, {
|
|
166
|
+
width: "100%",
|
|
167
|
+
height: row.height,
|
|
168
|
+
display: "flex",
|
|
169
|
+
flexDirection: "row",
|
|
170
|
+
justifyContent: "center",
|
|
171
|
+
alignItems: "center",
|
|
172
|
+
columnGap: computed(() => gap().column)
|
|
173
|
+
}, loop(row.entries, (entry) => h(Container, {
|
|
174
|
+
width: entry.width,
|
|
175
|
+
height: entry.height,
|
|
176
|
+
display: "flex",
|
|
177
|
+
justifyContent: "center",
|
|
178
|
+
alignItems: "center"
|
|
179
|
+
}, h(entry.component, {
|
|
180
|
+
object,
|
|
181
|
+
...entry.props
|
|
182
|
+
}))))));
|
|
183
|
+
}
|
|
184
|
+
var __ce_component = component;
|
|
185
|
+
//#endregion
|
|
186
|
+
export { __ce_component as default };
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=player-components.ce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"player-components.ce.js","names":[],"sources":["../../src/components/player-components.ce"],"sourcesContent":["<Container\n x={blockPosition().x}\n y={blockPosition().y}\n width={blockSize().width}\n height={blockSize().height}\n minWidth={blockSize().width}\n minHeight={blockSize().height}\n display=\"flex\"\n flexDirection=\"column\"\n justifyContent=\"center\"\n alignItems=\"center\"\n rowGap={gap().row}\n>\n @for (row of renderedRows) {\n <Container\n width=\"100%\"\n height={row.height}\n display=\"flex\"\n flexDirection=\"row\"\n justifyContent=\"center\"\n alignItems=\"center\"\n columnGap={gap().column}\n >\n @for (entry of row.entries) {\n <Container\n width={entry.width}\n height={entry.height}\n display=\"flex\"\n justifyContent=\"center\"\n alignItems=\"center\"\n >\n <entry.component object ...entry.props />\n </Container>\n }\n </Container>\n }\n</Container>\n\n<script>\nimport { computed } from \"canvasengine\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { inject } from \"../core/inject\";\nimport { resolveDynamicProps, resolveDynamicValue } from \"./dynamics/parse-value\";\nimport {\n computeBlockPosition,\n computeBlockSize,\n estimateComponentSize,\n getComponentId,\n getComponentProps\n} from \"./player-components-utils\";\n\nconst { object, position, graphicBounds } = defineProps({\n position: {\n default: 'top'\n }\n});\n\nconst client = inject(RpgClientEngine);\nconst warnedComponents = new Set();\n\nconst readPosition = computed(() => position?.() ?? 'top');\n\nconst componentSource = computed(() => {\n switch (readPosition()) {\n case 'bottom':\n return object.componentsBottom?.();\n case 'center':\n return object.componentsCenter?.();\n case 'left':\n return object.componentsLeft?.();\n case 'right':\n return object.componentsRight?.();\n case 'top':\n default:\n return object.componentsTop?.();\n }\n});\n\nconst componentData = computed(() => {\n const value = componentSource();\n if (!value) {\n return { components: [], layout: {} };\n }\n\n if (typeof value !== 'string') {\n return value;\n }\n\n try {\n return JSON.parse(value);\n } catch (error) {\n if (typeof process === 'undefined' || process.env?.NODE_ENV !== 'production') {\n console.warn('[RPGJS] Invalid server sprite component payload', error);\n }\n return { components: [], layout: {} };\n }\n});\n\nconst layout = computed(() => componentData()?.layout ?? {});\nconst rows = computed(() => componentData()?.components ?? []);\nconst hitbox = object.hitbox;\n\nconst toNumber = (value, fallback = 0) => {\n const resolved = resolveDynamicValue(value, object);\n const num = typeof resolved === 'number' ? resolved : parseFloat(resolved);\n return Number.isFinite(num) ? num : fallback;\n};\n\nconst estimateTextWidth = (value, style = {}) => {\n const text = String(resolveDynamicValue(value ?? '', object) ?? '');\n const fontSize = toNumber(style.fontSize, 12);\n return Math.max(1, Math.ceil(text.length * fontSize * 0.6));\n};\n\nconst rowMetrics = computed(() => {\n return rows().map((row) => {\n const cells = row.map((definition) => {\n const intrinsic = estimateComponentSize(definition, { toNumber, estimateTextWidth });\n return {\n definition,\n width: intrinsic.width,\n height: intrinsic.height\n };\n });\n\n return {\n cells,\n width: cells.reduce((sum, cell) => sum + cell.width, 0),\n height: cells.reduce((max, cell) => Math.max(max, cell.height), 0)\n };\n });\n});\n\nconst gap = computed(() => ({\n row: toNumber(layout().rowGap ?? layout().gap, 0),\n column: toNumber(layout().columnGap ?? layout().gap, 0)\n}));\n\nconst fallbackBounds = computed(() => {\n const box = hitbox();\n const width = box?.w ?? 0;\n const height = box?.h ?? 0;\n\n return {\n left: 0,\n top: 0,\n right: width,\n bottom: height,\n width,\n height,\n centerX: width / 2,\n centerY: height / 2\n };\n});\n\nconst bounds = computed(() => {\n const resolvedBounds = typeof graphicBounds === 'function' ? graphicBounds() : undefined;\n return resolvedBounds ?? fallbackBounds();\n});\n\nconst blockSize = computed(() => {\n const box = hitbox() ?? { w: 0, h: 0 };\n const graphic = bounds();\n return computeBlockSize({\n position: readPosition(),\n layout: layout(),\n rowMetrics: rowMetrics(),\n gap: gap(),\n graphic,\n hitbox: box\n });\n});\n\nconst blockPosition = computed(() => {\n const box = hitbox() ?? { w: 0, h: 0 };\n const graphic = bounds();\n return computeBlockPosition({\n position: readPosition(),\n size: blockSize(),\n layout: layout(),\n graphic,\n hitbox: box\n });\n});\n\nconst warnMissingComponent = (id) => {\n if (!id || warnedComponents.has(id)) return;\n if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'production') return;\n warnedComponents.add(id);\n console.warn(`[RPGJS] Server sprite component \"${id}\" is not registered on the client.`);\n};\n\nconst renderedRows = computed(() => {\n return rowMetrics().map((row) => {\n const entries = [];\n\n row.cells.forEach((cell) => {\n const definition = cell.definition;\n const id = getComponentId(definition);\n const component = client.getSpriteComponent(id);\n\n if (!component) {\n warnMissingComponent(id);\n return;\n }\n\n entries.push({\n component,\n props: resolveDynamicProps(getComponentProps(definition), object),\n width: cell.width,\n height: cell.height\n });\n });\n\n return {\n height: row.height,\n entries\n };\n });\n});\n</script>\n"],"mappings":";;;;;;AAUE,SAAY,UAAM,SAAA;CACD,SAAA,OAAA;CAEX,MAAM,EAAC,QAAA,UAAc,kBAD7B,eAAA,OAC6B,EAAA,EACzB,UAAC,EACC,SAAW,MACb,EACJ,CAAC;CACD,MAAM,SAAA,OAAe,eAAG;CACxB,MAAM,mCAAgB,IAAM,IAAA;CAC5B,MAAM,eAAY,eAAM,WAAA,KAAA,KAAA;CACxB,MAAM,kBAAiB,eAAM;EACzB,QAAA,aAAA,GAAA;GACG,KAAK,UACH,OAAA,OAAA,mBAAA;GACD,KAA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