@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,103 @@
|
|
|
1
|
+
import type { SaveSlotList, SaveSlotMeta } from "@rpgjs/common";
|
|
2
|
+
import { inject } from "../core/inject";
|
|
3
|
+
import { AbstractWebsocket, WebSocketToken } from "./AbstractSocket";
|
|
4
|
+
|
|
5
|
+
export const SaveClientToken = "SaveClientToken";
|
|
6
|
+
|
|
7
|
+
type SaveListResult = {
|
|
8
|
+
requestId: string;
|
|
9
|
+
slots: SaveSlotList;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type SaveSaveResult = {
|
|
13
|
+
requestId: string;
|
|
14
|
+
index: number;
|
|
15
|
+
slots: SaveSlotList;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type SaveLoadResult = {
|
|
19
|
+
requestId: string;
|
|
20
|
+
index: number;
|
|
21
|
+
ok: boolean;
|
|
22
|
+
slot?: SaveSlotMeta;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type SaveErrorResult = {
|
|
26
|
+
requestId: string;
|
|
27
|
+
message: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type PendingRequest = {
|
|
31
|
+
resolve: (value: any) => void;
|
|
32
|
+
reject: (error: Error) => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export class SaveClientService {
|
|
36
|
+
private webSocket: AbstractWebsocket = inject(WebSocketToken);
|
|
37
|
+
private pending: Map<string, PendingRequest> = new Map();
|
|
38
|
+
private requestCounter = 0;
|
|
39
|
+
|
|
40
|
+
initialize() {
|
|
41
|
+
const saveListResult = (data: SaveListResult) => this.resolveRequest(data.requestId, data);
|
|
42
|
+
const saveSaveResult = (data: SaveSaveResult) => this.resolveRequest(data.requestId, data);
|
|
43
|
+
const saveLoadResult = (data: SaveLoadResult) => this.resolveRequest(data.requestId, data);
|
|
44
|
+
const saveErrorResult = (data: SaveErrorResult) => this.rejectRequest(data.requestId, data.message);
|
|
45
|
+
this.webSocket.off("save.list.result", saveListResult);
|
|
46
|
+
this.webSocket.off("save.save.result", saveSaveResult);
|
|
47
|
+
this.webSocket.off("save.load.result", saveLoadResult);
|
|
48
|
+
this.webSocket.off("save.error", saveErrorResult);
|
|
49
|
+
this.webSocket.on("save.list.result", saveListResult);
|
|
50
|
+
this.webSocket.on("save.save.result", saveSaveResult);
|
|
51
|
+
this.webSocket.on("save.load.result", saveLoadResult);
|
|
52
|
+
this.webSocket.on("save.error", saveErrorResult);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
listSlots(): Promise<SaveSlotList> {
|
|
56
|
+
return this.request<SaveListResult>("save.list", {}).then((result) => result.slots);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
saveSlot(index: number, meta: SaveSlotMeta = {}): Promise<SaveSlotList> {
|
|
60
|
+
return this.request<SaveSaveResult>("save.save", { index, meta }).then((result) => result.slots);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
loadSlot(index: number): Promise<boolean> {
|
|
64
|
+
return this.request<SaveLoadResult>("save.load", { index }).then((result) => result.ok);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private request<T>(event: string, payload: Record<string, any>): Promise<T> {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
if (!this.webSocket) {
|
|
70
|
+
this.initialize();
|
|
71
|
+
}
|
|
72
|
+
const requestId = this.nextRequestId();
|
|
73
|
+
this.pending.set(requestId, { resolve, reject });
|
|
74
|
+
this.webSocket?.emit(event, { requestId, ...payload });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private resolveRequest(requestId: string, result: any) {
|
|
79
|
+
const pending = this.pending.get(requestId);
|
|
80
|
+
if (!pending) return;
|
|
81
|
+
this.pending.delete(requestId);
|
|
82
|
+
pending.resolve(result);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private rejectRequest(requestId: string, message: string) {
|
|
86
|
+
const pending = this.pending.get(requestId);
|
|
87
|
+
if (!pending) return;
|
|
88
|
+
this.pending.delete(requestId);
|
|
89
|
+
pending.reject(new Error(message));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private nextRequestId(): string {
|
|
93
|
+
this.requestCounter += 1;
|
|
94
|
+
return `${Date.now()}-${this.requestCounter}`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function provideSaveClient() {
|
|
99
|
+
return {
|
|
100
|
+
provide: SaveClientService,
|
|
101
|
+
useClass: SaveClientService,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -1,29 +1,55 @@
|
|
|
1
|
-
import { AbstractWebsocket, WebSocketToken } from "./AbstractSocket";
|
|
1
|
+
import { AbstractWebsocket, SocketUpdateProperties, WebSocketToken } from "./AbstractSocket";
|
|
2
2
|
import { ClientIo, ServerIo } from "@signe/room";
|
|
3
3
|
import { Context } from "@signe/di";
|
|
4
4
|
import { RpgClientEngine } from "../RpgClientEngine";
|
|
5
5
|
import { UpdateMapService, UpdateMapToken } from "@rpgjs/common";
|
|
6
6
|
import { LoadMapToken } from "./loadMap";
|
|
7
7
|
import { RpgGui } from "../Gui/Gui";
|
|
8
|
+
import { provideKeyboardControls } from "./keyboardControls";
|
|
9
|
+
import { provideSaveClient } from "./save";
|
|
8
10
|
|
|
9
11
|
type ServerIo = any;
|
|
10
12
|
type ClientIo = any;
|
|
11
13
|
|
|
14
|
+
interface StandaloneOptions {
|
|
15
|
+
env?: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
class BridgeWebsocket extends AbstractWebsocket {
|
|
13
19
|
private room: ServerIo;
|
|
14
20
|
private socket: ClientIo;
|
|
21
|
+
private pendingOn: Array<{ event: string; callback: (data: any) => void }> = [];
|
|
22
|
+
private rooms = {
|
|
23
|
+
partyFn: async (roomId: string) => {
|
|
24
|
+
this.room = new ServerIo(roomId, this.rooms);
|
|
25
|
+
const server = new this.server(this.room)
|
|
26
|
+
await server.onStart();
|
|
27
|
+
await server.subRoom.onStart()
|
|
28
|
+
this.context.set('server', server)
|
|
29
|
+
return server
|
|
30
|
+
},
|
|
31
|
+
env: {}
|
|
32
|
+
}
|
|
33
|
+
private serverInstance: any;
|
|
15
34
|
|
|
16
|
-
constructor(protected context: Context, private server: any) {
|
|
35
|
+
constructor(protected context: Context, private server: any, options: StandaloneOptions = {}) {
|
|
17
36
|
super(context);
|
|
18
37
|
// fake room
|
|
19
|
-
this.
|
|
38
|
+
this.rooms.env = options.env || {};
|
|
39
|
+
this.room = new ServerIo("lobby-1", this.rooms);
|
|
20
40
|
}
|
|
21
41
|
|
|
22
42
|
async connection(listeners?: (data: any) => void) {
|
|
23
|
-
|
|
24
|
-
await
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
43
|
+
this.serverInstance = new this.server(this.room);
|
|
44
|
+
await this.serverInstance.onStart();
|
|
45
|
+
await this.serverInstance.subRoom.onStart()
|
|
46
|
+
this.context.set('server', this.serverInstance)
|
|
47
|
+
return this._connection(listeners)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private async _connection(listeners?: (data: any) => void) {
|
|
51
|
+
this.serverInstance = this.context.get('server')
|
|
52
|
+
this.socket = new ClientIo(this.serverInstance, 'player-client-id');
|
|
27
53
|
const url = new URL('http://localhost')
|
|
28
54
|
const request = new Request(url.toString(), {
|
|
29
55
|
method: 'GET',
|
|
@@ -32,21 +58,29 @@ class BridgeWebsocket extends AbstractWebsocket {
|
|
|
32
58
|
}
|
|
33
59
|
})
|
|
34
60
|
listeners?.(this.socket)
|
|
35
|
-
await
|
|
61
|
+
await this.serverInstance.onConnect(this.socket.conn as any, { request } as any);
|
|
36
62
|
this.room.clients.set(this.socket.id, this.socket);
|
|
63
|
+
this.pendingOn.forEach(({ event, callback }) => this.socket.addEventListener(event, callback));
|
|
64
|
+
this.pendingOn = [];
|
|
37
65
|
return this.socket
|
|
38
66
|
}
|
|
39
67
|
|
|
40
68
|
on(key: string, callback: (data: any) => void) {
|
|
41
|
-
|
|
69
|
+
const handler = (event) => {
|
|
42
70
|
const object = JSON.parse(event);
|
|
43
71
|
if (object.type === key) {
|
|
44
72
|
callback(object.value);
|
|
45
73
|
}
|
|
46
|
-
}
|
|
74
|
+
};
|
|
75
|
+
if (!this.socket) {
|
|
76
|
+
this.pendingOn.push({ event: "message", callback: handler });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this.socket.addEventListener("message", handler);
|
|
47
80
|
}
|
|
48
81
|
|
|
49
82
|
off(event: string, callback: (data: any) => void) {
|
|
83
|
+
if (!this.socket) return;
|
|
50
84
|
this.socket.removeEventListener(event, callback);
|
|
51
85
|
}
|
|
52
86
|
|
|
@@ -57,24 +91,80 @@ class BridgeWebsocket extends AbstractWebsocket {
|
|
|
57
91
|
});
|
|
58
92
|
}
|
|
59
93
|
|
|
60
|
-
|
|
61
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Update underlying connection properties before a reconnect
|
|
96
|
+
*
|
|
97
|
+
* Design
|
|
98
|
+
* - Dynamically register a factory for the requested room to ensure a fresh server instance
|
|
99
|
+
* - Swap the internal ServerIo to target the new room
|
|
100
|
+
*
|
|
101
|
+
* @param params - Properties to update
|
|
102
|
+
* @param params.room - The target room id (e.g. `map-simplemap2`)
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* websocket.updateProperties({ room: 'map-simplemap2' })
|
|
107
|
+
* await websocket.reconnect()
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
updateProperties(_params: SocketUpdateProperties) {
|
|
111
|
+
// empty
|
|
62
112
|
}
|
|
63
113
|
|
|
64
|
-
|
|
65
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Reconnect the client to the current Party room
|
|
116
|
+
*
|
|
117
|
+
* Design
|
|
118
|
+
* - Must be called after `updateProperties()` when switching rooms
|
|
119
|
+
* - Rebuilds the client <-> server bridge and re-triggers connection listeners
|
|
120
|
+
*
|
|
121
|
+
* @param listeners - Optional callback to re-bind event handlers on the new socket
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* websocket.updateProperties({ room: 'map-dungeon' })
|
|
126
|
+
* await websocket.reconnect((socket) => {
|
|
127
|
+
* // re-bind events here
|
|
128
|
+
* })
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
async reconnect(listeners?: (data: any) => void): Promise<void> {
|
|
132
|
+
await this._connection((socket) => {
|
|
66
133
|
listeners?.(socket)
|
|
67
134
|
})
|
|
68
135
|
}
|
|
136
|
+
|
|
137
|
+
getServer() {
|
|
138
|
+
return this.serverInstance
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getSocket() {
|
|
142
|
+
return this.socket
|
|
143
|
+
}
|
|
69
144
|
}
|
|
70
145
|
|
|
71
146
|
class UpdateMapStandaloneService extends UpdateMapService {
|
|
72
147
|
private server: any;
|
|
73
148
|
|
|
74
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Update the current room map data on the server side
|
|
151
|
+
*
|
|
152
|
+
* Design
|
|
153
|
+
* - Uses the in-memory server instance stored in context (standalone mode)
|
|
154
|
+
* - Builds a local HTTP-like request to the current Party room endpoint
|
|
155
|
+
*
|
|
156
|
+
* @param map - The map payload to apply on the server
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* await updateMapService.update({ width: 1024, height: 768, events: [] })
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
async update(map: any) {
|
|
75
164
|
this.server = this.context.get('server')
|
|
165
|
+
const roomId = this.server?.room?.id ?? 'lobby-1'
|
|
76
166
|
const req = {
|
|
77
|
-
url: `http://localhost/parties/main/${
|
|
167
|
+
url: `http://localhost/parties/main/${roomId}/map/update`,
|
|
78
168
|
method: 'POST',
|
|
79
169
|
headers: new Headers({}),
|
|
80
170
|
json: async () => {
|
|
@@ -85,16 +175,18 @@ class UpdateMapStandaloneService extends UpdateMapService {
|
|
|
85
175
|
}
|
|
86
176
|
}
|
|
87
177
|
|
|
88
|
-
export function provideRpg(server: any) {
|
|
178
|
+
export function provideRpg(server: any, options: StandaloneOptions = {}) {
|
|
89
179
|
return [
|
|
90
180
|
{
|
|
91
181
|
provide: WebSocketToken,
|
|
92
|
-
useFactory: (context: Context) => new BridgeWebsocket(context, server),
|
|
182
|
+
useFactory: (context: Context) => new BridgeWebsocket(context, server, options),
|
|
93
183
|
},
|
|
94
184
|
{
|
|
95
185
|
provide: UpdateMapToken,
|
|
96
186
|
useClass: UpdateMapStandaloneService,
|
|
97
187
|
},
|
|
188
|
+
provideKeyboardControls(),
|
|
189
|
+
provideSaveClient(),
|
|
98
190
|
RpgGui,
|
|
99
191
|
RpgClientEngine,
|
|
100
192
|
];
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { computed, Signal } from "canvasengine";
|
|
2
|
+
import { RpgClientObject } from "../Game/Object";
|
|
3
|
+
|
|
4
|
+
const BUILTIN_PARAM_KEYS = [
|
|
5
|
+
"maxHp",
|
|
6
|
+
"maxSp",
|
|
7
|
+
"atk",
|
|
8
|
+
"pdef",
|
|
9
|
+
"sdef",
|
|
10
|
+
"str",
|
|
11
|
+
"agi",
|
|
12
|
+
"int",
|
|
13
|
+
"dex",
|
|
14
|
+
] as const;
|
|
15
|
+
|
|
16
|
+
type BuiltInParamKey = typeof BUILTIN_PARAM_KEYS[number];
|
|
17
|
+
type ParamPropKey = `params.${BuiltInParamKey}` | `params.${string}`;
|
|
18
|
+
|
|
19
|
+
const entityPropMap = {
|
|
20
|
+
level: (entity: RpgClientObject) => entity._level(),
|
|
21
|
+
exp: (entity: RpgClientObject) => entity._exp(),
|
|
22
|
+
gold: (entity: RpgClientObject) => entity._gold(),
|
|
23
|
+
hp: (entity: RpgClientObject) => entity.hpSignal(),
|
|
24
|
+
sp: (entity: RpgClientObject) => entity.spSignal(),
|
|
25
|
+
name: (entity: RpgClientObject) => entity.name(),
|
|
26
|
+
type: (entity: RpgClientObject) => entity.type(),
|
|
27
|
+
x: (entity: RpgClientObject) => entity.x(),
|
|
28
|
+
y: (entity: RpgClientObject) => entity.y(),
|
|
29
|
+
z: (entity: RpgClientObject) => entity.z(),
|
|
30
|
+
tint: (entity: RpgClientObject) => entity.tint(),
|
|
31
|
+
direction: (entity: RpgClientObject) => entity.direction(),
|
|
32
|
+
speed: (entity: RpgClientObject) => entity.speed(),
|
|
33
|
+
hitbox: (entity: RpgClientObject) => entity.hitbox(),
|
|
34
|
+
animation: (entity: RpgClientObject) => entity.animationName(),
|
|
35
|
+
canMove: (entity: RpgClientObject) => entity.canMove(),
|
|
36
|
+
graphics: (entity: RpgClientObject) => entity.graphics(),
|
|
37
|
+
items: (entity: RpgClientObject) => entity.items(),
|
|
38
|
+
equipments: (entity: RpgClientObject) => entity.equipments(),
|
|
39
|
+
states: (entity: RpgClientObject) => entity.states(),
|
|
40
|
+
skills: (entity: RpgClientObject) => entity.skills(),
|
|
41
|
+
effects: (entity: RpgClientObject) => entity._effects(),
|
|
42
|
+
componentsTop: (entity: RpgClientObject) => entity.componentsTop(),
|
|
43
|
+
componentsBottom: (entity: RpgClientObject) => entity.componentsBottom(),
|
|
44
|
+
componentsCenter: (entity: RpgClientObject) => entity.componentsCenter(),
|
|
45
|
+
componentsLeft: (entity: RpgClientObject) => entity.componentsLeft(),
|
|
46
|
+
componentsRight: (entity: RpgClientObject) => entity.componentsRight(),
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
type EntityPropMap = typeof entityPropMap;
|
|
50
|
+
type EntityPropKey = keyof EntityPropMap | ParamPropKey;
|
|
51
|
+
type EntityPropValue<K extends EntityPropKey> = K extends keyof EntityPropMap
|
|
52
|
+
? ReturnType<EntityPropMap[K]>
|
|
53
|
+
: K extends `params.${string}`
|
|
54
|
+
? number | undefined
|
|
55
|
+
: never;
|
|
56
|
+
|
|
57
|
+
const isSignal = <T>(value: unknown): value is Signal<T> =>
|
|
58
|
+
typeof value === "function";
|
|
59
|
+
|
|
60
|
+
const toSignal = <T>(value: Signal<T> | T): Signal<T> =>
|
|
61
|
+
isSignal<T>(value) ? value : computed(() => value);
|
|
62
|
+
|
|
63
|
+
export const getEntityProp = <K extends EntityPropKey>(
|
|
64
|
+
entity: Signal<RpgClientObject | undefined> | RpgClientObject | undefined,
|
|
65
|
+
key: K
|
|
66
|
+
): Signal<EntityPropValue<K>> => {
|
|
67
|
+
const entitySignal = toSignal(entity);
|
|
68
|
+
|
|
69
|
+
return computed(() => {
|
|
70
|
+
const current = entitySignal();
|
|
71
|
+
if (!current) {
|
|
72
|
+
return undefined as EntityPropValue<K>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (Object.prototype.hasOwnProperty.call(entityPropMap, key)) {
|
|
76
|
+
const getter = entityPropMap[key as keyof EntityPropMap];
|
|
77
|
+
return getter(current) as EntityPropValue<K>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (key.startsWith("params.")) {
|
|
81
|
+
const paramKey = key.slice("params.".length);
|
|
82
|
+
return current._param?.()?.[paramKey] as EntityPropValue<K>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return undefined as EntityPropValue<K>;
|
|
86
|
+
});
|
|
87
|
+
};
|
package/vite.config.ts
CHANGED
|
@@ -19,9 +19,11 @@ export default defineConfig({
|
|
|
19
19
|
sourcemap: true,
|
|
20
20
|
minify: false,
|
|
21
21
|
lib: {
|
|
22
|
-
entry:
|
|
22
|
+
entry: {
|
|
23
|
+
index: 'src/index.ts'
|
|
24
|
+
},
|
|
23
25
|
formats: ['es'],
|
|
24
|
-
fileName:
|
|
26
|
+
fileName: (format, entryName) => `${entryName}.js`
|
|
25
27
|
},
|
|
26
28
|
rollupOptions: {
|
|
27
29
|
external: [/@rpgjs/, 'esbuild', 'canvasengine', '@canvasengine/presets', 'rxjs', 'pixi.js'],
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
package/dist/index10.js
DELETED
package/dist/index10.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index10.js","sources":["../src/components/gui/index.ts"],"sourcesContent":["import Dialogbox from \"./dialogbox/index.ce\";\n\nexport const PrebuiltGui = {\n Dialogbox\n}"],"names":["Dialogbox"],"mappings":";;AAEO,MAAM,WAAc,GAAA;AAAA,aACvBA;AACJ;;;;"}
|
package/dist/index11.js
DELETED
package/dist/index11.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index11.js","sources":["../src/components/effects/index.ts"],"sourcesContent":["import Hit from \"./hit.ce\";\nimport Animation from \"./animation.ce\";\n\nexport const PrebuiltEffects = {\n Hit,\n Animation\n}"],"names":["Hit","Animation"],"mappings":";;;AAGO,MAAM,eAAkB,GAAA;AAAA,OAC3BA,WAAA;AAAA,aACAC;AACJ;;;;"}
|
package/dist/index12.js
DELETED
package/dist/index12.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index12.js","sources":["../src/presets/index.ts"],"sourcesContent":["import { RMSpritesheet } from \"./rmspritesheet\";\n\nexport const Presets = {\n RMSpritesheet\n}"],"names":[],"mappings":";;AAEO,MAAM,OAAU,GAAA;AAAA,EACnB;AACJ;;;;"}
|
package/dist/index13.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useProps, useDefineProps, h, Container, loop } from 'canvasengine';
|
|
2
|
-
import { inject } from './index6.js';
|
|
3
|
-
import { RpgClientEngine } from './index2.js';
|
|
4
|
-
import component$1 from './index14.js';
|
|
5
|
-
|
|
6
|
-
function component($$props) {
|
|
7
|
-
useProps($$props);
|
|
8
|
-
useDefineProps($$props);
|
|
9
|
-
var engine = inject(RpgClientEngine);
|
|
10
|
-
var players = engine.sceneMap.players;
|
|
11
|
-
var events = engine.sceneMap.events;
|
|
12
|
-
let $this = h(Container, { sortableChildren: true }, [loop(events, (event, id) => h(component$1, { id: id, object: event })), loop(players, (player, id) => h(component$1, { id: id, object: player }))]);
|
|
13
|
-
return $this
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { component as default };
|
|
17
|
-
//# sourceMappingURL=index13.js.map
|
package/dist/index13.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index13.js","sources":["../src/components/scenes/event-layer.ce"],"sourcesContent":["<Container sortableChildren={true}>\n @for ((event,id) of events) {\n <Character id={id} object={event} />\n }\n\n @for ((player,id) of players) {\n <Character id={id} object={player} />\n }\n</Container>\n\n<script>\n import { effect, signal } from 'canvasengine'\n import { inject } from \"../../core/inject\";\n import { RpgClientEngine } from \"../../RpgClientEngine\";\n import Character from \"../character.ce\";\n \n const engine = inject(RpgClientEngine);\n const players = engine.sceneMap.players\n const events = engine.sceneMap.events\n</script>"],"names":["Character"],"mappings":";;;;;AAQqB,SAAS,SAAS,CAAC,OAAO,EAAE;AACjD,QAAuB,QAAQ,CAAC,OAAO;AACvC,QAA4B,cAAc,CAAC,OAAO;AAClD,QAAQ,IAAI,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;AAC5C,IAAI,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO;AACrC,IAAI,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC7B,QAAQ,IAAI,KAAK,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAACA,WAAS,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,CAACA,WAAS,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AAC5M,QAAQ,OAAO;AACf;;;;"}
|
package/dist/index14.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { useProps, useDefineProps, computed, signal, mount, tick, h, Container, loop, Sprite } from 'canvasengine';
|
|
2
|
-
import { Particle } from '@canvasengine/presets';
|
|
3
|
-
import { Direction, ModulesToken } from '@rpgjs/common';
|
|
4
|
-
import { RpgClientEngine } from './index2.js';
|
|
5
|
-
import { inject } from './index6.js';
|
|
6
|
-
|
|
7
|
-
function component($$props) {
|
|
8
|
-
useProps($$props);
|
|
9
|
-
const defineProps = useDefineProps($$props);
|
|
10
|
-
var _a = defineProps(), object = _a.object, id = _a.id;
|
|
11
|
-
var client = inject(RpgClientEngine);
|
|
12
|
-
var hooks = inject(ModulesToken);
|
|
13
|
-
var spritesheets = client.spritesheets;
|
|
14
|
-
var playerId = client.playerId;
|
|
15
|
-
var componentsBehind = client.spriteComponentsBehind;
|
|
16
|
-
var componentsInFront = client.spriteComponentsInFront;
|
|
17
|
-
var isMe = computed(function () { return id() === playerId; });
|
|
18
|
-
var x = object.x;
|
|
19
|
-
var y = object.y;
|
|
20
|
-
var tint = object.tint;
|
|
21
|
-
var direction = object.direction;
|
|
22
|
-
var animationName = object.animationName;
|
|
23
|
-
var emitParticleTrigger = object.emitParticleTrigger;
|
|
24
|
-
var particleSettings = client.particleSettings;
|
|
25
|
-
var particleName = object.particleName;
|
|
26
|
-
var graphics = object.graphics;
|
|
27
|
-
var hitbox = object.hitbox;
|
|
28
|
-
var widthShadow = 10;
|
|
29
|
-
computed(function () { return ({
|
|
30
|
-
x: hitbox().w / 2,
|
|
31
|
-
y: hitbox().h - (hitbox().h / 2),
|
|
32
|
-
width: hitbox().w + widthShadow,
|
|
33
|
-
height: hitbox().h,
|
|
34
|
-
}); });
|
|
35
|
-
var canControls = function () { return isMe() && object.canMove(); };
|
|
36
|
-
var keyboardControls = client.globalConfig.keyboardControls;
|
|
37
|
-
var controls = signal({
|
|
38
|
-
down: {
|
|
39
|
-
repeat: true,
|
|
40
|
-
bind: keyboardControls.down,
|
|
41
|
-
keyDown: function () {
|
|
42
|
-
if (canControls())
|
|
43
|
-
client.processInput({ input: Direction.Down });
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
up: {
|
|
47
|
-
repeat: true,
|
|
48
|
-
bind: keyboardControls.up,
|
|
49
|
-
keyDown: function () {
|
|
50
|
-
if (canControls())
|
|
51
|
-
client.processInput({ input: Direction.Up });
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
left: {
|
|
55
|
-
repeat: true,
|
|
56
|
-
bind: keyboardControls.left,
|
|
57
|
-
keyDown: function () {
|
|
58
|
-
if (canControls())
|
|
59
|
-
client.processInput({ input: Direction.Left });
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
right: {
|
|
63
|
-
repeat: true,
|
|
64
|
-
bind: keyboardControls.right,
|
|
65
|
-
keyDown: function () {
|
|
66
|
-
if (canControls())
|
|
67
|
-
client.processInput({ input: Direction.Right });
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
action: {
|
|
71
|
-
bind: keyboardControls.action,
|
|
72
|
-
keyDown: function () {
|
|
73
|
-
if (canControls()) {
|
|
74
|
-
client.processAction({ action: 'action' });
|
|
75
|
-
// particleName.set('hit')
|
|
76
|
-
// emitParticleTrigger.start()
|
|
77
|
-
// object.flash('red')
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
var sheet = function (graphicId) {
|
|
83
|
-
return {
|
|
84
|
-
definition: spritesheets.get(graphicId),
|
|
85
|
-
playing: animationName,
|
|
86
|
-
params: {
|
|
87
|
-
direction: direction
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
mount(function (element) {
|
|
92
|
-
hooks.callHooks("client-sprite-onInit", element.componentInstance);
|
|
93
|
-
hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, element.componentInstance);
|
|
94
|
-
return function () {
|
|
95
|
-
hooks.callHooks("client-sprite-onDestroy", element.componentInstance);
|
|
96
|
-
hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, element.componentInstance);
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
tick(function () {
|
|
100
|
-
hooks.callHooks("client-sprite-onUpdate");
|
|
101
|
-
});
|
|
102
|
-
let $this = h(Container, { x, y, zIndex: y, viewportFollow: isMe, controls }, [loop(componentsBehind, component => h(Container, null, h(component, { object }))), h(Particle, { emit: emitParticleTrigger, settings: particleSettings, zIndex: 1000, name: particleName }), h(Container, null, loop(graphics, graphicId => h(Sprite, { sheet: sheet(graphicId), direction, tint }))), loop(componentsInFront, component => h(Container, null, h(component, { object })))]);
|
|
103
|
-
return $this
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export { component as default };
|
|
107
|
-
//# sourceMappingURL=index14.js.map
|
package/dist/index14.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index14.js","sources":["../src/components/character.ce"],"sourcesContent":["<Container x y zIndex={y} viewportFollow={isMe} controls>\n @for (component of componentsBehind) {\n <Container>\n <component object />\n </Container>\n } \n <Particle emit={@emitParticleTrigger} settings={@particleSettings} zIndex={1000} name={particleName} />\n <Container>\n @for (graphicId of graphics) {\n <Sprite sheet={@sheet(@graphicId)} direction tint />\n }\n </Container>\n @for (component of componentsInFront) {\n <Container>\n <component object />\n </Container>\n } \n <!-- <Ellipse \n x={shadow.@x} \n y={shadow.@y} \n width={shadow.@width} \n height={shadow.@height} \n color=\"black\" \n blur={10} \n alpha={0.5}\n /> -->\n</Container>\n\n<script>\n import { signal, effect, mount, computed, tick } from \"canvasengine\";\n import { Particle } from \"@canvasengine/presets\";\n import { GameEngineToken, ModulesToken } from \"@rpgjs/common\";\n import { RpgClientEngine } from \"../RpgClientEngine\";\n import { inject } from \"../core/inject\"; \n import { Direction } from \"@rpgjs/common\";\n import Hit from \"./effects/hit.ce\";\n\n const { object, id } = defineProps();\n \n const client = inject(RpgClientEngine);\n const hooks = inject(ModulesToken);\n\n const spritesheets = client.spritesheets;\n const playerId = client.playerId;\n const componentsBehind = client.spriteComponentsBehind;\n const componentsInFront = client.spriteComponentsInFront;\n const isMe = computed(() => id() === playerId);\n\n const x = object.x;\n const y = object.y;\n const tint = object.tint;\n const direction = object.direction;\n const animationName = object.animationName;\n const emitParticleTrigger = object.emitParticleTrigger;\n const particleSettings = client.particleSettings;\n const particleName = object.particleName;\n const graphics = object.graphics;\n\n const hitbox = object.hitbox;\n const widthShadow = 10;\n const shadow = computed(() => ({\n x: hitbox().w / 2,\n y: hitbox().h - (hitbox().h / 2),\n width: hitbox().w + widthShadow,\n height: hitbox().h,\n }))\n const canControls = () => isMe() && object.canMove()\n const keyboardControls = client.globalConfig.keyboardControls;\n\n const controls = signal({\n down: {\n repeat: true,\n bind: keyboardControls.down,\n keyDown() {\n if (canControls()) client.processInput({ input: Direction.Down })\n },\n },\n up: {\n repeat: true,\n bind: keyboardControls.up,\n keyDown() {\n if (canControls()) client.processInput({ input: Direction.Up })\n },\n },\n left: {\n repeat: true,\n bind: keyboardControls.left,\n keyDown() {\n if (canControls()) client.processInput({ input: Direction.Left })\n },\n },\n right: {\n repeat: true,\n bind: keyboardControls.right,\n keyDown() {\n if (canControls()) client.processInput({ input: Direction.Right })\n },\n },\n action: {\n bind: keyboardControls.action,\n keyDown() {\n if (canControls()) {\n client.processAction({ action: 'action' })\n // particleName.set('hit') \n // emitParticleTrigger.start()\n // object.flash('red')\n }\n },\n },\n });\n\n const sheet = (graphicId) => {\n return {\n definition: spritesheets.get(graphicId),\n playing: animationName,\n params: {\n direction\n },\n };\n }\n\n mount((element) => {\n hooks.callHooks(\"client-sprite-onInit\", element.componentInstance)\n hooks.callHooks(\"client-sceneMap-onAddSprite\", client.sceneMap, element.componentInstance)\n\n return () => {\n hooks.callHooks(\"client-sprite-onDestroy\", element.componentInstance)\n hooks.callHooks(\"client-sceneMap-onRemoveSprite\", client.sceneMap, element.componentInstance)\n }\n })\n\n tick(() => {\n hooks.callHooks(\"client-sprite-onUpdate\")\n })\n</script>"],"names":[],"mappings":";;;;;;AAYqB,SAAS,SAAS,CAAC,OAAO,EAAE;AACjD,QAAuB,QAAQ,CAAC,OAAO;AACvC,QAAQ,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO;AAClD,QAAQ,IAAI,EAAE,GAAG,WAAW,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;AAC9D,IAAI,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;AACpC,IAAI,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC;AAChC,IAAI,YAAY,GAAG,MAAM,CAAC,YAAY;AACtC,IAAI,QAAQ,GAAG,MAAM,CAAC,QAAQ;AAC9B,IAAI,gBAAgB,GAAG,MAAM,CAAC,sBAAsB;AACpD,IAAI,iBAAiB,GAAG,MAAM,CAAC,uBAAuB;AACtD,IAAI,IAAI,GAAG,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,EAAE,KAAK,QAAQ,CAAC,EAAE,CAAC;AAC9D,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;AAChB,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;AAChB,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI;AACtB,IAAI,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IAAI,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AACjd,QAAQ,OAAO;AACf;;;;"}
|
package/dist/index15.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useProps, useDefineProps, computed, effect, h, Canvas, loop, Viewport, cond, Container } from 'canvasengine';
|
|
2
|
-
import { inject } from './index6.js';
|
|
3
|
-
import { RpgClientEngine } from './index2.js';
|
|
4
|
-
import component$1 from './index29.js';
|
|
5
|
-
import { RpgGui } from './index9.js';
|
|
6
|
-
|
|
7
|
-
function component($$props) {
|
|
8
|
-
useProps($$props);
|
|
9
|
-
useDefineProps($$props);
|
|
10
|
-
var __assign = (this && this.__assign) || function () {
|
|
11
|
-
__assign = Object.assign || function(t) {
|
|
12
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
13
|
-
s = arguments[i];
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
}
|
|
17
|
-
return t;
|
|
18
|
-
};
|
|
19
|
-
return __assign.apply(this, arguments);
|
|
20
|
-
};
|
|
21
|
-
var engine = inject(RpgClientEngine);
|
|
22
|
-
var guiService = inject(RpgGui);
|
|
23
|
-
var sceneData = engine.sceneMap.data;
|
|
24
|
-
var gui = guiService.gui;
|
|
25
|
-
var worldWidth = computed(function () { var _a; return (_a = sceneData()) === null || _a === void 0 ? void 0 : _a.width; });
|
|
26
|
-
var worldHeight = computed(function () { var _a; return (_a = sceneData()) === null || _a === void 0 ? void 0 : _a.height; });
|
|
27
|
-
effect(function () {
|
|
28
|
-
if (sceneData() && !sceneData().component) {
|
|
29
|
-
throw new Error("Warning ! You need to define a component for the scene. Use provideLoadMap() to define a component for the scene.");
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
var onGuiFinish = function (gui, data) {
|
|
33
|
-
guiService.guiClose(gui.name, data);
|
|
34
|
-
};
|
|
35
|
-
var onGuiInteraction = function (gui, name, data) {
|
|
36
|
-
guiService.guiInteraction(gui.name, name, data);
|
|
37
|
-
};
|
|
38
|
-
var clamp = {
|
|
39
|
-
direction: "all"
|
|
40
|
-
};
|
|
41
|
-
let $this = h(Canvas, { width: computed(() => engine.width()), height: computed(() => engine.height()) }, [h(Viewport, { worldWidth, worldHeight, clamp }, cond(sceneData, () => h(component$1))), loop(gui, gui => h(Container, { display: 'flex' }, cond(gui.display, () => h(gui.component, { ...gui.data(), onFinish: (data) => {
|
|
42
|
-
onGuiFinish(gui, data);
|
|
43
|
-
}, onInteraction: (name, data) => {
|
|
44
|
-
onGuiInteraction(gui, name, data);
|
|
45
|
-
} }))))]);
|
|
46
|
-
return $this
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { component as default };
|
|
50
|
-
//# sourceMappingURL=index15.js.map
|