@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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Direction, RpgActionInput, RpgActionName } from '@rpgjs/common';
|
|
2
|
+
export type KeyboardActionDataResolver<TClient = any, TSprite = any> = (client: TClient, sprite: TSprite) => any;
|
|
3
|
+
export interface KeyboardActionConfig<TClient = any, TSprite = any> {
|
|
4
|
+
bind: any;
|
|
5
|
+
action?: RpgActionName;
|
|
6
|
+
data?: any | KeyboardActionDataResolver<TClient, TSprite>;
|
|
7
|
+
}
|
|
8
|
+
export declare function normalizeActionInput(action: RpgActionName, data?: any): RpgActionInput;
|
|
9
|
+
export declare function normalizeActionInput(action: RpgActionInput): RpgActionInput;
|
|
10
|
+
export declare function isKeyboardActionConfig(value: any): value is KeyboardActionConfig;
|
|
11
|
+
export declare function getKeyboardControlBind(control: any): any;
|
|
12
|
+
export declare function keyboardEventMatchesBind(event: KeyboardEvent, bind: any): boolean;
|
|
13
|
+
export declare function resolveKeyboardActionInput(control: any, client: any, sprite: any, defaultAction?: RpgActionName): RpgActionInput;
|
|
14
|
+
export declare function resolveKeyboardDirectionInput(event: KeyboardEvent, keyboardControls: any): Direction | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Direction } from "@rpgjs/common";
|
|
2
|
+
//#region src/services/actionInput.ts
|
|
3
|
+
function normalizeActionInput(action, data) {
|
|
4
|
+
if (typeof action === "object") return action;
|
|
5
|
+
return data === void 0 ? { action } : {
|
|
6
|
+
action,
|
|
7
|
+
data
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function isKeyboardActionConfig(value) {
|
|
11
|
+
return value !== null && typeof value === "object" && Object.prototype.hasOwnProperty.call(value, "bind");
|
|
12
|
+
}
|
|
13
|
+
function getKeyboardControlBind(control) {
|
|
14
|
+
return isKeyboardActionConfig(control) ? control.bind : control;
|
|
15
|
+
}
|
|
16
|
+
var KEY_CODE_NAMES = {
|
|
17
|
+
32: "space",
|
|
18
|
+
27: "escape",
|
|
19
|
+
37: "left",
|
|
20
|
+
38: "up",
|
|
21
|
+
39: "right",
|
|
22
|
+
40: "down"
|
|
23
|
+
};
|
|
24
|
+
var normalizeKeyboardName = (value) => {
|
|
25
|
+
if (typeof value !== "string") return void 0;
|
|
26
|
+
const normalized = value.toLowerCase();
|
|
27
|
+
if (normalized === " " || normalized === "spacebar" || normalized === "space") return "space";
|
|
28
|
+
if (normalized.startsWith("arrow")) return normalized.slice(5);
|
|
29
|
+
return normalized;
|
|
30
|
+
};
|
|
31
|
+
function keyboardEventMatchesBind(event, bind) {
|
|
32
|
+
if (Array.isArray(bind)) return bind.some((item) => keyboardEventMatchesBind(event, item));
|
|
33
|
+
if (typeof bind === "number") return event.keyCode === bind;
|
|
34
|
+
const expected = normalizeKeyboardName(bind);
|
|
35
|
+
if (!expected) return false;
|
|
36
|
+
return normalizeKeyboardName(event.key) === expected || normalizeKeyboardName(event.code) === expected || KEY_CODE_NAMES[event.keyCode] === expected;
|
|
37
|
+
}
|
|
38
|
+
function resolveKeyboardActionInput(control, client, sprite, defaultAction = "action") {
|
|
39
|
+
if (!isKeyboardActionConfig(control)) return { action: defaultAction };
|
|
40
|
+
const action = control.action ?? defaultAction;
|
|
41
|
+
const data = typeof control.data === "function" ? control.data(client, sprite) : control.data;
|
|
42
|
+
return data === void 0 ? { action } : {
|
|
43
|
+
action,
|
|
44
|
+
data
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function resolveKeyboardDirectionInput(event, keyboardControls) {
|
|
48
|
+
const directions = [
|
|
49
|
+
[keyboardControls?.up, Direction.Up],
|
|
50
|
+
[keyboardControls?.down, Direction.Down],
|
|
51
|
+
[keyboardControls?.left, Direction.Left],
|
|
52
|
+
[keyboardControls?.right, Direction.Right]
|
|
53
|
+
];
|
|
54
|
+
for (const [control, direction] of directions) if (keyboardEventMatchesBind(event, getKeyboardControlBind(control))) return direction;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { getKeyboardControlBind, isKeyboardActionConfig, keyboardEventMatchesBind, normalizeActionInput, resolveKeyboardActionInput, resolveKeyboardDirectionInput };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=actionInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actionInput.js","names":[],"sources":["../../src/services/actionInput.ts"],"sourcesContent":["import { Direction, type RpgActionInput, type RpgActionName } from \"@rpgjs/common\";\n\nexport type KeyboardActionDataResolver<TClient = any, TSprite = any> = (\n client: TClient,\n sprite: TSprite,\n) => any;\n\nexport interface KeyboardActionConfig<TClient = any, TSprite = any> {\n bind: any;\n action?: RpgActionName;\n data?: any | KeyboardActionDataResolver<TClient, TSprite>;\n}\n\nexport function normalizeActionInput(action: RpgActionName, data?: any): RpgActionInput;\nexport function normalizeActionInput(action: RpgActionInput): RpgActionInput;\nexport function normalizeActionInput(action: RpgActionName | RpgActionInput, data?: any): RpgActionInput {\n if (typeof action === \"object\") {\n return action;\n }\n return data === undefined\n ? { action }\n : { action, data };\n}\n\nexport function isKeyboardActionConfig(value: any): value is KeyboardActionConfig {\n return value !== null\n && typeof value === \"object\"\n && Object.prototype.hasOwnProperty.call(value, \"bind\");\n}\n\nexport function getKeyboardControlBind(control: any): any {\n return isKeyboardActionConfig(control) ? control.bind : control;\n}\n\nconst KEY_CODE_NAMES: Record<number, string> = {\n 32: \"space\",\n 27: \"escape\",\n 37: \"left\",\n 38: \"up\",\n 39: \"right\",\n 40: \"down\",\n};\n\nconst normalizeKeyboardName = (value: unknown): string | undefined => {\n if (typeof value !== \"string\") return undefined;\n const normalized = value.toLowerCase();\n if (\n normalized === \" \" ||\n normalized === \"spacebar\" ||\n normalized === \"space\"\n ) {\n return \"space\";\n }\n if (normalized.startsWith(\"arrow\")) {\n return normalized.slice(\"arrow\".length);\n }\n return normalized;\n};\n\nexport function keyboardEventMatchesBind(\n event: KeyboardEvent,\n bind: any\n): boolean {\n if (Array.isArray(bind)) {\n return bind.some(item => keyboardEventMatchesBind(event, item));\n }\n\n if (typeof bind === \"number\") {\n return event.keyCode === bind;\n }\n\n const expected = normalizeKeyboardName(bind);\n if (!expected) return false;\n\n return (\n normalizeKeyboardName(event.key) === expected ||\n normalizeKeyboardName(event.code) === expected ||\n KEY_CODE_NAMES[event.keyCode] === expected\n );\n}\n\nexport function resolveKeyboardActionInput(\n control: any,\n client: any,\n sprite: any,\n defaultAction: RpgActionName = \"action\",\n): RpgActionInput {\n if (!isKeyboardActionConfig(control)) {\n return { action: defaultAction };\n }\n\n const action = control.action ?? defaultAction;\n const data = typeof control.data === \"function\"\n ? control.data(client, sprite)\n : control.data;\n\n return data === undefined\n ? { action }\n : { action, data };\n}\n\nexport function resolveKeyboardDirectionInput(\n event: KeyboardEvent,\n keyboardControls: any\n): Direction | undefined {\n const directions: Array<[any, Direction]> = [\n [keyboardControls?.up, Direction.Up],\n [keyboardControls?.down, Direction.Down],\n [keyboardControls?.left, Direction.Left],\n [keyboardControls?.right, Direction.Right],\n ];\n\n for (const [control, direction] of directions) {\n if (keyboardEventMatchesBind(event, getKeyboardControlBind(control))) {\n return direction;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;AAeA,SAAgB,qBAAqB,QAAwC,MAA4B;CACvG,IAAI,OAAO,WAAW,UACpB,OAAO;CAET,OAAO,SAAS,KAAA,IACZ,EAAE,OAAO,IACT;EAAE;EAAQ;CAAK;AACrB;AAEA,SAAgB,uBAAuB,OAA2C;CAChF,OAAO,UAAU,QACZ,OAAO,UAAU,YACjB,OAAO,UAAU,eAAe,KAAK,OAAO,MAAM;AACzD;AAEA,SAAgB,uBAAuB,SAAmB;CACxD,OAAO,uBAAuB,OAAO,IAAI,QAAQ,OAAO;AAC1D;AAEA,IAAM,iBAAyC;CAC7C,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,IAAM,yBAAyB,UAAuC;CACpE,IAAI,OAAO,UAAU,UAAU,OAAO,KAAA;CACtC,MAAM,aAAa,MAAM,YAAY;CACrC,IACE,eAAe,OACf,eAAe,cACf,eAAe,SAEf,OAAO;CAET,IAAI,WAAW,WAAW,OAAO,GAC/B,OAAO,WAAW,MAAM,CAAc;CAExC,OAAO;AACT;AAEA,SAAgB,yBACd,OACA,MACS;CACT,IAAI,MAAM,QAAQ,IAAI,GACpB,OAAO,KAAK,MAAK,SAAQ,yBAAyB,OAAO,IAAI,CAAC;CAGhE,IAAI,OAAO,SAAS,UAClB,OAAO,MAAM,YAAY;CAG3B,MAAM,WAAW,sBAAsB,IAAI;CAC3C,IAAI,CAAC,UAAU,OAAO;CAEtB,OACE,sBAAsB,MAAM,GAAG,MAAM,YACrC,sBAAsB,MAAM,IAAI,MAAM,YACtC,eAAe,MAAM,aAAa;AAEtC;AAEA,SAAgB,2BACd,SACA,QACA,QACA,gBAA+B,UACf;CAChB,IAAI,CAAC,uBAAuB,OAAO,GACjC,OAAO,EAAE,QAAQ,cAAc;CAGjC,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,OAAO,OAAO,QAAQ,SAAS,aACjC,QAAQ,KAAK,QAAQ,MAAM,IAC3B,QAAQ;CAEZ,OAAO,SAAS,KAAA,IACZ,EAAE,OAAO,IACT;EAAE;EAAQ;CAAK;AACrB;AAEA,SAAgB,8BACd,OACA,kBACuB;CACvB,MAAM,aAAsC;EAC1C,CAAC,kBAAkB,IAAI,UAAU,EAAE;EACnC,CAAC,kBAAkB,MAAM,UAAU,IAAI;EACvC,CAAC,kBAAkB,MAAM,UAAU,IAAI;EACvC,CAAC,kBAAkB,OAAO,UAAU,KAAK;CAC3C;CAEA,KAAK,MAAM,CAAC,SAAS,cAAc,YACjC,IAAI,yBAAyB,OAAO,uBAAuB,OAAO,CAAC,GACjE,OAAO;AAKb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { RpgActionInput, RpgActionName } from '@rpgjs/common';
|
|
2
|
+
import { RpgClientEngine } from '../RpgClientEngine';
|
|
3
|
+
export type RpgInteractionEventName = "pointerenter" | "pointerleave" | "pointerover" | "pointerout" | "pointerdown" | "pointerup" | "pointermove" | "click" | "dragstart" | "dragmove" | "drop" | "cancel";
|
|
4
|
+
export type RpgInteractionPosition = {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
};
|
|
8
|
+
export type RpgInteractionBounds = {
|
|
9
|
+
left: number;
|
|
10
|
+
top: number;
|
|
11
|
+
right: number;
|
|
12
|
+
bottom: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
centerX: number;
|
|
16
|
+
centerY: number;
|
|
17
|
+
contains(point: RpgInteractionPosition | null | undefined): boolean;
|
|
18
|
+
};
|
|
19
|
+
export type RpgInteractionBoundsSet = {
|
|
20
|
+
bounds?: RpgInteractionBounds;
|
|
21
|
+
hitbox?: RpgInteractionBounds;
|
|
22
|
+
graphic?: RpgInteractionBounds;
|
|
23
|
+
[key: string]: RpgInteractionBounds | undefined;
|
|
24
|
+
};
|
|
25
|
+
export type RpgInteractionTile = {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
worldX: number;
|
|
29
|
+
worldY: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
33
|
+
export type RpgInteractionState = {
|
|
34
|
+
hovered: boolean;
|
|
35
|
+
pressed: boolean;
|
|
36
|
+
selected: boolean;
|
|
37
|
+
dragging: boolean;
|
|
38
|
+
data: Record<string, any>;
|
|
39
|
+
overlays: Record<string, RpgInteractionOverlay>;
|
|
40
|
+
};
|
|
41
|
+
export type RpgInteractionOverlay = {
|
|
42
|
+
component: any;
|
|
43
|
+
props?: Record<string, any>;
|
|
44
|
+
};
|
|
45
|
+
export type RpgInteractionMatcher = string | ((ctx: RpgInteractionMatcherContext) => boolean);
|
|
46
|
+
export type RpgInteractionMatcherContext = {
|
|
47
|
+
client: RpgClientEngine;
|
|
48
|
+
target: any;
|
|
49
|
+
sprite: any;
|
|
50
|
+
};
|
|
51
|
+
export type RpgInteractionHandler = (ctx: RpgInteractionContext) => void;
|
|
52
|
+
export type RpgInteractionBehavior = {
|
|
53
|
+
component?: any;
|
|
54
|
+
props?: Record<string, any> | ((ctx: RpgInteractionContext) => Record<string, any>);
|
|
55
|
+
dependencies?: any[] | ((ctx: RpgInteractionContext) => any[]);
|
|
56
|
+
cursor?: string | ((ctx: RpgInteractionContext) => string | undefined);
|
|
57
|
+
hitTest?: (ctx: RpgInteractionContext) => boolean;
|
|
58
|
+
pointerenter?: RpgInteractionHandler;
|
|
59
|
+
pointerleave?: RpgInteractionHandler;
|
|
60
|
+
pointerover?: RpgInteractionHandler;
|
|
61
|
+
pointerout?: RpgInteractionHandler;
|
|
62
|
+
pointerdown?: RpgInteractionHandler;
|
|
63
|
+
pointerup?: RpgInteractionHandler;
|
|
64
|
+
pointermove?: RpgInteractionHandler;
|
|
65
|
+
click?: RpgInteractionHandler;
|
|
66
|
+
dragstart?: RpgInteractionHandler;
|
|
67
|
+
dragmove?: RpgInteractionHandler;
|
|
68
|
+
drop?: RpgInteractionHandler;
|
|
69
|
+
cancel?: RpgInteractionHandler;
|
|
70
|
+
};
|
|
71
|
+
export type RpgInteractionComponentEntry = {
|
|
72
|
+
component: any;
|
|
73
|
+
props: Record<string, any>;
|
|
74
|
+
dependencies: any[];
|
|
75
|
+
};
|
|
76
|
+
export type RpgInteractionContext = {
|
|
77
|
+
client: RpgClientEngine;
|
|
78
|
+
target: any;
|
|
79
|
+
sprite: any;
|
|
80
|
+
event?: any;
|
|
81
|
+
behavior: RpgInteractionBehavior;
|
|
82
|
+
behaviorId: string;
|
|
83
|
+
pointer: {
|
|
84
|
+
screen(): RpgInteractionPosition | null;
|
|
85
|
+
world(): RpgInteractionPosition | null;
|
|
86
|
+
tile(): RpgInteractionTile | null;
|
|
87
|
+
};
|
|
88
|
+
bounds(kind?: string): RpgInteractionBounds;
|
|
89
|
+
state: {
|
|
90
|
+
value(): RpgInteractionState;
|
|
91
|
+
get<T = any>(key: string): T | undefined;
|
|
92
|
+
set(key: string, value: any): void;
|
|
93
|
+
patch(patch: Partial<Omit<RpgInteractionState, "data" | "overlays">>): void;
|
|
94
|
+
};
|
|
95
|
+
overlay: {
|
|
96
|
+
render(component: any, props?: Record<string, any>): void;
|
|
97
|
+
update(props?: Record<string, any>): void;
|
|
98
|
+
clear(): void;
|
|
99
|
+
};
|
|
100
|
+
select(selected?: boolean): void;
|
|
101
|
+
action(action: RpgActionName, data?: any): void;
|
|
102
|
+
action(input: RpgActionInput): void;
|
|
103
|
+
cancel(): void;
|
|
104
|
+
};
|
|
105
|
+
type InteractionEventInput = {
|
|
106
|
+
event?: any;
|
|
107
|
+
bounds?: RpgInteractionBoundsSet;
|
|
108
|
+
};
|
|
109
|
+
export declare class RpgClientInteractions {
|
|
110
|
+
private client;
|
|
111
|
+
private registrations;
|
|
112
|
+
private states;
|
|
113
|
+
private activeDrag?;
|
|
114
|
+
private nextId;
|
|
115
|
+
constructor(client: RpgClientEngine);
|
|
116
|
+
use(matcher: RpgInteractionMatcher, behavior: RpgInteractionBehavior | any): () => void;
|
|
117
|
+
getState(sprite: any): RpgInteractionState;
|
|
118
|
+
getRenderedComponents(sprite: any, bounds?: RpgInteractionBoundsSet): RpgInteractionComponentEntry[];
|
|
119
|
+
cursorFor(sprite: any, bounds?: RpgInteractionBoundsSet): string | undefined;
|
|
120
|
+
handle(sprite: any, type: RpgInteractionEventName, input?: InteractionEventInput): void;
|
|
121
|
+
handlePointerMove(event?: any): void;
|
|
122
|
+
handlePointerUp(event?: any): void;
|
|
123
|
+
cancelDrag(event?: any): void;
|
|
124
|
+
private getMatches;
|
|
125
|
+
private matches;
|
|
126
|
+
private createContext;
|
|
127
|
+
private callHandler;
|
|
128
|
+
private passesHitTest;
|
|
129
|
+
private isDraggable;
|
|
130
|
+
private defaultComponentProps;
|
|
131
|
+
private resolveProps;
|
|
132
|
+
private resolveDependencies;
|
|
133
|
+
private getSpriteId;
|
|
134
|
+
private patchState;
|
|
135
|
+
private patchStateData;
|
|
136
|
+
private patchOverlay;
|
|
137
|
+
private updateOverlay;
|
|
138
|
+
private clearOverlay;
|
|
139
|
+
private getPointerTile;
|
|
140
|
+
}
|
|
141
|
+
export declare function hoverPopover(component: any, props?: Record<string, any>): RpgInteractionBehavior;
|
|
142
|
+
export declare function selectable(options?: {
|
|
143
|
+
cursor?: string;
|
|
144
|
+
onSelect?: RpgInteractionHandler;
|
|
145
|
+
}): RpgInteractionBehavior;
|
|
146
|
+
export declare function draggable(options?: {
|
|
147
|
+
cursor?: string;
|
|
148
|
+
start?: RpgInteractionHandler;
|
|
149
|
+
move?: RpgInteractionHandler;
|
|
150
|
+
drop?: RpgInteractionHandler;
|
|
151
|
+
cancel?: RpgInteractionHandler;
|
|
152
|
+
}): RpgInteractionBehavior;
|
|
153
|
+
export declare function dragToTile(options: {
|
|
154
|
+
action?: RpgActionName;
|
|
155
|
+
data?: (ctx: RpgInteractionContext) => any;
|
|
156
|
+
onDrop?: RpgInteractionHandler;
|
|
157
|
+
cursor?: string;
|
|
158
|
+
}): RpgInteractionBehavior;
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import { signal } from "canvasengine";
|
|
2
|
+
//#region src/services/interactions.ts
|
|
3
|
+
var DEFAULT_STATE = {
|
|
4
|
+
hovered: false,
|
|
5
|
+
pressed: false,
|
|
6
|
+
selected: false,
|
|
7
|
+
dragging: false,
|
|
8
|
+
data: {},
|
|
9
|
+
overlays: {}
|
|
10
|
+
};
|
|
11
|
+
function readValue(value) {
|
|
12
|
+
return typeof value === "function" ? value() : value;
|
|
13
|
+
}
|
|
14
|
+
function createBounds(value) {
|
|
15
|
+
const left = Number(value?.left ?? value?.x ?? 0);
|
|
16
|
+
const top = Number(value?.top ?? value?.y ?? 0);
|
|
17
|
+
const width = Number(value?.width ?? value?.w ?? 0);
|
|
18
|
+
const height = Number(value?.height ?? value?.h ?? 0);
|
|
19
|
+
const right = Number(value?.right ?? left + width);
|
|
20
|
+
const bottom = Number(value?.bottom ?? top + height);
|
|
21
|
+
const resolvedWidth = Number.isFinite(width) && width > 0 ? width : Math.max(0, right - left);
|
|
22
|
+
const resolvedHeight = Number.isFinite(height) && height > 0 ? height : Math.max(0, bottom - top);
|
|
23
|
+
return {
|
|
24
|
+
left,
|
|
25
|
+
top,
|
|
26
|
+
right,
|
|
27
|
+
bottom,
|
|
28
|
+
width: resolvedWidth,
|
|
29
|
+
height: resolvedHeight,
|
|
30
|
+
centerX: Number(value?.centerX ?? left + resolvedWidth / 2),
|
|
31
|
+
centerY: Number(value?.centerY ?? top + resolvedHeight / 2),
|
|
32
|
+
contains(point) {
|
|
33
|
+
if (!point) return false;
|
|
34
|
+
return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function normalizeBounds(bounds) {
|
|
39
|
+
if (!bounds) return {};
|
|
40
|
+
return Object.entries(bounds).reduce((next, [key, value]) => {
|
|
41
|
+
if (value) next[key] = createBounds(value);
|
|
42
|
+
return next;
|
|
43
|
+
}, {});
|
|
44
|
+
}
|
|
45
|
+
function readNumber(value, fallback = 0) {
|
|
46
|
+
const resolved = readValue(value);
|
|
47
|
+
const number = Number(resolved);
|
|
48
|
+
return Number.isFinite(number) ? number : fallback;
|
|
49
|
+
}
|
|
50
|
+
function offsetBounds(bounds, x, y) {
|
|
51
|
+
return createBounds({
|
|
52
|
+
left: bounds.left + x,
|
|
53
|
+
top: bounds.top + y,
|
|
54
|
+
right: bounds.right + x,
|
|
55
|
+
bottom: bounds.bottom + y,
|
|
56
|
+
width: bounds.width,
|
|
57
|
+
height: bounds.height,
|
|
58
|
+
centerX: bounds.centerX + x,
|
|
59
|
+
centerY: bounds.centerY + y
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function toWorldBounds(sprite, bounds) {
|
|
63
|
+
const x = readNumber(sprite?.x);
|
|
64
|
+
const y = readNumber(sprite?.y);
|
|
65
|
+
return Object.entries(bounds).reduce((next, [key, value]) => {
|
|
66
|
+
if (value) next[key] = offsetBounds(value, x, y);
|
|
67
|
+
return next;
|
|
68
|
+
}, {});
|
|
69
|
+
}
|
|
70
|
+
function normalizeBehavior(behavior) {
|
|
71
|
+
if (typeof behavior === "function") return { component: behavior };
|
|
72
|
+
return behavior ?? {};
|
|
73
|
+
}
|
|
74
|
+
var RpgClientInteractions = class {
|
|
75
|
+
constructor(client) {
|
|
76
|
+
this.client = client;
|
|
77
|
+
this.registrations = signal([]);
|
|
78
|
+
this.states = signal({});
|
|
79
|
+
this.nextId = 0;
|
|
80
|
+
}
|
|
81
|
+
use(matcher, behavior) {
|
|
82
|
+
const registration = {
|
|
83
|
+
id: `interaction:${++this.nextId}`,
|
|
84
|
+
matcher,
|
|
85
|
+
behavior: normalizeBehavior(behavior)
|
|
86
|
+
};
|
|
87
|
+
this.registrations.update((registrations) => [...registrations, registration]);
|
|
88
|
+
return () => {
|
|
89
|
+
this.registrations.update((registrations) => registrations.filter((entry) => entry.id !== registration.id));
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
getState(sprite) {
|
|
93
|
+
const id = this.getSpriteId(sprite);
|
|
94
|
+
return {
|
|
95
|
+
...DEFAULT_STATE,
|
|
96
|
+
...id ? this.states()[id] : void 0,
|
|
97
|
+
data: id ? { ...this.states()[id]?.data ?? {} } : {},
|
|
98
|
+
overlays: id ? { ...this.states()[id]?.overlays ?? {} } : {}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
getRenderedComponents(sprite, bounds) {
|
|
102
|
+
const normalizedBounds = normalizeBounds(bounds);
|
|
103
|
+
const matched = this.getMatches(sprite);
|
|
104
|
+
const state = this.getState(sprite);
|
|
105
|
+
const entries = [];
|
|
106
|
+
matched.forEach((registration) => {
|
|
107
|
+
if (!registration.behavior.component) return;
|
|
108
|
+
const ctx = this.createContext(sprite, registration, { bounds: normalizedBounds });
|
|
109
|
+
entries.push({
|
|
110
|
+
component: registration.behavior.component,
|
|
111
|
+
props: {
|
|
112
|
+
...this.defaultComponentProps(sprite, state, normalizedBounds),
|
|
113
|
+
...this.resolveProps(registration.behavior.props, ctx)
|
|
114
|
+
},
|
|
115
|
+
dependencies: this.resolveDependencies(registration.behavior.dependencies, ctx)
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
Object.entries(state.overlays).forEach(([id, overlay]) => {
|
|
119
|
+
entries.push({
|
|
120
|
+
component: overlay.component,
|
|
121
|
+
props: {
|
|
122
|
+
...this.defaultComponentProps(sprite, state, normalizedBounds),
|
|
123
|
+
...overlay.props ?? {},
|
|
124
|
+
overlayId: id
|
|
125
|
+
},
|
|
126
|
+
dependencies: []
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
return entries;
|
|
130
|
+
}
|
|
131
|
+
cursorFor(sprite, bounds) {
|
|
132
|
+
this.states();
|
|
133
|
+
for (const registration of this.getMatches(sprite)) {
|
|
134
|
+
const cursor = registration.behavior.cursor;
|
|
135
|
+
if (!cursor) continue;
|
|
136
|
+
const ctx = this.createContext(sprite, registration, { bounds: normalizeBounds(bounds) });
|
|
137
|
+
if (!this.passesHitTest(registration.behavior, ctx, "pointermove")) continue;
|
|
138
|
+
const resolved = typeof cursor === "function" ? cursor(ctx) : cursor;
|
|
139
|
+
if (resolved) return resolved;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
handle(sprite, type, input = {}) {
|
|
143
|
+
const matches = this.getMatches(sprite);
|
|
144
|
+
const bounds = normalizeBounds(input.bounds);
|
|
145
|
+
const entries = matches.map((registration) => ({
|
|
146
|
+
registration,
|
|
147
|
+
ctx: this.createContext(sprite, registration, {
|
|
148
|
+
event: input.event,
|
|
149
|
+
bounds
|
|
150
|
+
})
|
|
151
|
+
})).filter(({ registration, ctx }) => this.passesHitTest(registration.behavior, ctx, type));
|
|
152
|
+
if (type === "pointerover" || type === "pointerenter") {
|
|
153
|
+
if (entries.length > 0) this.patchState(sprite, { hovered: true });
|
|
154
|
+
}
|
|
155
|
+
if (type === "pointerout" || type === "pointerleave") {
|
|
156
|
+
if (matches.length > 0) this.patchState(sprite, {
|
|
157
|
+
hovered: false,
|
|
158
|
+
pressed: false
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (type === "pointerdown") {
|
|
162
|
+
if (entries.length > 0) this.patchState(sprite, { pressed: true });
|
|
163
|
+
}
|
|
164
|
+
if (type === "pointermove" && matches.length > 0) this.patchState(sprite, { hovered: entries.length > 0 });
|
|
165
|
+
if (type === "pointerup") {
|
|
166
|
+
if (matches.length > 0) this.patchState(sprite, { pressed: false });
|
|
167
|
+
}
|
|
168
|
+
entries.forEach(({ registration, ctx }) => {
|
|
169
|
+
this.callHandler(registration.behavior, type, ctx);
|
|
170
|
+
if (type === "pointerdown" && this.isDraggable(registration.behavior)) {
|
|
171
|
+
this.activeDrag = {
|
|
172
|
+
sprite,
|
|
173
|
+
behavior: registration.behavior,
|
|
174
|
+
behaviorId: registration.id,
|
|
175
|
+
bounds,
|
|
176
|
+
cancelled: false
|
|
177
|
+
};
|
|
178
|
+
this.patchState(sprite, { dragging: true });
|
|
179
|
+
this.callHandler(registration.behavior, "dragstart", ctx);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
handlePointerMove(event) {
|
|
184
|
+
if (!this.activeDrag) return;
|
|
185
|
+
const drag = this.activeDrag;
|
|
186
|
+
const registration = {
|
|
187
|
+
id: drag.behaviorId,
|
|
188
|
+
matcher: "*",
|
|
189
|
+
behavior: drag.behavior
|
|
190
|
+
};
|
|
191
|
+
const ctx = this.createContext(drag.sprite, registration, {
|
|
192
|
+
event,
|
|
193
|
+
bounds: drag.bounds
|
|
194
|
+
});
|
|
195
|
+
this.callHandler(drag.behavior, "dragmove", ctx);
|
|
196
|
+
}
|
|
197
|
+
handlePointerUp(event) {
|
|
198
|
+
if (!this.activeDrag) return;
|
|
199
|
+
const drag = this.activeDrag;
|
|
200
|
+
this.activeDrag = void 0;
|
|
201
|
+
this.patchState(drag.sprite, {
|
|
202
|
+
dragging: false,
|
|
203
|
+
pressed: false
|
|
204
|
+
});
|
|
205
|
+
const registration = {
|
|
206
|
+
id: drag.behaviorId,
|
|
207
|
+
matcher: "*",
|
|
208
|
+
behavior: drag.behavior
|
|
209
|
+
};
|
|
210
|
+
const ctx = this.createContext(drag.sprite, registration, {
|
|
211
|
+
event,
|
|
212
|
+
bounds: drag.bounds
|
|
213
|
+
});
|
|
214
|
+
this.callHandler(drag.behavior, drag.cancelled ? "cancel" : "drop", ctx);
|
|
215
|
+
}
|
|
216
|
+
cancelDrag(event) {
|
|
217
|
+
if (!this.activeDrag) return;
|
|
218
|
+
this.activeDrag.cancelled = true;
|
|
219
|
+
this.handlePointerUp(event);
|
|
220
|
+
}
|
|
221
|
+
getMatches(sprite) {
|
|
222
|
+
return this.registrations().filter((registration) => this.matches(registration.matcher, sprite));
|
|
223
|
+
}
|
|
224
|
+
matches(matcher, sprite) {
|
|
225
|
+
if (typeof matcher === "function") return !!matcher({
|
|
226
|
+
client: this.client,
|
|
227
|
+
target: sprite,
|
|
228
|
+
sprite
|
|
229
|
+
});
|
|
230
|
+
if (matcher === "*") return true;
|
|
231
|
+
return [
|
|
232
|
+
readValue(sprite?.id),
|
|
233
|
+
readValue(sprite?.name),
|
|
234
|
+
readValue(sprite?._name),
|
|
235
|
+
readValue(sprite?.type),
|
|
236
|
+
readValue(sprite?._type),
|
|
237
|
+
sprite?.constructor?.name
|
|
238
|
+
].filter(Boolean).includes(matcher);
|
|
239
|
+
}
|
|
240
|
+
createContext(sprite, registration, input = {}) {
|
|
241
|
+
const bounds = toWorldBounds(sprite, normalizeBounds(input.bounds));
|
|
242
|
+
return {
|
|
243
|
+
client: this.client,
|
|
244
|
+
target: sprite,
|
|
245
|
+
sprite,
|
|
246
|
+
event: input.event,
|
|
247
|
+
behavior: registration.behavior,
|
|
248
|
+
behaviorId: registration.id,
|
|
249
|
+
pointer: {
|
|
250
|
+
screen: () => this.client.pointer.screen(),
|
|
251
|
+
world: () => this.client.pointer.world(),
|
|
252
|
+
tile: () => this.getPointerTile()
|
|
253
|
+
},
|
|
254
|
+
bounds: (kind = "bounds") => bounds[kind] ?? bounds.graphic ?? bounds.hitbox ?? bounds.bounds ?? createBounds({}),
|
|
255
|
+
state: {
|
|
256
|
+
value: () => this.getState(sprite),
|
|
257
|
+
get: (key) => this.getState(sprite).data[key],
|
|
258
|
+
set: (key, value) => this.patchStateData(sprite, { [key]: value }),
|
|
259
|
+
patch: (patch) => this.patchState(sprite, patch)
|
|
260
|
+
},
|
|
261
|
+
overlay: {
|
|
262
|
+
render: (component, props) => this.patchOverlay(sprite, registration.id, {
|
|
263
|
+
component,
|
|
264
|
+
props
|
|
265
|
+
}),
|
|
266
|
+
update: (props) => this.updateOverlay(sprite, registration.id, props),
|
|
267
|
+
clear: () => this.clearOverlay(sprite, registration.id)
|
|
268
|
+
},
|
|
269
|
+
select: (selected = true) => this.patchState(sprite, { selected }),
|
|
270
|
+
action: (action, data) => this.client.processAction(action, data),
|
|
271
|
+
cancel: () => {
|
|
272
|
+
const activeDrag = this.activeDrag;
|
|
273
|
+
if (activeDrag && activeDrag.sprite === sprite) activeDrag.cancelled = true;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
callHandler(behavior, type, ctx) {
|
|
278
|
+
const handler = behavior[type];
|
|
279
|
+
handler?.(ctx);
|
|
280
|
+
if (type === "pointerover") behavior.pointerenter?.(ctx);
|
|
281
|
+
if (type === "pointerout") behavior.pointerleave?.(ctx);
|
|
282
|
+
}
|
|
283
|
+
passesHitTest(behavior, ctx, type) {
|
|
284
|
+
if (!behavior.hitTest) return true;
|
|
285
|
+
if (type === "pointerout" || type === "pointerleave" || type === "cancel" || type === "drop") return true;
|
|
286
|
+
return behavior.hitTest(ctx);
|
|
287
|
+
}
|
|
288
|
+
isDraggable(behavior) {
|
|
289
|
+
return !!(behavior.dragstart || behavior.dragmove || behavior.drop || behavior.cancel);
|
|
290
|
+
}
|
|
291
|
+
defaultComponentProps(sprite, state, bounds) {
|
|
292
|
+
return {
|
|
293
|
+
target: sprite,
|
|
294
|
+
sprite,
|
|
295
|
+
state,
|
|
296
|
+
bounds: bounds.bounds ?? bounds.graphic ?? bounds.hitbox ?? createBounds({}),
|
|
297
|
+
hitboxBounds: bounds.hitbox,
|
|
298
|
+
graphicBounds: bounds.graphic,
|
|
299
|
+
pointer: this.client.pointer,
|
|
300
|
+
client: this.client
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
resolveProps(props, ctx) {
|
|
304
|
+
if (!props) return {};
|
|
305
|
+
return typeof props === "function" ? props(ctx) : props;
|
|
306
|
+
}
|
|
307
|
+
resolveDependencies(dependencies, ctx) {
|
|
308
|
+
if (!dependencies) return [];
|
|
309
|
+
return typeof dependencies === "function" ? dependencies(ctx) : dependencies;
|
|
310
|
+
}
|
|
311
|
+
getSpriteId(sprite) {
|
|
312
|
+
const id = readValue(sprite?.id);
|
|
313
|
+
return id == null ? void 0 : String(id);
|
|
314
|
+
}
|
|
315
|
+
patchState(sprite, patch) {
|
|
316
|
+
const id = this.getSpriteId(sprite);
|
|
317
|
+
if (!id) return;
|
|
318
|
+
this.states.update((states) => ({
|
|
319
|
+
...states,
|
|
320
|
+
[id]: {
|
|
321
|
+
...DEFAULT_STATE,
|
|
322
|
+
...states[id] ?? {},
|
|
323
|
+
...patch,
|
|
324
|
+
data: states[id]?.data ?? {},
|
|
325
|
+
overlays: states[id]?.overlays ?? {}
|
|
326
|
+
}
|
|
327
|
+
}));
|
|
328
|
+
}
|
|
329
|
+
patchStateData(sprite, patch) {
|
|
330
|
+
const id = this.getSpriteId(sprite);
|
|
331
|
+
if (!id) return;
|
|
332
|
+
const current = this.getState(sprite);
|
|
333
|
+
this.states.update((states) => ({
|
|
334
|
+
...states,
|
|
335
|
+
[id]: {
|
|
336
|
+
...current,
|
|
337
|
+
data: {
|
|
338
|
+
...current.data,
|
|
339
|
+
...patch
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}));
|
|
343
|
+
}
|
|
344
|
+
patchOverlay(sprite, id, overlay) {
|
|
345
|
+
const spriteId = this.getSpriteId(sprite);
|
|
346
|
+
if (!spriteId) return;
|
|
347
|
+
const current = this.getState(sprite);
|
|
348
|
+
this.states.update((states) => ({
|
|
349
|
+
...states,
|
|
350
|
+
[spriteId]: {
|
|
351
|
+
...current,
|
|
352
|
+
overlays: {
|
|
353
|
+
...current.overlays,
|
|
354
|
+
[id]: overlay
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}));
|
|
358
|
+
}
|
|
359
|
+
updateOverlay(sprite, id, props) {
|
|
360
|
+
const overlay = this.getState(sprite).overlays[id];
|
|
361
|
+
if (!overlay) return;
|
|
362
|
+
this.patchOverlay(sprite, id, {
|
|
363
|
+
...overlay,
|
|
364
|
+
props: {
|
|
365
|
+
...overlay.props ?? {},
|
|
366
|
+
...props ?? {}
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
clearOverlay(sprite, id) {
|
|
371
|
+
const spriteId = this.getSpriteId(sprite);
|
|
372
|
+
if (!spriteId) return;
|
|
373
|
+
const current = this.getState(sprite);
|
|
374
|
+
const { [id]: _removed, ...overlays } = current.overlays;
|
|
375
|
+
this.states.update((states) => ({
|
|
376
|
+
...states,
|
|
377
|
+
[spriteId]: {
|
|
378
|
+
...current,
|
|
379
|
+
overlays
|
|
380
|
+
}
|
|
381
|
+
}));
|
|
382
|
+
}
|
|
383
|
+
getPointerTile() {
|
|
384
|
+
const world = this.client.pointer.world();
|
|
385
|
+
if (!world) return null;
|
|
386
|
+
const map = this.client.sceneMap;
|
|
387
|
+
const width = Number(map?.tileWidth ?? 32);
|
|
388
|
+
const height = Number(map?.tileHeight ?? 32);
|
|
389
|
+
const tileX = Math.floor(world.x / width);
|
|
390
|
+
const tileY = Math.floor(world.y / height);
|
|
391
|
+
return {
|
|
392
|
+
x: tileX,
|
|
393
|
+
y: tileY,
|
|
394
|
+
worldX: tileX * width,
|
|
395
|
+
worldY: tileY * height,
|
|
396
|
+
width,
|
|
397
|
+
height
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
function hoverPopover(component, props) {
|
|
402
|
+
return {
|
|
403
|
+
component,
|
|
404
|
+
props,
|
|
405
|
+
cursor: "pointer"
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function selectable(options = {}) {
|
|
409
|
+
return {
|
|
410
|
+
cursor: options.cursor ?? "pointer",
|
|
411
|
+
click(ctx) {
|
|
412
|
+
ctx.select();
|
|
413
|
+
options.onSelect?.(ctx);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function draggable(options = {}) {
|
|
418
|
+
return {
|
|
419
|
+
cursor: options.cursor ?? "grab",
|
|
420
|
+
dragstart(ctx) {
|
|
421
|
+
ctx.state.patch({ dragging: true });
|
|
422
|
+
options.start?.(ctx);
|
|
423
|
+
},
|
|
424
|
+
dragmove: options.move,
|
|
425
|
+
drop(ctx) {
|
|
426
|
+
ctx.state.patch({
|
|
427
|
+
dragging: false,
|
|
428
|
+
pressed: false
|
|
429
|
+
});
|
|
430
|
+
options.drop?.(ctx);
|
|
431
|
+
},
|
|
432
|
+
cancel(ctx) {
|
|
433
|
+
ctx.state.patch({
|
|
434
|
+
dragging: false,
|
|
435
|
+
pressed: false
|
|
436
|
+
});
|
|
437
|
+
options.cancel?.(ctx);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function dragToTile(options) {
|
|
442
|
+
return draggable({
|
|
443
|
+
cursor: options.cursor,
|
|
444
|
+
drop(ctx) {
|
|
445
|
+
if (options.onDrop) {
|
|
446
|
+
options.onDrop(ctx);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (!options.action) return;
|
|
450
|
+
ctx.action(options.action, options.data ? options.data(ctx) : {
|
|
451
|
+
eventId: ctx.target.id,
|
|
452
|
+
position: ctx.pointer.tile()
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
//#endregion
|
|
458
|
+
export { RpgClientInteractions, dragToTile, draggable, hoverPopover, selectable };
|
|
459
|
+
|
|
460
|
+
//# sourceMappingURL=interactions.js.map
|