@rpgjs/client 5.0.0-beta.2 → 5.0.0-beta.20
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 +123 -0
- package/dist/Game/AnimationManager.d.ts +2 -1
- package/dist/Game/AnimationManager.js +21 -9
- package/dist/Game/AnimationManager.js.map +1 -1
- package/dist/Game/AnimationManager.spec.d.ts +1 -0
- package/dist/Game/ClientVisuals.d.ts +61 -0
- package/dist/Game/ClientVisuals.js +96 -0
- package/dist/Game/ClientVisuals.js.map +1 -0
- package/dist/Game/ClientVisuals.spec.d.ts +1 -0
- package/dist/Game/Event.js.map +1 -1
- package/dist/Game/EventComponentResolver.d.ts +16 -0
- package/dist/Game/EventComponentResolver.js +52 -0
- package/dist/Game/EventComponentResolver.js.map +1 -0
- package/dist/Game/EventComponentResolver.spec.d.ts +1 -0
- package/dist/Game/Map.d.ts +9 -1
- package/dist/Game/Map.js +83 -5
- package/dist/Game/Map.js.map +1 -1
- package/dist/Game/Object.d.ts +49 -15
- package/dist/Game/Object.js +101 -42
- package/dist/Game/Object.js.map +1 -1
- package/dist/Game/Object.spec.d.ts +1 -0
- package/dist/Game/Player.js.map +1 -1
- package/dist/Game/ProjectileManager.d.ts +98 -0
- package/dist/Game/ProjectileManager.js +196 -0
- package/dist/Game/ProjectileManager.js.map +1 -0
- package/dist/Game/ProjectileManager.spec.d.ts +1 -0
- package/dist/Gui/Gui.d.ts +20 -6
- package/dist/Gui/Gui.js +96 -54
- package/dist/Gui/Gui.js.map +1 -1
- package/dist/Gui/Gui.spec.d.ts +1 -0
- package/dist/Gui/NotificationManager.js.map +1 -1
- package/dist/Resource.js +1 -1
- package/dist/Resource.js.map +1 -1
- package/dist/RpgClient.d.ts +194 -15
- package/dist/RpgClientEngine.d.ts +176 -11
- package/dist/RpgClientEngine.js +669 -68
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/Sound.js.map +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0/helpers → _@oxc-project_runtime@0.133.0/helpers/esm}/decorate.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0/helpers → _@oxc-project_runtime@0.133.0/helpers/esm}/decorateMetadata.js +1 -1
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/components/animations/animation.ce.js +6 -5
- package/dist/components/animations/animation.ce.js.map +1 -1
- package/dist/components/animations/fx.ce.js +60 -0
- package/dist/components/animations/fx.ce.js.map +1 -0
- package/dist/components/animations/hit.ce.js +24 -28
- package/dist/components/animations/hit.ce.js.map +1 -1
- package/dist/components/animations/index.d.ts +1 -0
- package/dist/components/animations/index.js +6 -4
- package/dist/components/animations/index.js.map +1 -1
- package/dist/components/character.ce.js +606 -248
- package/dist/components/character.ce.js.map +1 -1
- package/dist/components/dynamics/bar.ce.js +99 -0
- package/dist/components/dynamics/bar.ce.js.map +1 -0
- package/dist/components/dynamics/image.ce.js +26 -0
- package/dist/components/dynamics/image.ce.js.map +1 -0
- package/dist/components/dynamics/parse-value.d.ts +3 -0
- package/dist/components/dynamics/parse-value.js +54 -35
- package/dist/components/dynamics/parse-value.js.map +1 -1
- package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
- package/dist/components/dynamics/shape-utils.d.ts +16 -0
- package/dist/components/dynamics/shape-utils.js +73 -0
- package/dist/components/dynamics/shape-utils.js.map +1 -0
- package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
- package/dist/components/dynamics/shape.ce.js +86 -0
- package/dist/components/dynamics/shape.ce.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +36 -56
- package/dist/components/dynamics/text.ce.js.map +1 -1
- package/dist/components/gui/box.ce.js +9 -9
- package/dist/components/gui/box.ce.js.map +1 -1
- package/dist/components/gui/dialogbox/index.ce.js +75 -65
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
- package/dist/components/gui/gameover.ce.js +47 -68
- package/dist/components/gui/gameover.ce.js.map +1 -1
- package/dist/components/gui/hud/hud.ce.js +23 -31
- package/dist/components/gui/hud/hud.ce.js.map +1 -1
- package/dist/components/gui/menu/equip-menu.ce.js +121 -172
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/exit-menu.ce.js +15 -10
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/items-menu.ce.js +62 -77
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/main-menu.ce.js +89 -104
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/options-menu.ce.js +12 -8
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/skills-menu.ce.js +17 -19
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
- package/dist/components/gui/mobile/index.js +2 -2
- package/dist/components/gui/mobile/index.js.map +1 -1
- package/dist/components/gui/mobile/mobile.ce.js +7 -5
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
- package/dist/components/gui/notification/notification.ce.js +28 -26
- package/dist/components/gui/notification/notification.ce.js.map +1 -1
- package/dist/components/gui/save-load.ce.js +81 -256
- package/dist/components/gui/save-load.ce.js.map +1 -1
- package/dist/components/gui/shop/shop.ce.js +107 -142
- package/dist/components/gui/shop/shop.ce.js.map +1 -1
- package/dist/components/gui/title-screen.ce.js +50 -73
- package/dist/components/gui/title-screen.ce.js.map +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +1 -0
- package/dist/components/interaction-components.ce.js +22 -0
- package/dist/components/interaction-components.ce.js.map +1 -0
- package/dist/components/player-components-utils.d.ts +67 -0
- package/dist/components/player-components-utils.js +162 -0
- package/dist/components/player-components-utils.js.map +1 -0
- package/dist/components/player-components-utils.spec.d.ts +1 -0
- package/dist/components/player-components.ce.js +191 -0
- package/dist/components/player-components.ce.js.map +1 -0
- package/dist/components/prebuilt/hp-bar.ce.js +45 -45
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
- package/dist/components/prebuilt/light-halo.ce.js +39 -60
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
- package/dist/components/scenes/canvas.ce.js +205 -27
- package/dist/components/scenes/canvas.ce.js.map +1 -1
- package/dist/components/scenes/draw-map.ce.js +39 -39
- package/dist/components/scenes/draw-map.ce.js.map +1 -1
- package/dist/components/scenes/event-layer.ce.js +51 -10
- package/dist/components/scenes/event-layer.ce.js.map +1 -1
- package/dist/core/inject.js +1 -1
- package/dist/core/inject.js.map +1 -1
- package/dist/core/setup.js +1 -1
- package/dist/core/setup.js.map +1 -1
- package/dist/decorators/spritesheet.d.ts +1 -0
- package/dist/decorators/spritesheet.js +11 -0
- package/dist/decorators/spritesheet.js.map +1 -0
- package/dist/i18n.d.ts +55 -0
- package/dist/i18n.js +60 -0
- package/dist/i18n.js.map +1 -0
- package/dist/i18n.spec.d.ts +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +29 -21
- package/dist/module.js +45 -4
- package/dist/module.js.map +1 -1
- package/dist/node_modules/.pnpm/{@signe_di@2.9.0 → @signe_di@3.1.0}/node_modules/@signe/di/dist/index.js +7 -117
- package/dist/node_modules/.pnpm/@signe_di@3.1.0/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@3.1.0/node_modules/@signe/reactive/dist/index.js +239 -0
- package/dist/node_modules/.pnpm/@signe_reactive@3.1.0/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@3.1.0_react@19.2.7/node_modules/@signe/room/dist/chunk-EUXUH3YW.js +13 -0
- package/dist/node_modules/.pnpm/@signe_room@3.1.0_react@19.2.7/node_modules/@signe/room/dist/chunk-EUXUH3YW.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@3.1.0_react@19.2.7/node_modules/@signe/room/dist/index.js +698 -0
- package/dist/node_modules/.pnpm/@signe_room@3.1.0_react@19.2.7/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.1.0_react@19.2.7/node_modules/@signe/sync/dist/client/index.js +43 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.1.0_react@19.2.7/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/node_modules/.pnpm/{@signe_sync@2.9.0 → @signe_sync@3.1.0_react@19.2.7}/node_modules/@signe/sync/dist/index.js +57 -141
- package/dist/node_modules/.pnpm/@signe_sync@3.1.0_react@19.2.7/node_modules/@signe/sync/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/{partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js → partysocket@1.2.0_react@19.2.7/node_modules/partysocket/dist/index.js} +30 -17
- package/dist/node_modules/.pnpm/partysocket@1.2.0_react@19.2.7/node_modules/partysocket/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/{partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js → partysocket@1.2.0_react@19.2.7/node_modules/partysocket/dist/ws.js} +65 -34
- package/dist/node_modules/.pnpm/partysocket@1.2.0_react@19.2.7/node_modules/partysocket/dist/ws.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/index.js +13 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/index.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js +106 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js +13 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js +121 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js +10 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js +110 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js +99 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js +82 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js.map +1 -0
- package/dist/node_modules/.pnpm/{zod@3.24.2/node_modules/zod/lib/index.js → zod@3.25.76/node_modules/zod/v3/types.js} +74 -611
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js.map +1 -0
- package/dist/presets/animation.js.map +1 -1
- package/dist/presets/faceset.js.map +1 -1
- package/dist/presets/icon.js.map +1 -1
- package/dist/presets/index.js.map +1 -1
- package/dist/presets/lpc.js.map +1 -1
- package/dist/presets/rmspritesheet.js.map +1 -1
- package/dist/services/AbstractSocket.d.ts +2 -0
- package/dist/services/AbstractSocket.js.map +1 -1
- package/dist/services/actionInput.d.ts +14 -0
- package/dist/services/actionInput.js +59 -0
- package/dist/services/actionInput.js.map +1 -0
- package/dist/services/actionInput.spec.d.ts +1 -0
- package/dist/services/interactions.d.ts +159 -0
- package/dist/services/interactions.js +460 -0
- package/dist/services/interactions.js.map +1 -0
- package/dist/services/interactions.spec.d.ts +1 -0
- package/dist/services/keyboardControls.d.ts +1 -0
- package/dist/services/keyboardControls.js +1 -0
- package/dist/services/keyboardControls.js.map +1 -1
- package/dist/services/loadMap.d.ts +9 -0
- package/dist/services/loadMap.js +1 -1
- package/dist/services/loadMap.js.map +1 -1
- package/dist/services/mmorpg-connection.d.ts +5 -0
- package/dist/services/mmorpg-connection.js +50 -0
- package/dist/services/mmorpg-connection.js.map +1 -0
- package/dist/services/mmorpg-connection.spec.d.ts +1 -0
- package/dist/services/mmorpg.d.ts +11 -4
- package/dist/services/mmorpg.js +57 -33
- package/dist/services/mmorpg.js.map +1 -1
- package/dist/services/pointerContext.d.ts +11 -0
- package/dist/services/pointerContext.js +48 -0
- package/dist/services/pointerContext.js.map +1 -0
- package/dist/services/pointerContext.spec.d.ts +1 -0
- package/dist/services/save.js.map +1 -1
- package/dist/services/save.spec.d.ts +1 -0
- package/dist/services/standalone-message.d.ts +1 -0
- package/dist/services/standalone-message.js +9 -0
- package/dist/services/standalone-message.js.map +1 -0
- package/dist/services/standalone.d.ts +4 -1
- package/dist/services/standalone.js +36 -16
- package/dist/services/standalone.js.map +1 -1
- package/dist/services/standalone.spec.d.ts +1 -0
- package/dist/utils/getEntityProp.js +4 -3
- package/dist/utils/getEntityProp.js.map +1 -1
- package/dist/utils/getEntityProp.spec.d.ts +1 -0
- package/dist/utils/mapId.d.ts +1 -0
- package/dist/utils/mapId.js +6 -0
- package/dist/utils/mapId.js.map +1 -0
- package/dist/utils/readPropValue.d.ts +2 -0
- package/dist/utils/readPropValue.js +13 -0
- package/dist/utils/readPropValue.js.map +1 -0
- package/package.json +13 -13
- package/src/Game/AnimationManager.spec.ts +30 -0
- package/src/Game/AnimationManager.ts +26 -10
- package/src/Game/ClientVisuals.spec.ts +56 -0
- package/src/Game/ClientVisuals.ts +184 -0
- package/src/Game/EventComponentResolver.spec.ts +84 -0
- package/src/Game/EventComponentResolver.ts +74 -0
- package/src/Game/Map.ts +134 -2
- package/src/Game/Object.spec.ts +59 -0
- package/src/Game/Object.ts +181 -77
- package/src/Game/ProjectileManager.spec.ts +449 -0
- package/src/Game/ProjectileManager.ts +346 -0
- package/src/Gui/Gui.spec.ts +340 -0
- package/src/Gui/Gui.ts +129 -57
- package/src/Resource.ts +1 -2
- package/src/RpgClient.ts +220 -17
- package/src/RpgClientEngine.ts +959 -116
- package/src/components/animations/fx.ce +101 -0
- package/src/components/animations/index.ts +4 -2
- package/src/components/character.ce +681 -45
- package/src/components/dynamics/bar.ce +88 -0
- package/src/components/dynamics/image.ce +21 -0
- package/src/components/dynamics/parse-value.spec.ts +83 -0
- package/src/components/dynamics/parse-value.ts +111 -37
- package/src/components/dynamics/shape-utils.spec.ts +46 -0
- package/src/components/dynamics/shape-utils.ts +61 -0
- package/src/components/dynamics/shape.ce +90 -0
- package/src/components/dynamics/text.ce +35 -149
- package/src/components/gui/dialogbox/index.ce +52 -21
- package/src/components/gui/gameover.ce +6 -4
- package/src/components/gui/menu/equip-menu.ce +11 -9
- package/src/components/gui/menu/exit-menu.ce +6 -4
- package/src/components/gui/menu/items-menu.ce +11 -9
- package/src/components/gui/menu/main-menu.ce +14 -12
- package/src/components/gui/menu/options-menu.ce +4 -3
- package/src/components/gui/menu/skills-menu.ce +2 -1
- package/src/components/gui/notification/notification.ce +7 -1
- package/src/components/gui/save-load.ce +13 -11
- package/src/components/gui/shop/shop.ce +20 -18
- package/src/components/gui/title-screen.ce +6 -4
- package/src/components/index.ts +2 -1
- package/src/components/interaction-components.ce +23 -0
- package/src/components/player-components-utils.spec.ts +109 -0
- package/src/components/player-components-utils.ts +205 -0
- package/src/components/player-components.ce +222 -0
- package/src/components/prebuilt/hp-bar.ce +4 -3
- package/src/components/prebuilt/light-halo.ce +2 -2
- package/src/components/scenes/canvas.ce +219 -15
- package/src/components/scenes/draw-map.ce +34 -22
- package/src/components/scenes/event-layer.ce +55 -4
- package/src/core/setup.ts +2 -2
- package/src/decorators/spritesheet.ts +8 -0
- package/src/i18n.spec.ts +39 -0
- package/src/i18n.ts +59 -0
- package/src/index.ts +7 -0
- package/src/module.ts +61 -11
- package/src/services/AbstractSocket.ts +3 -0
- package/src/services/actionInput.spec.ts +155 -0
- package/src/services/actionInput.ts +120 -0
- package/src/services/interactions.spec.ts +175 -0
- package/src/services/interactions.ts +722 -0
- package/src/services/keyboardControls.ts +2 -1
- package/src/services/loadMap.ts +5 -1
- package/src/services/mmorpg-connection.spec.ts +99 -0
- package/src/services/mmorpg-connection.ts +69 -0
- package/src/services/mmorpg.ts +70 -36
- package/src/services/pointerContext.spec.ts +36 -0
- package/src/services/pointerContext.ts +84 -0
- package/src/services/save.spec.ts +127 -0
- package/src/services/standalone-message.ts +7 -0
- package/src/services/standalone.spec.ts +54 -0
- package/src/services/standalone.ts +44 -12
- package/src/utils/getEntityProp.spec.ts +96 -0
- package/src/utils/getEntityProp.ts +4 -3
- package/src/utils/mapId.ts +2 -0
- package/src/utils/readPropValue.ts +16 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +0 -457
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +0 -463
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +0 -2191
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +0 -10
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +0 -91
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +0 -1
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +0 -14
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +0 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +0 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +0 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +0 -2
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +0 -1
|
@@ -9,8 +9,11 @@ export type SocketUpdateProperties = {
|
|
|
9
9
|
host?: string;
|
|
10
10
|
query?: SocketQuery;
|
|
11
11
|
};
|
|
12
|
+
export type WebSocketMode = "standalone" | "mmorpg";
|
|
12
13
|
|
|
13
14
|
export abstract class AbstractWebsocket {
|
|
15
|
+
readonly mode?: WebSocketMode;
|
|
16
|
+
|
|
14
17
|
constructor(protected context: Context) {}
|
|
15
18
|
|
|
16
19
|
abstract connection(listeners?: (data: any) => void): Promise<void>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
getKeyboardControlBind,
|
|
4
|
+
keyboardEventMatchesBind,
|
|
5
|
+
normalizeActionInput,
|
|
6
|
+
resolveKeyboardActionInput,
|
|
7
|
+
resolveKeyboardDirectionInput,
|
|
8
|
+
} from "./actionInput";
|
|
9
|
+
|
|
10
|
+
const keyboardEvent = (values: Partial<KeyboardEvent>) =>
|
|
11
|
+
values as KeyboardEvent;
|
|
12
|
+
|
|
13
|
+
describe("normalizeActionInput", () => {
|
|
14
|
+
test("keeps simple actions compatible", () => {
|
|
15
|
+
expect(normalizeActionInput("action")).toEqual({
|
|
16
|
+
action: "action",
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("adds custom data to action payloads", () => {
|
|
21
|
+
expect(normalizeActionInput("projectile:shoot", {
|
|
22
|
+
target: { x: 320, y: 180 },
|
|
23
|
+
source: "map-click",
|
|
24
|
+
})).toEqual({
|
|
25
|
+
action: "projectile:shoot",
|
|
26
|
+
data: {
|
|
27
|
+
target: { x: 320, y: 180 },
|
|
28
|
+
source: "map-click",
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("keeps object-form action payloads intact", () => {
|
|
34
|
+
const payload = {
|
|
35
|
+
action: "projectile:shoot",
|
|
36
|
+
data: { target: { x: 64, y: 96 } },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
expect(normalizeActionInput(payload)).toBe(payload);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("keyboard action controls", () => {
|
|
44
|
+
test("keeps string controls compatible", () => {
|
|
45
|
+
expect(getKeyboardControlBind("space")).toBe("space");
|
|
46
|
+
expect(resolveKeyboardActionInput("space", {}, {})).toEqual({
|
|
47
|
+
action: "action",
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("resolves object controls with static data", () => {
|
|
52
|
+
const control = {
|
|
53
|
+
bind: "space",
|
|
54
|
+
action: "projectile:shoot",
|
|
55
|
+
data: {
|
|
56
|
+
source: "keyboard",
|
|
57
|
+
target: { x: 10, y: 20 },
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
expect(getKeyboardControlBind(control)).toBe("space");
|
|
62
|
+
expect(resolveKeyboardActionInput(control, {}, {})).toEqual({
|
|
63
|
+
action: "projectile:shoot",
|
|
64
|
+
data: {
|
|
65
|
+
source: "keyboard",
|
|
66
|
+
target: { x: 10, y: 20 },
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("resolves object controls with functional data", () => {
|
|
72
|
+
const client = {
|
|
73
|
+
pointer: {
|
|
74
|
+
world: () => ({ x: 64, y: 96 }),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const sprite = { id: "player-1" };
|
|
78
|
+
const control = {
|
|
79
|
+
bind: "space",
|
|
80
|
+
action: "projectile:shoot",
|
|
81
|
+
data: (resolvedClient: typeof client, resolvedSprite: typeof sprite) => ({
|
|
82
|
+
source: "keyboard",
|
|
83
|
+
target: resolvedClient.pointer.world(),
|
|
84
|
+
playerId: resolvedSprite.id,
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
expect(resolveKeyboardActionInput(control, client, sprite)).toEqual({
|
|
89
|
+
action: "projectile:shoot",
|
|
90
|
+
data: {
|
|
91
|
+
source: "keyboard",
|
|
92
|
+
target: { x: 64, y: 96 },
|
|
93
|
+
playerId: "player-1",
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("omits data when object controls do not provide it", () => {
|
|
99
|
+
expect(resolveKeyboardActionInput({
|
|
100
|
+
bind: "space",
|
|
101
|
+
action: "projectile:shoot",
|
|
102
|
+
}, {}, {})).toEqual({
|
|
103
|
+
action: "projectile:shoot",
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("matches keyboard events against string, numeric, and array binds", () => {
|
|
108
|
+
expect(
|
|
109
|
+
keyboardEventMatchesBind(
|
|
110
|
+
keyboardEvent({ key: " ", code: "Space", keyCode: 32 }),
|
|
111
|
+
"space"
|
|
112
|
+
)
|
|
113
|
+
).toBe(true);
|
|
114
|
+
expect(
|
|
115
|
+
keyboardEventMatchesBind(
|
|
116
|
+
keyboardEvent({ key: "ArrowUp", code: "ArrowUp", keyCode: 38 }),
|
|
117
|
+
"up"
|
|
118
|
+
)
|
|
119
|
+
).toBe(true);
|
|
120
|
+
expect(
|
|
121
|
+
keyboardEventMatchesBind(
|
|
122
|
+
keyboardEvent({ key: "x", code: "KeyX", keyCode: 88 }),
|
|
123
|
+
["space", "x"]
|
|
124
|
+
)
|
|
125
|
+
).toBe(true);
|
|
126
|
+
expect(
|
|
127
|
+
keyboardEventMatchesBind(
|
|
128
|
+
keyboardEvent({ key: "Escape", code: "Escape", keyCode: 27 }),
|
|
129
|
+
27
|
|
130
|
+
)
|
|
131
|
+
).toBe(true);
|
|
132
|
+
expect(
|
|
133
|
+
keyboardEventMatchesBind(
|
|
134
|
+
keyboardEvent({ key: "a", code: "KeyA", keyCode: 65 }),
|
|
135
|
+
"space"
|
|
136
|
+
)
|
|
137
|
+
).toBe(false);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("resolves directional keyboard controls from a native keyboard event", () => {
|
|
141
|
+
const controls = {
|
|
142
|
+
up: "up",
|
|
143
|
+
down: "down",
|
|
144
|
+
left: "left",
|
|
145
|
+
right: "right",
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
expect(
|
|
149
|
+
resolveKeyboardDirectionInput(
|
|
150
|
+
keyboardEvent({ key: "ArrowRight", code: "ArrowRight", keyCode: 39 }),
|
|
151
|
+
controls
|
|
152
|
+
)
|
|
153
|
+
).toBe("right");
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Direction, type RpgActionInput, type RpgActionName } from "@rpgjs/common";
|
|
2
|
+
|
|
3
|
+
export type KeyboardActionDataResolver<TClient = any, TSprite = any> = (
|
|
4
|
+
client: TClient,
|
|
5
|
+
sprite: TSprite,
|
|
6
|
+
) => any;
|
|
7
|
+
|
|
8
|
+
export interface KeyboardActionConfig<TClient = any, TSprite = any> {
|
|
9
|
+
bind: any;
|
|
10
|
+
action?: RpgActionName;
|
|
11
|
+
data?: any | KeyboardActionDataResolver<TClient, TSprite>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function normalizeActionInput(action: RpgActionName, data?: any): RpgActionInput;
|
|
15
|
+
export function normalizeActionInput(action: RpgActionInput): RpgActionInput;
|
|
16
|
+
export function normalizeActionInput(action: RpgActionName | RpgActionInput, data?: any): RpgActionInput {
|
|
17
|
+
if (typeof action === "object") {
|
|
18
|
+
return action;
|
|
19
|
+
}
|
|
20
|
+
return data === undefined
|
|
21
|
+
? { action }
|
|
22
|
+
: { action, data };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isKeyboardActionConfig(value: any): value is KeyboardActionConfig {
|
|
26
|
+
return value !== null
|
|
27
|
+
&& typeof value === "object"
|
|
28
|
+
&& Object.prototype.hasOwnProperty.call(value, "bind");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getKeyboardControlBind(control: any): any {
|
|
32
|
+
return isKeyboardActionConfig(control) ? control.bind : control;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const KEY_CODE_NAMES: Record<number, string> = {
|
|
36
|
+
32: "space",
|
|
37
|
+
27: "escape",
|
|
38
|
+
37: "left",
|
|
39
|
+
38: "up",
|
|
40
|
+
39: "right",
|
|
41
|
+
40: "down",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const normalizeKeyboardName = (value: unknown): string | undefined => {
|
|
45
|
+
if (typeof value !== "string") return undefined;
|
|
46
|
+
const normalized = value.toLowerCase();
|
|
47
|
+
if (
|
|
48
|
+
normalized === " " ||
|
|
49
|
+
normalized === "spacebar" ||
|
|
50
|
+
normalized === "space"
|
|
51
|
+
) {
|
|
52
|
+
return "space";
|
|
53
|
+
}
|
|
54
|
+
if (normalized.startsWith("arrow")) {
|
|
55
|
+
return normalized.slice("arrow".length);
|
|
56
|
+
}
|
|
57
|
+
return normalized;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export function keyboardEventMatchesBind(
|
|
61
|
+
event: KeyboardEvent,
|
|
62
|
+
bind: any
|
|
63
|
+
): boolean {
|
|
64
|
+
if (Array.isArray(bind)) {
|
|
65
|
+
return bind.some(item => keyboardEventMatchesBind(event, item));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof bind === "number") {
|
|
69
|
+
return event.keyCode === bind;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const expected = normalizeKeyboardName(bind);
|
|
73
|
+
if (!expected) return false;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
normalizeKeyboardName(event.key) === expected ||
|
|
77
|
+
normalizeKeyboardName(event.code) === expected ||
|
|
78
|
+
KEY_CODE_NAMES[event.keyCode] === expected
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function resolveKeyboardActionInput(
|
|
83
|
+
control: any,
|
|
84
|
+
client: any,
|
|
85
|
+
sprite: any,
|
|
86
|
+
defaultAction: RpgActionName = "action",
|
|
87
|
+
): RpgActionInput {
|
|
88
|
+
if (!isKeyboardActionConfig(control)) {
|
|
89
|
+
return { action: defaultAction };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const action = control.action ?? defaultAction;
|
|
93
|
+
const data = typeof control.data === "function"
|
|
94
|
+
? control.data(client, sprite)
|
|
95
|
+
: control.data;
|
|
96
|
+
|
|
97
|
+
return data === undefined
|
|
98
|
+
? { action }
|
|
99
|
+
: { action, data };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function resolveKeyboardDirectionInput(
|
|
103
|
+
event: KeyboardEvent,
|
|
104
|
+
keyboardControls: any
|
|
105
|
+
): Direction | undefined {
|
|
106
|
+
const directions: Array<[any, Direction]> = [
|
|
107
|
+
[keyboardControls?.up, Direction.Up],
|
|
108
|
+
[keyboardControls?.down, Direction.Down],
|
|
109
|
+
[keyboardControls?.left, Direction.Left],
|
|
110
|
+
[keyboardControls?.right, Direction.Right],
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
for (const [control, direction] of directions) {
|
|
114
|
+
if (keyboardEventMatchesBind(event, getKeyboardControlBind(control))) {
|
|
115
|
+
return direction;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
dragToTile,
|
|
4
|
+
hoverPopover,
|
|
5
|
+
RpgClientInteractions,
|
|
6
|
+
selectable,
|
|
7
|
+
} from "./interactions";
|
|
8
|
+
import { createClientPointerContext } from "./pointerContext";
|
|
9
|
+
|
|
10
|
+
function createClient() {
|
|
11
|
+
const client = {
|
|
12
|
+
pointer: createClientPointerContext(),
|
|
13
|
+
processAction: vi.fn(),
|
|
14
|
+
sceneMap: {
|
|
15
|
+
tileWidth: 16,
|
|
16
|
+
tileHeight: 16,
|
|
17
|
+
},
|
|
18
|
+
} as any;
|
|
19
|
+
client.interactions = new RpgClientInteractions(client);
|
|
20
|
+
return client;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("RpgClientInteractions", () => {
|
|
24
|
+
test("renders registered components with sprite state and bounds", () => {
|
|
25
|
+
const client = createClient();
|
|
26
|
+
const Popover = () => null;
|
|
27
|
+
const sprite = { id: "event-1", name: "Guard" };
|
|
28
|
+
|
|
29
|
+
client.interactions.use("Guard", hoverPopover(Popover, { label: "Talk" }));
|
|
30
|
+
client.interactions.handle(sprite, "pointerover", {
|
|
31
|
+
bounds: {
|
|
32
|
+
graphic: { left: 1, top: 2, right: 11, bottom: 22, width: 10, height: 20, centerX: 6, centerY: 12 } as any,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const entries = client.interactions.getRenderedComponents(sprite, {
|
|
37
|
+
graphic: { left: 1, top: 2, right: 11, bottom: 22, width: 10, height: 20, centerX: 6, centerY: 12 } as any,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(entries).toHaveLength(1);
|
|
41
|
+
expect(entries[0].component).toBe(Popover);
|
|
42
|
+
expect(entries[0].props.label).toBe("Talk");
|
|
43
|
+
expect(entries[0].props.state.hovered).toBe(true);
|
|
44
|
+
expect(entries[0].props.bounds.centerX).toBe(6);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("keeps clicks client-only unless a behavior sends an action", () => {
|
|
48
|
+
const client = createClient();
|
|
49
|
+
const sprite = { id: "event-1", name: "Guard" };
|
|
50
|
+
|
|
51
|
+
client.interactions.use("Guard", selectable());
|
|
52
|
+
client.interactions.handle(sprite, "click");
|
|
53
|
+
|
|
54
|
+
expect(client.interactions.getState(sprite).selected).toBe(true);
|
|
55
|
+
expect(client.processAction).not.toHaveBeenCalled();
|
|
56
|
+
|
|
57
|
+
client.interactions.use("Guard", {
|
|
58
|
+
click(ctx) {
|
|
59
|
+
ctx.action("guard:talk", { eventId: ctx.target.id });
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
client.interactions.handle(sprite, "click");
|
|
63
|
+
|
|
64
|
+
expect(client.processAction).toHaveBeenCalledWith("guard:talk", { eventId: "event-1" });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("uses behavior hit tests before changing hover state", () => {
|
|
68
|
+
const client = createClient();
|
|
69
|
+
const sprite = { id: "event-1", name: "Tree" };
|
|
70
|
+
|
|
71
|
+
client.pointer.update({ x: 0, y: 0 }, { x: 40, y: 40 });
|
|
72
|
+
client.interactions.use("Tree", {
|
|
73
|
+
cursor: "pointer",
|
|
74
|
+
hitTest(ctx) {
|
|
75
|
+
return ctx.bounds("hitbox").contains(ctx.pointer.world());
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
client.interactions.handle(sprite, "pointerover", {
|
|
80
|
+
bounds: {
|
|
81
|
+
hitbox: { left: 0, top: 0, right: 16, bottom: 16, width: 16, height: 16, centerX: 8, centerY: 8 } as any,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(client.interactions.getState(sprite).hovered).toBe(false);
|
|
86
|
+
expect(client.interactions.cursorFor(sprite, {
|
|
87
|
+
hitbox: { left: 0, top: 0, right: 16, bottom: 16, width: 16, height: 16, centerX: 8, centerY: 8 } as any,
|
|
88
|
+
})).toBeUndefined();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("exposes handler bounds in world coordinates", () => {
|
|
92
|
+
const client = createClient();
|
|
93
|
+
const sprite = { id: "crate-1", name: "Crate", x: () => 100, y: () => 80 };
|
|
94
|
+
|
|
95
|
+
client.pointer.update({ x: 0, y: 0 }, { x: 112, y: 92 });
|
|
96
|
+
client.interactions.use("Crate", {
|
|
97
|
+
component: () => null,
|
|
98
|
+
cursor: "grab",
|
|
99
|
+
hitTest(ctx) {
|
|
100
|
+
return ctx.bounds("hitbox").contains(ctx.pointer.world());
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
client.interactions.handle(sprite, "pointerover", {
|
|
105
|
+
bounds: {
|
|
106
|
+
hitbox: { left: 0, top: 0, right: 16, bottom: 16, width: 16, height: 16, centerX: 8, centerY: 8 } as any,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(client.interactions.getState(sprite).hovered).toBe(true);
|
|
111
|
+
expect(client.interactions.cursorFor(sprite, {
|
|
112
|
+
hitbox: { left: 0, top: 0, right: 16, bottom: 16, width: 16, height: 16, centerX: 8, centerY: 8 } as any,
|
|
113
|
+
})).toBe("grab");
|
|
114
|
+
|
|
115
|
+
const [entry] = client.interactions.getRenderedComponents(sprite, {
|
|
116
|
+
hitbox: { left: 0, top: 0, right: 16, bottom: 16, width: 16, height: 16, centerX: 8, centerY: 8 } as any,
|
|
117
|
+
});
|
|
118
|
+
expect(entry?.props.bounds.centerX).toBe(8);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("updates hit-tested hover while moving inside an already hovered sprite", () => {
|
|
122
|
+
const client = createClient();
|
|
123
|
+
const sprite = { id: "crate-1", name: "Crate", x: () => 100, y: () => 80 };
|
|
124
|
+
|
|
125
|
+
client.interactions.use("Crate", {
|
|
126
|
+
hitTest(ctx) {
|
|
127
|
+
return ctx.bounds("hitbox").contains(ctx.pointer.world());
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
client.pointer.update({ x: 0, y: 0 }, { x: 140, y: 120 });
|
|
132
|
+
client.interactions.handle(sprite, "pointerover", {
|
|
133
|
+
bounds: {
|
|
134
|
+
hitbox: { left: 0, top: 0, right: 16, bottom: 16, width: 16, height: 16, centerX: 8, centerY: 8 } as any,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
expect(client.interactions.getState(sprite).hovered).toBe(false);
|
|
138
|
+
|
|
139
|
+
client.pointer.update({ x: 0, y: 0 }, { x: 112, y: 92 });
|
|
140
|
+
client.interactions.handle(sprite, "pointermove", {
|
|
141
|
+
bounds: {
|
|
142
|
+
hitbox: { left: 0, top: 0, right: 16, bottom: 16, width: 16, height: 16, centerX: 8, centerY: 8 } as any,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
expect(client.interactions.getState(sprite).hovered).toBe(true);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("runs drag lifecycle and resolves pointer tile on drop", () => {
|
|
150
|
+
const client = createClient();
|
|
151
|
+
const sprite = { id: "crate-1", name: "Crate" };
|
|
152
|
+
|
|
153
|
+
client.interactions.use("Crate", dragToTile({ action: "crate:move" }));
|
|
154
|
+
client.pointer.update({ x: 0, y: 0 }, { x: 18, y: 35 });
|
|
155
|
+
client.interactions.handle(sprite, "pointerdown");
|
|
156
|
+
|
|
157
|
+
expect(client.interactions.getState(sprite).dragging).toBe(true);
|
|
158
|
+
|
|
159
|
+
client.pointer.update({ x: 0, y: 0 }, { x: 33, y: 47 });
|
|
160
|
+
client.interactions.handlePointerUp();
|
|
161
|
+
|
|
162
|
+
expect(client.interactions.getState(sprite).dragging).toBe(false);
|
|
163
|
+
expect(client.processAction).toHaveBeenCalledWith("crate:move", {
|
|
164
|
+
eventId: "crate-1",
|
|
165
|
+
position: {
|
|
166
|
+
x: 2,
|
|
167
|
+
y: 2,
|
|
168
|
+
worldX: 32,
|
|
169
|
+
worldY: 32,
|
|
170
|
+
width: 16,
|
|
171
|
+
height: 16,
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|