@rpgjs/client 5.0.0-beta.1 → 5.0.0-beta.11
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 +49 -0
- package/LICENSE +19 -0
- package/dist/Game/AnimationManager.d.ts +1 -1
- package/dist/Game/AnimationManager.js +18 -9
- package/dist/Game/AnimationManager.js.map +1 -1
- package/dist/Game/AnimationManager.spec.d.ts +1 -0
- package/dist/Game/Event.js.map +1 -1
- package/dist/Game/Map.d.ts +9 -1
- package/dist/Game/Map.js +63 -5
- package/dist/Game/Map.js.map +1 -1
- package/dist/Game/Object.d.ts +47 -15
- package/dist/Game/Object.js +82 -38
- package/dist/Game/Object.js.map +1 -1
- package/dist/Game/Player.js.map +1 -1
- package/dist/Game/ProjectileManager.d.ts +89 -0
- package/dist/Game/ProjectileManager.js +179 -0
- package/dist/Game/ProjectileManager.js.map +1 -0
- package/dist/Game/ProjectileManager.spec.d.ts +1 -0
- package/dist/Gui/Gui.d.ts +17 -4
- package/dist/Gui/Gui.js +78 -48
- 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 +110 -15
- package/dist/RpgClientEngine.d.ts +86 -10
- package/dist/RpgClientEngine.js +306 -49
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/Sound.js.map +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.130.0}/helpers/decorate.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.130.0}/helpers/decorateMetadata.js +1 -1
- package/dist/components/animations/animation.ce.js +4 -5
- package/dist/components/animations/animation.ce.js.map +1 -1
- package/dist/components/animations/hit.ce.js +19 -25
- package/dist/components/animations/hit.ce.js.map +1 -1
- package/dist/components/animations/index.js +4 -4
- package/dist/components/animations/index.js.map +1 -1
- package/dist/components/character.ce.js +422 -240
- package/dist/components/character.ce.js.map +1 -1
- package/dist/components/dynamics/bar.ce.js +97 -0
- package/dist/components/dynamics/bar.ce.js.map +1 -0
- package/dist/components/dynamics/image.ce.js +24 -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 +84 -0
- package/dist/components/dynamics/shape.ce.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +34 -56
- package/dist/components/dynamics/text.ce.js.map +1 -1
- package/dist/components/gui/box.ce.js +6 -8
- package/dist/components/gui/box.ce.js.map +1 -1
- package/dist/components/gui/dialogbox/index.ce.js +56 -62
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
- package/dist/components/gui/gameover.ce.js +42 -65
- package/dist/components/gui/gameover.ce.js.map +1 -1
- package/dist/components/gui/hud/hud.ce.js +21 -30
- package/dist/components/gui/hud/hud.ce.js.map +1 -1
- package/dist/components/gui/menu/equip-menu.ce.js +112 -165
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/exit-menu.ce.js +8 -6
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/items-menu.ce.js +52 -69
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/main-menu.ce.js +75 -92
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/options-menu.ce.js +5 -4
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
- package/dist/components/gui/menu/skills-menu.ce.js +12 -17
- 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 +5 -4
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
- package/dist/components/gui/notification/notification.ce.js +22 -24
- package/dist/components/gui/notification/notification.ce.js.map +1 -1
- package/dist/components/gui/save-load.ce.js +72 -249
- package/dist/components/gui/save-load.ce.js.map +1 -1
- package/dist/components/gui/shop/shop.ce.js +90 -127
- package/dist/components/gui/shop/shop.ce.js.map +1 -1
- package/dist/components/gui/title-screen.ce.js +45 -70
- 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/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 +189 -0
- package/dist/components/player-components.ce.js.map +1 -0
- package/dist/components/prebuilt/hp-bar.ce.js +42 -44
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
- package/dist/components/prebuilt/light-halo.ce.js +36 -59
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
- package/dist/components/scenes/canvas.ce.js +165 -21
- package/dist/components/scenes/canvas.ce.js.map +1 -1
- package/dist/components/scenes/draw-map.ce.js +25 -32
- package/dist/components/scenes/draw-map.ce.js.map +1 -1
- package/dist/components/scenes/event-layer.ce.js +9 -8
- 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/index.d.ts +4 -0
- package/dist/index.js +26 -21
- package/dist/module.js +15 -1
- package/dist/module.js.map +1 -1
- package/dist/node_modules/.pnpm/{@signe_di@2.9.0 → @signe_di@3.0.1}/node_modules/@signe/di/dist/index.js +7 -117
- package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js +239 -0
- package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js +13 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js +696 -0
- package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js +44 -0
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/node_modules/.pnpm/{@signe_sync@2.9.0 → @signe_sync@3.0.1}/node_modules/@signe/sync/dist/index.js +57 -141
- package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -1
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -1
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +27 -27
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -1
- 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.js.map +1 -1
- package/dist/services/actionInput.d.ts +12 -0
- package/dist/services/actionInput.js +27 -0
- package/dist/services/actionInput.js.map +1 -0
- package/dist/services/actionInput.spec.d.ts +1 -0
- package/dist/services/keyboardControls.js.map +1 -1
- package/dist/services/loadMap.d.ts +6 -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 +10 -4
- package/dist/services/mmorpg.js +56 -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.js +4 -3
- 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/readPropValue.d.ts +2 -0
- package/dist/utils/readPropValue.js +13 -0
- package/dist/utils/readPropValue.js.map +1 -0
- package/package.json +13 -14
- package/src/Game/AnimationManager.spec.ts +30 -0
- package/src/Game/AnimationManager.ts +22 -10
- package/src/Game/Map.ts +91 -2
- package/src/Game/Object.ts +148 -69
- package/src/Game/ProjectileManager.spec.ts +338 -0
- package/src/Game/ProjectileManager.ts +324 -0
- package/src/Gui/Gui.spec.ts +273 -0
- package/src/Gui/Gui.ts +105 -50
- package/src/Resource.ts +1 -2
- package/src/RpgClient.ts +125 -17
- package/src/RpgClientEngine.ts +457 -87
- package/src/components/character.ce +441 -32
- 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 +18 -8
- package/src/components/gui/gameover.ce +2 -1
- package/src/components/gui/menu/equip-menu.ce +2 -1
- package/src/components/gui/menu/exit-menu.ce +2 -1
- package/src/components/gui/menu/items-menu.ce +3 -2
- package/src/components/gui/menu/main-menu.ce +2 -1
- package/src/components/gui/save-load.ce +2 -1
- package/src/components/gui/shop/shop.ce +3 -2
- package/src/components/gui/title-screen.ce +2 -1
- package/src/components/index.ts +2 -1
- 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 +175 -8
- package/src/components/scenes/draw-map.ce +18 -17
- package/src/components/scenes/event-layer.ce +1 -2
- package/src/core/setup.ts +2 -2
- package/src/decorators/spritesheet.ts +8 -0
- package/src/index.ts +4 -0
- package/src/module.ts +18 -1
- package/src/services/actionInput.spec.ts +101 -0
- package/src/services/actionInput.ts +53 -0
- package/src/services/loadMap.ts +2 -0
- package/src/services/mmorpg-connection.spec.ts +99 -0
- package/src/services/mmorpg-connection.ts +69 -0
- package/src/services/mmorpg.ts +68 -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 +34 -0
- package/src/services/standalone.ts +3 -2
- package/src/utils/getEntityProp.spec.ts +96 -0
- package/src/utils/getEntityProp.ts +4 -3
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.js","names":[],"sources":["../../src/services/save.ts"],"sourcesContent":["import type { SaveSlotList, SaveSlotMeta } from \"@rpgjs/common\";\nimport { inject } from \"../core/inject\";\nimport { AbstractWebsocket, WebSocketToken } from \"./AbstractSocket\";\n\nexport const SaveClientToken = \"SaveClientToken\";\n\ntype SaveListResult = {\n requestId: string;\n slots: SaveSlotList;\n};\n\ntype SaveSaveResult = {\n requestId: string;\n index: number;\n slots: SaveSlotList;\n};\n\ntype SaveLoadResult = {\n requestId: string;\n index: number;\n ok: boolean;\n slot?: SaveSlotMeta;\n};\n\ntype SaveErrorResult = {\n requestId: string;\n message: string;\n};\n\ntype PendingRequest = {\n resolve: (value: any) => void;\n reject: (error: Error) => void;\n};\n\nexport class SaveClientService {\n private webSocket: AbstractWebsocket = inject(WebSocketToken);\n private pending: Map<string, PendingRequest> = new Map();\n private requestCounter = 0;\n\n initialize() {\n const saveListResult = (data: SaveListResult) => this.resolveRequest(data.requestId, data);\n const saveSaveResult = (data: SaveSaveResult) => this.resolveRequest(data.requestId, data);\n const saveLoadResult = (data: SaveLoadResult) => this.resolveRequest(data.requestId, data);\n const saveErrorResult = (data: SaveErrorResult) => this.rejectRequest(data.requestId, data.message);\n this.webSocket.off(\"save.list.result\", saveListResult);\n this.webSocket.off(\"save.save.result\", saveSaveResult);\n this.webSocket.off(\"save.load.result\", saveLoadResult);\n this.webSocket.off(\"save.error\", saveErrorResult);\n this.webSocket.on(\"save.list.result\", saveListResult);\n this.webSocket.on(\"save.save.result\", saveSaveResult);\n this.webSocket.on(\"save.load.result\", saveLoadResult);\n this.webSocket.on(\"save.error\", saveErrorResult);\n }\n\n listSlots(): Promise<SaveSlotList> {\n return this.request<SaveListResult>(\"save.list\", {}).then((result) => result.slots);\n }\n\n saveSlot(index: number, meta: SaveSlotMeta = {}): Promise<SaveSlotList> {\n return this.request<SaveSaveResult>(\"save.save\", { index, meta }).then((result) => result.slots);\n }\n\n loadSlot(index: number): Promise<boolean> {\n return this.request<SaveLoadResult>(\"save.load\", { index }).then((result) => result.ok);\n }\n\n private request<T>(event: string, payload: Record<string, any>): Promise<T> {\n return new Promise((resolve, reject) => {\n if (!this.webSocket) {\n this.initialize();\n }\n const requestId = this.nextRequestId();\n this.pending.set(requestId, { resolve, reject });\n this.webSocket?.emit(event, { requestId, ...payload });\n });\n }\n\n private resolveRequest(requestId: string, result: any) {\n const pending = this.pending.get(requestId);\n if (!pending) return;\n this.pending.delete(requestId);\n pending.resolve(result);\n }\n\n private rejectRequest(requestId: string, message: string) {\n const pending = this.pending.get(requestId);\n if (!pending) return;\n this.pending.delete(requestId);\n pending.reject(new Error(message));\n }\n\n private nextRequestId(): string {\n this.requestCounter += 1;\n return `${Date.now()}-${this.requestCounter}`;\n }\n}\n\nexport function provideSaveClient() {\n return {\n provide: SaveClientService,\n useClass: SaveClientService,\n };\n}\n"],"mappings":";;;AAIA,IAAa,kBAAkB;AA8B/B,IAAa,oBAAb,MAA+B;;mBACU,OAAO,
|
|
1
|
+
{"version":3,"file":"save.js","names":[],"sources":["../../src/services/save.ts"],"sourcesContent":["import type { SaveSlotList, SaveSlotMeta } from \"@rpgjs/common\";\nimport { inject } from \"../core/inject\";\nimport { AbstractWebsocket, WebSocketToken } from \"./AbstractSocket\";\n\nexport const SaveClientToken = \"SaveClientToken\";\n\ntype SaveListResult = {\n requestId: string;\n slots: SaveSlotList;\n};\n\ntype SaveSaveResult = {\n requestId: string;\n index: number;\n slots: SaveSlotList;\n};\n\ntype SaveLoadResult = {\n requestId: string;\n index: number;\n ok: boolean;\n slot?: SaveSlotMeta;\n};\n\ntype SaveErrorResult = {\n requestId: string;\n message: string;\n};\n\ntype PendingRequest = {\n resolve: (value: any) => void;\n reject: (error: Error) => void;\n};\n\nexport class SaveClientService {\n private webSocket: AbstractWebsocket = inject(WebSocketToken);\n private pending: Map<string, PendingRequest> = new Map();\n private requestCounter = 0;\n\n initialize() {\n const saveListResult = (data: SaveListResult) => this.resolveRequest(data.requestId, data);\n const saveSaveResult = (data: SaveSaveResult) => this.resolveRequest(data.requestId, data);\n const saveLoadResult = (data: SaveLoadResult) => this.resolveRequest(data.requestId, data);\n const saveErrorResult = (data: SaveErrorResult) => this.rejectRequest(data.requestId, data.message);\n this.webSocket.off(\"save.list.result\", saveListResult);\n this.webSocket.off(\"save.save.result\", saveSaveResult);\n this.webSocket.off(\"save.load.result\", saveLoadResult);\n this.webSocket.off(\"save.error\", saveErrorResult);\n this.webSocket.on(\"save.list.result\", saveListResult);\n this.webSocket.on(\"save.save.result\", saveSaveResult);\n this.webSocket.on(\"save.load.result\", saveLoadResult);\n this.webSocket.on(\"save.error\", saveErrorResult);\n }\n\n listSlots(): Promise<SaveSlotList> {\n return this.request<SaveListResult>(\"save.list\", {}).then((result) => result.slots);\n }\n\n saveSlot(index: number, meta: SaveSlotMeta = {}): Promise<SaveSlotList> {\n return this.request<SaveSaveResult>(\"save.save\", { index, meta }).then((result) => result.slots);\n }\n\n loadSlot(index: number): Promise<boolean> {\n return this.request<SaveLoadResult>(\"save.load\", { index }).then((result) => result.ok);\n }\n\n private request<T>(event: string, payload: Record<string, any>): Promise<T> {\n return new Promise((resolve, reject) => {\n if (!this.webSocket) {\n this.initialize();\n }\n const requestId = this.nextRequestId();\n this.pending.set(requestId, { resolve, reject });\n this.webSocket?.emit(event, { requestId, ...payload });\n });\n }\n\n private resolveRequest(requestId: string, result: any) {\n const pending = this.pending.get(requestId);\n if (!pending) return;\n this.pending.delete(requestId);\n pending.resolve(result);\n }\n\n private rejectRequest(requestId: string, message: string) {\n const pending = this.pending.get(requestId);\n if (!pending) return;\n this.pending.delete(requestId);\n pending.reject(new Error(message));\n }\n\n private nextRequestId(): string {\n this.requestCounter += 1;\n return `${Date.now()}-${this.requestCounter}`;\n }\n}\n\nexport function provideSaveClient() {\n return {\n provide: SaveClientService,\n useClass: SaveClientService,\n };\n}\n"],"mappings":";;;AAIA,IAAa,kBAAkB;AA8B/B,IAAa,oBAAb,MAA+B;;mBACU,OAAO,cAAc;iCACb,IAAI,IAAI;wBAC9B;;CAEzB,aAAa;EACX,MAAM,kBAAkB,SAAyB,KAAK,eAAe,K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B,QAAQ,QAAQ,MAAM;CACxB;CAEA,cAAsB,WAAmB,SAAiB;EACxD,MAAM,UAAU,KAAK,QAAQ,IAAI,SAAS;EAC1C,IAAI,CAAC,SAAS;EACd,KAAK,QAAQ,OAAO,SAAS;EAC7B,QAAQ,OAAO,IAAI,MAAM,OAAO,CAAC;CACnC;CAEA,gBAAgC;EAC9B,KAAK,kBAAkB;EACvB,OAAO,GAAG,KAAK,IAAI,EAAE,GAAG,KAAK;CAC/B;AACF;AAEA,SAAgB,oBAAoB;CAClC,OAAO;EACL,SAAS;EACT,UAAU;CACZ;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeStandaloneMessage(event: unknown): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/services/standalone-message.ts
|
|
2
|
+
function normalizeStandaloneMessage(event) {
|
|
3
|
+
const raw = event && typeof event === "object" && "data" in event ? event.data : event;
|
|
4
|
+
return typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { normalizeStandaloneMessage };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=standalone-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone-message.js","names":[],"sources":["../../src/services/standalone-message.ts"],"sourcesContent":["export function normalizeStandaloneMessage(event: unknown): any {\n const raw = event && typeof event === \"object\" && \"data\" in event\n ? (event as MessageEvent).data\n : event;\n\n return typeof raw === \"string\" ? JSON.parse(raw) : raw;\n}\n"],"mappings":";AAAA,SAAgB,2BAA2B,OAAqB;CAC9D,MAAM,MAAM,SAAS,OAAO,UAAU,YAAY,UAAU,QACvD,MAAuB,OACxB;CAEJ,OAAO,OAAO,QAAQ,WAAW,KAAK,MAAM,GAAG,IAAI;AACrD"}
|
|
@@ -2,8 +2,9 @@ import { AbstractWebsocket, WebSocketToken } from "./AbstractSocket.js";
|
|
|
2
2
|
import { provideSaveClient } from "./save.js";
|
|
3
3
|
import { RpgGui } from "../Gui/Gui.js";
|
|
4
4
|
import { RpgClientEngine } from "../RpgClientEngine.js";
|
|
5
|
-
import { ClientIo, ServerIo } from "../node_modules/.pnpm/@signe_room@
|
|
5
|
+
import { ClientIo, ServerIo } from "../node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js";
|
|
6
6
|
import { provideKeyboardControls } from "./keyboardControls.js";
|
|
7
|
+
import { normalizeStandaloneMessage } from "./standalone-message.js";
|
|
7
8
|
import { UpdateMapService, UpdateMapToken } from "@rpgjs/common";
|
|
8
9
|
//#region src/services/standalone.ts
|
|
9
10
|
var BridgeWebsocket = class extends AbstractWebsocket {
|
|
@@ -42,15 +43,15 @@ var BridgeWebsocket = class extends AbstractWebsocket {
|
|
|
42
43
|
headers: { "Content-Type": "application/json" }
|
|
43
44
|
});
|
|
44
45
|
listeners?.(this.socket);
|
|
45
|
-
await this.serverInstance.onConnect(this.socket.conn, { request });
|
|
46
46
|
this.room.clients.set(this.socket.id, this.socket);
|
|
47
47
|
this.pendingOn.forEach(({ event, callback }) => this.socket.addEventListener(event, callback));
|
|
48
48
|
this.pendingOn = [];
|
|
49
|
+
await this.serverInstance.onConnect(this.socket.conn, { request });
|
|
49
50
|
return this.socket;
|
|
50
51
|
}
|
|
51
52
|
on(key, callback) {
|
|
52
53
|
const handler = (event) => {
|
|
53
|
-
const object =
|
|
54
|
+
const object = normalizeStandaloneMessage(event);
|
|
54
55
|
if (object.type === key) callback(object.value);
|
|
55
56
|
};
|
|
56
57
|
if (!this.socket) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone.js","names":[],"sources":["../../src/services/standalone.ts"],"sourcesContent":["import { AbstractWebsocket, SocketUpdateProperties, WebSocketToken } from \"./AbstractSocket\";\nimport { ClientIo, ServerIo } from \"@signe/room\";\nimport { Context } from \"@signe/di\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { UpdateMapService, UpdateMapToken } from \"@rpgjs/common\";\nimport { LoadMapToken } from \"./loadMap\";\nimport { RpgGui } from \"../Gui/Gui\";\nimport { provideKeyboardControls } from \"./keyboardControls\";\nimport { provideSaveClient } from \"./save\";\n\ntype ServerIo = any;\ntype ClientIo = any;\n\ninterface StandaloneOptions {\n env?: Record<string, any>;\n}\n\nclass BridgeWebsocket extends AbstractWebsocket {\n private room: ServerIo;\n private socket: ClientIo;\n private pendingOn: Array<{ event: string; callback: (data: any) => void }> = [];\n private rooms = {\n partyFn: async (roomId: string) => {\n this.room = new ServerIo(roomId, this.rooms);\n const server = new this.server(this.room)\n await server.onStart();\n await server.subRoom.onStart()\n this.context.set('server', server)\n return server\n },\n env: {}\n }\n private serverInstance: any;\n\n constructor(protected context: Context, private server: any, options: StandaloneOptions = {}) {\n super(context);\n // fake room\n this.rooms.env = options.env || {};\n this.room = new ServerIo(\"lobby-1\", this.rooms);\n }\n\n async connection(listeners?: (data: any) => void) {\n this.serverInstance = new this.server(this.room);\n await this.serverInstance.onStart();\n await this.serverInstance.subRoom.onStart()\n this.context.set('server', this.serverInstance)\n return this._connection(listeners)\n }\n\n private async _connection(listeners?: (data: any) => void) {\n this.serverInstance = this.context.get('server')\n this.socket = new ClientIo(this.serverInstance, 'player-client-id');\n const url = new URL('http://localhost')\n const request = new Request(url.toString(), {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n }\n })\n listeners?.(this.socket)\n
|
|
1
|
+
{"version":3,"file":"standalone.js","names":[],"sources":["../../src/services/standalone.ts"],"sourcesContent":["import { AbstractWebsocket, SocketUpdateProperties, WebSocketToken } from \"./AbstractSocket\";\nimport { ClientIo, ServerIo } from \"@signe/room\";\nimport { Context } from \"@signe/di\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport { UpdateMapService, UpdateMapToken } from \"@rpgjs/common\";\nimport { LoadMapToken } from \"./loadMap\";\nimport { RpgGui } from \"../Gui/Gui\";\nimport { provideKeyboardControls } from \"./keyboardControls\";\nimport { provideSaveClient } from \"./save\";\nimport { normalizeStandaloneMessage } from \"./standalone-message\";\n\ntype ServerIo = any;\ntype ClientIo = any;\n\ninterface StandaloneOptions {\n env?: Record<string, any>;\n}\n\nclass BridgeWebsocket extends AbstractWebsocket {\n private room: ServerIo;\n private socket: ClientIo;\n private pendingOn: Array<{ event: string; callback: (data: any) => void }> = [];\n private rooms = {\n partyFn: async (roomId: string) => {\n this.room = new ServerIo(roomId, this.rooms);\n const server = new this.server(this.room)\n await server.onStart();\n await server.subRoom.onStart()\n this.context.set('server', server)\n return server\n },\n env: {}\n }\n private serverInstance: any;\n\n constructor(protected context: Context, private server: any, options: StandaloneOptions = {}) {\n super(context);\n // fake room\n this.rooms.env = options.env || {};\n this.room = new ServerIo(\"lobby-1\", this.rooms);\n }\n\n async connection(listeners?: (data: any) => void) {\n this.serverInstance = new this.server(this.room);\n await this.serverInstance.onStart();\n await this.serverInstance.subRoom.onStart()\n this.context.set('server', this.serverInstance)\n return this._connection(listeners)\n }\n\n private async _connection(listeners?: (data: any) => void) {\n this.serverInstance = this.context.get('server')\n this.socket = new ClientIo(this.serverInstance, 'player-client-id');\n const url = new URL('http://localhost')\n const request = new Request(url.toString(), {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n }\n })\n listeners?.(this.socket)\n this.room.clients.set(this.socket.id, this.socket);\n this.pendingOn.forEach(({ event, callback }) => this.socket.addEventListener(event, callback));\n this.pendingOn = [];\n await this.serverInstance.onConnect(this.socket.conn as any, { request } as any);\n return this.socket\n }\n\n on(key: string, callback: (data: any) => void) {\n const handler = (event) => {\n const object = normalizeStandaloneMessage(event);\n if (object.type === key) {\n callback(object.value);\n }\n };\n if (!this.socket) {\n this.pendingOn.push({ event: \"message\", callback: handler });\n return;\n }\n this.socket.addEventListener(\"message\", handler);\n }\n\n off(event: string, callback: (data: any) => void) {\n if (!this.socket) return;\n this.socket.removeEventListener(event, callback);\n }\n\n emit(event: string, data: any) {\n this.socket.send({\n action: event,\n value: data,\n });\n }\n\n /**\n * Update underlying connection properties before a reconnect\n *\n * Design\n * - Dynamically register a factory for the requested room to ensure a fresh server instance\n * - Swap the internal ServerIo to target the new room\n *\n * @param params - Properties to update\n * @param params.room - The target room id (e.g. `map-simplemap2`)\n *\n * @example\n * ```ts\n * websocket.updateProperties({ room: 'map-simplemap2' })\n * await websocket.reconnect()\n * ```\n */\n updateProperties(_params: SocketUpdateProperties) {\n // empty\n }\n\n /**\n * Reconnect the client to the current Party room\n *\n * Design\n * - Must be called after `updateProperties()` when switching rooms\n * - Rebuilds the client <-> server bridge and re-triggers connection listeners\n *\n * @param listeners - Optional callback to re-bind event handlers on the new socket\n *\n * @example\n * ```ts\n * websocket.updateProperties({ room: 'map-dungeon' })\n * await websocket.reconnect((socket) => {\n * // re-bind events here\n * })\n * ```\n */\n async reconnect(listeners?: (data: any) => void): Promise<void> {\n await this._connection((socket) => {\n listeners?.(socket)\n })\n }\n\n getServer() {\n return this.serverInstance\n }\n\n getSocket() {\n return this.socket\n }\n}\n\nclass UpdateMapStandaloneService extends UpdateMapService {\n private server: any;\n\n /**\n * Update the current room map data on the server side\n *\n * Design\n * - Uses the in-memory server instance stored in context (standalone mode)\n * - Builds a local HTTP-like request to the current Party room endpoint\n *\n * @param map - The map payload to apply on the server\n *\n * @example\n * ```ts\n * await updateMapService.update({ width: 1024, height: 768, events: [] })\n * ```\n */\n async update(map: any) {\n this.server = this.context.get('server')\n const roomId = this.server?.room?.id ?? 'lobby-1'\n const req = {\n url: `http://localhost/parties/main/${roomId}/map/update`,\n method: 'POST',\n headers: new Headers({}),\n json: async () => {\n return map;\n }\n };\n await this.server.onRequest(req)\n }\n}\n\nexport function provideRpg(server: any, options: StandaloneOptions = {}) {\n return [\n {\n provide: WebSocketToken,\n useFactory: (context: Context) => new BridgeWebsocket(context, server, options),\n },\n {\n provide: UpdateMapToken,\n useClass: UpdateMapStandaloneService,\n },\n provideKeyboardControls(),\n provideSaveCl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;GACT,aAAa,YAAqB,IAAI,gBAAgB,SAAS,QAAQ,OAAO;EAChF;EACA;GACE,SAAS;GACT,UAAU;EACZ;EACA,wBAAwB;EACxB,kBAAkB;EAClB;EACA;CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readPropValue } from "./readPropValue.js";
|
|
1
2
|
import { computed } from "canvasengine";
|
|
2
3
|
//#region src/utils/getEntityProp.ts
|
|
3
4
|
var entityPropMap = {
|
|
@@ -6,17 +7,17 @@ var entityPropMap = {
|
|
|
6
7
|
gold: (entity) => entity._gold(),
|
|
7
8
|
hp: (entity) => entity.hpSignal(),
|
|
8
9
|
sp: (entity) => entity.spSignal(),
|
|
9
|
-
name: (entity) => entity.name
|
|
10
|
+
name: (entity) => entity.name,
|
|
10
11
|
type: (entity) => entity.type(),
|
|
11
12
|
x: (entity) => entity.x(),
|
|
12
13
|
y: (entity) => entity.y(),
|
|
13
14
|
z: (entity) => entity.z(),
|
|
14
15
|
tint: (entity) => entity.tint(),
|
|
15
16
|
direction: (entity) => entity.direction(),
|
|
16
|
-
speed: (entity) => entity.speed
|
|
17
|
+
speed: (entity) => entity.speed,
|
|
17
18
|
hitbox: (entity) => entity.hitbox(),
|
|
18
19
|
animation: (entity) => entity.animationName(),
|
|
19
|
-
canMove: (entity) => entity.canMove
|
|
20
|
+
canMove: (entity) => readPropValue(entity._canMove ?? entity.canMove),
|
|
20
21
|
graphics: (entity) => entity.graphics(),
|
|
21
22
|
items: (entity) => entity.items(),
|
|
22
23
|
equipments: (entity) => entity.equipments(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntityProp.js","names":[],"sources":["../../src/utils/getEntityProp.ts"],"sourcesContent":["import { computed, Signal } from \"canvasengine\";\nimport { RpgClientObject } from \"../Game/Object\";\n\nconst BUILTIN_PARAM_KEYS = [\n \"maxHp\",\n \"maxSp\",\n \"atk\",\n \"pdef\",\n \"sdef\",\n \"str\",\n \"agi\",\n \"int\",\n \"dex\",\n] as const;\n\ntype BuiltInParamKey = typeof BUILTIN_PARAM_KEYS[number];\ntype ParamPropKey = `params.${BuiltInParamKey}` | `params.${string}`;\n\nconst entityPropMap = {\n level: (entity: RpgClientObject) => entity._level(),\n exp: (entity: RpgClientObject) => entity._exp(),\n gold: (entity: RpgClientObject) => entity._gold(),\n hp: (entity: RpgClientObject) => entity.hpSignal(),\n sp: (entity: RpgClientObject) => entity.spSignal(),\n name: (entity: RpgClientObject) => entity.name
|
|
1
|
+
{"version":3,"file":"getEntityProp.js","names":[],"sources":["../../src/utils/getEntityProp.ts"],"sourcesContent":["import { computed, Signal } from \"canvasengine\";\nimport { RpgClientObject } from \"../Game/Object\";\nimport { readPropValue } from \"./readPropValue\";\n\nconst BUILTIN_PARAM_KEYS = [\n \"maxHp\",\n \"maxSp\",\n \"atk\",\n \"pdef\",\n \"sdef\",\n \"str\",\n \"agi\",\n \"int\",\n \"dex\",\n] as const;\n\ntype BuiltInParamKey = typeof BUILTIN_PARAM_KEYS[number];\ntype ParamPropKey = `params.${BuiltInParamKey}` | `params.${string}`;\n\nconst entityPropMap = {\n level: (entity: RpgClientObject) => entity._level(),\n exp: (entity: RpgClientObject) => entity._exp(),\n gold: (entity: RpgClientObject) => entity._gold(),\n hp: (entity: RpgClientObject) => entity.hpSignal(),\n sp: (entity: RpgClientObject) => entity.spSignal(),\n name: (entity: RpgClientObject) => entity.name,\n type: (entity: RpgClientObject) => entity.type(),\n x: (entity: RpgClientObject) => entity.x(),\n y: (entity: RpgClientObject) => entity.y(),\n z: (entity: RpgClientObject) => entity.z(),\n tint: (entity: RpgClientObject) => entity.tint(),\n direction: (entity: RpgClientObject) => entity.direction(),\n speed: (entity: RpgClientObject) => entity.speed,\n hitbox: (entity: RpgClientObject) => entity.hitbox(),\n animation: (entity: RpgClientObject) => entity.animationName(),\n canMove: (entity: RpgClientObject) => readPropValue<boolean>((entity as any)._canMove ?? entity.canMove),\n graphics: (entity: RpgClientObject) => entity.graphics(),\n items: (entity: RpgClientObject) => entity.items(),\n equipments: (entity: RpgClientObject) => entity.equipments(),\n states: (entity: RpgClientObject) => entity.states(),\n skills: (entity: RpgClientObject) => entity.skills(),\n effects: (entity: RpgClientObject) => entity._effects(),\n componentsTop: (entity: RpgClientObject) => entity.componentsTop(),\n componentsBottom: (entity: RpgClientObject) => entity.componentsBottom(),\n componentsCenter: (entity: RpgClientObject) => entity.componentsCenter(),\n componentsLeft: (entity: RpgClientObject) => entity.componentsLeft(),\n componentsRight: (entity: RpgClientObject) => entity.componentsRight(),\n} as const;\n\ntype EntityPropMap = typeof entityPropMap;\ntype EntityPropKey = keyof EntityPropMap | ParamPropKey;\ntype EntityPropValue<K extends EntityPropKey> = K extends keyof EntityPropMap\n ? ReturnType<EntityPropMap[K]>\n : K extends `params.${string}`\n ? number | undefined\n : never;\n\nconst isSignal = <T>(value: unknown): value is Signal<T> =>\n typeof value === \"function\";\n\nconst toSignal = <T>(value: Signal<T> | T): Signal<T> =>\n isSignal<T>(value) ? value : computed(() => value);\n\nexport const getEntityProp = <K extends EntityPropKey>(\n entity: Signal<RpgClientObject | undefined> | RpgClientObject | undefined,\n key: K\n): Signal<EntityPropValue<K>> => {\n const entitySignal = toSignal(entity);\n\n return computed(() => {\n const current = entitySignal();\n if (!current) {\n return undefined as EntityPropValue<K>;\n }\n\n if (Object.prototype.hasOwnProperty.call(entityPropMap, key)) {\n const getter = entityPropMap[key as keyof EntityPropMap];\n return getter(current) as EntityPropValue<K>;\n }\n\n if (key.startsWith(\"params.\")) {\n const paramKey = key.slice(\"params.\".length);\n return current._param?.()?.[paramKey] as EntityPropValue<K>;\n }\n\n return undefined as EntityPropValue<K>;\n });\n};\n"],"mappings":";;;AAmBA,IAAM,gBAAgB;CACpB,QAAQ,WAA4B,OAAO,OAAO;CAClD,MAAM,WAA4B,OAAO,KAAK;CAC9C,OAAO,WAA4B,OAAO,MAAM;CAChD,KAAK,WAA4B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F,CAAC;AACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/utils/readPropValue.ts
|
|
2
|
+
var readPropValue = (value) => {
|
|
3
|
+
if (typeof value === "function") return readPropValue(value());
|
|
4
|
+
if (value && typeof value === "object" && "value" in value) return readPropValue(value.value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
var getCanMoveValue = (entity) => {
|
|
8
|
+
return readPropValue(entity?._canMove ?? entity?.canMove) !== false;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getCanMoveValue, readPropValue };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=readPropValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readPropValue.js","names":[],"sources":["../../src/utils/readPropValue.ts"],"sourcesContent":["export const readPropValue = <T = unknown>(value: unknown): T => {\n if (typeof value === \"function\") {\n return readPropValue((value as () => unknown)());\n }\n\n if (value && typeof value === \"object\" && \"value\" in value) {\n return readPropValue((value as { value: unknown }).value);\n }\n\n return value as T;\n};\n\nexport const getCanMoveValue = (entity: any): boolean => {\n const value = readPropValue(entity?._canMove ?? entity?.canMove);\n return value !== false;\n};\n"],"mappings":";AAAA,IAAa,iBAA8B,UAAsB;CAC/D,IAAI,OAAO,UAAU,YACnB,OAAO,cAAe,MAAwB,CAAC;CAGjD,IAAI,SAAS,OAAO,UAAU,YAAY,WAAW,OACnD,OAAO,cAAe,MAA6B,KAAK;CAG1D,OAAO;AACT;AAEA,IAAa,mBAAmB,WAAyB;CAEvD,OADc,cAAc,QAAQ,YAAY,QAAQ,OACjD,MAAU;AACnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/client",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.11",
|
|
4
4
|
"description": "RPGJS is a framework for creating RPG/MMORPG games",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,26 +17,25 @@
|
|
|
17
17
|
"author": "Samuel Ronce",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@canvasengine/presets": "
|
|
21
|
-
"canvasengine": "
|
|
20
|
+
"@canvasengine/presets": "^2.0.0-rc.4",
|
|
21
|
+
"canvasengine": "^2.0.0-rc.4",
|
|
22
22
|
"pixi.js": "^8.9.2"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@rpgjs/
|
|
26
|
-
"@rpgjs/
|
|
27
|
-
"@rpgjs/
|
|
28
|
-
"@
|
|
29
|
-
"@signe/
|
|
30
|
-
"@signe/
|
|
31
|
-
"@signe/sync": "^2.9.0",
|
|
25
|
+
"@rpgjs/common": "5.0.0-beta.11",
|
|
26
|
+
"@rpgjs/server": "5.0.0-beta.11",
|
|
27
|
+
"@rpgjs/ui-css": "5.0.0-beta.11",
|
|
28
|
+
"@signe/di": "3.0.1",
|
|
29
|
+
"@signe/room": "3.0.1",
|
|
30
|
+
"@signe/sync": "3.0.1",
|
|
32
31
|
"pixi-filters": "^6.1.5",
|
|
33
32
|
"rxjs": "^7.8.2"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@canvasengine/compiler": "2.0.0-
|
|
37
|
-
"vite": "^8.0.
|
|
38
|
-
"vite-plugin-dts": "^
|
|
39
|
-
"vitest": "^4.1.
|
|
35
|
+
"@canvasengine/compiler": "2.0.0-rc.4",
|
|
36
|
+
"vite": "^8.0.13",
|
|
37
|
+
"vite-plugin-dts": "^5.0.0",
|
|
38
|
+
"vitest": "^4.1.6"
|
|
40
39
|
},
|
|
41
40
|
"type": "module",
|
|
42
41
|
"scripts": {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
|
+
import { AnimationManager } from "./AnimationManager";
|
|
3
|
+
|
|
4
|
+
describe("AnimationManager", () => {
|
|
5
|
+
test("resolves displayEffect when the component calls onFinish", async () => {
|
|
6
|
+
const manager = new AnimationManager();
|
|
7
|
+
const done = manager.displayEffect({}, { x: 10, y: 20 });
|
|
8
|
+
|
|
9
|
+
expect(manager.current()).toHaveLength(1);
|
|
10
|
+
manager.current()[0].onFinish();
|
|
11
|
+
|
|
12
|
+
await expect(done).resolves.toBeUndefined();
|
|
13
|
+
expect(manager.current()).toHaveLength(0);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("keeps onFinish idempotent and forwards user callback data", async () => {
|
|
17
|
+
const manager = new AnimationManager();
|
|
18
|
+
const onFinish = vi.fn();
|
|
19
|
+
const done = manager.displayEffect({ onFinish }, { x: 10, y: 20 });
|
|
20
|
+
const finish = manager.current()[0].onFinish;
|
|
21
|
+
|
|
22
|
+
finish({ ok: true });
|
|
23
|
+
finish({ ok: false });
|
|
24
|
+
|
|
25
|
+
await done;
|
|
26
|
+
expect(onFinish).toHaveBeenCalledTimes(1);
|
|
27
|
+
expect(onFinish).toHaveBeenCalledWith({ ok: true });
|
|
28
|
+
expect(manager.current()).toHaveLength(0);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -4,18 +4,30 @@ import { signal } from "canvasengine";
|
|
|
4
4
|
export class AnimationManager {
|
|
5
5
|
current = signal<any[]>([]);
|
|
6
6
|
|
|
7
|
-
displayEffect(params: any, player: RpgCommonPlayer | { x: number, y: number }) {
|
|
7
|
+
displayEffect(params: any, player: RpgCommonPlayer | { x: number, y: number }): Promise<void> {
|
|
8
8
|
const id = generateUID();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onFinish: () => {
|
|
9
|
+
const effectParams = params ?? {};
|
|
10
|
+
return new Promise<void>((resolve) => {
|
|
11
|
+
let finished = false;
|
|
12
|
+
const finish = (data?: any) => {
|
|
13
|
+
if (finished) return;
|
|
14
|
+
finished = true;
|
|
16
15
|
const index = this.current().findIndex((value) => value.id === id);
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (index !== -1) {
|
|
17
|
+
this.current().splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
effectParams.onFinish?.(data);
|
|
20
|
+
resolve();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
this.current().push({
|
|
24
|
+
...effectParams,
|
|
25
|
+
id,
|
|
26
|
+
x: player.x,
|
|
27
|
+
y: player.y,
|
|
28
|
+
object: player,
|
|
29
|
+
onFinish: finish,
|
|
30
|
+
});
|
|
19
31
|
});
|
|
20
32
|
}
|
|
21
33
|
}
|
package/src/Game/Map.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RpgCommonMap,
|
|
3
|
+
cloneLightingState,
|
|
4
|
+
normalizeLightingState,
|
|
5
|
+
type LightSpot,
|
|
6
|
+
type LightingState,
|
|
3
7
|
type WeatherState,
|
|
4
8
|
type MapPhysicsInitContext,
|
|
5
9
|
type MapPhysicsEntityContext,
|
|
@@ -11,6 +15,15 @@ import { RpgClientEvent } from "./Event";
|
|
|
11
15
|
import { RpgClientEngine } from "../RpgClientEngine";
|
|
12
16
|
import { inject } from "../core/inject";
|
|
13
17
|
|
|
18
|
+
type TestGlobalScope = typeof globalThis & {
|
|
19
|
+
process?: {
|
|
20
|
+
env?: {
|
|
21
|
+
TEST?: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
__RPGJS_TEST__?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
14
27
|
export class RpgClientMap extends RpgCommonMap<any> {
|
|
15
28
|
engine: RpgClientEngine = inject(RpgClientEngine)
|
|
16
29
|
@users(RpgClientPlayer) players = signal<Record<string, RpgClientPlayer>>({});
|
|
@@ -18,19 +31,43 @@ export class RpgClientMap extends RpgCommonMap<any> {
|
|
|
18
31
|
currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()!])
|
|
19
32
|
weatherState = signal<WeatherState | null>(null);
|
|
20
33
|
localWeatherOverride = signal<WeatherState | null>(null);
|
|
34
|
+
lightingState = signal<LightingState | null>(null);
|
|
35
|
+
localLightSpots = signal<Record<string, LightSpot>>({});
|
|
21
36
|
weather = computed<WeatherState | null>(() => {
|
|
22
37
|
const local = this.localWeatherOverride()
|
|
23
38
|
const state = this.weatherState()
|
|
24
39
|
return local ?? state
|
|
25
40
|
});
|
|
41
|
+
lighting = computed<LightingState | null>(() => {
|
|
42
|
+
const state = cloneLightingState(this.lightingState());
|
|
43
|
+
const localSpots = Object.entries(this.localLightSpots()).map(([id, spot]) => ({
|
|
44
|
+
...spot,
|
|
45
|
+
id: spot.id ?? id,
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
if (!state && localSpots.length === 0) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const next: LightingState = { ...(state ?? {}) };
|
|
53
|
+
if (!state?.ambient) {
|
|
54
|
+
delete next.ambient;
|
|
55
|
+
}
|
|
56
|
+
next.spots = [
|
|
57
|
+
...(state?.spots ?? []),
|
|
58
|
+
...localSpots,
|
|
59
|
+
];
|
|
60
|
+
return next;
|
|
61
|
+
});
|
|
26
62
|
private manualClientPhysicsTick = false;
|
|
27
63
|
private readonly isTestEnvironment: boolean;
|
|
28
64
|
|
|
29
65
|
constructor() {
|
|
30
66
|
super();
|
|
31
67
|
// Détecter l'environnement de test
|
|
32
|
-
const
|
|
33
|
-
|
|
68
|
+
const testGlobal = globalThis as TestGlobalScope;
|
|
69
|
+
const isTest = testGlobal.process?.env?.TEST === 'true'
|
|
70
|
+
|| testGlobal.__RPGJS_TEST__ === true;
|
|
34
71
|
this.isTestEnvironment = isTest;
|
|
35
72
|
if (isTest) {
|
|
36
73
|
this.autoTickEnabled = false;
|
|
@@ -58,6 +95,8 @@ export class RpgClientMap extends RpgCommonMap<any> {
|
|
|
58
95
|
this.events.set({})
|
|
59
96
|
this.weatherState.set(null);
|
|
60
97
|
this.localWeatherOverride.set(null);
|
|
98
|
+
this.lightingState.set(null);
|
|
99
|
+
this.localLightSpots.set({});
|
|
61
100
|
this.clearPhysic()
|
|
62
101
|
}
|
|
63
102
|
|
|
@@ -73,6 +112,56 @@ export class RpgClientMap extends RpgCommonMap<any> {
|
|
|
73
112
|
this.localWeatherOverride.set(null);
|
|
74
113
|
}
|
|
75
114
|
|
|
115
|
+
getLighting(): LightingState | null {
|
|
116
|
+
return this.lighting();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
addLightSpot(id: string, spot: LightSpot): void {
|
|
120
|
+
const normalized = normalizeLightingState({ spots: [{ ...spot, id }] });
|
|
121
|
+
const nextSpot = normalized?.spots?.[0];
|
|
122
|
+
if (!nextSpot) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.localLightSpots.update((spots) => ({
|
|
126
|
+
...spots,
|
|
127
|
+
[id]: nextSpot,
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
patchLightSpot(id: string, patch: Partial<LightSpot>): void {
|
|
132
|
+
this.localLightSpots.update((spots) => {
|
|
133
|
+
const current = spots[id];
|
|
134
|
+
if (!current) {
|
|
135
|
+
return spots;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
...spots,
|
|
139
|
+
[id]: {
|
|
140
|
+
...current,
|
|
141
|
+
...patch,
|
|
142
|
+
id,
|
|
143
|
+
x: patch.x ?? current.x,
|
|
144
|
+
y: patch.y ?? current.y,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
removeLightSpot(id: string): void {
|
|
151
|
+
this.localLightSpots.update((spots) => {
|
|
152
|
+
if (!(id in spots)) {
|
|
153
|
+
return spots;
|
|
154
|
+
}
|
|
155
|
+
const next = { ...spots };
|
|
156
|
+
delete next[id];
|
|
157
|
+
return next;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
clearLightSpots(): void {
|
|
162
|
+
this.localLightSpots.set({});
|
|
163
|
+
}
|
|
164
|
+
|
|
76
165
|
stepClientPhysics(deltaMs: number): number {
|
|
77
166
|
if (!this.manualClientPhysicsTick) {
|
|
78
167
|
return 0;
|