@rpgjs/client 5.0.0-beta.20 → 5.0.0-beta.22
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 +7 -0
- package/dist/Gui/Gui.js +37 -4
- package/dist/Gui/Gui.js.map +1 -1
- package/dist/RpgClientEngine.d.ts +16 -9
- package/dist/RpgClientEngine.js +25 -7
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/components/character.ce.js +150 -9
- package/dist/components/character.ce.js.map +1 -1
- package/dist/components/gui/mobile/index.d.ts +51 -2
- package/dist/components/gui/mobile/index.js +12 -4
- package/dist/components/gui/mobile/index.js.map +1 -1
- package/dist/components/gui/mobile/index.spec.d.ts +1 -0
- package/dist/components/gui/mobile/mobile.ce.js +303 -55
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/services/cameraFollow.d.ts +51 -0
- package/dist/services/cameraFollow.js +134 -0
- package/dist/services/cameraFollow.js.map +1 -0
- package/dist/services/cameraFollow.spec.d.ts +1 -0
- package/package.json +5 -5
- package/src/Gui/Gui.spec.ts +19 -0
- package/src/Gui/Gui.ts +50 -11
- package/src/RpgClientEngine.ts +37 -18
- package/src/components/character.ce +167 -9
- package/src/components/gui/mobile/index.spec.ts +94 -0
- package/src/components/gui/mobile/index.ts +74 -6
- package/src/components/gui/mobile/mobile.ce +347 -65
- package/src/index.ts +12 -0
- package/src/services/cameraFollow.spec.ts +220 -0
- package/src/services/cameraFollow.ts +222 -0
|
@@ -4,6 +4,7 @@ import { getCanMoveValue } from "../utils/readPropValue.js";
|
|
|
4
4
|
import { RpgGui } from "../Gui/Gui.js";
|
|
5
5
|
import { normalizeEventComponent } from "../Game/EventComponentResolver.js";
|
|
6
6
|
import { RpgClientEngine } from "../RpgClientEngine.js";
|
|
7
|
+
import { applyCameraFollow, clearCameraFollowPlugins, ownsCameraFollowRevision } from "../services/cameraFollow.js";
|
|
7
8
|
import __ce_component$1 from "./player-components.ce.js";
|
|
8
9
|
import __ce_component$2 from "./interaction-components.ce.js";
|
|
9
10
|
import { Container, Sprite, animatedSignal, computed, cond, effect, h, loop, mount, on, signal, tick, useDefineEmits, useDefineProps, useProps } from "canvasengine";
|
|
@@ -118,8 +119,33 @@ function component($$props) {
|
|
|
118
119
|
const canControls = () => isMe() && getCanMoveValue(sprite);
|
|
119
120
|
const keyboardControls = client.globalConfig.keyboardControls;
|
|
120
121
|
const activeDirectionKeys = /* @__PURE__ */ new Map();
|
|
122
|
+
const activeControlDirections = /* @__PURE__ */ new Map();
|
|
123
|
+
const activeControlDirectionReleaseTimers = /* @__PURE__ */ new Map();
|
|
124
|
+
const CONTROL_DIRECTION_RELEASE_GRACE_MS = 160;
|
|
125
|
+
const hasHeldDirection = () => activeDirectionKeys.size > 0 || activeControlDirections.size > 0;
|
|
126
|
+
const publishMobileDebug = (type, payload = {}) => {
|
|
127
|
+
const target = typeof window !== "undefined" ? window : globalThis;
|
|
128
|
+
if (!target.__RPGJS_MOBILE_DEBUG__) return;
|
|
129
|
+
const event = {
|
|
130
|
+
source: "character",
|
|
131
|
+
type,
|
|
132
|
+
time: Date.now(),
|
|
133
|
+
isCurrentPlayer: isCurrentPlayer(),
|
|
134
|
+
animationName: animationName(),
|
|
135
|
+
realAnimationName: realAnimationName?.(),
|
|
136
|
+
activeKeyboardDirections: Array.from(activeDirectionKeys.values()),
|
|
137
|
+
activeControlDirections: Array.from(activeControlDirections.values()),
|
|
138
|
+
heldDirection: resolveHeldDirection(),
|
|
139
|
+
canControls: canControls(),
|
|
140
|
+
x: x(),
|
|
141
|
+
y: y(),
|
|
142
|
+
...payload
|
|
143
|
+
};
|
|
144
|
+
target.__RPGJS_MOBILE_DEBUG_EVENTS__ = [...(target.__RPGJS_MOBILE_DEBUG_EVENTS__ || []).slice(-199), event];
|
|
145
|
+
target.__RPGJS_MOBILE_DEBUG_LAST__ = event;
|
|
146
|
+
};
|
|
121
147
|
const resolveHeldDirection = () => {
|
|
122
|
-
const directions = Array.from(activeDirectionKeys.values());
|
|
148
|
+
const directions = [...Array.from(activeDirectionKeys.values()), ...Array.from(activeControlDirections.values())];
|
|
123
149
|
return directions[directions.length - 1];
|
|
124
150
|
};
|
|
125
151
|
const resolveSpriteDirection = () => {
|
|
@@ -163,24 +189,75 @@ function component($$props) {
|
|
|
163
189
|
};
|
|
164
190
|
const resolveCurrentActionInput = () => withCurrentDirection(resolveKeyboardActionInput(keyboardControls.action, client, sprite));
|
|
165
191
|
const playPredictedWalkAnimation = () => {
|
|
166
|
-
if (sprite.animationFixed)
|
|
167
|
-
|
|
192
|
+
if (sprite.animationFixed) {
|
|
193
|
+
publishMobileDebug("walk:skip", { reason: "animationFixed" });
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (sprite.animationIsPlaying && sprite.animationIsPlaying()) {
|
|
197
|
+
publishMobileDebug("walk:skip", { reason: "animationIsPlaying" });
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
168
200
|
realAnimationName.set("walk");
|
|
201
|
+
publishMobileDebug("walk:set", { reason: "predicted" });
|
|
169
202
|
};
|
|
170
203
|
const resumeHeldDirectionWalkAnimation = () => {
|
|
171
|
-
if (!isCurrentPlayer())
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
204
|
+
if (!isCurrentPlayer()) {
|
|
205
|
+
publishMobileDebug("walk:resume-fail", { reason: "notCurrentPlayer" });
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if (!hasHeldDirection()) {
|
|
209
|
+
publishMobileDebug("walk:resume-fail", { reason: "noHeldDirection" });
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
if (!canControls()) {
|
|
213
|
+
publishMobileDebug("walk:resume-fail", { reason: "cannotControl" });
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
if (sprite.animationFixed) {
|
|
217
|
+
publishMobileDebug("walk:resume-fail", { reason: "animationFixed" });
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
if (sprite.animationIsPlaying && sprite.animationIsPlaying()) {
|
|
221
|
+
publishMobileDebug("walk:resume-fail", { reason: "animationIsPlaying" });
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
176
224
|
realAnimationName.set("walk");
|
|
225
|
+
publishMobileDebug("walk:set", { reason: "resumeHeldDirection" });
|
|
177
226
|
return true;
|
|
178
227
|
};
|
|
179
228
|
const processMovementInput = (input) => {
|
|
180
229
|
if (!canControls()) return;
|
|
230
|
+
publishMobileDebug("movement:input", { input });
|
|
181
231
|
client.processInput({ input });
|
|
182
232
|
playPredictedWalkAnimation();
|
|
183
233
|
};
|
|
234
|
+
const activateControlDirection = (name, directionInput) => {
|
|
235
|
+
const releaseTimer = activeControlDirectionReleaseTimers.get(name);
|
|
236
|
+
if (releaseTimer) {
|
|
237
|
+
clearTimeout(releaseTimer);
|
|
238
|
+
activeControlDirectionReleaseTimers.delete(name);
|
|
239
|
+
}
|
|
240
|
+
activeControlDirections.delete(name);
|
|
241
|
+
activeControlDirections.set(name, directionInput);
|
|
242
|
+
publishMobileDebug("control:activate", {
|
|
243
|
+
name,
|
|
244
|
+
directionInput
|
|
245
|
+
});
|
|
246
|
+
resumeHeldDirectionWalkAnimation();
|
|
247
|
+
};
|
|
248
|
+
const releaseControlDirection = (name) => {
|
|
249
|
+
const previousTimer = activeControlDirectionReleaseTimers.get(name);
|
|
250
|
+
if (previousTimer) clearTimeout(previousTimer);
|
|
251
|
+
activeControlDirectionReleaseTimers.set(name, setTimeout(() => {
|
|
252
|
+
activeControlDirectionReleaseTimers.delete(name);
|
|
253
|
+
activeControlDirections.delete(name);
|
|
254
|
+
publishMobileDebug("control:release", { name });
|
|
255
|
+
if (!hasHeldDirection() && animationName() === "stand") {
|
|
256
|
+
realAnimationName.set("stand");
|
|
257
|
+
publishMobileDebug("stand:set", { reason: "controlRelease" });
|
|
258
|
+
}
|
|
259
|
+
}, CONTROL_DIRECTION_RELEASE_GRACE_MS));
|
|
260
|
+
};
|
|
184
261
|
const processDashInput = () => {
|
|
185
262
|
if (!canControls()) return;
|
|
186
263
|
client.processDash({ direction: directionToDashVector(resolveSpriteDirection()) });
|
|
@@ -213,28 +290,44 @@ function component($$props) {
|
|
|
213
290
|
repeat: true,
|
|
214
291
|
bind: keyboardControls.down,
|
|
215
292
|
keyDown() {
|
|
293
|
+
activateControlDirection("down", Direction.Down);
|
|
216
294
|
processMovementInput(Direction.Down);
|
|
295
|
+
},
|
|
296
|
+
keyUp() {
|
|
297
|
+
releaseControlDirection("down");
|
|
217
298
|
}
|
|
218
299
|
},
|
|
219
300
|
up: {
|
|
220
301
|
repeat: true,
|
|
221
302
|
bind: keyboardControls.up,
|
|
222
303
|
keyDown() {
|
|
304
|
+
activateControlDirection("up", Direction.Up);
|
|
223
305
|
processMovementInput(Direction.Up);
|
|
306
|
+
},
|
|
307
|
+
keyUp() {
|
|
308
|
+
releaseControlDirection("up");
|
|
224
309
|
}
|
|
225
310
|
},
|
|
226
311
|
left: {
|
|
227
312
|
repeat: true,
|
|
228
313
|
bind: keyboardControls.left,
|
|
229
314
|
keyDown() {
|
|
315
|
+
activateControlDirection("left", Direction.Left);
|
|
230
316
|
processMovementInput(Direction.Left);
|
|
317
|
+
},
|
|
318
|
+
keyUp() {
|
|
319
|
+
releaseControlDirection("left");
|
|
231
320
|
}
|
|
232
321
|
},
|
|
233
322
|
right: {
|
|
234
323
|
repeat: true,
|
|
235
324
|
bind: keyboardControls.right,
|
|
236
325
|
keyDown() {
|
|
326
|
+
activateControlDirection("right", Direction.Right);
|
|
237
327
|
processMovementInput(Direction.Right);
|
|
328
|
+
},
|
|
329
|
+
keyUp() {
|
|
330
|
+
releaseControlDirection("right");
|
|
238
331
|
}
|
|
239
332
|
},
|
|
240
333
|
action: {
|
|
@@ -249,12 +342,33 @@ function component($$props) {
|
|
|
249
342
|
processDashInput();
|
|
250
343
|
}
|
|
251
344
|
},
|
|
345
|
+
back: {
|
|
346
|
+
bind: keyboardControls.escape,
|
|
347
|
+
keyDown() {
|
|
348
|
+
if (canControls()) client.processAction({ action: "escape" });
|
|
349
|
+
}
|
|
350
|
+
},
|
|
252
351
|
escape: {
|
|
253
352
|
bind: keyboardControls.escape,
|
|
254
353
|
keyDown() {
|
|
255
354
|
if (canControls()) client.processAction({ action: "escape" });
|
|
256
355
|
}
|
|
257
356
|
},
|
|
357
|
+
joystick: {
|
|
358
|
+
enabled: true,
|
|
359
|
+
directionMapping: {
|
|
360
|
+
top: "up",
|
|
361
|
+
bottom: "down",
|
|
362
|
+
left: "left",
|
|
363
|
+
right: "right",
|
|
364
|
+
top_left: ["up", "left"],
|
|
365
|
+
top_right: ["up", "right"],
|
|
366
|
+
bottom_left: ["down", "left"],
|
|
367
|
+
bottom_right: ["down", "right"]
|
|
368
|
+
},
|
|
369
|
+
moveInterval: 50,
|
|
370
|
+
threshold: .1
|
|
371
|
+
},
|
|
258
372
|
gamepad: { enabled: true }
|
|
259
373
|
};
|
|
260
374
|
const smoothX = animatedSignal(x(), { duration: isMe() ? 0 : 0 });
|
|
@@ -628,12 +742,15 @@ function component($$props) {
|
|
|
628
742
|
removeTransitionSubscription?.unsubscribe();
|
|
629
743
|
animationMovementSubscription.unsubscribe();
|
|
630
744
|
resumeWalkSubscriptions.forEach((subscription) => subscription.unsubscribe());
|
|
745
|
+
activeControlDirectionReleaseTimers.forEach((timer) => clearTimeout(timer));
|
|
746
|
+
activeControlDirectionReleaseTimers.clear();
|
|
631
747
|
xSubscription.unsubscribe();
|
|
632
748
|
ySubscription.unsubscribe();
|
|
633
749
|
await lastValueFrom(hooks.callHooks("client-sprite-onDestroy", sprite));
|
|
634
750
|
await lastValueFrom(hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, sprite));
|
|
635
751
|
};
|
|
636
752
|
mount((element) => {
|
|
753
|
+
let appliedCameraFollowRevision = null;
|
|
637
754
|
if (typeof document !== "undefined") {
|
|
638
755
|
document.addEventListener("keydown", handleNativeActionWhileMoving);
|
|
639
756
|
document.addEventListener("keyup", handleNativeActionWhileMoving);
|
|
@@ -643,6 +760,31 @@ function component($$props) {
|
|
|
643
760
|
effect(() => {
|
|
644
761
|
if (isCurrentPlayer()) client.setKeyboardControls(element.directives.controls);
|
|
645
762
|
});
|
|
763
|
+
effect(() => {
|
|
764
|
+
const followRevision = client.cameraFollowRevision();
|
|
765
|
+
if (!shouldFollowCamera()) {
|
|
766
|
+
appliedCameraFollowRevision = null;
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const smoothMove = client.cameraFollowSmoothMove;
|
|
770
|
+
const viewport = element.props.context?.viewport;
|
|
771
|
+
const target = element.componentInstance;
|
|
772
|
+
if (!viewport || !target) {
|
|
773
|
+
appliedCameraFollowRevision = null;
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
appliedCameraFollowRevision = applyCameraFollow({
|
|
777
|
+
viewport,
|
|
778
|
+
target,
|
|
779
|
+
smoothMove,
|
|
780
|
+
followRevision,
|
|
781
|
+
isCurrentRevision: (revision) => client.cameraFollowRevision() === revision,
|
|
782
|
+
shouldFollowCamera
|
|
783
|
+
}) ? followRevision : null;
|
|
784
|
+
});
|
|
785
|
+
return () => {
|
|
786
|
+
if (ownsCameraFollowRevision(appliedCameraFollowRevision, client.cameraFollowRevision())) clearCameraFollowPlugins(element.props.context?.viewport);
|
|
787
|
+
};
|
|
646
788
|
});
|
|
647
789
|
const normalizeOpenId = (value) => {
|
|
648
790
|
const resolved = typeof value === "function" ? value() : value;
|
|
@@ -664,7 +806,6 @@ function component($$props) {
|
|
|
664
806
|
x: smoothX,
|
|
665
807
|
y: smoothY,
|
|
666
808
|
zIndex: z,
|
|
667
|
-
viewportFollow: shouldFollowCamera,
|
|
668
809
|
controls,
|
|
669
810
|
onBeforeDestroy,
|
|
670
811
|
visible,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"character.ce.js","names":[],"sources":["../../src/components/character.ce"],"sourcesContent":["<Container\n x={smoothX}\n y={smoothY}\n zIndex={z}\n viewportFollow={shouldFollowCamera}\n controls\n onBeforeDestroy\n visible\n cursor={interactionCursor}\n pointerover={interactionPointerOver}\n pointerout={interactionPointerOut}\n pointerdown={interactionPointerDown}\n pointerup={interactionPointerUp}\n pointermove={interactionPointerMove}\n click={interactionClick}\n>\n @for (compConfig of normalizedComponentsBehind) {\n <Container>\n <compConfig.component object={sprite} ...compConfig.props />\n </Container>\n } \n <PlayerComponents object={sprite} position=\"bottom\" graphicBounds />\n <PlayerComponents object={sprite} position=\"left\" graphicBounds />\n <Particle emit={emitParticleTrigger} settings={particleSettings} zIndex={1000} name={particleName} />\n <Container>\n @for (graphicObj of renderedGraphics) {\n <Container scale={graphicScale(graphicObj)}>\n <Sprite \n sheet={sheet(graphicObj)} \n direction \n tint \n hitbox\n shadowCaster={shadowCaster(graphicObj)}\n flash={flashConfig}\n />\n </Container>\n }\n @for (eventComponent of resolvedEventComponents) {\n <Container dependencies={eventComponent.dependencies}>\n <eventComponent.component ...eventComponent.props />\n </Container>\n }\n </Container>\n <PlayerComponents object={sprite} position=\"center\" graphicBounds />\n <PlayerComponents object={sprite} position=\"right\" graphicBounds />\n <PlayerComponents object={sprite} position=\"top\" graphicBounds />\n @for (compConfig of normalizedComponentsInFront) {\n <Container dependencies={compConfig.dependencies}>\n <compConfig.component object={sprite} ...compConfig.props />\n </Container>\n }\n <InteractionComponents\n object={sprite}\n bounds={graphicBounds}\n hitboxBounds={hitboxBounds}\n graphicBounds={graphicBounds}\n />\n @for (attachedGui of attachedGuis) {\n @if (shouldDisplayAttachedGui) {\n <Container>\n <attachedGui.component ...attachedGui.data() dependencies={attachedGui.dependencies} object={sprite} guiOpenId={attachedGui.openId} onFinish={(data, guiOpenId) => {\n onAttachedGuiFinish(attachedGui, data, guiOpenId)\n }} onInteraction={(name, data) => {\n onAttachedGuiInteraction(attachedGui, name, data)\n }} />\n </Container>\n }\n }\n</Container>\n\n<script>\n import { signal, effect, mount, computed, tick, animatedSignal, on } from \"canvasengine\";\n import { Assets } from \"pixi.js\";\n\n import { lastValueFrom, combineLatest, pairwise, filter, map, startWith } from \"rxjs\";\n import { Particle } from \"@canvasengine/presets\";\n import { GameEngineToken, ModulesToken, shouldRenderLightingShadows } from \"@rpgjs/common\";\n import { RpgClientEngine } from \"../RpgClientEngine\";\n import { inject } from \"../core/inject\"; \n import { Direction, Animation } from \"@rpgjs/common\";\n import { normalizeEventComponent } from \"../Game/EventComponentResolver\";\n import Hit from \"./effects/hit.ce\";\n import PlayerComponents from \"./player-components.ce\";\n import InteractionComponents from \"./interaction-components.ce\";\n import { RpgGui } from \"../Gui/Gui\";\n import { getCanMoveValue } from \"../utils/readPropValue\";\n import {\n getKeyboardControlBind,\n keyboardEventMatchesBind,\n resolveKeyboardActionInput,\n resolveKeyboardDirectionInput,\n } from \"../services/actionInput\";\n\n const { object, id } = defineProps();\n const sprite = object();\n\n const client = inject(RpgClientEngine);\n const hooks = inject(ModulesToken);\n const guiService = inject(RpgGui);\n\n const spritesheets = client.spritesheets;\n const componentsBehind = client.spriteComponentsBehind;\n const componentsInFront = client.spriteComponentsInFront;\n const readProp = (value) => typeof value === 'function' ? value() : value;\n const isCurrentPlayer = () => {\n const playerId = client.playerIdSignal();\n const currentPlayer = playerId ? client.sceneMap?.players?.()?.[playerId] : undefined;\n return readProp(id) === playerId\n || readProp(sprite?.id) === playerId\n || sprite === currentPlayer\n || sprite === client.sceneMap?.getCurrentPlayer?.();\n };\n const isMe = computed(isCurrentPlayer);\n const shadowsEnabled = computed(() => {\n const lighting = client.sceneMap?.lighting?.();\n return shouldRenderLightingShadows(lighting);\n });\n\n /**\n * Normalize a single sprite component configuration\n * \n * Handles both direct component references and configuration objects with optional props and dependencies.\n * Extracts the component reference and creates a computed function that returns the props.\n * \n * ## Design\n * \n * Supports two formats:\n * 1. Direct component: `ShadowComponent`\n * 2. Configuration object: `{ component: LightHalo, props: {...}, dependencies: (object) => [...] }`\n * \n * The normalization process:\n * - Extracts the actual component from either format\n * - Extracts dependencies function if provided\n * - Creates a computed function that returns props (static object or dynamic function result)\n * - Returns a normalized object with `component`, `props`, and `dependencies`\n * \n * @param comp - Component reference or configuration object\n * @returns Normalized component configuration with component, props, and dependencies\n * \n * @example\n * ```ts\n * // Direct component\n * normalizeComponent(ShadowComponent)\n * // => { component: ShadowComponent, props: {}, dependencies: undefined }\n * \n * // With static props\n * normalizeComponent({ component: LightHalo, props: { radius: 30 } })\n * // => { component: LightHalo, props: { radius: 30 }, dependencies: undefined }\n * \n * // With dynamic props and dependencies\n * normalizeComponent({ \n * component: HealthBar, \n * props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),\n * dependencies: (object) => [object.hp, object.param.maxHp]\n * })\n * // => { component: HealthBar, props: {...}, dependencies: (object) => [...] }\n * ```\n */\n const normalizeComponent = (comp) => {\n let componentRef;\n let propsValue;\n let dependenciesFn;\n \n // If it's a direct component reference\n if (typeof comp === 'function' || (comp && typeof comp === 'object' && !comp.component)) {\n componentRef = comp;\n propsValue = undefined;\n dependenciesFn = undefined;\n }\n // If it's a configuration object with component and props\n else if (comp && typeof comp === 'object' && comp.component) {\n componentRef = comp.component;\n // Support both \"data\" (legacy) and \"props\" (new) for backward compatibility\n propsValue = comp.props !== undefined ? comp.props : comp.data;\n dependenciesFn = comp.dependencies;\n }\n // Fallback: treat as direct component\n else {\n componentRef = comp;\n propsValue = undefined;\n dependenciesFn = undefined;\n }\n \n // Return props directly (object or function), not as computed\n // The computed will be created in the template when needed\n return {\n component: componentRef,\n props: typeof propsValue === 'function' ? propsValue(sprite) : propsValue || {},\n dependencies: dependenciesFn ? dependenciesFn(sprite) : []\n };\n };\n\n /**\n * Normalize an array of sprite components\n * \n * Applies normalization to each component in the array using `normalizeComponent`.\n * \n * @param components - Array of component references or configuration objects\n * @returns Array of normalized component configurations\n */\n const normalizeComponents = (components) => {\n return components.map((comp) => normalizeComponent(comp));\n };\n\n\n /**\n * Normalized components to render behind sprites\n * Handles both direct component references and configuration objects with optional props and dependencies\n * \n * Supports multiple formats:\n * 1. Direct component: `ShadowComponent`\n * 2. Configuration object: `{ component: LightHalo, props: {...} }`\n * 3. With dynamic props: `{ component: LightHalo, props: (object) => {...} }`\n * 4. With dependencies: `{ component: HealthBar, dependencies: (object) => [object.hp, object.param.maxHp] }`\n * \n * Components with dependencies will only be displayed when all dependencies are resolved (!= undefined).\n * The object is passed to the dependencies function to allow sprite-specific dependency resolution.\n * \n * @example\n * ```ts\n * // Direct component\n * componentsBehind: [ShadowComponent]\n * \n * // With static props\n * componentsBehind: [{ component: LightHalo, props: { radius: 30 } }]\n * \n * // With dynamic props and dependencies\n * componentsBehind: [{ \n * component: HealthBar, \n * props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),\n * dependencies: (object) => [object.hp, object.param.maxHp]\n * }]\n * ```\n */\n const normalizedComponentsBehind = computed(() => {\n return normalizeComponents(componentsBehind());\n });\n\n /**\n * Normalized components to render in front of sprites\n * Handles both direct component references and configuration objects with optional props and dependencies\n * \n * See `normalizedComponentsBehind` for format details.\n * Components with dependencies will only be displayed when all dependencies are resolved.\n */\n const normalizedComponentsInFront = computed(() => {\n return normalizeComponents(componentsInFront());\n });\n\n const isEventSprite = () => {\n return typeof sprite?.isEvent === 'function'\n ? sprite.isEvent()\n : sprite?._type === 'event';\n };\n\n const resolvedEventComponents = computed(() => {\n if (!isEventSprite()) return [];\n const eventComponent = normalizeEventComponent(client.resolveEventComponent(sprite), sprite);\n return eventComponent ? [eventComponent] : [];\n });\n \n /**\n * Determine if the camera should follow this sprite\n * \n * The camera follows this sprite if:\n * - It's explicitly set as the camera follow target, OR\n * - It's the current player and no explicit target is set (default behavior)\n */\n const shouldFollowCamera = computed(() => {\n const cameraTargetId = client.cameraFollowTargetId();\n // If a target is explicitly set, only follow if this sprite is the target\n if (cameraTargetId !== null) {\n return id() === cameraTargetId;\n }\n // Otherwise, follow the current player (default behavior)\n return isMe();\n });\n\n /**\n * Get all attached GUI components that should be rendered on sprites\n * These are GUIs with attachToSprite: true\n */\n const attachedGuis = computed(() => {\n return guiService.getAttachedGuis();\n });\n\n /**\n * Check if attached GUIs should be displayed for this sprite\n * This is controlled by showAttachedGui/hideAttachedGui on the server\n */\n const shouldDisplayAttachedGui = computed(() => {\n return guiService.shouldDisplayAttachedGui(id());\n });\n\n const { \n x, \n y, \n tint, \n direction, \n animationName, \n animationCurrentIndex,\n emitParticleTrigger, \n particleName, \n graphics, \n hitbox,\n isConnected,\n graphicsSignals,\n flashTrigger\n } = sprite;\n\n const renderedGraphics = computed(() => {\n const eventComponent = resolvedEventComponents()[0];\n if (eventComponent && !eventComponent.renderGraphic) return [];\n return graphicsSignals();\n });\n\n /**\n * Flash configuration signals for dynamic options\n * These signals are updated when the flash trigger is activated with options\n */\n const flashType = signal<'alpha' | 'tint' | 'both'>('alpha');\n const flashDuration = signal(300);\n const flashCycles = signal(1);\n const flashAlpha = signal(0.3);\n const flashTint = signal(0xffffff);\n\n /**\n * Listen to flash trigger to update configuration dynamically\n * When flash is triggered with options, update the signals\n */\n on(flashTrigger, (data) => {\n if (data && typeof data === 'object') {\n if (data.type !== undefined) flashType.set(data.type);\n if (data.duration !== undefined) flashDuration.set(data.duration);\n if (data.cycles !== undefined) flashCycles.set(data.cycles);\n if (data.alpha !== undefined) flashAlpha.set(data.alpha);\n if (data.tint !== undefined) flashTint.set(data.tint);\n }\n });\n\n /**\n * Flash configuration for the sprite\n * \n * This configuration is used by the flash directive to create visual feedback effects.\n * The flash trigger is exposed through the object, allowing both server events and\n * client-side code to trigger flash animations. Options can be passed dynamically\n * through the trigger, which updates the reactive signals.\n */\n const flashConfig = computed(() => ({\n trigger: flashTrigger,\n type: flashType(),\n duration: flashDuration(),\n cycles: flashCycles(),\n alpha: flashAlpha(),\n tint: flashTint(),\n }));\n\n const particleSettings = client.particleSettings;\n\n const canControls = () => isMe() && getCanMoveValue(sprite)\n const keyboardControls = client.globalConfig.keyboardControls;\n const activeDirectionKeys = new Map();\n\n const resolveHeldDirection = () => {\n const directions = Array.from(activeDirectionKeys.values());\n return directions[directions.length - 1];\n };\n\n const resolveSpriteDirection = () => {\n const heldDirection = resolveHeldDirection();\n if (heldDirection) return heldDirection;\n if (typeof sprite.getDirection === 'function') return sprite.getDirection();\n if (typeof sprite.direction === 'function') return sprite.direction();\n return direction();\n };\n\n const directionToDashVector = (currentDirection) => {\n switch (currentDirection) {\n case Direction.Left:\n return { x: -1, y: 0 };\n case Direction.Right:\n return { x: 1, y: 0 };\n case Direction.Up:\n return { x: 0, y: -1 };\n case Direction.Down:\n default:\n return { x: 0, y: 1 };\n }\n };\n\n const withCurrentDirection = (payload) => {\n if (payload.action !== 'action') return payload;\n const data = payload.data && typeof payload.data === 'object'\n ? { ...payload.data }\n : {};\n return {\n ...payload,\n data: {\n ...data,\n direction: data.direction ?? resolveSpriteDirection(),\n },\n };\n };\n\n const resolveCurrentActionInput = () =>\n withCurrentDirection(\n resolveKeyboardActionInput(keyboardControls.action, client, sprite)\n );\n\n const playPredictedWalkAnimation = () => {\n if (sprite.animationFixed) return;\n if (sprite.animationIsPlaying && sprite.animationIsPlaying()) return;\n realAnimationName.set('walk');\n };\n\n const resumeHeldDirectionWalkAnimation = () => {\n if (!isCurrentPlayer()) return false;\n if (activeDirectionKeys.size === 0) return false;\n if (!canControls()) return false;\n if (sprite.animationFixed) return false;\n if (sprite.animationIsPlaying && sprite.animationIsPlaying()) return false;\n realAnimationName.set('walk');\n return true;\n };\n\n const processMovementInput = (input) => {\n if (!canControls()) return;\n client.processInput({ input });\n playPredictedWalkAnimation();\n };\n\n const processDashInput = () => {\n if (!canControls()) return;\n client.processDash({\n direction: directionToDashVector(resolveSpriteDirection()),\n });\n };\n\n const actionBind = () => getKeyboardControlBind(keyboardControls.action);\n const keyboardEventId = (event) => `${event.keyCode}:${event.code}:${event.key}`;\n\n const handleNativeActionWhileMoving = (event) => {\n const inputDirection = resolveKeyboardDirectionInput(event, keyboardControls);\n if (inputDirection) {\n const keyId = keyboardEventId(event);\n if (event.type === 'keydown') {\n activeDirectionKeys.delete(keyId);\n activeDirectionKeys.set(keyId, inputDirection);\n resumeHeldDirectionWalkAnimation();\n }\n else {\n activeDirectionKeys.delete(keyId);\n }\n }\n\n if (!isCurrentPlayer()) return;\n if (event.type !== 'keydown' || event.repeat) return;\n if (activeDirectionKeys.size === 0) return;\n if (!keyboardEventMatchesBind(event, actionBind())) return;\n if (!canControls()) return;\n\n client.processAction(resolveCurrentActionInput());\n };\n\n const visible = computed(() => {\n if (sprite.isEvent()) {\n return true\n }\n return isConnected()\n });\n\n const controls = {\n down: {\n repeat: true,\n bind: keyboardControls.down,\n keyDown() {\n processMovementInput(Direction.Down)\n },\n },\n up: {\n repeat: true,\n bind: keyboardControls.up,\n keyDown() {\n processMovementInput(Direction.Up)\n },\n },\n left: {\n repeat: true,\n bind: keyboardControls.left,\n keyDown() {\n processMovementInput(Direction.Left)\n },\n },\n right: {\n repeat: true,\n bind: keyboardControls.right,\n keyDown() {\n processMovementInput(Direction.Right)\n },\n },\n action: {\n bind: getKeyboardControlBind(keyboardControls.action),\n keyDown() {\n if (canControls()) {\n client.processAction(resolveCurrentActionInput())\n }\n },\n },\n dash: {\n bind: keyboardControls.dash,\n keyDown() {\n processDashInput()\n },\n },\n escape: {\n bind: keyboardControls.escape,\n keyDown() {\n if (canControls()) {\n client.processAction({ action: 'escape' })\n }\n },\n },\n gamepad: {\n enabled: true\n }\n };\n\n const smoothX = animatedSignal(x(), {\n duration: isMe() ? 0 : 0\n });\n\n const smoothY = animatedSignal(y(), {\n duration: isMe() ? 0 : 0,\n });\n\n const z = computed(() => {\n const box = hitbox?.()\n return sprite.y() + (box?.h ?? 0) + sprite.z()\n });\n\n const realAnimationName = signal(animationName());\n\n const xSubscription = x.observable.subscribe((value) => {\n smoothX.set(value);\n });\n\n const ySubscription = y.observable.subscribe((value) => {\n smoothY.set(value);\n });\n \n const sheet = (graphicObject) => {\n return {\n definition: graphicObject,\n playing: realAnimationName(),\n params: {\n direction: direction()\n },\n onFinish() {\n animationCurrentIndex.update(index => index + 1)\n }\n };\n }\n\n const graphicScale = (graphicObject) => {\n const scale = graphicObject?.displayScale ?? graphicObject?.scale;\n if (Array.isArray(scale)) return scale;\n if (typeof scale === 'number') return [scale, scale];\n if (scale && typeof scale === 'object') {\n const x = typeof scale.x === 'number' ? scale.x : 1;\n const y = typeof scale.y === 'number' ? scale.y : x;\n return [x, y];\n }\n return undefined;\n }\n\n const shadowCaster = (graphicObject) => {\n const box = hitbox();\n const bounds = graphicBounds();\n const scale = graphicScale(graphicObject);\n const scaleY = Array.isArray(scale) && typeof scale[1] === 'number' ? Math.abs(scale[1]) : 1;\n const height = Math.max(bounds?.height ?? box?.h ?? 32, box?.h ?? 32) * scaleY;\n\n return {\n enabled: shadowsEnabled,\n height,\n footAnchor: { x: 0.5, y: 1 },\n footOffset: { x: 0, y: 2 },\n alpha: 0.5,\n blur: 3.5,\n gradientPower: 2,\n hardness: 0.42,\n minLength: Math.max(6, (box?.h ?? 32) * 0.25),\n maxLength: Math.max(90, height * 1.8),\n contactAlpha: 0.3,\n contactScale: 0.3,\n };\n }\n\n const imageDimensions = signal({});\n const loadingImageDimensions = new Set();\n\n const toPositiveNumber = (value) => {\n const number = typeof value === 'number' ? value : parseFloat(value);\n return Number.isFinite(number) && number > 0 ? number : undefined;\n };\n\n const toFiniteNumber = (value, fallback = 0) => {\n const number = typeof value === 'number' ? value : parseFloat(value);\n return Number.isFinite(number) ? number : fallback;\n };\n\n const clampRatio = (value) => Math.min(1, Math.max(0, value));\n\n const normalizePair = (value, fallback = [1, 1]) => {\n if (Array.isArray(value)) {\n const x = toFiniteNumber(value[0], fallback[0]);\n const y = toFiniteNumber(value[1] ?? value[0], x);\n return [x, y];\n }\n if (typeof value === 'number') {\n return [value, value];\n }\n if (value && typeof value === 'object') {\n const x = toFiniteNumber(value.x, fallback[0]);\n const y = toFiniteNumber(value.y ?? value.x, x);\n return [x, y];\n }\n return fallback;\n };\n\n const normalizeAnchor = (value) => {\n if (!Array.isArray(value)) return undefined;\n const [x, y] = normalizePair(value, [0, 0]);\n return [clampRatio(x), clampRatio(y)];\n };\n\n const resolveImageSource = (image) => {\n if (typeof image === 'string') return image;\n if (typeof image?.default === 'string') return image.default;\n return undefined;\n };\n\n const parentTextureOptions = (graphicObject) => {\n const props = [\n 'width',\n 'height',\n 'framesHeight',\n 'framesWidth',\n 'rectWidth',\n 'rectHeight',\n 'offset',\n 'image',\n 'sound',\n 'spriteRealSize',\n 'scale',\n 'anchor',\n 'pivot',\n 'x',\n 'y',\n 'opacity'\n ];\n\n return props.reduce((options, prop) => {\n if (graphicObject?.[prop] !== undefined) {\n options[prop] = graphicObject[prop];\n }\n return options;\n }, {});\n };\n\n const resolveTextureOptions = (graphicObject) => {\n const textures = graphicObject?.textures ?? {};\n const texture =\n textures[realAnimationName()] ??\n textures[Animation.Stand] ??\n Object.values(textures)[0] ??\n {};\n\n return {\n ...parentTextureOptions(graphicObject),\n ...texture\n };\n };\n\n const resolveFirstAnimationFrame = (textureOptions) => {\n const animations = textureOptions?.animations;\n if (!animations) return {};\n\n try {\n const frames = typeof animations === 'function'\n ? animations({ direction: direction() })\n : animations;\n if (!Array.isArray(frames)) return {};\n const firstGroup = frames[0];\n return Array.isArray(firstGroup) ? firstGroup[0] ?? {} : firstGroup ?? {};\n }\n catch {\n return {};\n }\n };\n\n const optionValue = (prop, frame, textureOptions, graphicObject) => {\n return frame?.[prop] ?? textureOptions?.[prop] ?? graphicObject?.[prop];\n };\n\n const resolveFrameSize = (textureOptions, dimensions) => {\n const framesWidth = toPositiveNumber(textureOptions?.framesWidth) ?? 1;\n const framesHeight = toPositiveNumber(textureOptions?.framesHeight) ?? 1;\n const imageSource = resolveImageSource(textureOptions?.image);\n const loadedSize = imageSource ? dimensions[imageSource] : undefined;\n const fullWidth = toPositiveNumber(textureOptions?.width) ?? loadedSize?.width;\n const fullHeight = toPositiveNumber(textureOptions?.height) ?? loadedSize?.height;\n const width = toPositiveNumber(textureOptions?.rectWidth) ??\n toPositiveNumber(textureOptions?.spriteWidth) ??\n (fullWidth ? fullWidth / framesWidth : undefined);\n const height = toPositiveNumber(textureOptions?.rectHeight) ??\n toPositiveNumber(textureOptions?.spriteHeight) ??\n (fullHeight ? fullHeight / framesHeight : undefined);\n\n return {\n width,\n height\n };\n };\n\n const resolveHitboxAnchor = (spriteWidth, spriteHeight, realSize, box) => {\n if (!spriteWidth || !spriteHeight || !box) {\n return [0, 0];\n }\n\n const heightOfSprite = typeof realSize === 'number' ? realSize : realSize?.height;\n const resolvedHeight = toPositiveNumber(heightOfSprite) ?? spriteHeight;\n const gap = Math.max(0, (spriteHeight - resolvedHeight) / 2);\n const hitboxTopLeftX = clampRatio((spriteWidth - box.w) / 2 / spriteWidth);\n const hitboxTopLeftY = clampRatio((spriteHeight - box.h - gap) / spriteHeight);\n const hitboxCenterX = clampRatio(hitboxTopLeftX + box.w / 2 / spriteWidth);\n const hitboxCenterY = clampRatio(hitboxTopLeftY + box.h / 2 / spriteHeight);\n const footY = clampRatio((spriteHeight - gap) / spriteHeight);\n\n switch (box.anchorMode ?? 'top-left') {\n case 'center':\n return [hitboxCenterX, hitboxCenterY];\n case 'foot':\n return [hitboxCenterX, footY];\n case 'top-left':\n default:\n return [hitboxTopLeftX, hitboxTopLeftY];\n }\n };\n\n const loadImageDimensions = (image) => {\n const source = resolveImageSource(image);\n if (!source || imageDimensions()[source] || loadingImageDimensions.has(source)) {\n return;\n }\n\n loadingImageDimensions.add(source);\n Assets.load(source)\n .then((texture) => {\n const width = toPositiveNumber(texture?.width);\n const height = toPositiveNumber(texture?.height);\n if (!width || !height) return;\n\n imageDimensions.update((dimensions) => ({\n ...dimensions,\n [source]: { width, height }\n }));\n })\n .catch(() => {})\n .finally(() => {\n loadingImageDimensions.delete(source);\n });\n };\n\n effect(() => {\n const sources = new Set();\n\n graphicsSignals().forEach((graphicObject) => {\n const baseImage = resolveImageSource(graphicObject?.image);\n if (baseImage) sources.add(baseImage);\n\n Object.values(graphicObject?.textures ?? {}).forEach((textureOptions) => {\n const image = resolveImageSource(textureOptions?.image ?? graphicObject?.image);\n if (image) sources.add(image);\n });\n });\n\n sources.forEach((source) => loadImageDimensions(source));\n });\n\n const hitboxBounds = 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\n const graphicBounds = computed(() => {\n const box = hitbox();\n const fallback = hitboxBounds();\n const customEventComponent = resolvedEventComponents()[0];\n if (customEventComponent && !customEventComponent.renderGraphic) {\n return fallback;\n }\n const dimensions = imageDimensions();\n const graphics = graphicsSignals();\n let bounds = null;\n\n graphics.forEach((graphicObject) => {\n const textureOptions = resolveTextureOptions(graphicObject);\n const frame = resolveFirstAnimationFrame(textureOptions);\n const size = resolveFrameSize(textureOptions, dimensions);\n const spriteWidth = size.width ?? box?.w;\n const spriteHeight = size.height ?? box?.h;\n\n if (!spriteWidth || !spriteHeight) {\n return;\n }\n\n const explicitAnchor = normalizeAnchor(optionValue('anchor', frame, textureOptions, graphicObject));\n const anchor = explicitAnchor ?? resolveHitboxAnchor(\n spriteWidth,\n spriteHeight,\n optionValue('spriteRealSize', frame, textureOptions, graphicObject),\n box\n );\n const scale = normalizePair(optionValue('scale', frame, textureOptions, graphicObject) ?? graphicScale(graphicObject));\n const x = toFiniteNumber(optionValue('x', frame, textureOptions, graphicObject), 0);\n const y = toFiniteNumber(optionValue('y', frame, textureOptions, graphicObject), 0);\n const leftEdge = -anchor[0] * spriteWidth * scale[0];\n const rightEdge = (1 - anchor[0]) * spriteWidth * scale[0];\n const topEdge = -anchor[1] * spriteHeight * scale[1];\n const bottomEdge = (1 - anchor[1]) * spriteHeight * scale[1];\n const graphic = {\n left: x + Math.min(leftEdge, rightEdge),\n top: y + Math.min(topEdge, bottomEdge),\n right: x + Math.max(leftEdge, rightEdge),\n bottom: y + Math.max(topEdge, bottomEdge)\n };\n\n bounds = bounds\n ? {\n left: Math.min(bounds.left, graphic.left),\n top: Math.min(bounds.top, graphic.top),\n right: Math.max(bounds.right, graphic.right),\n bottom: Math.max(bounds.bottom, graphic.bottom)\n }\n : graphic;\n });\n\n if (!bounds) {\n return fallback;\n }\n\n const width = bounds.right - bounds.left;\n const height = bounds.bottom - bounds.top;\n\n return {\n ...bounds,\n width,\n height,\n centerX: bounds.left + width / 2,\n centerY: bounds.top + height / 2\n };\n });\n\n const interactionBounds = () => ({\n bounds: graphicBounds(),\n hitbox: hitboxBounds(),\n graphic: graphicBounds()\n });\n\n const interactionCursor = computed(() =>\n client.interactions.cursorFor(sprite, interactionBounds())\n );\n\n const handleInteraction = (type) => (event) => {\n client.updatePointerFromInteractionEvent(event);\n client.interactions.handle(sprite, type, {\n event,\n bounds: interactionBounds()\n });\n };\n\n const interactionPointerOver = handleInteraction('pointerover');\n const interactionPointerOut = handleInteraction('pointerout');\n const interactionPointerDown = handleInteraction('pointerdown');\n const interactionPointerUp = handleInteraction('pointerup');\n const interactionPointerMove = handleInteraction('pointermove');\n const interactionClick = handleInteraction('click');\n\n // Combine animation change detection with movement state from smoothX/smoothY\n const movementAnimations = ['walk', 'stand'];\n const epsilon = 0; // movement threshold to consider the easing still running\n\n const stateX$ = smoothX.animatedState.observable;\n const stateY$ = smoothY.animatedState.observable;\n const animationName$ = animationName.observable;\n\n const moving$ = combineLatest([stateX$, stateY$]).pipe(\n map(([sx, sy]) => {\n const xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;\n const yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;\n return !xFinished || !yFinished; // moving if X or Y is not finished\n }),\n startWith(false)\n );\n\n const animationChange$ = animationName$.pipe(\n startWith(animationName()),\n pairwise(),\n filter(([prev, curr]) => prev !== curr)\n );\n\n let beforeRemovePromise = null;\n let beforeRemoveTransitionValue = null;\n const resolveRemoveContext = () => {\n if (!sprite._removeTransition) return null;\n const value = sprite._removeTransition();\n if (!value || typeof value !== 'string') return null;\n try {\n const context = JSON.parse(value);\n if (!context || typeof context !== 'object' || !context.active) return null;\n context.__transitionValue = value;\n return context;\n }\n catch {\n return null;\n }\n };\n\n const withTimeout = (promise, timeoutMs = 0) => {\n if (!timeoutMs || timeoutMs <= 0) return promise;\n return Promise.race([\n promise,\n new Promise((resolve) => setTimeout(resolve, timeoutMs)),\n ]);\n };\n\n const runBeforeRemove = () => {\n const context = resolveRemoveContext();\n if (!context) return Promise.resolve();\n if (beforeRemovePromise && beforeRemoveTransitionValue === context.__transitionValue) {\n return beforeRemovePromise;\n }\n beforeRemoveTransitionValue = context.__transitionValue;\n beforeRemovePromise = withTimeout(\n lastValueFrom(hooks.callHooks(\"client-sprite-onBeforeRemove\", sprite, context)),\n context.timeoutMs\n );\n return beforeRemovePromise;\n };\n\n const removeTransitionSubscription = sprite._removeTransition?.observable?.subscribe(() => {\n if (resolveRemoveContext()) {\n runBeforeRemove();\n }\n });\n\n const animationMovementSubscription = combineLatest([animationChange$, moving$]).subscribe(([[prev, curr], isMoving]) => {\n const isMovementAnimation = movementAnimations.includes(curr);\n const isTemporaryAnimationPlaying =\n sprite.animationIsPlaying && sprite.animationIsPlaying();\n\n if (sprite.animationFixed && isMovementAnimation) {\n realAnimationName.set(curr);\n return;\n }\n\n if (curr == 'stand' && !isMoving) {\n if (!resumeHeldDirectionWalkAnimation()) {\n realAnimationName.set(curr);\n }\n }\n else if (curr == 'walk' && isMoving) {\n realAnimationName.set(curr);\n }\n else if (!isMovementAnimation) {\n realAnimationName.set(curr);\n }\n if (!isMoving && isTemporaryAnimationPlaying) {\n if (isMovementAnimation) {\n if (typeof sprite.resetAnimationState === 'function') {\n sprite.resetAnimationState();\n }\n }\n }\n });\n\n const resumeWalkSubscriptions = [\n sprite._canMove,\n sprite._animationFixed,\n sprite.animationIsPlaying,\n ]\n .filter(signal => signal?.observable)\n .map(signal => signal.observable.subscribe(() => {\n resumeHeldDirectionWalkAnimation();\n }));\n\n /**\n * Cleanup subscriptions and call hooks before sprite destruction.\n *\n * # Design\n * - Prevent memory leaks by unsubscribing from all local subscriptions created in this component.\n * - Execute destruction hooks to notify modules and scene map of sprite removal.\n *\n * @example\n * await onBeforeDestroy();\n */\n const waitForTemporaryAnimationEnd = (maxDuration = 1200) => {\n if (!sprite.animationIsPlaying || !sprite.animationIsPlaying()) {\n return Promise.resolve();\n }\n\n return new Promise((resolve) => {\n let finished = false;\n let timeout;\n let subscription;\n const finish = () => {\n if (finished) return;\n finished = true;\n clearTimeout(timeout);\n subscription?.unsubscribe();\n resolve();\n };\n timeout = setTimeout(finish, maxDuration);\n subscription = sprite.animationIsPlaying.observable.subscribe((isPlaying) => {\n if (!isPlaying) finish();\n });\n if (finished) subscription.unsubscribe();\n });\n };\n\n const onBeforeDestroy = async () => {\n await runBeforeRemove();\n await waitForTemporaryAnimationEnd();\n if (typeof document !== 'undefined') {\n document.removeEventListener('keydown', handleNativeActionWhileMoving);\n document.removeEventListener('keyup', handleNativeActionWhileMoving);\n }\n removeTransitionSubscription?.unsubscribe();\n animationMovementSubscription.unsubscribe();\n resumeWalkSubscriptions.forEach(subscription => subscription.unsubscribe());\n xSubscription.unsubscribe();\n ySubscription.unsubscribe();\n await lastValueFrom(hooks.callHooks(\"client-sprite-onDestroy\", sprite)) \n await lastValueFrom(hooks.callHooks(\"client-sceneMap-onRemoveSprite\", client.sceneMap, sprite))\n }\n\n mount((element) => {\n if (typeof document !== 'undefined') {\n document.addEventListener('keydown', handleNativeActionWhileMoving);\n document.addEventListener('keyup', handleNativeActionWhileMoving);\n }\n hooks.callHooks(\"client-sprite-onAdd\", sprite).subscribe()\n hooks.callHooks(\"client-sceneMap-onAddSprite\", client.sceneMap, sprite).subscribe()\n effect(() => {\n if (isCurrentPlayer()) {\n client.setKeyboardControls(element.directives.controls)\n }\n })\n })\n\n /**\n * Handle attached GUI finish event\n * \n * @param gui - The GUI instance\n * @param data - Data passed from the GUI component\n */\n const normalizeOpenId = (value) => {\n const resolved = typeof value === \"function\" ? value() : value;\n return typeof resolved === \"string\" && resolved.length > 0 ? resolved : undefined;\n };\n\n const onAttachedGuiFinish = (gui, data, guiOpenId) => {\n const completedOpenId = normalizeOpenId(guiOpenId);\n const currentOpenId = normalizeOpenId(gui.openId);\n if (completedOpenId && currentOpenId && completedOpenId !== currentOpenId) return;\n guiService.guiClose(gui.name, data, completedOpenId ?? currentOpenId);\n };\n\n /**\n * Handle attached GUI interaction event\n * \n * @param gui - The GUI instance\n * @param name - Interaction name\n * @param data - Interaction data\n */\n const onAttachedGuiInteraction = (gui, name, data) => {\n guiService.guiInteraction(gui.name, name, data);\n };\n\n tick(() => {\n hooks.callHooks(\"client-sprite-onUpdate\").subscribe()\n })\n</script>\n"],"mappings":";;;;;;;;;;;;;;AAoBG,SAAA,UAAA,SAAA;CACiB,SAAQ,OAAQ;CACjC,MAAA,cAAyB,eAAQ,OAAc;CAChC,eAAqB,OAAU;CAC9C,MAAS,EAAA,QAAA,OAAA,YAAA;CACZ,MAAK,SAAK,OAAW;CACrB,MAAM,SAAC,OAAe,eAAe;CACrC,MAAM,QAAG,OAAM,YAAA;CACf,MAAM,aAAW,OAAM,MAAA;CACJ,OAAA;CACnB,MAAM,mBAAQ,OAAA;CACd,MAAM,oBAAI,OAAA;CACV,MAAM,YAAI,UAAc,OAAA,UAAa,aAAW,MAAA,IAAA;CAChD,MAAM,wBAAsB;EACxB,MAAK,WAAA,OAAA,eAAA;EACL,MAAI,gBAAS,WAAA,OAAA,UAAA,UAAA,IAAA,YAAA,KAAA;EACb,OAAA,SAAA,EAAA,MAAA,YACM,SAAA,QAAkB,EAAA,MAAA,YACrB,WAAU,iBACR,WAAA,OAAe,UAAa,mBAAqB;CAC1D;CACA,MAAI,OAAA,SAAA,eAAA;CACJ,MAAI,iBAAS,eAAA;EACV,MAAA,WAAiB,OAAQ,UAAQ,WAAU;EAC3C,OAAA,4BAAiC,QAAU;CAC9C,CAAC;CACD,MAAM,sBA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AAK,aAAA,MAAA,SAAA;GACL;GAAA,gBAAM,MAAA,SAAA;IACN,yBAAkB,aAAA,MAAA,IAAA;GAClB;EAAA,CAAA,CAAA,CAAO,CAAC;CAAC,CACV;AACD;AAEF,IAAM,iBAAgB"}
|
|
1
|
+
{"version":3,"file":"character.ce.js","names":[],"sources":["../../src/components/character.ce"],"sourcesContent":["<Container\n x={smoothX}\n y={smoothY}\n zIndex={z}\n controls\n onBeforeDestroy\n visible\n cursor={interactionCursor}\n pointerover={interactionPointerOver}\n pointerout={interactionPointerOut}\n pointerdown={interactionPointerDown}\n pointerup={interactionPointerUp}\n pointermove={interactionPointerMove}\n click={interactionClick}\n>\n @for (compConfig of normalizedComponentsBehind) {\n <Container>\n <compConfig.component object={sprite} ...compConfig.props />\n </Container>\n } \n <PlayerComponents object={sprite} position=\"bottom\" graphicBounds />\n <PlayerComponents object={sprite} position=\"left\" graphicBounds />\n <Particle emit={emitParticleTrigger} settings={particleSettings} zIndex={1000} name={particleName} />\n <Container>\n @for (graphicObj of renderedGraphics) {\n <Container scale={graphicScale(graphicObj)}>\n <Sprite \n sheet={sheet(graphicObj)} \n direction \n tint \n hitbox\n shadowCaster={shadowCaster(graphicObj)}\n flash={flashConfig}\n />\n </Container>\n }\n @for (eventComponent of resolvedEventComponents) {\n <Container dependencies={eventComponent.dependencies}>\n <eventComponent.component ...eventComponent.props />\n </Container>\n }\n </Container>\n <PlayerComponents object={sprite} position=\"center\" graphicBounds />\n <PlayerComponents object={sprite} position=\"right\" graphicBounds />\n <PlayerComponents object={sprite} position=\"top\" graphicBounds />\n @for (compConfig of normalizedComponentsInFront) {\n <Container dependencies={compConfig.dependencies}>\n <compConfig.component object={sprite} ...compConfig.props />\n </Container>\n }\n <InteractionComponents\n object={sprite}\n bounds={graphicBounds}\n hitboxBounds={hitboxBounds}\n graphicBounds={graphicBounds}\n />\n @for (attachedGui of attachedGuis) {\n @if (shouldDisplayAttachedGui) {\n <Container>\n <attachedGui.component ...attachedGui.data() dependencies={attachedGui.dependencies} object={sprite} guiOpenId={attachedGui.openId} onFinish={(data, guiOpenId) => {\n onAttachedGuiFinish(attachedGui, data, guiOpenId)\n }} onInteraction={(name, data) => {\n onAttachedGuiInteraction(attachedGui, name, data)\n }} />\n </Container>\n }\n }\n</Container>\n\n<script>\n import { signal, effect, mount, computed, tick, animatedSignal, on } from \"canvasengine\";\n import { Assets } from \"pixi.js\";\n\n import { lastValueFrom, combineLatest, pairwise, filter, map, startWith } from \"rxjs\";\n import { Particle } from \"@canvasengine/presets\";\n import { GameEngineToken, ModulesToken, shouldRenderLightingShadows } from \"@rpgjs/common\";\n import { RpgClientEngine } from \"../RpgClientEngine\";\n import { applyCameraFollow, clearCameraFollowPlugins, ownsCameraFollowRevision } from \"../services/cameraFollow\";\n import { inject } from \"../core/inject\"; \n import { Direction, Animation } from \"@rpgjs/common\";\n import { normalizeEventComponent } from \"../Game/EventComponentResolver\";\n import Hit from \"./effects/hit.ce\";\n import PlayerComponents from \"./player-components.ce\";\n import InteractionComponents from \"./interaction-components.ce\";\n import { RpgGui } from \"../Gui/Gui\";\n import { getCanMoveValue } from \"../utils/readPropValue\";\n import {\n getKeyboardControlBind,\n keyboardEventMatchesBind,\n resolveKeyboardActionInput,\n resolveKeyboardDirectionInput,\n } from \"../services/actionInput\";\n\n const { object, id } = defineProps();\n const sprite = object();\n\n const client = inject(RpgClientEngine);\n const hooks = inject(ModulesToken);\n const guiService = inject(RpgGui);\n\n const spritesheets = client.spritesheets;\n const componentsBehind = client.spriteComponentsBehind;\n const componentsInFront = client.spriteComponentsInFront;\n const readProp = (value) => typeof value === 'function' ? value() : value;\n const isCurrentPlayer = () => {\n const playerId = client.playerIdSignal();\n const currentPlayer = playerId ? client.sceneMap?.players?.()?.[playerId] : undefined;\n return readProp(id) === playerId\n || readProp(sprite?.id) === playerId\n || sprite === currentPlayer\n || sprite === client.sceneMap?.getCurrentPlayer?.();\n };\n const isMe = computed(isCurrentPlayer);\n const shadowsEnabled = computed(() => {\n const lighting = client.sceneMap?.lighting?.();\n return shouldRenderLightingShadows(lighting);\n });\n\n /**\n * Normalize a single sprite component configuration\n * \n * Handles both direct component references and configuration objects with optional props and dependencies.\n * Extracts the component reference and creates a computed function that returns the props.\n * \n * ## Design\n * \n * Supports two formats:\n * 1. Direct component: `ShadowComponent`\n * 2. Configuration object: `{ component: LightHalo, props: {...}, dependencies: (object) => [...] }`\n * \n * The normalization process:\n * - Extracts the actual component from either format\n * - Extracts dependencies function if provided\n * - Creates a computed function that returns props (static object or dynamic function result)\n * - Returns a normalized object with `component`, `props`, and `dependencies`\n * \n * @param comp - Component reference or configuration object\n * @returns Normalized component configuration with component, props, and dependencies\n * \n * @example\n * ```ts\n * // Direct component\n * normalizeComponent(ShadowComponent)\n * // => { component: ShadowComponent, props: {}, dependencies: undefined }\n * \n * // With static props\n * normalizeComponent({ component: LightHalo, props: { radius: 30 } })\n * // => { component: LightHalo, props: { radius: 30 }, dependencies: undefined }\n * \n * // With dynamic props and dependencies\n * normalizeComponent({ \n * component: HealthBar, \n * props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),\n * dependencies: (object) => [object.hp, object.param.maxHp]\n * })\n * // => { component: HealthBar, props: {...}, dependencies: (object) => [...] }\n * ```\n */\n const normalizeComponent = (comp) => {\n let componentRef;\n let propsValue;\n let dependenciesFn;\n \n // If it's a direct component reference\n if (typeof comp === 'function' || (comp && typeof comp === 'object' && !comp.component)) {\n componentRef = comp;\n propsValue = undefined;\n dependenciesFn = undefined;\n }\n // If it's a configuration object with component and props\n else if (comp && typeof comp === 'object' && comp.component) {\n componentRef = comp.component;\n // Support both \"data\" (legacy) and \"props\" (new) for backward compatibility\n propsValue = comp.props !== undefined ? comp.props : comp.data;\n dependenciesFn = comp.dependencies;\n }\n // Fallback: treat as direct component\n else {\n componentRef = comp;\n propsValue = undefined;\n dependenciesFn = undefined;\n }\n \n // Return props directly (object or function), not as computed\n // The computed will be created in the template when needed\n return {\n component: componentRef,\n props: typeof propsValue === 'function' ? propsValue(sprite) : propsValue || {},\n dependencies: dependenciesFn ? dependenciesFn(sprite) : []\n };\n };\n\n /**\n * Normalize an array of sprite components\n * \n * Applies normalization to each component in the array using `normalizeComponent`.\n * \n * @param components - Array of component references or configuration objects\n * @returns Array of normalized component configurations\n */\n const normalizeComponents = (components) => {\n return components.map((comp) => normalizeComponent(comp));\n };\n\n\n /**\n * Normalized components to render behind sprites\n * Handles both direct component references and configuration objects with optional props and dependencies\n * \n * Supports multiple formats:\n * 1. Direct component: `ShadowComponent`\n * 2. Configuration object: `{ component: LightHalo, props: {...} }`\n * 3. With dynamic props: `{ component: LightHalo, props: (object) => {...} }`\n * 4. With dependencies: `{ component: HealthBar, dependencies: (object) => [object.hp, object.param.maxHp] }`\n * \n * Components with dependencies will only be displayed when all dependencies are resolved (!= undefined).\n * The object is passed to the dependencies function to allow sprite-specific dependency resolution.\n * \n * @example\n * ```ts\n * // Direct component\n * componentsBehind: [ShadowComponent]\n * \n * // With static props\n * componentsBehind: [{ component: LightHalo, props: { radius: 30 } }]\n * \n * // With dynamic props and dependencies\n * componentsBehind: [{ \n * component: HealthBar, \n * props: (object) => ({ hp: object.hp(), maxHp: object.param.maxHp() }),\n * dependencies: (object) => [object.hp, object.param.maxHp]\n * }]\n * ```\n */\n const normalizedComponentsBehind = computed(() => {\n return normalizeComponents(componentsBehind());\n });\n\n /**\n * Normalized components to render in front of sprites\n * Handles both direct component references and configuration objects with optional props and dependencies\n * \n * See `normalizedComponentsBehind` for format details.\n * Components with dependencies will only be displayed when all dependencies are resolved.\n */\n const normalizedComponentsInFront = computed(() => {\n return normalizeComponents(componentsInFront());\n });\n\n const isEventSprite = () => {\n return typeof sprite?.isEvent === 'function'\n ? sprite.isEvent()\n : sprite?._type === 'event';\n };\n\n const resolvedEventComponents = computed(() => {\n if (!isEventSprite()) return [];\n const eventComponent = normalizeEventComponent(client.resolveEventComponent(sprite), sprite);\n return eventComponent ? [eventComponent] : [];\n });\n \n /**\n * Determine if the camera should follow this sprite\n * \n * The camera follows this sprite if:\n * - It's explicitly set as the camera follow target, OR\n * - It's the current player and no explicit target is set (default behavior)\n */\n const shouldFollowCamera = computed(() => {\n const cameraTargetId = client.cameraFollowTargetId();\n // If a target is explicitly set, only follow if this sprite is the target\n if (cameraTargetId !== null) {\n return id() === cameraTargetId;\n }\n // Otherwise, follow the current player (default behavior)\n return isMe();\n });\n\n /**\n * Get all attached GUI components that should be rendered on sprites\n * These are GUIs with attachToSprite: true\n */\n const attachedGuis = computed(() => {\n return guiService.getAttachedGuis();\n });\n\n /**\n * Check if attached GUIs should be displayed for this sprite\n * This is controlled by showAttachedGui/hideAttachedGui on the server\n */\n const shouldDisplayAttachedGui = computed(() => {\n return guiService.shouldDisplayAttachedGui(id());\n });\n\n const { \n x, \n y, \n tint, \n direction, \n animationName, \n animationCurrentIndex,\n emitParticleTrigger, \n particleName, \n graphics, \n hitbox,\n isConnected,\n graphicsSignals,\n flashTrigger\n } = sprite;\n\n const renderedGraphics = computed(() => {\n const eventComponent = resolvedEventComponents()[0];\n if (eventComponent && !eventComponent.renderGraphic) return [];\n return graphicsSignals();\n });\n\n /**\n * Flash configuration signals for dynamic options\n * These signals are updated when the flash trigger is activated with options\n */\n const flashType = signal<'alpha' | 'tint' | 'both'>('alpha');\n const flashDuration = signal(300);\n const flashCycles = signal(1);\n const flashAlpha = signal(0.3);\n const flashTint = signal(0xffffff);\n\n /**\n * Listen to flash trigger to update configuration dynamically\n * When flash is triggered with options, update the signals\n */\n on(flashTrigger, (data) => {\n if (data && typeof data === 'object') {\n if (data.type !== undefined) flashType.set(data.type);\n if (data.duration !== undefined) flashDuration.set(data.duration);\n if (data.cycles !== undefined) flashCycles.set(data.cycles);\n if (data.alpha !== undefined) flashAlpha.set(data.alpha);\n if (data.tint !== undefined) flashTint.set(data.tint);\n }\n });\n\n /**\n * Flash configuration for the sprite\n * \n * This configuration is used by the flash directive to create visual feedback effects.\n * The flash trigger is exposed through the object, allowing both server events and\n * client-side code to trigger flash animations. Options can be passed dynamically\n * through the trigger, which updates the reactive signals.\n */\n const flashConfig = computed(() => ({\n trigger: flashTrigger,\n type: flashType(),\n duration: flashDuration(),\n cycles: flashCycles(),\n alpha: flashAlpha(),\n tint: flashTint(),\n }));\n\n const particleSettings = client.particleSettings;\n\n const canControls = () => isMe() && getCanMoveValue(sprite)\n const keyboardControls = client.globalConfig.keyboardControls;\n const activeDirectionKeys = new Map();\n const activeControlDirections = new Map();\n const activeControlDirectionReleaseTimers = new Map();\n const CONTROL_DIRECTION_RELEASE_GRACE_MS = 160;\n\n const hasHeldDirection = () =>\n activeDirectionKeys.size > 0 || activeControlDirections.size > 0;\n\n const publishMobileDebug = (type, payload = {}) => {\n const target = typeof window !== \"undefined\" ? window : globalThis;\n if (!target.__RPGJS_MOBILE_DEBUG__) return;\n const event = {\n source: \"character\",\n type,\n time: Date.now(),\n isCurrentPlayer: isCurrentPlayer(),\n animationName: animationName(),\n realAnimationName: realAnimationName?.(),\n activeKeyboardDirections: Array.from(activeDirectionKeys.values()),\n activeControlDirections: Array.from(activeControlDirections.values()),\n heldDirection: resolveHeldDirection(),\n canControls: canControls(),\n x: x(),\n y: y(),\n ...payload\n };\n target.__RPGJS_MOBILE_DEBUG_EVENTS__ = [\n ...(target.__RPGJS_MOBILE_DEBUG_EVENTS__ || []).slice(-199),\n event\n ];\n target.__RPGJS_MOBILE_DEBUG_LAST__ = event;\n };\n\n const resolveHeldDirection = () => {\n const directions = [\n ...Array.from(activeDirectionKeys.values()),\n ...Array.from(activeControlDirections.values()),\n ];\n return directions[directions.length - 1];\n };\n\n const resolveSpriteDirection = () => {\n const heldDirection = resolveHeldDirection();\n if (heldDirection) return heldDirection;\n if (typeof sprite.getDirection === 'function') return sprite.getDirection();\n if (typeof sprite.direction === 'function') return sprite.direction();\n return direction();\n };\n\n const directionToDashVector = (currentDirection) => {\n switch (currentDirection) {\n case Direction.Left:\n return { x: -1, y: 0 };\n case Direction.Right:\n return { x: 1, y: 0 };\n case Direction.Up:\n return { x: 0, y: -1 };\n case Direction.Down:\n default:\n return { x: 0, y: 1 };\n }\n };\n\n const withCurrentDirection = (payload) => {\n if (payload.action !== 'action') return payload;\n const data = payload.data && typeof payload.data === 'object'\n ? { ...payload.data }\n : {};\n return {\n ...payload,\n data: {\n ...data,\n direction: data.direction ?? resolveSpriteDirection(),\n },\n };\n };\n\n const resolveCurrentActionInput = () =>\n withCurrentDirection(\n resolveKeyboardActionInput(keyboardControls.action, client, sprite)\n );\n\n const playPredictedWalkAnimation = () => {\n if (sprite.animationFixed) {\n publishMobileDebug(\"walk:skip\", { reason: \"animationFixed\" });\n return;\n }\n if (sprite.animationIsPlaying && sprite.animationIsPlaying()) {\n publishMobileDebug(\"walk:skip\", { reason: \"animationIsPlaying\" });\n return;\n }\n realAnimationName.set('walk');\n publishMobileDebug(\"walk:set\", { reason: \"predicted\" });\n };\n\n const resumeHeldDirectionWalkAnimation = () => {\n if (!isCurrentPlayer()) {\n publishMobileDebug(\"walk:resume-fail\", { reason: \"notCurrentPlayer\" });\n return false;\n }\n if (!hasHeldDirection()) {\n publishMobileDebug(\"walk:resume-fail\", { reason: \"noHeldDirection\" });\n return false;\n }\n if (!canControls()) {\n publishMobileDebug(\"walk:resume-fail\", { reason: \"cannotControl\" });\n return false;\n }\n if (sprite.animationFixed) {\n publishMobileDebug(\"walk:resume-fail\", { reason: \"animationFixed\" });\n return false;\n }\n if (sprite.animationIsPlaying && sprite.animationIsPlaying()) {\n publishMobileDebug(\"walk:resume-fail\", { reason: \"animationIsPlaying\" });\n return false;\n }\n realAnimationName.set('walk');\n publishMobileDebug(\"walk:set\", { reason: \"resumeHeldDirection\" });\n return true;\n };\n\n const processMovementInput = (input) => {\n if (!canControls()) return;\n publishMobileDebug(\"movement:input\", { input });\n client.processInput({ input });\n playPredictedWalkAnimation();\n };\n\n const activateControlDirection = (name, directionInput) => {\n const releaseTimer = activeControlDirectionReleaseTimers.get(name);\n if (releaseTimer) {\n clearTimeout(releaseTimer);\n activeControlDirectionReleaseTimers.delete(name);\n }\n activeControlDirections.delete(name);\n activeControlDirections.set(name, directionInput);\n publishMobileDebug(\"control:activate\", { name, directionInput });\n resumeHeldDirectionWalkAnimation();\n };\n\n const releaseControlDirection = (name) => {\n const previousTimer = activeControlDirectionReleaseTimers.get(name);\n if (previousTimer) clearTimeout(previousTimer);\n activeControlDirectionReleaseTimers.set(name, setTimeout(() => {\n activeControlDirectionReleaseTimers.delete(name);\n activeControlDirections.delete(name);\n publishMobileDebug(\"control:release\", { name });\n if (!hasHeldDirection() && animationName() === 'stand') {\n realAnimationName.set('stand');\n publishMobileDebug(\"stand:set\", { reason: \"controlRelease\" });\n }\n }, CONTROL_DIRECTION_RELEASE_GRACE_MS));\n };\n\n const processDashInput = () => {\n if (!canControls()) return;\n client.processDash({\n direction: directionToDashVector(resolveSpriteDirection()),\n });\n };\n\n const actionBind = () => getKeyboardControlBind(keyboardControls.action);\n const keyboardEventId = (event) => `${event.keyCode}:${event.code}:${event.key}`;\n\n const handleNativeActionWhileMoving = (event) => {\n const inputDirection = resolveKeyboardDirectionInput(event, keyboardControls);\n if (inputDirection) {\n const keyId = keyboardEventId(event);\n if (event.type === 'keydown') {\n activeDirectionKeys.delete(keyId);\n activeDirectionKeys.set(keyId, inputDirection);\n resumeHeldDirectionWalkAnimation();\n }\n else {\n activeDirectionKeys.delete(keyId);\n }\n }\n\n if (!isCurrentPlayer()) return;\n if (event.type !== 'keydown' || event.repeat) return;\n if (activeDirectionKeys.size === 0) return;\n if (!keyboardEventMatchesBind(event, actionBind())) return;\n if (!canControls()) return;\n\n client.processAction(resolveCurrentActionInput());\n };\n\n const visible = computed(() => {\n if (sprite.isEvent()) {\n return true\n }\n return isConnected()\n });\n\n const controls = {\n down: {\n repeat: true,\n bind: keyboardControls.down,\n keyDown() {\n activateControlDirection('down', Direction.Down)\n processMovementInput(Direction.Down)\n },\n keyUp() {\n releaseControlDirection('down')\n },\n },\n up: {\n repeat: true,\n bind: keyboardControls.up,\n keyDown() {\n activateControlDirection('up', Direction.Up)\n processMovementInput(Direction.Up)\n },\n keyUp() {\n releaseControlDirection('up')\n },\n },\n left: {\n repeat: true,\n bind: keyboardControls.left,\n keyDown() {\n activateControlDirection('left', Direction.Left)\n processMovementInput(Direction.Left)\n },\n keyUp() {\n releaseControlDirection('left')\n },\n },\n right: {\n repeat: true,\n bind: keyboardControls.right,\n keyDown() {\n activateControlDirection('right', Direction.Right)\n processMovementInput(Direction.Right)\n },\n keyUp() {\n releaseControlDirection('right')\n },\n },\n action: {\n bind: getKeyboardControlBind(keyboardControls.action),\n keyDown() {\n if (canControls()) {\n client.processAction(resolveCurrentActionInput())\n }\n },\n },\n dash: {\n bind: keyboardControls.dash,\n keyDown() {\n processDashInput()\n },\n },\n back: {\n bind: keyboardControls.escape,\n keyDown() {\n if (canControls()) {\n client.processAction({ action: 'escape' })\n }\n },\n },\n escape: {\n bind: keyboardControls.escape,\n keyDown() {\n if (canControls()) {\n client.processAction({ action: 'escape' })\n }\n },\n },\n joystick: {\n enabled: true,\n directionMapping: {\n top: 'up',\n bottom: 'down',\n left: 'left',\n right: 'right',\n top_left: ['up', 'left'],\n top_right: ['up', 'right'],\n bottom_left: ['down', 'left'],\n bottom_right: ['down', 'right']\n },\n moveInterval: 50,\n threshold: 0.1\n },\n gamepad: {\n enabled: true\n }\n };\n\n const smoothX = animatedSignal(x(), {\n duration: isMe() ? 0 : 0\n });\n\n const smoothY = animatedSignal(y(), {\n duration: isMe() ? 0 : 0,\n });\n\n const z = computed(() => {\n const box = hitbox?.()\n return sprite.y() + (box?.h ?? 0) + sprite.z()\n });\n\n const realAnimationName = signal(animationName());\n\n const xSubscription = x.observable.subscribe((value) => {\n smoothX.set(value);\n });\n\n const ySubscription = y.observable.subscribe((value) => {\n smoothY.set(value);\n });\n \n const sheet = (graphicObject) => {\n return {\n definition: graphicObject,\n playing: realAnimationName(),\n params: {\n direction: direction()\n },\n onFinish() {\n animationCurrentIndex.update(index => index + 1)\n }\n };\n }\n\n const graphicScale = (graphicObject) => {\n const scale = graphicObject?.displayScale ?? graphicObject?.scale;\n if (Array.isArray(scale)) return scale;\n if (typeof scale === 'number') return [scale, scale];\n if (scale && typeof scale === 'object') {\n const x = typeof scale.x === 'number' ? scale.x : 1;\n const y = typeof scale.y === 'number' ? scale.y : x;\n return [x, y];\n }\n return undefined;\n }\n\n const shadowCaster = (graphicObject) => {\n const box = hitbox();\n const bounds = graphicBounds();\n const scale = graphicScale(graphicObject);\n const scaleY = Array.isArray(scale) && typeof scale[1] === 'number' ? Math.abs(scale[1]) : 1;\n const height = Math.max(bounds?.height ?? box?.h ?? 32, box?.h ?? 32) * scaleY;\n\n return {\n enabled: shadowsEnabled,\n height,\n footAnchor: { x: 0.5, y: 1 },\n footOffset: { x: 0, y: 2 },\n alpha: 0.5,\n blur: 3.5,\n gradientPower: 2,\n hardness: 0.42,\n minLength: Math.max(6, (box?.h ?? 32) * 0.25),\n maxLength: Math.max(90, height * 1.8),\n contactAlpha: 0.3,\n contactScale: 0.3,\n };\n }\n\n const imageDimensions = signal({});\n const loadingImageDimensions = new Set();\n\n const toPositiveNumber = (value) => {\n const number = typeof value === 'number' ? value : parseFloat(value);\n return Number.isFinite(number) && number > 0 ? number : undefined;\n };\n\n const toFiniteNumber = (value, fallback = 0) => {\n const number = typeof value === 'number' ? value : parseFloat(value);\n return Number.isFinite(number) ? number : fallback;\n };\n\n const clampRatio = (value) => Math.min(1, Math.max(0, value));\n\n const normalizePair = (value, fallback = [1, 1]) => {\n if (Array.isArray(value)) {\n const x = toFiniteNumber(value[0], fallback[0]);\n const y = toFiniteNumber(value[1] ?? value[0], x);\n return [x, y];\n }\n if (typeof value === 'number') {\n return [value, value];\n }\n if (value && typeof value === 'object') {\n const x = toFiniteNumber(value.x, fallback[0]);\n const y = toFiniteNumber(value.y ?? value.x, x);\n return [x, y];\n }\n return fallback;\n };\n\n const normalizeAnchor = (value) => {\n if (!Array.isArray(value)) return undefined;\n const [x, y] = normalizePair(value, [0, 0]);\n return [clampRatio(x), clampRatio(y)];\n };\n\n const resolveImageSource = (image) => {\n if (typeof image === 'string') return image;\n if (typeof image?.default === 'string') return image.default;\n return undefined;\n };\n\n const parentTextureOptions = (graphicObject) => {\n const props = [\n 'width',\n 'height',\n 'framesHeight',\n 'framesWidth',\n 'rectWidth',\n 'rectHeight',\n 'offset',\n 'image',\n 'sound',\n 'spriteRealSize',\n 'scale',\n 'anchor',\n 'pivot',\n 'x',\n 'y',\n 'opacity'\n ];\n\n return props.reduce((options, prop) => {\n if (graphicObject?.[prop] !== undefined) {\n options[prop] = graphicObject[prop];\n }\n return options;\n }, {});\n };\n\n const resolveTextureOptions = (graphicObject) => {\n const textures = graphicObject?.textures ?? {};\n const texture =\n textures[realAnimationName()] ??\n textures[Animation.Stand] ??\n Object.values(textures)[0] ??\n {};\n\n return {\n ...parentTextureOptions(graphicObject),\n ...texture\n };\n };\n\n const resolveFirstAnimationFrame = (textureOptions) => {\n const animations = textureOptions?.animations;\n if (!animations) return {};\n\n try {\n const frames = typeof animations === 'function'\n ? animations({ direction: direction() })\n : animations;\n if (!Array.isArray(frames)) return {};\n const firstGroup = frames[0];\n return Array.isArray(firstGroup) ? firstGroup[0] ?? {} : firstGroup ?? {};\n }\n catch {\n return {};\n }\n };\n\n const optionValue = (prop, frame, textureOptions, graphicObject) => {\n return frame?.[prop] ?? textureOptions?.[prop] ?? graphicObject?.[prop];\n };\n\n const resolveFrameSize = (textureOptions, dimensions) => {\n const framesWidth = toPositiveNumber(textureOptions?.framesWidth) ?? 1;\n const framesHeight = toPositiveNumber(textureOptions?.framesHeight) ?? 1;\n const imageSource = resolveImageSource(textureOptions?.image);\n const loadedSize = imageSource ? dimensions[imageSource] : undefined;\n const fullWidth = toPositiveNumber(textureOptions?.width) ?? loadedSize?.width;\n const fullHeight = toPositiveNumber(textureOptions?.height) ?? loadedSize?.height;\n const width = toPositiveNumber(textureOptions?.rectWidth) ??\n toPositiveNumber(textureOptions?.spriteWidth) ??\n (fullWidth ? fullWidth / framesWidth : undefined);\n const height = toPositiveNumber(textureOptions?.rectHeight) ??\n toPositiveNumber(textureOptions?.spriteHeight) ??\n (fullHeight ? fullHeight / framesHeight : undefined);\n\n return {\n width,\n height\n };\n };\n\n const resolveHitboxAnchor = (spriteWidth, spriteHeight, realSize, box) => {\n if (!spriteWidth || !spriteHeight || !box) {\n return [0, 0];\n }\n\n const heightOfSprite = typeof realSize === 'number' ? realSize : realSize?.height;\n const resolvedHeight = toPositiveNumber(heightOfSprite) ?? spriteHeight;\n const gap = Math.max(0, (spriteHeight - resolvedHeight) / 2);\n const hitboxTopLeftX = clampRatio((spriteWidth - box.w) / 2 / spriteWidth);\n const hitboxTopLeftY = clampRatio((spriteHeight - box.h - gap) / spriteHeight);\n const hitboxCenterX = clampRatio(hitboxTopLeftX + box.w / 2 / spriteWidth);\n const hitboxCenterY = clampRatio(hitboxTopLeftY + box.h / 2 / spriteHeight);\n const footY = clampRatio((spriteHeight - gap) / spriteHeight);\n\n switch (box.anchorMode ?? 'top-left') {\n case 'center':\n return [hitboxCenterX, hitboxCenterY];\n case 'foot':\n return [hitboxCenterX, footY];\n case 'top-left':\n default:\n return [hitboxTopLeftX, hitboxTopLeftY];\n }\n };\n\n const loadImageDimensions = (image) => {\n const source = resolveImageSource(image);\n if (!source || imageDimensions()[source] || loadingImageDimensions.has(source)) {\n return;\n }\n\n loadingImageDimensions.add(source);\n Assets.load(source)\n .then((texture) => {\n const width = toPositiveNumber(texture?.width);\n const height = toPositiveNumber(texture?.height);\n if (!width || !height) return;\n\n imageDimensions.update((dimensions) => ({\n ...dimensions,\n [source]: { width, height }\n }));\n })\n .catch(() => {})\n .finally(() => {\n loadingImageDimensions.delete(source);\n });\n };\n\n effect(() => {\n const sources = new Set();\n\n graphicsSignals().forEach((graphicObject) => {\n const baseImage = resolveImageSource(graphicObject?.image);\n if (baseImage) sources.add(baseImage);\n\n Object.values(graphicObject?.textures ?? {}).forEach((textureOptions) => {\n const image = resolveImageSource(textureOptions?.image ?? graphicObject?.image);\n if (image) sources.add(image);\n });\n });\n\n sources.forEach((source) => loadImageDimensions(source));\n });\n\n const hitboxBounds = 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\n const graphicBounds = computed(() => {\n const box = hitbox();\n const fallback = hitboxBounds();\n const customEventComponent = resolvedEventComponents()[0];\n if (customEventComponent && !customEventComponent.renderGraphic) {\n return fallback;\n }\n const dimensions = imageDimensions();\n const graphics = graphicsSignals();\n let bounds = null;\n\n graphics.forEach((graphicObject) => {\n const textureOptions = resolveTextureOptions(graphicObject);\n const frame = resolveFirstAnimationFrame(textureOptions);\n const size = resolveFrameSize(textureOptions, dimensions);\n const spriteWidth = size.width ?? box?.w;\n const spriteHeight = size.height ?? box?.h;\n\n if (!spriteWidth || !spriteHeight) {\n return;\n }\n\n const explicitAnchor = normalizeAnchor(optionValue('anchor', frame, textureOptions, graphicObject));\n const anchor = explicitAnchor ?? resolveHitboxAnchor(\n spriteWidth,\n spriteHeight,\n optionValue('spriteRealSize', frame, textureOptions, graphicObject),\n box\n );\n const scale = normalizePair(optionValue('scale', frame, textureOptions, graphicObject) ?? graphicScale(graphicObject));\n const x = toFiniteNumber(optionValue('x', frame, textureOptions, graphicObject), 0);\n const y = toFiniteNumber(optionValue('y', frame, textureOptions, graphicObject), 0);\n const leftEdge = -anchor[0] * spriteWidth * scale[0];\n const rightEdge = (1 - anchor[0]) * spriteWidth * scale[0];\n const topEdge = -anchor[1] * spriteHeight * scale[1];\n const bottomEdge = (1 - anchor[1]) * spriteHeight * scale[1];\n const graphic = {\n left: x + Math.min(leftEdge, rightEdge),\n top: y + Math.min(topEdge, bottomEdge),\n right: x + Math.max(leftEdge, rightEdge),\n bottom: y + Math.max(topEdge, bottomEdge)\n };\n\n bounds = bounds\n ? {\n left: Math.min(bounds.left, graphic.left),\n top: Math.min(bounds.top, graphic.top),\n right: Math.max(bounds.right, graphic.right),\n bottom: Math.max(bounds.bottom, graphic.bottom)\n }\n : graphic;\n });\n\n if (!bounds) {\n return fallback;\n }\n\n const width = bounds.right - bounds.left;\n const height = bounds.bottom - bounds.top;\n\n return {\n ...bounds,\n width,\n height,\n centerX: bounds.left + width / 2,\n centerY: bounds.top + height / 2\n };\n });\n\n const interactionBounds = () => ({\n bounds: graphicBounds(),\n hitbox: hitboxBounds(),\n graphic: graphicBounds()\n });\n\n const interactionCursor = computed(() =>\n client.interactions.cursorFor(sprite, interactionBounds())\n );\n\n const handleInteraction = (type) => (event) => {\n client.updatePointerFromInteractionEvent(event);\n client.interactions.handle(sprite, type, {\n event,\n bounds: interactionBounds()\n });\n };\n\n const interactionPointerOver = handleInteraction('pointerover');\n const interactionPointerOut = handleInteraction('pointerout');\n const interactionPointerDown = handleInteraction('pointerdown');\n const interactionPointerUp = handleInteraction('pointerup');\n const interactionPointerMove = handleInteraction('pointermove');\n const interactionClick = handleInteraction('click');\n\n // Combine animation change detection with movement state from smoothX/smoothY\n const movementAnimations = ['walk', 'stand'];\n const epsilon = 0; // movement threshold to consider the easing still running\n\n const stateX$ = smoothX.animatedState.observable;\n const stateY$ = smoothY.animatedState.observable;\n const animationName$ = animationName.observable;\n\n const moving$ = combineLatest([stateX$, stateY$]).pipe(\n map(([sx, sy]) => {\n const xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;\n const yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;\n return !xFinished || !yFinished; // moving if X or Y is not finished\n }),\n startWith(false)\n );\n\n const animationChange$ = animationName$.pipe(\n startWith(animationName()),\n pairwise(),\n filter(([prev, curr]) => prev !== curr)\n );\n\n let beforeRemovePromise = null;\n let beforeRemoveTransitionValue = null;\n const resolveRemoveContext = () => {\n if (!sprite._removeTransition) return null;\n const value = sprite._removeTransition();\n if (!value || typeof value !== 'string') return null;\n try {\n const context = JSON.parse(value);\n if (!context || typeof context !== 'object' || !context.active) return null;\n context.__transitionValue = value;\n return context;\n }\n catch {\n return null;\n }\n };\n\n const withTimeout = (promise, timeoutMs = 0) => {\n if (!timeoutMs || timeoutMs <= 0) return promise;\n return Promise.race([\n promise,\n new Promise((resolve) => setTimeout(resolve, timeoutMs)),\n ]);\n };\n\n const runBeforeRemove = () => {\n const context = resolveRemoveContext();\n if (!context) return Promise.resolve();\n if (beforeRemovePromise && beforeRemoveTransitionValue === context.__transitionValue) {\n return beforeRemovePromise;\n }\n beforeRemoveTransitionValue = context.__transitionValue;\n beforeRemovePromise = withTimeout(\n lastValueFrom(hooks.callHooks(\"client-sprite-onBeforeRemove\", sprite, context)),\n context.timeoutMs\n );\n return beforeRemovePromise;\n };\n\n const removeTransitionSubscription = sprite._removeTransition?.observable?.subscribe(() => {\n if (resolveRemoveContext()) {\n runBeforeRemove();\n }\n });\n\n const animationMovementSubscription = combineLatest([animationChange$, moving$]).subscribe(([[prev, curr], isMoving]) => {\n const isMovementAnimation = movementAnimations.includes(curr);\n const isTemporaryAnimationPlaying =\n sprite.animationIsPlaying && sprite.animationIsPlaying();\n\n if (sprite.animationFixed && isMovementAnimation) {\n realAnimationName.set(curr);\n return;\n }\n\n if (curr == 'stand' && !isMoving) {\n if (!resumeHeldDirectionWalkAnimation()) {\n realAnimationName.set(curr);\n }\n }\n else if (curr == 'walk' && isMoving) {\n realAnimationName.set(curr);\n }\n else if (!isMovementAnimation) {\n realAnimationName.set(curr);\n }\n if (!isMoving && isTemporaryAnimationPlaying) {\n if (isMovementAnimation) {\n if (typeof sprite.resetAnimationState === 'function') {\n sprite.resetAnimationState();\n }\n }\n }\n });\n\n const resumeWalkSubscriptions = [\n sprite._canMove,\n sprite._animationFixed,\n sprite.animationIsPlaying,\n ]\n .filter(signal => signal?.observable)\n .map(signal => signal.observable.subscribe(() => {\n resumeHeldDirectionWalkAnimation();\n }));\n\n /**\n * Cleanup subscriptions and call hooks before sprite destruction.\n *\n * # Design\n * - Prevent memory leaks by unsubscribing from all local subscriptions created in this component.\n * - Execute destruction hooks to notify modules and scene map of sprite removal.\n *\n * @example\n * await onBeforeDestroy();\n */\n const waitForTemporaryAnimationEnd = (maxDuration = 1200) => {\n if (!sprite.animationIsPlaying || !sprite.animationIsPlaying()) {\n return Promise.resolve();\n }\n\n return new Promise((resolve) => {\n let finished = false;\n let timeout;\n let subscription;\n const finish = () => {\n if (finished) return;\n finished = true;\n clearTimeout(timeout);\n subscription?.unsubscribe();\n resolve();\n };\n timeout = setTimeout(finish, maxDuration);\n subscription = sprite.animationIsPlaying.observable.subscribe((isPlaying) => {\n if (!isPlaying) finish();\n });\n if (finished) subscription.unsubscribe();\n });\n };\n\n const onBeforeDestroy = async () => {\n await runBeforeRemove();\n await waitForTemporaryAnimationEnd();\n if (typeof document !== 'undefined') {\n document.removeEventListener('keydown', handleNativeActionWhileMoving);\n document.removeEventListener('keyup', handleNativeActionWhileMoving);\n }\n removeTransitionSubscription?.unsubscribe();\n animationMovementSubscription.unsubscribe();\n resumeWalkSubscriptions.forEach(subscription => subscription.unsubscribe());\n activeControlDirectionReleaseTimers.forEach(timer => clearTimeout(timer));\n activeControlDirectionReleaseTimers.clear();\n xSubscription.unsubscribe();\n ySubscription.unsubscribe();\n await lastValueFrom(hooks.callHooks(\"client-sprite-onDestroy\", sprite)) \n await lastValueFrom(hooks.callHooks(\"client-sceneMap-onRemoveSprite\", client.sceneMap, sprite))\n }\n\n mount((element) => {\n let appliedCameraFollowRevision = null;\n if (typeof document !== 'undefined') {\n document.addEventListener('keydown', handleNativeActionWhileMoving);\n document.addEventListener('keyup', handleNativeActionWhileMoving);\n }\n hooks.callHooks(\"client-sprite-onAdd\", sprite).subscribe()\n hooks.callHooks(\"client-sceneMap-onAddSprite\", client.sceneMap, sprite).subscribe()\n effect(() => {\n if (isCurrentPlayer()) {\n client.setKeyboardControls(element.directives.controls)\n }\n })\n\n effect(() => {\n const followRevision = client.cameraFollowRevision();\n if (!shouldFollowCamera()) {\n appliedCameraFollowRevision = null;\n return;\n }\n\n const smoothMove = client.cameraFollowSmoothMove;\n const viewport = element.props.context?.viewport;\n const target = element.componentInstance;\n if (!viewport || !target) {\n appliedCameraFollowRevision = null;\n return;\n }\n\n const appliedCameraFollow = applyCameraFollow({\n viewport,\n target,\n smoothMove,\n followRevision,\n isCurrentRevision: (revision) => client.cameraFollowRevision() === revision,\n shouldFollowCamera\n });\n appliedCameraFollowRevision = appliedCameraFollow ? followRevision : null;\n })\n\n return () => {\n if (ownsCameraFollowRevision(appliedCameraFollowRevision, client.cameraFollowRevision())) {\n clearCameraFollowPlugins(element.props.context?.viewport);\n }\n }\n })\n\n /**\n * Handle attached GUI finish event\n * \n * @param gui - The GUI instance\n * @param data - Data passed from the GUI component\n */\n const normalizeOpenId = (value) => {\n const resolved = typeof value === \"function\" ? value() : value;\n return typeof resolved === \"string\" && resolved.length > 0 ? resolved : undefined;\n };\n\n const onAttachedGuiFinish = (gui, data, guiOpenId) => {\n const completedOpenId = normalizeOpenId(guiOpenId);\n const currentOpenId = normalizeOpenId(gui.openId);\n if (completedOpenId && currentOpenId && completedOpenId !== currentOpenId) return;\n guiService.guiClose(gui.name, data, completedOpenId ?? currentOpenId);\n };\n\n /**\n * Handle attached GUI interaction event\n * \n * @param gui - The GUI instance\n * @param name - Interaction name\n * @param data - Interaction data\n */\n const onAttachedGuiInteraction = (gui, name, data) => {\n guiService.guiInteraction(gui.name, name, data);\n };\n\n tick(() => {\n hooks.callHooks(\"client-sprite-onUpdate\").subscribe()\n })\n</script>\n"],"mappings":";;;;;;;;;;;;;;;AAqBG,SAAA,UAAiB,SAAc;CAChB,SAAA,OAAqB;CACpC,MAAS,cAAA,eAAA,OAAA;CACY,eAAkB,OAAA;CACnC,MAAA,EAAS,QAAQ,OAAA,YAAa;CACrC,MAAM,SAAS,OAAA;CACf,MAAM,SAAS,OAAO,eAAa;CACnC,MAAM,QAAI,OAAS,YAAA;CACnB,MAAM,aAAQ,OAAA,MAAA;CACJ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AAA,WAAA,eAAA,KAAA,CAAA,CAAA,CAAA,CAAA;EAAA,EAAA,kBAAA;GAAA,QAAA;GAAA,UAAA;GAAA;EAAA,CAAA;EAAA,EAAA,kBAAA;GAAA,QAAA;GAAA,UAAA;GAAA;EAAA,CAAA;EAAA,EAAA,kBAAA;GAAA,QAAA;GAAA,UAAA;GAAA;EAAA,CAAA;EAAA,KAAA,8BAAA,eAAA,EAAA,WAAA,EAAA,cAAA,WAAA,aAAA,GAAA,EAAA,WAAA,WAAA;GAAA,QAAA;GAAA,GAAA,WAAA;EAAA,CAAA,CAAA,CAAA;EAAA,EAAA,kBAAA;GAAA,QAAA;GAAA,QAAA;GAAA;GAAA;EAAA,CAAA;EAAA,KAAA,eAAA,gBAAA,KAAA,gCAAA,EAAA,WAAA,MAAA,EAAA,YAAA,WAAA;GAAA,GAAA,YAAA,KAAA;GAAA,cAAA,YAAA;GAAA,QAAA;GAAA,WAAA,YAAA;GAAA,WAAA,MAAA,cAAA;IACzD,oBAAwB,aAAa,MAAG,SAAA;GACxC;GAAK,gBAAgB,MAAK,SAAU;;GAElC;EAAE,CAAC,CAAA,CAAA,CAAA;CAAA,CACG;AACR;AAEA,IAAM,iBAAiB"}
|
|
@@ -1,8 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
import { ButtonProps, ComponentFunction, JoystickSettings } from 'canvasengine';
|
|
2
|
+
export type MobileGuiEnabled = "auto" | "always" | "never" | (() => boolean);
|
|
3
|
+
export type MobileGuiJoystickSide = "left" | "right";
|
|
4
|
+
export type MobileGuiMargin = number | [number, number, number, number];
|
|
5
|
+
export interface MobileGuiLayoutOptions {
|
|
6
|
+
joystickSide?: MobileGuiJoystickSide;
|
|
7
|
+
margin?: MobileGuiMargin;
|
|
8
|
+
buttonsMargin?: MobileGuiMargin;
|
|
9
|
+
joystickMargin?: MobileGuiMargin;
|
|
10
|
+
gap?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface MobileJoystickComponentProps extends JoystickSettings {
|
|
13
|
+
defaultProps: JoystickSettings;
|
|
14
|
+
}
|
|
15
|
+
export interface MobileButtonComponentProps extends ButtonProps {
|
|
16
|
+
controlName: "action" | "back" | "dash";
|
|
17
|
+
defaultProps: ButtonProps;
|
|
18
|
+
}
|
|
19
|
+
export interface MobileGuiComponentsOptions {
|
|
20
|
+
joystick?: ComponentFunction<MobileJoystickComponentProps>;
|
|
21
|
+
buttons?: {
|
|
22
|
+
action?: ComponentFunction<MobileButtonComponentProps>;
|
|
23
|
+
back?: ComponentFunction<MobileButtonComponentProps>;
|
|
24
|
+
dash?: ComponentFunction<MobileButtonComponentProps>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface MobileGuiButtonOptions extends Partial<ButtonProps> {
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
component?: ComponentFunction<MobileButtonComponentProps>;
|
|
30
|
+
container?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
export interface MobileGuiJoystickOptions extends Partial<JoystickSettings> {
|
|
33
|
+
component?: ComponentFunction<MobileJoystickComponentProps>;
|
|
34
|
+
moveInterval?: number;
|
|
35
|
+
threshold?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface MobileGuiOptions {
|
|
38
|
+
id?: string;
|
|
39
|
+
enabled?: MobileGuiEnabled;
|
|
40
|
+
layout?: MobileGuiLayoutOptions;
|
|
41
|
+
components?: MobileGuiComponentsOptions;
|
|
42
|
+
joystick?: false | MobileGuiJoystickOptions;
|
|
43
|
+
buttons?: {
|
|
44
|
+
action?: boolean | MobileGuiButtonOptions;
|
|
45
|
+
back?: boolean | MobileGuiButtonOptions;
|
|
46
|
+
dash?: boolean | MobileGuiButtonOptions;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export declare const withMobile: (options?: MobileGuiOptions) => {
|
|
2
50
|
gui: {
|
|
3
51
|
id: string;
|
|
4
52
|
component: any;
|
|
5
53
|
autoDisplay: boolean;
|
|
6
|
-
|
|
54
|
+
data: MobileGuiOptions;
|
|
55
|
+
dependencies: () => (import('canvasengine').WritableSignal<boolean | undefined> | import('canvasengine').ComputedSignal<true | undefined>)[];
|
|
7
56
|
}[];
|
|
8
57
|
};
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { inject } from "../../../core/inject.js";
|
|
2
2
|
import { RpgClientEngine } from "../../../RpgClientEngine.js";
|
|
3
3
|
import __ce_component from "./mobile.ce.js";
|
|
4
|
-
import {
|
|
4
|
+
import { computed } from "canvasengine";
|
|
5
5
|
//#region src/components/gui/mobile/index.ts
|
|
6
6
|
function isMobile() {
|
|
7
|
+
if (typeof navigator === "undefined") return false;
|
|
7
8
|
return /Android|iPhone|iPad|iPod|Windows Phone|webOS|BlackBerry/i.test(navigator.userAgent);
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
function resolveEnabled(enabled = "auto") {
|
|
11
|
+
if (enabled === "always") return true;
|
|
12
|
+
if (enabled === "never") return false;
|
|
13
|
+
if (typeof enabled === "function") return enabled();
|
|
14
|
+
return isMobile();
|
|
15
|
+
}
|
|
16
|
+
var withMobile = (options = {}) => ({ gui: [{
|
|
17
|
+
id: options.id ?? "mobile-gui",
|
|
11
18
|
component: __ce_component,
|
|
12
19
|
autoDisplay: true,
|
|
20
|
+
data: options,
|
|
13
21
|
dependencies: () => {
|
|
14
22
|
const engine = inject(RpgClientEngine);
|
|
15
|
-
return [
|
|
23
|
+
return [computed(() => resolveEnabled(options.enabled) || void 0), engine.controlsReady];
|
|
16
24
|
}
|
|
17
25
|
}] });
|
|
18
26
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/gui/mobile/index.ts"],"sourcesContent":["import { inject } from \"../../../core/inject\";\nimport { RpgClientEngine } from \"../../../RpgClientEngine\";\nimport MobileGui from \"./mobile.ce\";\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/gui/mobile/index.ts"],"sourcesContent":["import { inject } from \"../../../core/inject\";\nimport { RpgClientEngine } from \"../../../RpgClientEngine\";\nimport MobileGui from \"./mobile.ce\";\nimport { computed } from \"canvasengine\";\nimport type { ButtonProps, ComponentFunction, JoystickSettings } from \"canvasengine\";\n\nexport type MobileGuiEnabled = \"auto\" | \"always\" | \"never\" | (() => boolean);\nexport type MobileGuiJoystickSide = \"left\" | \"right\";\nexport type MobileGuiMargin = number | [number, number, number, number];\n\nexport interface MobileGuiLayoutOptions {\n joystickSide?: MobileGuiJoystickSide;\n margin?: MobileGuiMargin;\n buttonsMargin?: MobileGuiMargin;\n joystickMargin?: MobileGuiMargin;\n gap?: number;\n}\n\nexport interface MobileJoystickComponentProps extends JoystickSettings {\n defaultProps: JoystickSettings;\n}\n\nexport interface MobileButtonComponentProps extends ButtonProps {\n controlName: \"action\" | \"back\" | \"dash\";\n defaultProps: ButtonProps;\n}\n\nexport interface MobileGuiComponentsOptions {\n joystick?: ComponentFunction<MobileJoystickComponentProps>;\n buttons?: {\n action?: ComponentFunction<MobileButtonComponentProps>;\n back?: ComponentFunction<MobileButtonComponentProps>;\n dash?: ComponentFunction<MobileButtonComponentProps>;\n };\n}\n\nexport interface MobileGuiButtonOptions extends Partial<ButtonProps> {\n enabled?: boolean;\n component?: ComponentFunction<MobileButtonComponentProps>;\n container?: Record<string, unknown>;\n}\n\nexport interface MobileGuiJoystickOptions extends Partial<JoystickSettings> {\n component?: ComponentFunction<MobileJoystickComponentProps>;\n moveInterval?: number;\n threshold?: number;\n}\n\nexport interface MobileGuiOptions {\n id?: string;\n enabled?: MobileGuiEnabled;\n layout?: MobileGuiLayoutOptions;\n components?: MobileGuiComponentsOptions;\n joystick?: false | MobileGuiJoystickOptions;\n buttons?: {\n action?: boolean | MobileGuiButtonOptions;\n back?: boolean | MobileGuiButtonOptions;\n dash?: boolean | MobileGuiButtonOptions;\n };\n}\n\nfunction isMobile() {\n if (typeof navigator === \"undefined\") return false;\n return /Android|iPhone|iPad|iPod|Windows Phone|webOS|BlackBerry/i.test(navigator.userAgent);\n}\n\nfunction resolveEnabled(enabled: MobileGuiEnabled = \"auto\") {\n if (enabled === \"always\") return true;\n if (enabled === \"never\") return false;\n if (typeof enabled === \"function\") return enabled();\n return isMobile();\n}\n\nexport const withMobile = (options: MobileGuiOptions = {}) => (\n {\n gui: [\n {\n id: options.id ?? 'mobile-gui',\n component: MobileGui,\n autoDisplay: true,\n data: options,\n dependencies: () => {\n const engine = inject(RpgClientEngine);\n return [\n computed(() => resolveEnabled(options.enabled) || undefined),\n engine.controlsReady\n ]\n }\n }\n ]\n }\n)\n"],"mappings":";;;;;AA6DA,SAAS,WAAW;CAChB,IAAI,OAAO,cAAc,aAAa,OAAO;CAC7C,OAAO,2DAA2D,KAAK,UAAU,SAAS;AAC9F;AAEA,SAAS,eAAe,UAA4B,QAAQ;CACxD,IAAI,YAAY,UAAU,OAAO;CACjC,IAAI,YAAY,SAAS,OAAO;CAChC,IAAI,OAAO,YAAY,YAAY,OAAO,QAAQ;CAClD,OAAO,SAAS;AACpB;AAEA,IAAa,cAAc,UAA4B,CAAC,OACpD,EACI,KAAK,CACD;CACI,IAAI,QAAQ,MAAM;CAClB,WAAW;CACX,aAAa;CACb,MAAM;CACN,oBAAoB;EAChB,MAAM,SAAS,OAAO,eAAe;EACrC,OAAO,CACH,eAAe,eAAe,QAAQ,OAAO,KAAK,KAAA,CAAS,GAC3D,OAAO,aACX;CACJ;AACJ,CACJ,EACJ"}
|