@rpgjs/client 5.0.0-alpha.11 → 5.0.0-alpha.12
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/Gui/Gui.d.ts +48 -2
- package/dist/RpgClient.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/index10.js +56 -11
- package/dist/index10.js.map +1 -1
- package/dist/index11.js +1 -1
- package/dist/index13.js +3 -1
- package/dist/index13.js.map +1 -1
- package/dist/index16.js +228 -45
- package/dist/index16.js.map +1 -1
- package/dist/index17.js +45 -228
- package/dist/index17.js.map +1 -1
- package/dist/index19.js +2 -2
- package/dist/index2.js +20 -8
- package/dist/index2.js.map +1 -1
- package/dist/index20.js +2 -2
- package/dist/index22.js +3 -3
- package/dist/index23.js +1 -1
- package/dist/index29.js +22 -3
- package/dist/index29.js.map +1 -1
- package/dist/index30.js +1 -331
- package/dist/index30.js.map +1 -1
- package/dist/index31.js +332 -24
- package/dist/index31.js.map +1 -1
- package/dist/index32.js +24 -8
- package/dist/index32.js.map +1 -1
- package/dist/index33.js +4 -4
- package/dist/index33.js.map +1 -1
- package/dist/index34.js +8 -9
- package/dist/index34.js.map +1 -1
- package/dist/index35.js +9 -4400
- package/dist/index35.js.map +1 -1
- package/dist/index36.js +4394 -307
- package/dist/index36.js.map +1 -1
- package/dist/index37.js +310 -55
- package/dist/index37.js.map +1 -1
- package/dist/index40.js +67 -10
- package/dist/index40.js.map +1 -1
- package/dist/index41.js +16 -92
- package/dist/index41.js.map +1 -1
- package/dist/index42.js +96 -0
- package/dist/index42.js.map +1 -0
- package/dist/index5.js +1 -1
- package/dist/index6.js +1 -1
- package/dist/index7.js +1 -1
- package/dist/index8.js +1 -1
- package/dist/index9.js +129 -6
- package/dist/index9.js.map +1 -1
- package/dist/presets/faceset.d.ts +30 -0
- package/dist/presets/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/Gui/Gui.ts +164 -6
- package/src/RpgClient.ts +2 -2
- package/src/RpgClientEngine.ts +21 -8
- package/src/components/gui/dialogbox/index.ce +73 -35
- package/src/components/gui/dialogbox/selection.ce +16 -1
- package/src/index.ts +2 -1
- package/src/presets/faceset.ts +60 -0
- package/src/presets/index.ts +3 -1
package/dist/index41.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index41.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index41.js","sources":["../src/components/gui/dialogbox/itemMenu.ce"],"sourcesContent":["<Container>\n <Rect width height color=\"#595971\" alpha visible={isSelected} />\n <Container flexDirection=\"row\" alignItems=\"center\" justifyContent=\"center\">\n <Text text color=\"#fff\" fontSize={18} margin={10} />\n </Container>\n</Container>\n\n<script>\nimport { animatedSignal } from \"canvasengine\";\n\nconst { text, isSelected } = defineProps();\n\nconst alpha = animatedSignal(1, {\n repeatType: \"reverse\",\n duration: 500,\n repeat: Infinity,\n});\n\nalpha.set(0.5);\n\nconst height = 40;\nconst width = 256;\n</script>"],"names":[],"mappings":";;AAQqB,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,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,UAAU,GAAG,EAAE,CAAC,UAAU;AAC1E,IAAI,KAAK,GAAG,cAAc,CAAC,CAAC,EAAE;AAC9B,IAAI,UAAU,EAAE,SAAS;AACzB,IAAI,QAAQ,EAAE,GAAG;AACjB,IAAI,MAAM,EAAE,QAAQ;AACpB,CAAC,CAAC;AACF,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;AACd,IAAI,MAAM,GAAG,EAAE;AACf,IAAI,KAAK,GAAG,GAAG;AACf,QAAQ,IAAI,KAAK,GAAG,CAAC,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACrQ,QAAQ,OAAO;AACf;;;;"}
|
package/dist/index42.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { RpgCommonPlayer, ModulesToken } from '@rpgjs/common';
|
|
2
|
+
import { trigger, signal } from 'canvasengine';
|
|
3
|
+
import { inject } from './index6.js';
|
|
4
|
+
import { RpgClientEngine } from './index2.js';
|
|
5
|
+
|
|
6
|
+
class RpgClientObject extends RpgCommonPlayer {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.emitParticleTrigger = trigger();
|
|
10
|
+
this.particleName = signal("");
|
|
11
|
+
this.animationCurrentIndex = signal(0);
|
|
12
|
+
this.animationIsPlaying = signal(false);
|
|
13
|
+
this._param = signal({});
|
|
14
|
+
this.hooks.callHooks("client-sprite-onInit", this).subscribe();
|
|
15
|
+
}
|
|
16
|
+
get hooks() {
|
|
17
|
+
return inject(ModulesToken);
|
|
18
|
+
}
|
|
19
|
+
flash(color, duration = 100) {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const lastTint = this.tint();
|
|
22
|
+
this.tint.set(color);
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
this.tint.set(lastTint);
|
|
25
|
+
resolve(true);
|
|
26
|
+
}, duration);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reset animation state when animation changes externally
|
|
31
|
+
*
|
|
32
|
+
* This method should be called when the animation changes due to movement
|
|
33
|
+
* or other external factors to ensure the animation system doesn't get stuck
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* // Reset when player starts moving
|
|
38
|
+
* player.resetAnimationState();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
resetAnimationState() {
|
|
42
|
+
this.animationIsPlaying.set(false);
|
|
43
|
+
this.animationCurrentIndex.set(0);
|
|
44
|
+
if (this.animationSubscription) {
|
|
45
|
+
this.animationSubscription.unsubscribe();
|
|
46
|
+
this.animationSubscription = void 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Set a custom animation for a specific number of times
|
|
51
|
+
*
|
|
52
|
+
* Plays a custom animation for the specified number of repetitions.
|
|
53
|
+
* The animation system prevents overlapping animations and automatically
|
|
54
|
+
* returns to the previous animation when complete.
|
|
55
|
+
*
|
|
56
|
+
* @param animationName - Name of the animation to play
|
|
57
|
+
* @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* // Play attack animation 3 times
|
|
62
|
+
* player.setAnimation('attack', 3);
|
|
63
|
+
*
|
|
64
|
+
* // Play continuous spell animation
|
|
65
|
+
* player.setAnimation('spell');
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
setAnimation(animationName, nbTimes = Infinity) {
|
|
69
|
+
if (this.animationIsPlaying()) return;
|
|
70
|
+
this.animationIsPlaying.set(true);
|
|
71
|
+
const previousAnimationName = this.animationName();
|
|
72
|
+
this.animationCurrentIndex.set(0);
|
|
73
|
+
if (this.animationSubscription) {
|
|
74
|
+
this.animationSubscription.unsubscribe();
|
|
75
|
+
}
|
|
76
|
+
this.animationSubscription = this.animationCurrentIndex.observable.subscribe((index) => {
|
|
77
|
+
if (index >= nbTimes) {
|
|
78
|
+
this.animationCurrentIndex.set(0);
|
|
79
|
+
this.animationName.set(previousAnimationName);
|
|
80
|
+
this.animationIsPlaying.set(false);
|
|
81
|
+
if (this.animationSubscription) {
|
|
82
|
+
this.animationSubscription.unsubscribe();
|
|
83
|
+
this.animationSubscription = void 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.animationName.set(animationName);
|
|
88
|
+
}
|
|
89
|
+
showComponentAnimation(id, params) {
|
|
90
|
+
const engine = inject(RpgClientEngine);
|
|
91
|
+
engine.getComponentAnimation(id).displayEffect(params, this);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { RpgClientObject };
|
|
96
|
+
//# sourceMappingURL=index42.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index42.js","sources":["../src/Game/Object.ts"],"sourcesContent":["import { Hooks, ModulesToken, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { sync } from \"@signe/sync\";\nimport { trigger, signal } from \"canvasengine\";\nimport { Subscription } from \"rxjs\";\nimport { inject } from \"../core/inject\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\n\nexport abstract class RpgClientObject extends RpgCommonPlayer {\n abstract type: string;\n emitParticleTrigger = trigger()\n particleName = signal('')\n animationCurrentIndex = signal(0)\n animationIsPlaying = signal(false)\n _param = signal({})\n\n constructor() {\n super()\n this.hooks.callHooks(\"client-sprite-onInit\", this).subscribe();\n }\n\n get hooks() {\n return inject<Hooks>(ModulesToken);\n }\n \n private animationSubscription?: Subscription\n\n flash(color: string, duration: number = 100) {\n return new Promise((resolve) => {\n const lastTint = this.tint()\n this.tint.set(color);\n setTimeout(() => {\n this.tint.set(lastTint)\n resolve(true)\n }, duration)\n })\n }\n\n /**\n * Reset animation state when animation changes externally\n * \n * This method should be called when the animation changes due to movement\n * or other external factors to ensure the animation system doesn't get stuck\n * \n * @example\n * ```ts\n * // Reset when player starts moving\n * player.resetAnimationState();\n * ```\n */\n resetAnimationState() {\n this.animationIsPlaying.set(false);\n this.animationCurrentIndex.set(0);\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n this.animationSubscription = undefined;\n }\n }\n\n /**\n * Set a custom animation for a specific number of times\n * \n * Plays a custom animation for the specified number of repetitions.\n * The animation system prevents overlapping animations and automatically\n * returns to the previous animation when complete.\n * \n * @param animationName - Name of the animation to play\n * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)\n * \n * @example\n * ```ts\n * // Play attack animation 3 times\n * player.setAnimation('attack', 3);\n * \n * // Play continuous spell animation\n * player.setAnimation('spell');\n * ```\n */\n setAnimation(animationName: string, nbTimes: number = Infinity) {\n if (this.animationIsPlaying()) return;\n this.animationIsPlaying.set(true);\n const previousAnimationName = this.animationName();\n this.animationCurrentIndex.set(0);\n \n // Clean up any existing subscription\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n }\n \n this.animationSubscription = this.animationCurrentIndex.observable.subscribe(index => {\n if (index >= nbTimes) {\n this.animationCurrentIndex.set(0);\n this.animationName.set(previousAnimationName);\n this.animationIsPlaying.set(false);\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n this.animationSubscription = undefined;\n }\n }\n })\n this.animationName.set(animationName);\n }\n\n showComponentAnimation(id: string, params: any) {\n const engine = inject(RpgClientEngine)\n engine.getComponentAnimation(id).displayEffect(params, this)\n }\n} "],"names":[],"mappings":";;;;;AAOO,MAAe,wBAAwB,eAAgB,CAAA;AAAA,EAQ5D,WAAc,GAAA;AACZ,IAAM,KAAA,EAAA;AAPR,IAAA,IAAA,CAAA,mBAAA,GAAsB,OAAQ,EAAA;AAC9B,IAAA,IAAA,CAAA,YAAA,GAAe,OAAO,EAAE,CAAA;AACxB,IAAA,IAAA,CAAA,qBAAA,GAAwB,OAAO,CAAC,CAAA;AAChC,IAAA,IAAA,CAAA,kBAAA,GAAqB,OAAO,KAAK,CAAA;AACjC,IAAS,IAAA,CAAA,MAAA,GAAA,MAAA,CAAO,EA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B,KAAK,aAAc,EAAA;AACjD,IAAK,IAAA,CAAA,qBAAA,CAAsB,IAAI,CAAC,CAAA;AAGhC,IAAA,IAAI,KAAK,qBAAuB,EAAA;AAC9B,MAAA,IAAA,CAAK,sBAAsB,WAAY,EAAA;AAAA;AAGzC,IAAA,IAAA,CAAK,qBAAwB,GAAA,IAAA,CAAK,qBAAsB,CAAA,UAAA,CAAW,UAAU,CAAS,KAAA,KAAA;AACpF,MAAA,IAAI,SAAS,OAAS,EAAA;AACpB,QAAK,IAAA,CAAA,qBAAA,CAAsB,IAAI,CAAC,CAAA;AAChC,QAAK,IAAA,CAAA,aAAA,CAAc,IAAI,qBAAqB,CAAA;AAC5C,QAAK,IAAA,CAAA,kBAAA,CAAmB,IAAI,KAAK,CAAA;AACjC,QAAA,IAAI,KAAK,qBAAuB,EAAA;AAC9B,UAAA,IAAA,CAAK,sBAAsB,WAAY,EAAA;AACvC,UAAA,IAAA,CAAK,qBAAwB,GAAA,MAAA;AAAA;AAC/B;AACF,KACD,CAAA;AACD,IAAK,IAAA,CAAA,aAAA,CAAc,IAAI,aAAa,CAAA;AAAA;AACtC,EAEA,sBAAA,CAAuB,IAAY,MAAa,EAAA;AAC9C,IAAM,MAAA,MAAA,GAAS,OAAO,eAAe,CAAA;AACrC,IAAA,MAAA,CAAO,qBAAsB,CAAA,EAAE,CAAE,CAAA,aAAA,CAAc,QAAQ,IAAI,CAAA;AAAA;AAE/D;;;;"}
|
package/dist/index5.js
CHANGED
package/dist/index6.js
CHANGED
package/dist/index7.js
CHANGED
package/dist/index8.js
CHANGED
package/dist/index9.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inject } from './
|
|
1
|
+
import { inject } from './index16.js';
|
|
2
2
|
import { signal } from 'canvasengine';
|
|
3
3
|
import { WebSocketToken } from './index18.js';
|
|
4
4
|
import component from './index10.js';
|
|
@@ -15,9 +15,12 @@ const throwError = (id) => {
|
|
|
15
15
|
throw `The GUI named ${id} is non-existent. Please add the component in the gui property of the decorator @RpgClient`;
|
|
16
16
|
};
|
|
17
17
|
class RpgGui {
|
|
18
|
+
// Reference to VueGui instance
|
|
18
19
|
constructor(context) {
|
|
19
20
|
this.context = context;
|
|
20
21
|
this.gui = signal({});
|
|
22
|
+
this.extraGuis = [];
|
|
23
|
+
this.vueGuiInstance = null;
|
|
21
24
|
this.webSocket = inject(context, WebSocketToken);
|
|
22
25
|
this.add({
|
|
23
26
|
name: "rpg-dialog",
|
|
@@ -32,6 +35,55 @@ class RpgGui {
|
|
|
32
35
|
this.hide(guiId);
|
|
33
36
|
});
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Set the VueGui instance reference for Vue component management
|
|
40
|
+
* This is called by VueGui when it's initialized
|
|
41
|
+
*
|
|
42
|
+
* @param vueGuiInstance - The VueGui instance
|
|
43
|
+
*/
|
|
44
|
+
_setVueGuiInstance(vueGuiInstance) {
|
|
45
|
+
this.vueGuiInstance = vueGuiInstance;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Notify VueGui about GUI state changes
|
|
49
|
+
* This synchronizes the Vue component display state
|
|
50
|
+
*
|
|
51
|
+
* @param guiId - The GUI component ID
|
|
52
|
+
* @param display - Display state
|
|
53
|
+
* @param data - Component data
|
|
54
|
+
*/
|
|
55
|
+
_notifyVueGui(guiId, display, data = {}) {
|
|
56
|
+
if (this.vueGuiInstance && this.vueGuiInstance.vm) {
|
|
57
|
+
const extraGui = this.extraGuis.find((gui) => gui.name === guiId);
|
|
58
|
+
if (extraGui) {
|
|
59
|
+
this.vueGuiInstance.vm.gui[guiId] = {
|
|
60
|
+
name: guiId,
|
|
61
|
+
display,
|
|
62
|
+
data,
|
|
63
|
+
attachToSprite: false
|
|
64
|
+
// Default value, could be configurable
|
|
65
|
+
};
|
|
66
|
+
this.vueGuiInstance.vm.gui = Object.assign({}, this.vueGuiInstance.vm.gui);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Initialize Vue components in the VueGui instance
|
|
72
|
+
* This should be called after VueGui is mounted
|
|
73
|
+
*/
|
|
74
|
+
_initializeVueComponents() {
|
|
75
|
+
if (this.vueGuiInstance && this.vueGuiInstance.vm) {
|
|
76
|
+
this.extraGuis.forEach((gui) => {
|
|
77
|
+
this.vueGuiInstance.vm.gui[gui.name] = {
|
|
78
|
+
name: gui.name,
|
|
79
|
+
display: gui.display(),
|
|
80
|
+
data: gui.data(),
|
|
81
|
+
attachToSprite: false
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
this.vueGuiInstance.vm.gui = Object.assign({}, this.vueGuiInstance.vm.gui);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
35
87
|
guiInteraction(guiId, name, data) {
|
|
36
88
|
this.webSocket.emit("gui.interaction", {
|
|
37
89
|
guiId,
|
|
@@ -48,10 +100,13 @@ class RpgGui {
|
|
|
48
100
|
/**
|
|
49
101
|
* Add a GUI component to the system
|
|
50
102
|
*
|
|
103
|
+
* By default, only CanvasEngine components (.ce files) are accepted.
|
|
104
|
+
* Vue components should be handled by the @rpgjs/vue package.
|
|
105
|
+
*
|
|
51
106
|
* @param gui - GUI configuration options
|
|
52
107
|
* @param gui.name - Name or ID of the GUI component
|
|
53
108
|
* @param gui.id - Alternative ID if name is not provided
|
|
54
|
-
* @param gui.component - The component to render
|
|
109
|
+
* @param gui.component - The component to render (must be a CanvasEngine component)
|
|
55
110
|
* @param gui.display - Initial display state (default: false)
|
|
56
111
|
* @param gui.data - Initial data for the component
|
|
57
112
|
* @param gui.autoDisplay - Auto display when added (default: false)
|
|
@@ -61,7 +116,7 @@ class RpgGui {
|
|
|
61
116
|
* ```ts
|
|
62
117
|
* gui.add({
|
|
63
118
|
* name: 'inventory',
|
|
64
|
-
* component: InventoryComponent,
|
|
119
|
+
* component: InventoryComponent, // Must be a .ce component
|
|
65
120
|
* autoDisplay: true,
|
|
66
121
|
* dependencies: () => [playerSignal, inventorySignal]
|
|
67
122
|
* });
|
|
@@ -80,19 +135,35 @@ class RpgGui {
|
|
|
80
135
|
autoDisplay: gui.autoDisplay || false,
|
|
81
136
|
dependencies: gui.dependencies
|
|
82
137
|
};
|
|
138
|
+
if (typeof gui.component !== "function") {
|
|
139
|
+
guiInstance.component = gui;
|
|
140
|
+
this.extraGuis.push(guiInstance);
|
|
141
|
+
if (guiInstance.autoDisplay) {
|
|
142
|
+
this._notifyVueGui(guiId, true, gui.data || {});
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
83
146
|
this.gui()[guiId] = guiInstance;
|
|
84
|
-
if (guiInstance.autoDisplay) {
|
|
147
|
+
if (guiInstance.autoDisplay && typeof gui.component === "function") {
|
|
85
148
|
this.display(guiId);
|
|
86
149
|
}
|
|
87
150
|
}
|
|
88
151
|
get(id) {
|
|
89
|
-
|
|
152
|
+
const canvasGui = this.gui()[id];
|
|
153
|
+
if (canvasGui) {
|
|
154
|
+
return canvasGui;
|
|
155
|
+
}
|
|
156
|
+
return this.extraGuis.find((gui) => gui.name === id);
|
|
90
157
|
}
|
|
91
158
|
exists(id) {
|
|
92
159
|
return !!this.get(id);
|
|
93
160
|
}
|
|
94
161
|
getAll() {
|
|
95
|
-
|
|
162
|
+
const allGuis = { ...this.gui() };
|
|
163
|
+
this.extraGuis.forEach((gui) => {
|
|
164
|
+
allGuis[gui.name] = gui;
|
|
165
|
+
});
|
|
166
|
+
return allGuis;
|
|
96
167
|
}
|
|
97
168
|
/**
|
|
98
169
|
* Display a GUI component
|
|
@@ -100,6 +171,7 @@ class RpgGui {
|
|
|
100
171
|
* Displays the GUI immediately if no dependencies are configured,
|
|
101
172
|
* or waits for all dependencies to be resolved if dependencies are present.
|
|
102
173
|
* Automatically manages subscriptions to prevent memory leaks.
|
|
174
|
+
* Works with both CanvasEngine components and Vue components.
|
|
103
175
|
*
|
|
104
176
|
* @param id - The GUI component ID
|
|
105
177
|
* @param data - Data to pass to the component
|
|
@@ -119,6 +191,52 @@ class RpgGui {
|
|
|
119
191
|
throw throwError(id);
|
|
120
192
|
}
|
|
121
193
|
const guiInstance = this.get(id);
|
|
194
|
+
const isVueComponent = this.extraGuis.some((gui) => gui.name === id);
|
|
195
|
+
if (isVueComponent) {
|
|
196
|
+
this._handleVueComponentDisplay(id, data, dependencies, guiInstance);
|
|
197
|
+
} else {
|
|
198
|
+
this._handleCanvasComponentDisplay(id, data, dependencies, guiInstance);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Handle Vue component display logic
|
|
203
|
+
*
|
|
204
|
+
* @param id - GUI component ID
|
|
205
|
+
* @param data - Component data
|
|
206
|
+
* @param dependencies - Runtime dependencies
|
|
207
|
+
* @param guiInstance - GUI instance
|
|
208
|
+
*/
|
|
209
|
+
_handleVueComponentDisplay(id, data, dependencies, guiInstance) {
|
|
210
|
+
if (guiInstance.subscription) {
|
|
211
|
+
guiInstance.subscription.unsubscribe();
|
|
212
|
+
guiInstance.subscription = void 0;
|
|
213
|
+
}
|
|
214
|
+
const deps = dependencies.length > 0 ? dependencies : guiInstance.dependencies ? guiInstance.dependencies() : [];
|
|
215
|
+
if (deps.length > 0) {
|
|
216
|
+
guiInstance.subscription = combineLatest(
|
|
217
|
+
deps.map((dependency) => dependency.observable)
|
|
218
|
+
).subscribe((values) => {
|
|
219
|
+
if (values.every((value) => value !== void 0)) {
|
|
220
|
+
guiInstance.data.set(data);
|
|
221
|
+
guiInstance.display.set(true);
|
|
222
|
+
this._notifyVueGui(id, true, data);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
guiInstance.data.set(data);
|
|
228
|
+
guiInstance.display.set(true);
|
|
229
|
+
this._notifyVueGui(id, true, data);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Handle CanvasEngine component display logic
|
|
233
|
+
*
|
|
234
|
+
* @param id - GUI component ID
|
|
235
|
+
* @param data - Component data
|
|
236
|
+
* @param dependencies - Runtime dependencies
|
|
237
|
+
* @param guiInstance - GUI instance
|
|
238
|
+
*/
|
|
239
|
+
_handleCanvasComponentDisplay(id, data, dependencies, guiInstance) {
|
|
122
240
|
if (guiInstance.subscription) {
|
|
123
241
|
guiInstance.subscription.unsubscribe();
|
|
124
242
|
guiInstance.subscription = void 0;
|
|
@@ -142,6 +260,7 @@ class RpgGui {
|
|
|
142
260
|
* Hide a GUI component
|
|
143
261
|
*
|
|
144
262
|
* Hides the GUI and cleans up any active subscriptions.
|
|
263
|
+
* Works with both CanvasEngine components and Vue components.
|
|
145
264
|
*
|
|
146
265
|
* @param id - The GUI component ID
|
|
147
266
|
*
|
|
@@ -160,6 +279,10 @@ class RpgGui {
|
|
|
160
279
|
guiInstance.subscription = void 0;
|
|
161
280
|
}
|
|
162
281
|
guiInstance.display.set(false);
|
|
282
|
+
const isVueComponent = this.extraGuis.some((gui) => gui.name === id);
|
|
283
|
+
if (isVueComponent) {
|
|
284
|
+
this._notifyVueGui(id, false);
|
|
285
|
+
}
|
|
163
286
|
}
|
|
164
287
|
}
|
|
165
288
|
|
package/dist/index9.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index9.js","sources":["../src/Gui/Gui.ts"],"sourcesContent":["import { Context, inject } from \"@signe/di\";\nimport { signal, Signal, WritableSignal } from \"canvasengine\";\nimport { AbstractWebsocket, WebSocketToken } from \"../services/AbstractSocket\";\nimport { DialogboxComponent } from \"../components/gui\";\nimport { combineLatest, Subscription } from \"rxjs\";\n\ninterface GuiOptions {\n name?: string;\n id?: string;\n component: any;\n display?: boolean;\n data?: any;\n /**\n * Auto display the GUI when added to the system\n * @default false\n */\n autoDisplay?: boolean;\n /**\n * Function that returns an array of Signal dependencies\n * The GUI will only display when all dependencies are resolved (!= undefined)\n * @returns Array of Signal dependencies\n */\n dependencies?: () => Signal[];\n}\n\ninterface GuiInstance {\n name: string;\n component: any;\n display: WritableSignal<boolean>;\n data: WritableSignal<any>;\n autoDisplay: boolean;\n dependencies?: () => Signal[];\n subscription?: Subscription;\n}\n\nconst throwError = (id: string) => {\n throw `The GUI named ${id} is non-existent. Please add the component in the gui property of the decorator @RpgClient`;\n};\n\nexport class RpgGui {\n private webSocket: AbstractWebsocket;\n gui = signal<Record<string, GuiInstance>>({});\n\n constructor(private context: Context) {\n this.webSocket = inject(context, WebSocketToken);\n this.add({\n name: \"rpg-dialog\",\n component: DialogboxComponent,\n });\n }\n\n async _initialize() {\n this.webSocket.on(\"gui.open\", (data: { guiId: string; data: any }) => {\n this.display(data.guiId, data.data);\n });\n\n this.webSocket.on(\"gui.exit\", (guiId: string) => {\n this.hide(guiId);\n });\n }\n\n guiInteraction(guiId: string, name: string, data: any) {\n this.webSocket.emit(\"gui.interaction\", {\n guiId,\n name,\n data,\n });\n }\n\n guiClose(guiId: string, data?: any) {\n this.webSocket.emit(\"gui.exit\", {\n guiId,\n data,\n });\n }\n\n /**\n * Add a GUI component to the system\n * \n * @param gui - GUI configuration options\n * @param gui.name - Name or ID of the GUI component\n * @param gui.id - Alternative ID if name is not provided\n * @param gui.component - The component to render\n * @param gui.display - Initial display state (default: false)\n * @param gui.data - Initial data for the component\n * @param gui.autoDisplay - Auto display when added (default: false)\n * @param gui.dependencies - Function returning Signal dependencies\n * \n * @example\n * ```ts\n * gui.add({\n * name: 'inventory',\n * component: InventoryComponent,\n * autoDisplay: true,\n * dependencies: () => [playerSignal, inventorySignal]\n * });\n * ```\n */\n add(gui: GuiOptions) {\n const guiId = gui.name || gui.id;\n if (!guiId) {\n throw new Error(\"GUI must have a name or id\");\n }\n\n const guiInstance: GuiInstance = {\n name: guiId,\n component: gui.component,\n display: signal(gui.display || false),\n data: signal(gui.data || {}),\n autoDisplay: gui.autoDisplay || false,\n dependencies: gui.dependencies,\n };\n\n this.gui()[guiId] = guiInstance;\n\n // Auto display if enabled\n if (guiInstance.autoDisplay) {\n this.display(guiId);\n }\n }\n\n get(id: string): GuiInstance | undefined {\n return this.gui()[id];\n }\n\n exists(id: string): boolean {\n return !!this.get(id);\n }\n\n getAll(): Record<string, GuiInstance> {\n return this.gui();\n }\n\n /**\n * Display a GUI component\n * \n * Displays the GUI immediately if no dependencies are configured,\n * or waits for all dependencies to be resolved if dependencies are present.\n * Automatically manages subscriptions to prevent memory leaks.\n * \n * @param id - The GUI component ID\n * @param data - Data to pass to the component\n * @param dependencies - Optional runtime dependencies (overrides config dependencies)\n * \n * @example\n * ```ts\n * // Display immediately\n * gui.display('inventory', { items: [] });\n * \n * // Display with runtime dependencies\n * gui.display('shop', { shopId: 1 }, [playerSignal, shopSignal]);\n * ```\n */\n display(id: string, data = {}, dependencies: Signal[] = []) {\n if (!this.exists(id)) {\n throw throwError(id);\n }\n\n const guiInstance = this.get(id)!;\n \n // Unsubscribe from previous subscription if exists\n if (guiInstance.subscription) {\n guiInstance.subscription.unsubscribe();\n guiInstance.subscription = undefined;\n }\n\n // Use runtime dependencies or config dependencies\n const deps = dependencies.length > 0 \n ? dependencies \n : (guiInstance.dependencies ? guiInstance.dependencies() : []);\n\n if (deps.length > 0) {\n // Subscribe to dependencies\n guiInstance.subscription = combineLatest(\n deps.map(dependency => dependency.observable)\n ).subscribe((values) => {\n if (values.every(value => value !== undefined)) {\n guiInstance.data.set(data);\n guiInstance.display.set(true);\n }\n });\n return;\n }\n\n // No dependencies, display immediately\n guiInstance.data.set(data);\n guiInstance.display.set(true);\n }\n\n /**\n * Hide a GUI component\n * \n * Hides the GUI and cleans up any active subscriptions.\n * \n * @param id - The GUI component ID\n * \n * @example\n * ```ts\n * gui.hide('inventory');\n * ```\n */\n hide(id: string) {\n if (!this.exists(id)) {\n throw throwError(id);\n }\n\n const guiInstance = this.get(id)!;\n \n // Unsubscribe if there's an active subscription\n if (guiInstance.subscription) {\n guiInstance.subscription.unsubscribe();\n guiInstance.subscription = undefined;\n }\n\n guiInstance.display.set(false);\n }\n}\n"],"names":["DialogboxComponent"],"mappings":";;;;;;;;;;;;;AAmCA,MAAM,UAAA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,EAAE,CAAA;AAG/B,IAAA,IAAI,YAAY,YAAc,EAAA;AAC5B,MAAA,WAAA,CAAY,aAAa,WAAY,EAAA;AACrC,MAAA,WAAA,CAAY,YAAe,GAAA,MAAA;AAAA;AAG7B,IAAY,WAAA,CAAA,OAAA,CAAQ,IAAI,KAAK,CAAA;AAAA;AAEjC;;;;"}
|
|
1
|
+
{"version":3,"file":"index9.js","sources":["../src/Gui/Gui.ts"],"sourcesContent":["import { Context, inject } from \"@signe/di\";\nimport { signal, Signal, WritableSignal } from \"canvasengine\";\nimport { AbstractWebsocket, WebSocketToken } from \"../services/AbstractSocket\";\nimport { DialogboxComponent } from \"../components/gui\";\nimport { combineLatest, Subscription } from \"rxjs\";\n\ninterface GuiOptions {\n name?: string;\n id?: string;\n component: any;\n display?: boolean;\n data?: any;\n /**\n * Auto display the GUI when added to the system\n * @default false\n */\n autoDisplay?: boolean;\n /**\n * Function that returns an array of Signal dependencies\n * The GUI will only display when all dependencies are resolved (!= undefined)\n * @returns Array of Signal dependencies\n */\n dependencies?: () => Signal[];\n}\n\ninterface GuiInstance {\n name: string;\n component: any;\n display: WritableSignal<boolean>;\n data: WritableSignal<any>;\n autoDisplay: boolean;\n dependencies?: () => Signal[];\n subscription?: Subscription;\n}\n\nconst throwError = (id: string) => {\n throw `The GUI named ${id} is non-existent. Please add the component in the gui property of the decorator @RpgClient`;\n};\n\nexport class RpgGui {\n private webSocket: AbstractWebsocket;\n gui = signal<Record<string, GuiInstance>>({});\n extraGuis: GuiInstance[] = [];\n private vueGuiInstance: any = null; // Reference to VueGui instance\n\n constructor(private context: Context) {\n this.webSocket = inject(context, WebSocketToken);\n this.add({\n name: \"rpg-dialog\",\n component: DialogboxComponent,\n });\n }\n\n async _initialize() {\n this.webSocket.on(\"gui.open\", (data: { guiId: string; data: any }) => {\n this.display(data.guiId, data.data);\n });\n\n this.webSocket.on(\"gui.exit\", (guiId: string) => {\n this.hide(guiId);\n });\n }\n\n /**\n * Set the VueGui instance reference for Vue component management\n * This is called by VueGui when it's initialized\n * \n * @param vueGuiInstance - The VueGui instance\n */\n _setVueGuiInstance(vueGuiInstance: any) {\n this.vueGuiInstance = vueGuiInstance;\n }\n\n /**\n * Notify VueGui about GUI state changes\n * This synchronizes the Vue component display state\n * \n * @param guiId - The GUI component ID\n * @param display - Display state\n * @param data - Component data\n */\n private _notifyVueGui(guiId: string, display: boolean, data: any = {}) {\n if (this.vueGuiInstance && this.vueGuiInstance.vm) {\n // Find the GUI in extraGuis\n const extraGui = this.extraGuis.find(gui => gui.name === guiId);\n if (extraGui) {\n // Update the Vue component's display state and data\n this.vueGuiInstance.vm.gui[guiId] = {\n name: guiId,\n display,\n data,\n attachToSprite: false // Default value, could be configurable\n };\n // Trigger Vue reactivity\n this.vueGuiInstance.vm.gui = Object.assign({}, this.vueGuiInstance.vm.gui);\n }\n }\n }\n\n /**\n * Initialize Vue components in the VueGui instance\n * This should be called after VueGui is mounted\n */\n _initializeVueComponents() {\n if (this.vueGuiInstance && this.vueGuiInstance.vm) {\n // Initialize all extraGuis in the Vue instance\n this.extraGuis.forEach(gui => {\n this.vueGuiInstance.vm.gui[gui.name] = {\n name: gui.name,\n display: gui.display(),\n data: gui.data(),\n attachToSprite: false\n };\n });\n \n // Trigger Vue reactivity\n this.vueGuiInstance.vm.gui = Object.assign({}, this.vueGuiInstance.vm.gui);\n }\n }\n\n guiInteraction(guiId: string, name: string, data: any) {\n this.webSocket.emit(\"gui.interaction\", {\n guiId,\n name,\n data,\n });\n }\n\n guiClose(guiId: string, data?: any) {\n this.webSocket.emit(\"gui.exit\", {\n guiId,\n data,\n });\n }\n\n /**\n * Add a GUI component to the system\n * \n * By default, only CanvasEngine components (.ce files) are accepted.\n * Vue components should be handled by the @rpgjs/vue package.\n * \n * @param gui - GUI configuration options\n * @param gui.name - Name or ID of the GUI component\n * @param gui.id - Alternative ID if name is not provided\n * @param gui.component - The component to render (must be a CanvasEngine component)\n * @param gui.display - Initial display state (default: false)\n * @param gui.data - Initial data for the component\n * @param gui.autoDisplay - Auto display when added (default: false)\n * @param gui.dependencies - Function returning Signal dependencies\n * \n * @example\n * ```ts\n * gui.add({\n * name: 'inventory',\n * component: InventoryComponent, // Must be a .ce component\n * autoDisplay: true,\n * dependencies: () => [playerSignal, inventorySignal]\n * });\n * ```\n */\n add(gui: GuiOptions) {\n const guiId = gui.name || gui.id;\n if (!guiId) {\n throw new Error(\"GUI must have a name or id\");\n }\n\n const guiInstance: GuiInstance = {\n name: guiId,\n component: gui.component,\n display: signal(gui.display || false),\n data: signal(gui.data || {}),\n autoDisplay: gui.autoDisplay || false,\n dependencies: gui.dependencies,\n };\n\n // Accept both CanvasEngine components (.ce) and Vue components\n // Vue components will be handled by VueGui if available\n if (typeof gui.component !== 'function') {\n guiInstance.component = gui;\n this.extraGuis.push(guiInstance);\n \n // Auto display Vue components if enabled\n if (guiInstance.autoDisplay) {\n this._notifyVueGui(guiId, true, gui.data || {});\n }\n return;\n }\n\n this.gui()[guiId] = guiInstance;\n\n // Auto display if enabled and it's a CanvasEngine component\n if (guiInstance.autoDisplay && typeof gui.component === 'function') {\n this.display(guiId);\n }\n }\n\n get(id: string): GuiInstance | undefined {\n // Check CanvasEngine GUIs first\n const canvasGui = this.gui()[id];\n if (canvasGui) {\n return canvasGui;\n }\n \n // Check Vue GUIs in extraGuis\n return this.extraGuis.find(gui => gui.name === id);\n }\n\n exists(id: string): boolean {\n return !!this.get(id);\n }\n\n getAll(): Record<string, GuiInstance> {\n const allGuis = { ...this.gui() };\n \n // Add extraGuis to the result\n this.extraGuis.forEach(gui => {\n allGuis[gui.name] = gui;\n });\n \n return allGuis;\n }\n\n /**\n * Display a GUI component\n * \n * Displays the GUI immediately if no dependencies are configured,\n * or waits for all dependencies to be resolved if dependencies are present.\n * Automatically manages subscriptions to prevent memory leaks.\n * Works with both CanvasEngine components and Vue components.\n * \n * @param id - The GUI component ID\n * @param data - Data to pass to the component\n * @param dependencies - Optional runtime dependencies (overrides config dependencies)\n * \n * @example\n * ```ts\n * // Display immediately\n * gui.display('inventory', { items: [] });\n * \n * // Display with runtime dependencies\n * gui.display('shop', { shopId: 1 }, [playerSignal, shopSignal]);\n * ```\n */\n display(id: string, data = {}, dependencies: Signal[] = []) {\n if (!this.exists(id)) {\n throw throwError(id);\n }\n\n const guiInstance = this.get(id)!;\n \n // Check if it's a Vue component (in extraGuis)\n const isVueComponent = this.extraGuis.some(gui => gui.name === id);\n \n if (isVueComponent) {\n // Handle Vue component display\n this._handleVueComponentDisplay(id, data, dependencies, guiInstance);\n } else {\n // Handle CanvasEngine component display\n this._handleCanvasComponentDisplay(id, data, dependencies, guiInstance);\n }\n }\n\n /**\n * Handle Vue component display logic\n * \n * @param id - GUI component ID\n * @param data - Component data\n * @param dependencies - Runtime dependencies\n * @param guiInstance - GUI instance\n */\n private _handleVueComponentDisplay(id: string, data: any, dependencies: Signal[], guiInstance: GuiInstance) {\n // Unsubscribe from previous subscription if exists\n if (guiInstance.subscription) {\n guiInstance.subscription.unsubscribe();\n guiInstance.subscription = undefined;\n }\n\n // Use runtime dependencies or config dependencies\n const deps = dependencies.length > 0 \n ? dependencies \n : (guiInstance.dependencies ? guiInstance.dependencies() : []);\n\n if (deps.length > 0) {\n // Subscribe to dependencies\n guiInstance.subscription = combineLatest(\n deps.map(dependency => dependency.observable)\n ).subscribe((values) => {\n if (values.every(value => value !== undefined)) {\n guiInstance.data.set(data);\n guiInstance.display.set(true);\n this._notifyVueGui(id, true, data);\n }\n });\n return;\n }\n\n // No dependencies, display immediately\n guiInstance.data.set(data);\n guiInstance.display.set(true);\n this._notifyVueGui(id, true, data);\n }\n\n /**\n * Handle CanvasEngine component display logic\n * \n * @param id - GUI component ID\n * @param data - Component data\n * @param dependencies - Runtime dependencies\n * @param guiInstance - GUI instance\n */\n private _handleCanvasComponentDisplay(id: string, data: any, dependencies: Signal[], guiInstance: GuiInstance) {\n // Unsubscribe from previous subscription if exists\n if (guiInstance.subscription) {\n guiInstance.subscription.unsubscribe();\n guiInstance.subscription = undefined;\n }\n\n // Use runtime dependencies or config dependencies\n const deps = dependencies.length > 0 \n ? dependencies \n : (guiInstance.dependencies ? guiInstance.dependencies() : []);\n\n if (deps.length > 0) {\n // Subscribe to dependencies\n guiInstance.subscription = combineLatest(\n deps.map(dependency => dependency.observable)\n ).subscribe((values) => {\n if (values.every(value => value !== undefined)) {\n guiInstance.data.set(data);\n guiInstance.display.set(true);\n }\n });\n return;\n }\n\n // No dependencies, display immediately\n guiInstance.data.set(data);\n guiInstance.display.set(true);\n }\n\n /**\n * Hide a GUI component\n * \n * Hides the GUI and cleans up any active subscriptions.\n * Works with both CanvasEngine components and Vue components.\n * \n * @param id - The GUI component ID\n * \n * @example\n * ```ts\n * gui.hide('inventory');\n * ```\n */\n hide(id: string) {\n if (!this.exists(id)) {\n throw throwError(id);\n }\n\n const guiInstance = this.get(id)!;\n \n // Unsubscribe if there's an active subscription\n if (guiInstance.subscription) {\n guiInstance.subscription.unsubscribe();\n guiInstance.subscription = undefined;\n }\n\n guiInstance.display.set(false);\n \n // Check if it's a Vue component and notify VueGui\n const isVueComponent = this.extraGuis.some(gui => gui.name === id);\n if (isVueComponent) {\n this._notifyVueGui(id, false);\n }\n }\n}\n"],"names":["DialogboxComponent"],"mappings":";;;;;;;;;;;;;AAmCA,MAAM,UAAA,GAAa,CAAC,EAAe,KAAA;AACjC,EAAA,MAAM,iBAAiB,EAAE,CAAA,0FAAA,CAAA;AAC3B,CAAA;AAEO,MAAM,MAAO,CAAA;AAAA;AAAA,EAMlB,YAAoB,OAAkB,EAAA;AAAlB,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAJpB,IAAM,IAAA,CAAA,GAAA,GAAA,MAAA,CAAoC,EAAE,CAAA;AAC5C,IAAA,IAAA,CAAA,SAAA,GAA2B,EAAC;AAC5B,IAAA,IAAA,CAAQ,cAAsB,GAAA,IAAA;AAG5B,IAAK,IAAA,CAAA,SAAA,GAAY,MAAO,CAAA,OAAA,EAAS,cAAc,CAAA;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SAAS,EAAE,CAAA;AACjE,IAAA,IAAI,cAAgB,EAAA;AAClB,MAAK,IAAA,CAAA,aAAA,CAAc,IAAI,KAAK,CAAA;AAAA;AAC9B;AAEJ;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a faceset preset for character expressions
|
|
3
|
+
*
|
|
4
|
+
* This preset allows you to define multiple facial expressions for a character,
|
|
5
|
+
* where each expression corresponds to a specific frame position (frameX, frameY)
|
|
6
|
+
* within a single faceset texture. Each expression is defined by its position
|
|
7
|
+
* in the faceset grid.
|
|
8
|
+
*
|
|
9
|
+
* @param options - Object containing the faceset configuration
|
|
10
|
+
* @param framesWidth - Number of frames horizontally in the faceset texture
|
|
11
|
+
* @param framesHeight - Number of frames vertically in the faceset texture
|
|
12
|
+
* @param expressions - Object mapping expression names to their frame positions as tuples [frameX, frameY]
|
|
13
|
+
* @returns Faceset configuration with animations for each expression
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const faceset = FacesetPreset({
|
|
18
|
+
* id: "facesetId",
|
|
19
|
+
* image: "faceset.png",
|
|
20
|
+
* width: 1024,
|
|
21
|
+
* height: 1024,
|
|
22
|
+
* }, 4, 2, {
|
|
23
|
+
* happy: [0, 0],
|
|
24
|
+
* sad: [1, 0],
|
|
25
|
+
* angry: [2, 0],
|
|
26
|
+
* surprised: [3, 0]
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const FacesetPreset: (options: any, framesWidth: number, framesHeight: number, expressions: Record<string, [number, number]>) => any;
|
package/dist/presets/index.d.ts
CHANGED