@rpgjs/client 5.0.0-alpha.9 → 5.0.0-beta.1
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/dist/Game/AnimationManager.d.ts +8 -0
- package/dist/Game/AnimationManager.js +26 -0
- package/dist/Game/AnimationManager.js.map +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 +23 -2
- package/dist/Game/Map.js +80 -0
- package/dist/Game/Map.js.map +1 -0
- package/dist/Game/Object.d.ts +157 -0
- package/dist/Game/Object.js +211 -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 +177 -5
- package/dist/Gui/Gui.js +445 -0
- package/dist/Gui/Gui.js.map +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 +238 -11
- package/dist/RpgClientEngine.d.ts +615 -14
- package/dist/RpgClientEngine.js +1334 -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.122.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/animations/animation.ce.js +24 -0
- package/dist/components/animations/animation.ce.js.map +1 -0
- package/dist/components/animations/hit.ce.js +70 -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 +392 -0
- package/dist/components/character.ce.js.map +1 -0
- package/dist/components/dynamics/parse-value.d.ts +1 -0
- package/dist/components/dynamics/parse-value.js +44 -0
- package/dist/components/dynamics/parse-value.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +73 -0
- package/dist/components/dynamics/text.ce.js.map +1 -0
- package/dist/components/gui/box.ce.js +28 -0
- package/dist/components/gui/box.ce.js.map +1 -0
- package/dist/components/gui/dialogbox/index.ce.js +205 -0
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
- package/dist/components/gui/gameover.ce.js +193 -0
- package/dist/components/gui/gameover.ce.js.map +1 -0
- package/dist/components/gui/hud/hud.ce.js +92 -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 +481 -0
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/exit-menu.ce.js +54 -0
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/items-menu.ce.js +344 -0
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/main-menu.ce.js +417 -0
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/options-menu.ce.js +48 -0
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/skills-menu.ce.js +107 -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 +78 -0
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
- package/dist/components/gui/notification/notification.ce.js +64 -0
- package/dist/components/gui/notification/notification.ce.js.map +1 -0
- package/dist/components/gui/save-load.ce.js +389 -0
- package/dist/components/gui/save-load.ce.js.map +1 -0
- package/dist/components/gui/shop/shop.ce.js +652 -0
- package/dist/components/gui/shop/shop.ce.js.map +1 -0
- package/dist/components/gui/title-screen.ce.js +190 -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/prebuilt/hp-bar.ce.js +116 -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 +94 -0
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
- package/dist/components/scenes/canvas.ce.js +60 -0
- package/dist/components/scenes/canvas.ce.js.map +1 -0
- package/dist/components/scenes/draw-map.ce.js +89 -0
- package/dist/components/scenes/draw-map.ce.js.map +1 -0
- package/dist/components/scenes/event-layer.ce.js +28 -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/index.d.ts +15 -1
- package/dist/index.js +44 -14
- package/dist/module.d.ts +43 -4
- package/dist/module.js +176 -0
- package/dist/module.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js +277 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +457 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +463 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +2191 -0
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +10 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +91 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js +325 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +14 -0
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/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.js +123 -0
- package/dist/services/loadMap.js.map +1 -0
- package/dist/services/mmorpg.d.ts +21 -9
- package/dist/services/mmorpg.js +131 -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/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 +52 -0
- package/dist/utils/getEntityProp.js.map +1 -0
- package/package.json +13 -9
- package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
- package/src/Game/Event.ts +1 -1
- package/src/Game/Map.ts +95 -3
- package/src/Game/Object.ts +330 -14
- package/src/Game/Player.ts +1 -1
- package/src/Gui/Gui.ts +506 -18
- package/src/Gui/NotificationManager.ts +69 -0
- package/src/Resource.ts +150 -0
- package/src/RpgClient.ts +246 -12
- package/src/RpgClientEngine.ts +1641 -62
- 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 +387 -52
- package/src/components/dynamics/parse-value.ts +80 -0
- package/src/components/dynamics/text.ce +183 -0
- package/src/components/gui/box.ce +17 -0
- package/src/components/gui/dialogbox/index.ce +204 -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/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 +20 -15
- package/src/components/scenes/draw-map.ce +60 -13
- package/src/components/scenes/event-layer.ce +7 -0
- package/src/components/scenes/transition.ce +60 -0
- package/src/index.ts +16 -2
- package/src/module.ts +127 -9
- 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 +1 -1
- package/src/services/mmorpg.ts +100 -12
- package/src/services/save.ts +103 -0
- package/src/services/standalone.ts +110 -18
- package/src/utils/getEntityProp.ts +87 -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/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
|
@@ -1,44 +1,57 @@
|
|
|
1
|
-
<Container x y zIndex={
|
|
2
|
-
@for (
|
|
1
|
+
<Container x={smoothX} y={smoothY} zIndex={z} viewportFollow={shouldFollowCamera} controls onBeforeDestroy visible>
|
|
2
|
+
@for (compConfig of normalizedComponentsBehind) {
|
|
3
3
|
<Container>
|
|
4
|
-
<component object />
|
|
4
|
+
<compConfig.component object ...compConfig.props />
|
|
5
5
|
</Container>
|
|
6
6
|
}
|
|
7
|
-
<Particle emit={
|
|
7
|
+
<Particle emit={emitParticleTrigger} settings={particleSettings} zIndex={1000} name={particleName} />
|
|
8
8
|
<Container>
|
|
9
|
-
@for (
|
|
10
|
-
<Sprite
|
|
9
|
+
@for (graphicObj of graphicsSignals) {
|
|
10
|
+
<Sprite
|
|
11
|
+
sheet={sheet(graphicObj)}
|
|
12
|
+
direction
|
|
13
|
+
tint
|
|
14
|
+
hitbox
|
|
15
|
+
flash={flashConfig}
|
|
16
|
+
/>
|
|
11
17
|
}
|
|
12
18
|
</Container>
|
|
13
|
-
@for (
|
|
14
|
-
<Container>
|
|
15
|
-
<component object />
|
|
19
|
+
@for (compConfig of normalizedComponentsInFront) {
|
|
20
|
+
<Container dependencies={compConfig.dependencies}>
|
|
21
|
+
<compConfig.component object ...compConfig.props />
|
|
16
22
|
</Container>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
}
|
|
24
|
+
@for (attachedGui of attachedGuis) {
|
|
25
|
+
@if (shouldDisplayAttachedGui) {
|
|
26
|
+
<Container>
|
|
27
|
+
<attachedGui.component ...attachedGui.data() dependencies={attachedGui.dependencies} object={object} onFinish={(data) => {
|
|
28
|
+
onAttachedGuiFinish(attachedGui, data)
|
|
29
|
+
}} onInteraction={(name, data) => {
|
|
30
|
+
onAttachedGuiInteraction(attachedGui, name, data)
|
|
31
|
+
}} />
|
|
32
|
+
</Container>
|
|
33
|
+
}
|
|
34
|
+
}
|
|
27
35
|
</Container>
|
|
28
36
|
|
|
29
37
|
<script>
|
|
30
|
-
import { signal, effect, mount, computed, tick } from "canvasengine";
|
|
38
|
+
import { signal, effect, mount, computed, tick, animatedSignal, on } from "canvasengine";
|
|
39
|
+
|
|
40
|
+
import { lastValueFrom, combineLatest, pairwise, filter, map, startWith } from "rxjs";
|
|
31
41
|
import { Particle } from "@canvasengine/presets";
|
|
32
42
|
import { GameEngineToken, ModulesToken } from "@rpgjs/common";
|
|
33
43
|
import { RpgClientEngine } from "../RpgClientEngine";
|
|
34
44
|
import { inject } from "../core/inject";
|
|
35
45
|
import { Direction } from "@rpgjs/common";
|
|
36
46
|
import Hit from "./effects/hit.ce";
|
|
47
|
+
import PlayerComponents from "./player-components.ce";
|
|
48
|
+
import { RpgGui } from "../Gui/Gui";
|
|
37
49
|
|
|
38
50
|
const { object, id } = defineProps();
|
|
39
|
-
|
|
51
|
+
|
|
40
52
|
const client = inject(RpgClientEngine);
|
|
41
53
|
const hooks = inject(ModulesToken);
|
|
54
|
+
const guiService = inject(RpgGui);
|
|
42
55
|
|
|
43
56
|
const spritesheets = client.spritesheets;
|
|
44
57
|
const playerId = client.playerId;
|
|
@@ -46,27 +59,239 @@
|
|
|
46
59
|
const componentsInFront = client.spriteComponentsInFront;
|
|
47
60
|
const isMe = computed(() => id() === playerId);
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Normalize a single sprite component configuration
|
|
64
|
+
*
|
|
65
|
+
* Handles both direct component references and configuration objects with optional props and dependencies.
|
|
66
|
+
* Extracts the component reference and creates a computed function that returns the props.
|
|
67
|
+
*
|
|
68
|
+
* ## Design
|
|
69
|
+
*
|
|
70
|
+
* Supports two formats:
|
|
71
|
+
* 1. Direct component: `ShadowComponent`
|
|
72
|
+
* 2. Configuration object: `{ component: LightHalo, props: {...}, dependencies: (object) => [...] }`
|
|
73
|
+
*
|
|
74
|
+
* The normalization process:
|
|
75
|
+
* - Extracts the actual component from either format
|
|
76
|
+
* - Extracts dependencies function if provided
|
|
77
|
+
* - Creates a computed function that returns props (static object or dynamic function result)
|
|
78
|
+
* - Returns a normalized object with `component`, `props`, and `dependencies`
|
|
79
|
+
*
|
|
80
|
+
* @param comp - Component reference or configuration object
|
|
81
|
+
* @returns Normalized component configuration with component, props, and dependencies
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // Direct component
|
|
86
|
+
* normalizeComponent(ShadowComponent)
|
|
87
|
+
* // => { component: ShadowComponent, props: {}, dependencies: undefined }
|
|
88
|
+
*
|
|
89
|
+
* // With static props
|
|
90
|
+
* normalizeComponent({ component: LightHalo, props: { radius: 30 } })
|
|
91
|
+
* // => { component: LightHalo, props: { radius: 30 }, dependencies: undefined }
|
|
92
|
+
*
|
|
93
|
+
* // With dynamic props and dependencies
|
|
94
|
+
* normalizeComponent({
|
|
95
|
+
* component: HealthBar,
|
|
96
|
+
* props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),
|
|
97
|
+
* dependencies: (object) => [object.hp, object.param.maxHp]
|
|
98
|
+
* })
|
|
99
|
+
* // => { component: HealthBar, props: {...}, dependencies: (object) => [...] }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
const normalizeComponent = (comp) => {
|
|
103
|
+
let componentRef;
|
|
104
|
+
let propsValue;
|
|
105
|
+
let dependenciesFn;
|
|
106
|
+
|
|
107
|
+
// If it's a direct component reference
|
|
108
|
+
if (typeof comp === 'function' || (comp && typeof comp === 'object' && !comp.component)) {
|
|
109
|
+
componentRef = comp;
|
|
110
|
+
propsValue = undefined;
|
|
111
|
+
dependenciesFn = undefined;
|
|
112
|
+
}
|
|
113
|
+
// If it's a configuration object with component and props
|
|
114
|
+
else if (comp && typeof comp === 'object' && comp.component) {
|
|
115
|
+
componentRef = comp.component;
|
|
116
|
+
// Support both "data" (legacy) and "props" (new) for backward compatibility
|
|
117
|
+
propsValue = comp.props !== undefined ? comp.props : comp.data;
|
|
118
|
+
dependenciesFn = comp.dependencies;
|
|
119
|
+
}
|
|
120
|
+
// Fallback: treat as direct component
|
|
121
|
+
else {
|
|
122
|
+
componentRef = comp;
|
|
123
|
+
propsValue = undefined;
|
|
124
|
+
dependenciesFn = undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Return props directly (object or function), not as computed
|
|
128
|
+
// The computed will be created in the template when needed
|
|
129
|
+
return {
|
|
130
|
+
component: componentRef,
|
|
131
|
+
props: typeof propsValue === 'function' ? propsValue(object) : propsValue || {},
|
|
132
|
+
dependencies: dependenciesFn ? dependenciesFn(object) : []
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Normalize an array of sprite components
|
|
138
|
+
*
|
|
139
|
+
* Applies normalization to each component in the array using `normalizeComponent`.
|
|
140
|
+
*
|
|
141
|
+
* @param components - Array of component references or configuration objects
|
|
142
|
+
* @returns Array of normalized component configurations
|
|
143
|
+
*/
|
|
144
|
+
const normalizeComponents = (components) => {
|
|
145
|
+
return components.map((comp) => normalizeComponent(comp));
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Normalized components to render behind sprites
|
|
151
|
+
* Handles both direct component references and configuration objects with optional props and dependencies
|
|
152
|
+
*
|
|
153
|
+
* Supports multiple formats:
|
|
154
|
+
* 1. Direct component: `ShadowComponent`
|
|
155
|
+
* 2. Configuration object: `{ component: LightHalo, props: {...} }`
|
|
156
|
+
* 3. With dynamic props: `{ component: LightHalo, props: (object) => {...} }`
|
|
157
|
+
* 4. With dependencies: `{ component: HealthBar, dependencies: (object) => [object.hp, object.param.maxHp] }`
|
|
158
|
+
*
|
|
159
|
+
* Components with dependencies will only be displayed when all dependencies are resolved (!= undefined).
|
|
160
|
+
* The object is passed to the dependencies function to allow sprite-specific dependency resolution.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* // Direct component
|
|
165
|
+
* componentsBehind: [ShadowComponent]
|
|
166
|
+
*
|
|
167
|
+
* // With static props
|
|
168
|
+
* componentsBehind: [{ component: LightHalo, props: { radius: 30 } }]
|
|
169
|
+
*
|
|
170
|
+
* // With dynamic props and dependencies
|
|
171
|
+
* componentsBehind: [{
|
|
172
|
+
* component: HealthBar,
|
|
173
|
+
* props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),
|
|
174
|
+
* dependencies: (object) => [object.hp, object.param.maxHp]
|
|
175
|
+
* }]
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
const normalizedComponentsBehind = computed(() => {
|
|
179
|
+
return normalizeComponents(componentsBehind());
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Normalized components to render in front of sprites
|
|
184
|
+
* Handles both direct component references and configuration objects with optional props and dependencies
|
|
185
|
+
*
|
|
186
|
+
* See `normalizedComponentsBehind` for format details.
|
|
187
|
+
* Components with dependencies will only be displayed when all dependencies are resolved.
|
|
188
|
+
*/
|
|
189
|
+
const normalizedComponentsInFront = computed(() => {
|
|
190
|
+
return normalizeComponents(componentsInFront());
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Determine if the camera should follow this sprite
|
|
195
|
+
*
|
|
196
|
+
* The camera follows this sprite if:
|
|
197
|
+
* - It's explicitly set as the camera follow target, OR
|
|
198
|
+
* - It's the current player and no explicit target is set (default behavior)
|
|
199
|
+
*/
|
|
200
|
+
const shouldFollowCamera = computed(() => {
|
|
201
|
+
const cameraTargetId = client.cameraFollowTargetId();
|
|
202
|
+
// If a target is explicitly set, only follow if this sprite is the target
|
|
203
|
+
if (cameraTargetId !== null) {
|
|
204
|
+
return id() === cameraTargetId;
|
|
205
|
+
}
|
|
206
|
+
// Otherwise, follow the current player (default behavior)
|
|
207
|
+
return isMe();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Get all attached GUI components that should be rendered on sprites
|
|
212
|
+
* These are GUIs with attachToSprite: true
|
|
213
|
+
*/
|
|
214
|
+
const attachedGuis = computed(() => {
|
|
215
|
+
return guiService.getAttachedGuis();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Check if attached GUIs should be displayed for this sprite
|
|
220
|
+
* This is controlled by showAttachedGui/hideAttachedGui on the server
|
|
221
|
+
*/
|
|
222
|
+
const shouldDisplayAttachedGui = computed(() => {
|
|
223
|
+
return guiService.shouldDisplayAttachedGui(id());
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const {
|
|
227
|
+
x,
|
|
228
|
+
y,
|
|
229
|
+
tint,
|
|
230
|
+
direction,
|
|
231
|
+
animationName,
|
|
232
|
+
animationCurrentIndex,
|
|
233
|
+
emitParticleTrigger,
|
|
234
|
+
particleName,
|
|
235
|
+
graphics,
|
|
236
|
+
hitbox,
|
|
237
|
+
isConnected,
|
|
238
|
+
graphicsSignals,
|
|
239
|
+
flashTrigger
|
|
240
|
+
} = object;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Flash configuration signals for dynamic options
|
|
244
|
+
* These signals are updated when the flash trigger is activated with options
|
|
245
|
+
*/
|
|
246
|
+
const flashType = signal<'alpha' | 'tint' | 'both'>('alpha');
|
|
247
|
+
const flashDuration = signal(300);
|
|
248
|
+
const flashCycles = signal(1);
|
|
249
|
+
const flashAlpha = signal(0.3);
|
|
250
|
+
const flashTint = signal(0xffffff);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Listen to flash trigger to update configuration dynamically
|
|
254
|
+
* When flash is triggered with options, update the signals
|
|
255
|
+
*/
|
|
256
|
+
on(flashTrigger, (data) => {
|
|
257
|
+
if (data && typeof data === 'object') {
|
|
258
|
+
if (data.type !== undefined) flashType.set(data.type);
|
|
259
|
+
if (data.duration !== undefined) flashDuration.set(data.duration);
|
|
260
|
+
if (data.cycles !== undefined) flashCycles.set(data.cycles);
|
|
261
|
+
if (data.alpha !== undefined) flashAlpha.set(data.alpha);
|
|
262
|
+
if (data.tint !== undefined) flashTint.set(data.tint);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Flash configuration for the sprite
|
|
268
|
+
*
|
|
269
|
+
* This configuration is used by the flash directive to create visual feedback effects.
|
|
270
|
+
* The flash trigger is exposed through the object, allowing both server events and
|
|
271
|
+
* client-side code to trigger flash animations. Options can be passed dynamically
|
|
272
|
+
* through the trigger, which updates the reactive signals.
|
|
273
|
+
*/
|
|
274
|
+
const flashConfig = computed(() => ({
|
|
275
|
+
trigger: flashTrigger,
|
|
276
|
+
type: flashType(),
|
|
277
|
+
duration: flashDuration(),
|
|
278
|
+
cycles: flashCycles(),
|
|
279
|
+
alpha: flashAlpha(),
|
|
280
|
+
tint: flashTint(),
|
|
281
|
+
}));
|
|
282
|
+
|
|
55
283
|
const particleSettings = client.particleSettings;
|
|
56
|
-
|
|
57
|
-
const graphics = object.graphics;
|
|
58
|
-
|
|
59
|
-
const hitbox = object.hitbox;
|
|
60
|
-
const widthShadow = 10;
|
|
61
|
-
const shadow = computed(() => ({
|
|
62
|
-
x: hitbox().w / 2,
|
|
63
|
-
y: hitbox().h - (hitbox().h / 2),
|
|
64
|
-
width: hitbox().w + widthShadow,
|
|
65
|
-
height: hitbox().h,
|
|
66
|
-
}))
|
|
284
|
+
|
|
67
285
|
const canControls = () => isMe() && object.canMove()
|
|
68
286
|
const keyboardControls = client.globalConfig.keyboardControls;
|
|
69
287
|
|
|
288
|
+
const visible = computed(() => {
|
|
289
|
+
if (object.isEvent()) {
|
|
290
|
+
return true
|
|
291
|
+
}
|
|
292
|
+
return isConnected()
|
|
293
|
+
});
|
|
294
|
+
|
|
70
295
|
const controls = signal({
|
|
71
296
|
down: {
|
|
72
297
|
repeat: true,
|
|
@@ -101,35 +326,145 @@
|
|
|
101
326
|
keyDown() {
|
|
102
327
|
if (canControls()) {
|
|
103
328
|
client.processAction({ action: 'action' })
|
|
104
|
-
// particleName.set('hit')
|
|
105
|
-
// emitParticleTrigger.start()
|
|
106
|
-
// object.flash('red')
|
|
107
329
|
}
|
|
108
330
|
},
|
|
109
331
|
},
|
|
332
|
+
escape: {
|
|
333
|
+
bind: keyboardControls.escape,
|
|
334
|
+
keyDown() {
|
|
335
|
+
if (canControls()) {
|
|
336
|
+
client.processAction({ action: 'escape' })
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
gamepad: {
|
|
341
|
+
enabled: true
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const smoothX = animatedSignal(x(), {
|
|
346
|
+
duration: isMe() ? 0 : 0
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const smoothY = animatedSignal(y(), {
|
|
350
|
+
duration: isMe() ? 0 : 0,
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
const z = computed(() => {
|
|
354
|
+
return object.y() + object.z()
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const realAnimationName = signal(animationName());
|
|
358
|
+
|
|
359
|
+
const xSubscription = x.observable.subscribe((value) => {
|
|
360
|
+
smoothX.set(value);
|
|
110
361
|
});
|
|
111
362
|
|
|
112
|
-
const
|
|
363
|
+
const ySubscription = y.observable.subscribe((value) => {
|
|
364
|
+
smoothY.set(value);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
const sheet = (graphicObject) => {
|
|
113
368
|
return {
|
|
114
|
-
definition:
|
|
115
|
-
playing:
|
|
369
|
+
definition: graphicObject,
|
|
370
|
+
playing: realAnimationName(),
|
|
116
371
|
params: {
|
|
117
|
-
direction
|
|
372
|
+
direction: direction()
|
|
118
373
|
},
|
|
374
|
+
onFinish() {
|
|
375
|
+
animationCurrentIndex.update(index => index + 1)
|
|
376
|
+
}
|
|
119
377
|
};
|
|
120
378
|
}
|
|
121
379
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
380
|
+
// Combine animation change detection with movement state from smoothX/smoothY
|
|
381
|
+
const movementAnimations = ['walk', 'stand'];
|
|
382
|
+
const epsilon = 0; // movement threshold to consider the easing still running
|
|
383
|
+
|
|
384
|
+
const stateX$ = smoothX.animatedState.observable;
|
|
385
|
+
const stateY$ = smoothY.animatedState.observable;
|
|
386
|
+
const animationName$ = animationName.observable;
|
|
387
|
+
|
|
388
|
+
const moving$ = combineLatest([stateX$, stateY$]).pipe(
|
|
389
|
+
map(([sx, sy]) => {
|
|
390
|
+
const xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;
|
|
391
|
+
const yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;
|
|
392
|
+
return !xFinished || !yFinished; // moving if X or Y is not finished
|
|
393
|
+
}),
|
|
394
|
+
startWith(false)
|
|
395
|
+
);
|
|
125
396
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
397
|
+
const animationChange$ = animationName$.pipe(
|
|
398
|
+
startWith(animationName()),
|
|
399
|
+
pairwise(),
|
|
400
|
+
filter(([prev, curr]) => prev !== curr)
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
const animationMovementSubscription = combineLatest([animationChange$, moving$]).subscribe(([[prev, curr], isMoving]) => {
|
|
404
|
+
if (curr == 'stand' && !isMoving) {
|
|
405
|
+
realAnimationName.set(curr);
|
|
406
|
+
}
|
|
407
|
+
else if (curr == 'walk' && isMoving) {
|
|
408
|
+
realAnimationName.set(curr);
|
|
129
409
|
}
|
|
410
|
+
else if (!movementAnimations.includes(curr)) {
|
|
411
|
+
realAnimationName.set(curr);
|
|
412
|
+
}
|
|
413
|
+
if (!isMoving && object.animationIsPlaying && object.animationIsPlaying()) {
|
|
414
|
+
if (movementAnimations.includes(curr)) {
|
|
415
|
+
if (typeof object.resetAnimationState === 'function') {
|
|
416
|
+
object.resetAnimationState();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Cleanup subscriptions and call hooks before sprite destruction.
|
|
424
|
+
*
|
|
425
|
+
* # Design
|
|
426
|
+
* - Prevent memory leaks by unsubscribing from all local subscriptions created in this component.
|
|
427
|
+
* - Execute destruction hooks to notify modules and scene map of sprite removal.
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* await onBeforeDestroy();
|
|
431
|
+
*/
|
|
432
|
+
const onBeforeDestroy = async () => {
|
|
433
|
+
animationMovementSubscription.unsubscribe();
|
|
434
|
+
xSubscription.unsubscribe();
|
|
435
|
+
ySubscription.unsubscribe();
|
|
436
|
+
await lastValueFrom(hooks.callHooks("client-sprite-onDestroy", object))
|
|
437
|
+
await lastValueFrom(hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, object))
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
mount((element) => {
|
|
441
|
+
hooks.callHooks("client-sprite-onAdd", object).subscribe()
|
|
442
|
+
hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, object).subscribe()
|
|
443
|
+
if (isMe()) client.setKeyboardControls(element.directives.controls)
|
|
130
444
|
})
|
|
131
445
|
|
|
446
|
+
/**
|
|
447
|
+
* Handle attached GUI finish event
|
|
448
|
+
*
|
|
449
|
+
* @param gui - The GUI instance
|
|
450
|
+
* @param data - Data passed from the GUI component
|
|
451
|
+
*/
|
|
452
|
+
const onAttachedGuiFinish = (gui, data) => {
|
|
453
|
+
guiService.guiClose(gui.name, data);
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Handle attached GUI interaction event
|
|
458
|
+
*
|
|
459
|
+
* @param gui - The GUI instance
|
|
460
|
+
* @param name - Interaction name
|
|
461
|
+
* @param data - Interaction data
|
|
462
|
+
*/
|
|
463
|
+
const onAttachedGuiInteraction = (gui, name, data) => {
|
|
464
|
+
guiService.guiInteraction(gui.name, name, data);
|
|
465
|
+
};
|
|
466
|
+
|
|
132
467
|
tick(() => {
|
|
133
|
-
hooks.callHooks("client-sprite-onUpdate")
|
|
468
|
+
hooks.callHooks("client-sprite-onUpdate").subscribe()
|
|
134
469
|
})
|
|
135
470
|
</script>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { computed } from "canvasengine";
|
|
2
|
+
|
|
3
|
+
interface MatchResult {
|
|
4
|
+
property: string;
|
|
5
|
+
fullMatch: string;
|
|
6
|
+
index: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const parseDynamicValue = (value: any, object?: any) => {
|
|
10
|
+
if (typeof value !== 'string') {
|
|
11
|
+
return computed(() => String(value ?? ''));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Find all dynamic references like {propertyName}
|
|
15
|
+
const pattern = /\{([^}]+)\}/g;
|
|
16
|
+
const matches: MatchResult[] = [];
|
|
17
|
+
let match;
|
|
18
|
+
|
|
19
|
+
while ((match = pattern.exec(value)) !== null) {
|
|
20
|
+
matches.push({
|
|
21
|
+
property: match[1],
|
|
22
|
+
fullMatch: match[0],
|
|
23
|
+
index: match.index!
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// If no dynamic references found, return simple computed
|
|
28
|
+
if (matches.length === 0) {
|
|
29
|
+
return computed(() => value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Create computed that tracks all referenced signals
|
|
33
|
+
return computed(() => {
|
|
34
|
+
let result = value;
|
|
35
|
+
|
|
36
|
+
// Replace from end to start to preserve indices
|
|
37
|
+
for (let i = matches.length - 1; i >= 0; i--) {
|
|
38
|
+
const { property, fullMatch } = matches[i];
|
|
39
|
+
|
|
40
|
+
// Try to access the property from the object
|
|
41
|
+
// Support nested properties like {param.maxHp}
|
|
42
|
+
let propertyValue = '';
|
|
43
|
+
try {
|
|
44
|
+
const propertyPath = property.split('.');
|
|
45
|
+
let currentValue = object;
|
|
46
|
+
|
|
47
|
+
for (let j = 0; j < propertyPath.length; j++) {
|
|
48
|
+
const prop = propertyPath[j];
|
|
49
|
+
|
|
50
|
+
// Check if currentValue is a signal (function) and call it
|
|
51
|
+
if (typeof currentValue === 'function') {
|
|
52
|
+
currentValue = currentValue();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Access the property
|
|
56
|
+
if (currentValue && typeof currentValue === 'object' && prop in currentValue) {
|
|
57
|
+
currentValue = currentValue[prop];
|
|
58
|
+
} else {
|
|
59
|
+
currentValue = undefined;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// If the final value is a signal, call it
|
|
65
|
+
if (typeof currentValue === 'function') {
|
|
66
|
+
currentValue = currentValue();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
propertyValue = currentValue != null ? String(currentValue) : '';
|
|
70
|
+
} catch (error) {
|
|
71
|
+
// If property doesn't exist or can't be accessed, use empty string
|
|
72
|
+
propertyValue = '';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
result = result.replace(fullMatch, propertyValue);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return result;
|
|
79
|
+
});
|
|
80
|
+
};
|