@rpgjs/client 5.0.0-alpha.9 → 5.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Game/AnimationManager.d.ts +8 -0
- package/dist/Game/AnimationManager.js +26 -0
- package/dist/Game/AnimationManager.js.map +1 -0
- package/dist/Game/Event.d.ts +1 -1
- package/dist/Game/Event.js +12 -0
- package/dist/Game/Event.js.map +1 -0
- package/dist/Game/Map.d.ts +23 -2
- package/dist/Game/Map.js +80 -0
- package/dist/Game/Map.js.map +1 -0
- package/dist/Game/Object.d.ts +157 -0
- package/dist/Game/Object.js +211 -0
- package/dist/Game/Object.js.map +1 -0
- package/dist/Game/Player.d.ts +1 -1
- package/dist/Game/Player.js +12 -0
- package/dist/Game/Player.js.map +1 -0
- package/dist/Gui/Gui.d.ts +177 -5
- package/dist/Gui/Gui.js +445 -0
- package/dist/Gui/Gui.js.map +1 -0
- package/dist/Gui/NotificationManager.d.ts +23 -0
- package/dist/Gui/NotificationManager.js +49 -0
- package/dist/Gui/NotificationManager.js.map +1 -0
- package/dist/Resource.d.ts +97 -0
- package/dist/Resource.js +133 -0
- package/dist/Resource.js.map +1 -0
- package/dist/RpgClient.d.ts +238 -11
- package/dist/RpgClientEngine.d.ts +615 -14
- package/dist/RpgClientEngine.js +1334 -0
- package/dist/RpgClientEngine.js.map +1 -0
- package/dist/Sound.d.ts +199 -0
- package/dist/Sound.js +167 -0
- package/dist/Sound.js.map +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js +6 -0
- package/dist/components/animations/animation.ce.js +24 -0
- package/dist/components/animations/animation.ce.js.map +1 -0
- package/dist/components/animations/hit.ce.js +70 -0
- package/dist/components/animations/hit.ce.js.map +1 -0
- package/dist/components/animations/index.d.ts +4 -0
- package/dist/components/animations/index.js +11 -0
- package/dist/components/animations/index.js.map +1 -0
- package/dist/components/character.ce.js +392 -0
- package/dist/components/character.ce.js.map +1 -0
- package/dist/components/dynamics/parse-value.d.ts +1 -0
- package/dist/components/dynamics/parse-value.js +44 -0
- package/dist/components/dynamics/parse-value.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +73 -0
- package/dist/components/dynamics/text.ce.js.map +1 -0
- package/dist/components/gui/box.ce.js +28 -0
- package/dist/components/gui/box.ce.js.map +1 -0
- package/dist/components/gui/dialogbox/index.ce.js +205 -0
- package/dist/components/gui/dialogbox/index.ce.js.map +1 -0
- package/dist/components/gui/gameover.ce.js +193 -0
- package/dist/components/gui/gameover.ce.js.map +1 -0
- package/dist/components/gui/hud/hud.ce.js +92 -0
- package/dist/components/gui/hud/hud.ce.js.map +1 -0
- package/dist/components/gui/index.d.ts +15 -3
- package/dist/components/gui/index.js +14 -0
- package/dist/components/gui/menu/equip-menu.ce.js +481 -0
- package/dist/components/gui/menu/equip-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/exit-menu.ce.js +54 -0
- package/dist/components/gui/menu/exit-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/items-menu.ce.js +344 -0
- package/dist/components/gui/menu/items-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/main-menu.ce.js +417 -0
- package/dist/components/gui/menu/main-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/options-menu.ce.js +48 -0
- package/dist/components/gui/menu/options-menu.ce.js.map +1 -0
- package/dist/components/gui/menu/skills-menu.ce.js +107 -0
- package/dist/components/gui/menu/skills-menu.ce.js.map +1 -0
- package/dist/components/gui/mobile/index.d.ts +8 -0
- package/dist/components/gui/mobile/index.js +21 -0
- package/dist/components/gui/mobile/index.js.map +1 -0
- package/dist/components/gui/mobile/mobile.ce.js +78 -0
- package/dist/components/gui/mobile/mobile.ce.js.map +1 -0
- package/dist/components/gui/notification/notification.ce.js +64 -0
- package/dist/components/gui/notification/notification.ce.js.map +1 -0
- package/dist/components/gui/save-load.ce.js +389 -0
- package/dist/components/gui/save-load.ce.js.map +1 -0
- package/dist/components/gui/shop/shop.ce.js +652 -0
- package/dist/components/gui/shop/shop.ce.js.map +1 -0
- package/dist/components/gui/title-screen.ce.js +190 -0
- package/dist/components/gui/title-screen.ce.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/prebuilt/hp-bar.ce.js +116 -0
- package/dist/components/prebuilt/hp-bar.ce.js.map +1 -0
- package/dist/components/prebuilt/index.d.ts +19 -0
- package/dist/components/prebuilt/index.js +2 -0
- package/dist/components/prebuilt/light-halo.ce.js +94 -0
- package/dist/components/prebuilt/light-halo.ce.js.map +1 -0
- package/dist/components/scenes/canvas.ce.js +60 -0
- package/dist/components/scenes/canvas.ce.js.map +1 -0
- package/dist/components/scenes/draw-map.ce.js +89 -0
- package/dist/components/scenes/draw-map.ce.js.map +1 -0
- package/dist/components/scenes/event-layer.ce.js +28 -0
- package/dist/components/scenes/event-layer.ce.js.map +1 -0
- package/dist/core/inject.js +18 -0
- package/dist/core/inject.js.map +1 -0
- package/dist/core/setup.js +16 -0
- package/dist/core/setup.js.map +1 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.js +44 -14
- package/dist/module.d.ts +43 -4
- package/dist/module.js +176 -0
- package/dist/module.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js +277 -0
- package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +457 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +463 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +2191 -0
- package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +10 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +91 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js +325 -0
- package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +14 -0
- package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +115 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +401 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -0
- package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3756 -0
- package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -0
- package/dist/presets/animation.d.ts +31 -0
- package/dist/presets/animation.js +39 -0
- package/dist/presets/animation.js.map +1 -0
- package/dist/presets/faceset.d.ts +30 -0
- package/dist/presets/faceset.js +51 -0
- package/dist/presets/faceset.js.map +1 -0
- package/dist/presets/icon.d.ts +20 -0
- package/dist/presets/icon.js +15 -0
- package/dist/presets/icon.js.map +1 -0
- package/dist/presets/index.d.ts +123 -0
- package/dist/presets/index.js +17 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/lpc.d.ts +89 -0
- package/dist/presets/lpc.js +98 -0
- package/dist/presets/lpc.js.map +1 -0
- package/dist/presets/rmspritesheet.js +42 -0
- package/dist/presets/rmspritesheet.js.map +1 -0
- package/dist/services/AbstractSocket.d.ts +9 -5
- package/dist/services/AbstractSocket.js +11 -0
- package/dist/services/AbstractSocket.js.map +1 -0
- package/dist/services/keyboardControls.d.ts +15 -0
- package/dist/services/keyboardControls.js +23 -0
- package/dist/services/keyboardControls.js.map +1 -0
- package/dist/services/loadMap.js +123 -0
- package/dist/services/loadMap.js.map +1 -0
- package/dist/services/mmorpg.d.ts +21 -9
- package/dist/services/mmorpg.js +131 -0
- package/dist/services/mmorpg.js.map +1 -0
- package/dist/services/save.d.ts +19 -0
- package/dist/services/save.js +77 -0
- package/dist/services/save.js.map +1 -0
- package/dist/services/standalone.d.ts +67 -7
- package/dist/services/standalone.js +168 -0
- package/dist/services/standalone.js.map +1 -0
- package/dist/utils/getEntityProp.d.ts +39 -0
- package/dist/utils/getEntityProp.js +52 -0
- package/dist/utils/getEntityProp.js.map +1 -0
- package/package.json +13 -9
- package/src/Game/{EffectManager.ts → AnimationManager.ts} +3 -2
- package/src/Game/Event.ts +1 -1
- package/src/Game/Map.ts +95 -3
- package/src/Game/Object.ts +330 -14
- package/src/Game/Player.ts +1 -1
- package/src/Gui/Gui.ts +506 -18
- package/src/Gui/NotificationManager.ts +69 -0
- package/src/Resource.ts +150 -0
- package/src/RpgClient.ts +246 -12
- package/src/RpgClientEngine.ts +1641 -62
- package/src/Sound.ts +253 -0
- package/src/components/{effects → animations}/animation.ce +3 -6
- package/src/components/{effects → animations}/index.ts +1 -1
- package/src/components/character.ce +387 -52
- package/src/components/dynamics/parse-value.ts +80 -0
- package/src/components/dynamics/text.ce +183 -0
- package/src/components/gui/box.ce +17 -0
- package/src/components/gui/dialogbox/index.ce +204 -187
- package/src/components/gui/gameover.ce +158 -0
- package/src/components/gui/hud/hud.ce +61 -0
- package/src/components/gui/index.ts +30 -4
- package/src/components/gui/menu/equip-menu.ce +410 -0
- package/src/components/gui/menu/exit-menu.ce +41 -0
- package/src/components/gui/menu/items-menu.ce +317 -0
- package/src/components/gui/menu/main-menu.ce +294 -0
- package/src/components/gui/menu/options-menu.ce +35 -0
- package/src/components/gui/menu/skills-menu.ce +83 -0
- package/src/components/gui/mobile/index.ts +24 -0
- package/src/components/gui/mobile/mobile.ce +80 -0
- package/src/components/gui/notification/notification.ce +51 -0
- package/src/components/gui/save-load.ce +208 -0
- package/src/components/gui/shop/shop.ce +493 -0
- package/src/components/gui/title-screen.ce +163 -0
- package/src/components/index.ts +3 -0
- package/src/components/prebuilt/hp-bar.ce +255 -0
- package/src/components/prebuilt/index.ts +24 -0
- package/src/components/prebuilt/light-halo.ce +148 -0
- package/src/components/scenes/canvas.ce +20 -15
- package/src/components/scenes/draw-map.ce +60 -13
- package/src/components/scenes/event-layer.ce +7 -0
- package/src/components/scenes/transition.ce +60 -0
- package/src/index.ts +16 -2
- package/src/module.ts +127 -9
- package/src/presets/animation.ts +46 -0
- package/src/presets/faceset.ts +60 -0
- package/src/presets/icon.ts +17 -0
- package/src/presets/index.ts +9 -1
- package/src/presets/lpc.ts +108 -0
- package/src/services/AbstractSocket.ts +10 -2
- package/src/services/keyboardControls.ts +20 -0
- package/src/services/loadMap.ts +1 -1
- package/src/services/mmorpg.ts +100 -12
- package/src/services/save.ts +103 -0
- package/src/services/standalone.ts +110 -18
- package/src/utils/getEntityProp.ts +87 -0
- package/vite.config.ts +4 -2
- package/dist/Game/EffectManager.d.ts +0 -5
- package/dist/components/effects/index.d.ts +0 -4
- package/dist/index.js.map +0 -1
- package/dist/index10.js +0 -8
- package/dist/index10.js.map +0 -1
- package/dist/index11.js +0 -10
- package/dist/index11.js.map +0 -1
- package/dist/index12.js +0 -8
- package/dist/index12.js.map +0 -1
- package/dist/index13.js +0 -17
- package/dist/index13.js.map +0 -1
- package/dist/index14.js +0 -107
- package/dist/index14.js.map +0 -1
- package/dist/index15.js +0 -50
- package/dist/index15.js.map +0 -1
- package/dist/index16.js +0 -191
- package/dist/index16.js.map +0 -1
- package/dist/index17.js +0 -9
- package/dist/index17.js.map +0 -1
- package/dist/index18.js +0 -387
- package/dist/index18.js.map +0 -1
- package/dist/index19.js +0 -31
- package/dist/index19.js.map +0 -1
- package/dist/index2.js +0 -181
- package/dist/index2.js.map +0 -1
- package/dist/index20.js +0 -24
- package/dist/index20.js.map +0 -1
- package/dist/index21.js +0 -2421
- package/dist/index21.js.map +0 -1
- package/dist/index22.js +0 -114
- package/dist/index22.js.map +0 -1
- package/dist/index23.js +0 -109
- package/dist/index23.js.map +0 -1
- package/dist/index24.js +0 -71
- package/dist/index24.js.map +0 -1
- package/dist/index25.js +0 -21
- package/dist/index25.js.map +0 -1
- package/dist/index26.js +0 -41
- package/dist/index26.js.map +0 -1
- package/dist/index27.js +0 -5
- package/dist/index27.js.map +0 -1
- package/dist/index28.js +0 -322
- package/dist/index28.js.map +0 -1
- package/dist/index29.js +0 -27
- package/dist/index29.js.map +0 -1
- package/dist/index3.js +0 -87
- package/dist/index3.js.map +0 -1
- package/dist/index30.js +0 -11
- package/dist/index30.js.map +0 -1
- package/dist/index31.js +0 -11
- package/dist/index31.js.map +0 -1
- package/dist/index32.js +0 -174
- package/dist/index32.js.map +0 -1
- package/dist/index33.js +0 -501
- package/dist/index33.js.map +0 -1
- package/dist/index34.js +0 -12
- package/dist/index34.js.map +0 -1
- package/dist/index35.js +0 -4403
- package/dist/index35.js.map +0 -1
- package/dist/index36.js +0 -316
- package/dist/index36.js.map +0 -1
- package/dist/index37.js +0 -61
- package/dist/index37.js.map +0 -1
- package/dist/index38.js +0 -20
- package/dist/index38.js.map +0 -1
- package/dist/index39.js +0 -20
- package/dist/index39.js.map +0 -1
- package/dist/index4.js +0 -67
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -16
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -17
- package/dist/index6.js.map +0 -1
- package/dist/index7.js +0 -39
- package/dist/index7.js.map +0 -1
- package/dist/index8.js +0 -108
- package/dist/index8.js.map +0 -1
- package/dist/index9.js +0 -76
- package/dist/index9.js.map +0 -1
- package/src/components/gui/dialogbox/itemMenu.ce +0 -23
- package/src/components/gui/dialogbox/selection.ce +0 -67
- /package/src/components/{effects → animations}/hit.ce +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { AbstractWebsocket, WebSocketToken } from "./AbstractSocket.js";
|
|
2
|
+
import { provideSaveClient } from "./save.js";
|
|
3
|
+
import { RpgGui } from "../Gui/Gui.js";
|
|
4
|
+
import { RpgClientEngine } from "../RpgClientEngine.js";
|
|
5
|
+
import { ClientIo, ServerIo } from "../node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js";
|
|
6
|
+
import { provideKeyboardControls } from "./keyboardControls.js";
|
|
7
|
+
import { UpdateMapService, UpdateMapToken } from "@rpgjs/common";
|
|
8
|
+
//#region src/services/standalone.ts
|
|
9
|
+
var BridgeWebsocket = class extends AbstractWebsocket {
|
|
10
|
+
constructor(context, server, options = {}) {
|
|
11
|
+
super(context);
|
|
12
|
+
this.context = context;
|
|
13
|
+
this.server = server;
|
|
14
|
+
this.pendingOn = [];
|
|
15
|
+
this.rooms = {
|
|
16
|
+
partyFn: async (roomId) => {
|
|
17
|
+
this.room = new ServerIo(roomId, this.rooms);
|
|
18
|
+
const server = new this.server(this.room);
|
|
19
|
+
await server.onStart();
|
|
20
|
+
await server.subRoom.onStart();
|
|
21
|
+
this.context.set("server", server);
|
|
22
|
+
return server;
|
|
23
|
+
},
|
|
24
|
+
env: {}
|
|
25
|
+
};
|
|
26
|
+
this.rooms.env = options.env || {};
|
|
27
|
+
this.room = new ServerIo("lobby-1", this.rooms);
|
|
28
|
+
}
|
|
29
|
+
async connection(listeners) {
|
|
30
|
+
this.serverInstance = new this.server(this.room);
|
|
31
|
+
await this.serverInstance.onStart();
|
|
32
|
+
await this.serverInstance.subRoom.onStart();
|
|
33
|
+
this.context.set("server", this.serverInstance);
|
|
34
|
+
return this._connection(listeners);
|
|
35
|
+
}
|
|
36
|
+
async _connection(listeners) {
|
|
37
|
+
this.serverInstance = this.context.get("server");
|
|
38
|
+
this.socket = new ClientIo(this.serverInstance, "player-client-id");
|
|
39
|
+
const url = new URL("http://localhost");
|
|
40
|
+
const request = new Request(url.toString(), {
|
|
41
|
+
method: "GET",
|
|
42
|
+
headers: { "Content-Type": "application/json" }
|
|
43
|
+
});
|
|
44
|
+
listeners?.(this.socket);
|
|
45
|
+
await this.serverInstance.onConnect(this.socket.conn, { request });
|
|
46
|
+
this.room.clients.set(this.socket.id, this.socket);
|
|
47
|
+
this.pendingOn.forEach(({ event, callback }) => this.socket.addEventListener(event, callback));
|
|
48
|
+
this.pendingOn = [];
|
|
49
|
+
return this.socket;
|
|
50
|
+
}
|
|
51
|
+
on(key, callback) {
|
|
52
|
+
const handler = (event) => {
|
|
53
|
+
const object = JSON.parse(event);
|
|
54
|
+
if (object.type === key) callback(object.value);
|
|
55
|
+
};
|
|
56
|
+
if (!this.socket) {
|
|
57
|
+
this.pendingOn.push({
|
|
58
|
+
event: "message",
|
|
59
|
+
callback: handler
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.socket.addEventListener("message", handler);
|
|
64
|
+
}
|
|
65
|
+
off(event, callback) {
|
|
66
|
+
if (!this.socket) return;
|
|
67
|
+
this.socket.removeEventListener(event, callback);
|
|
68
|
+
}
|
|
69
|
+
emit(event, data) {
|
|
70
|
+
this.socket.send({
|
|
71
|
+
action: event,
|
|
72
|
+
value: data
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Update underlying connection properties before a reconnect
|
|
77
|
+
*
|
|
78
|
+
* Design
|
|
79
|
+
* - Dynamically register a factory for the requested room to ensure a fresh server instance
|
|
80
|
+
* - Swap the internal ServerIo to target the new room
|
|
81
|
+
*
|
|
82
|
+
* @param params - Properties to update
|
|
83
|
+
* @param params.room - The target room id (e.g. `map-simplemap2`)
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* websocket.updateProperties({ room: 'map-simplemap2' })
|
|
88
|
+
* await websocket.reconnect()
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
updateProperties(_params) {}
|
|
92
|
+
/**
|
|
93
|
+
* Reconnect the client to the current Party room
|
|
94
|
+
*
|
|
95
|
+
* Design
|
|
96
|
+
* - Must be called after `updateProperties()` when switching rooms
|
|
97
|
+
* - Rebuilds the client <-> server bridge and re-triggers connection listeners
|
|
98
|
+
*
|
|
99
|
+
* @param listeners - Optional callback to re-bind event handlers on the new socket
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* websocket.updateProperties({ room: 'map-dungeon' })
|
|
104
|
+
* await websocket.reconnect((socket) => {
|
|
105
|
+
* // re-bind events here
|
|
106
|
+
* })
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
async reconnect(listeners) {
|
|
110
|
+
await this._connection((socket) => {
|
|
111
|
+
listeners?.(socket);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
getServer() {
|
|
115
|
+
return this.serverInstance;
|
|
116
|
+
}
|
|
117
|
+
getSocket() {
|
|
118
|
+
return this.socket;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var UpdateMapStandaloneService = class extends UpdateMapService {
|
|
122
|
+
/**
|
|
123
|
+
* Update the current room map data on the server side
|
|
124
|
+
*
|
|
125
|
+
* Design
|
|
126
|
+
* - Uses the in-memory server instance stored in context (standalone mode)
|
|
127
|
+
* - Builds a local HTTP-like request to the current Party room endpoint
|
|
128
|
+
*
|
|
129
|
+
* @param map - The map payload to apply on the server
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* await updateMapService.update({ width: 1024, height: 768, events: [] })
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
async update(map) {
|
|
137
|
+
this.server = this.context.get("server");
|
|
138
|
+
const req = {
|
|
139
|
+
url: `http://localhost/parties/main/${this.server?.room?.id ?? "lobby-1"}/map/update`,
|
|
140
|
+
method: "POST",
|
|
141
|
+
headers: new Headers({}),
|
|
142
|
+
json: async () => {
|
|
143
|
+
return map;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
await this.server.onRequest(req);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
function provideRpg(server, options = {}) {
|
|
150
|
+
return [
|
|
151
|
+
{
|
|
152
|
+
provide: WebSocketToken,
|
|
153
|
+
useFactory: (context) => new BridgeWebsocket(context, server, options)
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
provide: UpdateMapToken,
|
|
157
|
+
useClass: UpdateMapStandaloneService
|
|
158
|
+
},
|
|
159
|
+
provideKeyboardControls(),
|
|
160
|
+
provideSaveClient(),
|
|
161
|
+
RpgGui,
|
|
162
|
+
RpgClientEngine
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
export { provideRpg };
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=standalone.js.map
|
|
@@ -0,0 +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 await this.serverInstance.onConnect(this.socket.conn as any, { request } as any);\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 return this.socket\n }\n\n on(key: string, callback: (data: any) => void) {\n const handler = (event) => {\n const object = JSON.parse(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 provideSaveClient(),\n RpgGui,\n RpgClientEngine,\n ];\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Signal } from 'canvasengine';
|
|
2
|
+
import { RpgClientObject } from '../Game/Object';
|
|
3
|
+
declare const BUILTIN_PARAM_KEYS: readonly ["maxHp", "maxSp", "atk", "pdef", "sdef", "str", "agi", "int", "dex"];
|
|
4
|
+
type BuiltInParamKey = typeof BUILTIN_PARAM_KEYS[number];
|
|
5
|
+
type ParamPropKey = `params.${BuiltInParamKey}` | `params.${string}`;
|
|
6
|
+
declare const entityPropMap: {
|
|
7
|
+
readonly level: (entity: RpgClientObject) => number;
|
|
8
|
+
readonly exp: (entity: RpgClientObject) => number;
|
|
9
|
+
readonly gold: (entity: RpgClientObject) => number;
|
|
10
|
+
readonly hp: (entity: RpgClientObject) => number;
|
|
11
|
+
readonly sp: (entity: RpgClientObject) => number;
|
|
12
|
+
readonly name: (entity: RpgClientObject) => string;
|
|
13
|
+
readonly type: (entity: RpgClientObject) => string;
|
|
14
|
+
readonly x: (entity: RpgClientObject) => number;
|
|
15
|
+
readonly y: (entity: RpgClientObject) => number;
|
|
16
|
+
readonly z: (entity: RpgClientObject) => number;
|
|
17
|
+
readonly tint: (entity: RpgClientObject) => string;
|
|
18
|
+
readonly direction: (entity: RpgClientObject) => import('@rpgjs/common').Direction;
|
|
19
|
+
readonly speed: (entity: RpgClientObject) => number;
|
|
20
|
+
readonly hitbox: (entity: RpgClientObject) => import('@rpgjs/common').Hitbox;
|
|
21
|
+
readonly animation: (entity: RpgClientObject) => string;
|
|
22
|
+
readonly canMove: (entity: RpgClientObject) => boolean;
|
|
23
|
+
readonly graphics: (entity: RpgClientObject) => any;
|
|
24
|
+
readonly items: (entity: RpgClientObject) => import('@rpgjs/common').Item[];
|
|
25
|
+
readonly equipments: (entity: RpgClientObject) => any[];
|
|
26
|
+
readonly states: (entity: RpgClientObject) => any[];
|
|
27
|
+
readonly skills: (entity: RpgClientObject) => import('@rpgjs/common').Skill[];
|
|
28
|
+
readonly effects: (entity: RpgClientObject) => any[];
|
|
29
|
+
readonly componentsTop: (entity: RpgClientObject) => string | null;
|
|
30
|
+
readonly componentsBottom: (entity: RpgClientObject) => string | null;
|
|
31
|
+
readonly componentsCenter: (entity: RpgClientObject) => string | null;
|
|
32
|
+
readonly componentsLeft: (entity: RpgClientObject) => string | null;
|
|
33
|
+
readonly componentsRight: (entity: RpgClientObject) => string | null;
|
|
34
|
+
};
|
|
35
|
+
type EntityPropMap = typeof entityPropMap;
|
|
36
|
+
type EntityPropKey = keyof EntityPropMap | ParamPropKey;
|
|
37
|
+
type EntityPropValue<K extends EntityPropKey> = K extends keyof EntityPropMap ? ReturnType<EntityPropMap[K]> : K extends `params.${string}` ? number | undefined : never;
|
|
38
|
+
export declare const getEntityProp: <K extends EntityPropKey>(entity: Signal<RpgClientObject | undefined> | RpgClientObject | undefined, key: K) => Signal<EntityPropValue<K>>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { computed } from "canvasengine";
|
|
2
|
+
//#region src/utils/getEntityProp.ts
|
|
3
|
+
var entityPropMap = {
|
|
4
|
+
level: (entity) => entity._level(),
|
|
5
|
+
exp: (entity) => entity._exp(),
|
|
6
|
+
gold: (entity) => entity._gold(),
|
|
7
|
+
hp: (entity) => entity.hpSignal(),
|
|
8
|
+
sp: (entity) => entity.spSignal(),
|
|
9
|
+
name: (entity) => entity.name(),
|
|
10
|
+
type: (entity) => entity.type(),
|
|
11
|
+
x: (entity) => entity.x(),
|
|
12
|
+
y: (entity) => entity.y(),
|
|
13
|
+
z: (entity) => entity.z(),
|
|
14
|
+
tint: (entity) => entity.tint(),
|
|
15
|
+
direction: (entity) => entity.direction(),
|
|
16
|
+
speed: (entity) => entity.speed(),
|
|
17
|
+
hitbox: (entity) => entity.hitbox(),
|
|
18
|
+
animation: (entity) => entity.animationName(),
|
|
19
|
+
canMove: (entity) => entity.canMove(),
|
|
20
|
+
graphics: (entity) => entity.graphics(),
|
|
21
|
+
items: (entity) => entity.items(),
|
|
22
|
+
equipments: (entity) => entity.equipments(),
|
|
23
|
+
states: (entity) => entity.states(),
|
|
24
|
+
skills: (entity) => entity.skills(),
|
|
25
|
+
effects: (entity) => entity._effects(),
|
|
26
|
+
componentsTop: (entity) => entity.componentsTop(),
|
|
27
|
+
componentsBottom: (entity) => entity.componentsBottom(),
|
|
28
|
+
componentsCenter: (entity) => entity.componentsCenter(),
|
|
29
|
+
componentsLeft: (entity) => entity.componentsLeft(),
|
|
30
|
+
componentsRight: (entity) => entity.componentsRight()
|
|
31
|
+
};
|
|
32
|
+
var isSignal = (value) => typeof value === "function";
|
|
33
|
+
var toSignal = (value) => isSignal(value) ? value : computed(() => value);
|
|
34
|
+
var getEntityProp = (entity, key) => {
|
|
35
|
+
const entitySignal = toSignal(entity);
|
|
36
|
+
return computed(() => {
|
|
37
|
+
const current = entitySignal();
|
|
38
|
+
if (!current) return;
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(entityPropMap, key)) {
|
|
40
|
+
const getter = entityPropMap[key];
|
|
41
|
+
return getter(current);
|
|
42
|
+
}
|
|
43
|
+
if (key.startsWith("params.")) {
|
|
44
|
+
const paramKey = key.slice(7);
|
|
45
|
+
return current._param?.()?.[paramKey];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { getEntityProp };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=getEntityProp.js.map
|
|
@@ -0,0 +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(),\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) => 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":";;AAkBA,IAAM,gBAAgB;CACpB,QAAQ,WAA4B,OAAO,QAAQ;CACnD,MAAM,WAA4B,OAAO,MAAM;CAC/C,OAAO,WAA4B,OAAO,OAAO;CACjD,KAAK,WAA4B,OAAO,UAAU;CAClD,KAAK,WAA4B,OAAO,UAAU;CAClD,OAAO,WAA4B,OAAO,MAAM;CAChD,OAAO,WAA4B,OAAO,MAAM;CAChD,IAAI,WAA4B,OAAO,GAAG;CAC1C,IAAI,WAA4B,OAAO,GAAG;CAC1C,IAAI,WAA4B,OAAO,GAAG;CAC1C,OAAO,WAA4B,OAAO,MAAM;CAChD,YAAY,WAA4B,OAAO,WAAW;CAC1D,QAAQ,WAA4B,OAAO,OAAO;CAClD,SAAS,WAA4B,OAAO,QAAQ;CACpD,YAAY,WAA4B,OAAO,eAAe;CAC9D,UAAU,WAA4B,OAAO,SAAS;CACtD,WAAW,WAA4B,OAAO,UAAU;CACxD,QAAQ,WAA4B,OAAO,OAAO;CAClD,aAAa,WAA4B,OAAO,YAAY;CAC5D,SAAS,WAA4B,OAAO,QAAQ;CACpD,SAAS,WAA4B,OAAO,QAAQ;CACpD,UAAU,WAA4B,OAAO,UAAU;CACvD,gBAAgB,WAA4B,OAAO,eAAe;CAClE,mBAAmB,WAA4B,OAAO,kBAAkB;CACxE,mBAAmB,WAA4B,OAAO,kBAAkB;CACxE,iBAAiB,WAA4B,OAAO,gBAAgB;CACpE,kBAAkB,WAA4B,OAAO,iBAAiB;CACvE;AAUD,IAAM,YAAe,UACnB,OAAO,UAAU;AAEnB,IAAM,YAAe,UACnB,SAAY,MAAM,GAAG,QAAQ,eAAe,MAAM;AAEpD,IAAa,iBACX,QACA,QAC+B;CAC/B,MAAM,eAAe,SAAS,OAAO;AAErC,QAAO,eAAe;EACpB,MAAM,UAAU,cAAc;AAC9B,MAAI,CAAC,QACH;AAGF,MAAI,OAAO,UAAU,eAAe,KAAK,eAAe,IAAI,EAAE;GAC5D,MAAM,SAAS,cAAc;AAC7B,UAAO,OAAO,QAAQ;;AAGxB,MAAI,IAAI,WAAW,UAAU,EAAE;GAC7B,MAAM,WAAW,IAAI,MAAM,EAAiB;AAC5C,UAAO,QAAQ,UAAU,GAAG;;GAI9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/client",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-beta.1",
|
|
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",
|
|
@@ -22,17 +22,21 @@
|
|
|
22
22
|
"pixi.js": "^8.9.2"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@rpgjs/
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
25
|
+
"@rpgjs/client": "5.0.0-beta.1",
|
|
26
|
+
"@rpgjs/common": "5.0.0-beta.1",
|
|
27
|
+
"@rpgjs/server": "5.0.0-beta.1",
|
|
28
|
+
"@rpgjs/ui-css": "5.0.0-beta.1",
|
|
29
|
+
"@signe/di": "^2.9.0",
|
|
30
|
+
"@signe/room": "^2.9.0",
|
|
31
|
+
"@signe/sync": "^2.9.0",
|
|
32
|
+
"pixi-filters": "^6.1.5",
|
|
29
33
|
"rxjs": "^7.8.2"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"@canvasengine/compiler": "2.0.0-beta.
|
|
33
|
-
"vite": "^
|
|
34
|
-
"vite-plugin-dts": "^4.5.
|
|
35
|
-
"vitest": "^
|
|
36
|
+
"@canvasengine/compiler": "2.0.0-beta.56",
|
|
37
|
+
"vite": "^8.0.3",
|
|
38
|
+
"vite-plugin-dts": "^4.5.4",
|
|
39
|
+
"vitest": "^4.1.2"
|
|
36
40
|
},
|
|
37
41
|
"type": "module",
|
|
38
42
|
"scripts": {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { generateUID, RpgCommonPlayer } from "@rpgjs/common";
|
|
2
2
|
import { signal } from "canvasengine";
|
|
3
3
|
|
|
4
|
-
export class
|
|
4
|
+
export class AnimationManager {
|
|
5
5
|
current = signal<any[]>([]);
|
|
6
6
|
|
|
7
|
-
displayEffect(params: any, player: RpgCommonPlayer) {
|
|
7
|
+
displayEffect(params: any, player: RpgCommonPlayer | { x: number, y: number }) {
|
|
8
8
|
const id = generateUID();
|
|
9
9
|
this.current().push({
|
|
10
10
|
...params,
|
|
11
11
|
id,
|
|
12
12
|
x: player.x,
|
|
13
13
|
y: player.y,
|
|
14
|
+
object: player,
|
|
14
15
|
onFinish: () => {
|
|
15
16
|
const index = this.current().findIndex((value) => value.id === id);
|
|
16
17
|
this.current().splice(index, 1);
|
package/src/Game/Event.ts
CHANGED
package/src/Game/Map.ts
CHANGED
|
@@ -1,10 +1,102 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
RpgCommonMap,
|
|
3
|
+
type WeatherState,
|
|
4
|
+
type MapPhysicsInitContext,
|
|
5
|
+
type MapPhysicsEntityContext,
|
|
6
|
+
} from "@rpgjs/common";
|
|
2
7
|
import { sync, users } from "@signe/sync";
|
|
3
8
|
import { RpgClientPlayer } from "./Player";
|
|
4
|
-
import { Signal, signal } from "canvasengine";
|
|
9
|
+
import { Signal, signal, computed, effect } from "canvasengine";
|
|
5
10
|
import { RpgClientEvent } from "./Event";
|
|
11
|
+
import { RpgClientEngine } from "../RpgClientEngine";
|
|
12
|
+
import { inject } from "../core/inject";
|
|
6
13
|
|
|
7
|
-
export class RpgClientMap extends RpgCommonMap<
|
|
14
|
+
export class RpgClientMap extends RpgCommonMap<any> {
|
|
15
|
+
engine: RpgClientEngine = inject(RpgClientEngine)
|
|
8
16
|
@users(RpgClientPlayer) players = signal<Record<string, RpgClientPlayer>>({});
|
|
9
17
|
@sync(RpgClientEvent) events = signal<Record<string, RpgClientEvent>>({});
|
|
18
|
+
currentPlayer = computed(() => this.players()[this.engine.playerIdSignal()!])
|
|
19
|
+
weatherState = signal<WeatherState | null>(null);
|
|
20
|
+
localWeatherOverride = signal<WeatherState | null>(null);
|
|
21
|
+
weather = computed<WeatherState | null>(() => {
|
|
22
|
+
const local = this.localWeatherOverride()
|
|
23
|
+
const state = this.weatherState()
|
|
24
|
+
return local ?? state
|
|
25
|
+
});
|
|
26
|
+
private manualClientPhysicsTick = false;
|
|
27
|
+
private readonly isTestEnvironment: boolean;
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
// Détecter l'environnement de test
|
|
32
|
+
const isTest = (typeof process !== 'undefined' && process.env?.TEST === 'true')
|
|
33
|
+
|| (typeof window !== 'undefined' && (window as any).__RPGJS_TEST__ === true);
|
|
34
|
+
this.isTestEnvironment = isTest;
|
|
35
|
+
if (isTest) {
|
|
36
|
+
this.autoTickEnabled = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
configureClientPrediction(enabled: boolean): void {
|
|
41
|
+
this.manualClientPhysicsTick = enabled;
|
|
42
|
+
this.autoTickEnabled = enabled ? false : !this.isTestEnvironment;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getCurrentPlayer() {
|
|
46
|
+
return this.currentPlayer()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
reset(force = false) {
|
|
50
|
+
const currentPlayerId = this.engine.playerIdSignal();
|
|
51
|
+
const currentPlayer = !force && currentPlayerId
|
|
52
|
+
? this.players()[currentPlayerId]
|
|
53
|
+
: undefined;
|
|
54
|
+
|
|
55
|
+
this.players.set(
|
|
56
|
+
currentPlayerId && currentPlayer ? { [currentPlayerId]: currentPlayer } : {}
|
|
57
|
+
);
|
|
58
|
+
this.events.set({})
|
|
59
|
+
this.weatherState.set(null);
|
|
60
|
+
this.localWeatherOverride.set(null);
|
|
61
|
+
this.clearPhysic()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getWeather(): WeatherState | null {
|
|
65
|
+
return this.weather();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
setLocalWeather(next: WeatherState | null): void {
|
|
69
|
+
this.localWeatherOverride.set(next);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
clearLocalWeather(): void {
|
|
73
|
+
this.localWeatherOverride.set(null);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
stepClientPhysics(deltaMs: number): number {
|
|
77
|
+
if (!this.manualClientPhysicsTick) {
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
return this.nextTick(deltaMs);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
stepPredictionTick(): void {
|
|
84
|
+
this.forceSingleTick();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected emitPhysicsInit(context: MapPhysicsInitContext): void {
|
|
88
|
+
this.engine?.emitSceneMapHook?.("onPhysicsInit", this, context);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected emitPhysicsEntityAdd(context: MapPhysicsEntityContext): void {
|
|
92
|
+
this.engine?.emitSceneMapHook?.("onPhysicsEntityAdd", this, context);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
protected emitPhysicsEntityRemove(context: MapPhysicsEntityContext): void {
|
|
96
|
+
this.engine?.emitSceneMapHook?.("onPhysicsEntityRemove", this, context);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected emitPhysicsReset(): void {
|
|
100
|
+
this.engine?.emitSceneMapHook?.("onPhysicsReset", this);
|
|
101
|
+
}
|
|
10
102
|
}
|