@rpgjs/client 5.0.0-alpha.43 → 5.0.0-alpha.44

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.
Files changed (137) hide show
  1. package/dist/Game/AnimationManager.js +25 -24
  2. package/dist/Game/AnimationManager.js.map +1 -1
  3. package/dist/Game/Event.js +11 -10
  4. package/dist/Game/Event.js.map +1 -1
  5. package/dist/Game/Map.js +78 -94
  6. package/dist/Game/Map.js.map +1 -1
  7. package/dist/Game/Object.js +182 -216
  8. package/dist/Game/Object.js.map +1 -1
  9. package/dist/Game/Player.js +11 -10
  10. package/dist/Game/Player.js.map +1 -1
  11. package/dist/Gui/Gui.js +440 -473
  12. package/dist/Gui/Gui.js.map +1 -1
  13. package/dist/Gui/NotificationManager.js +48 -50
  14. package/dist/Gui/NotificationManager.js.map +1 -1
  15. package/dist/Resource.js +132 -113
  16. package/dist/Resource.js.map +1 -1
  17. package/dist/RpgClientEngine.js +1333 -1486
  18. package/dist/RpgClientEngine.js.map +1 -1
  19. package/dist/Sound.js +162 -92
  20. package/dist/Sound.js.map +1 -1
  21. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.js +9 -0
  22. package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.js +6 -0
  23. package/dist/components/animations/animation.ce.js +22 -19
  24. package/dist/components/animations/animation.ce.js.map +1 -1
  25. package/dist/components/animations/hit.ce.js +67 -68
  26. package/dist/components/animations/hit.ce.js.map +1 -1
  27. package/dist/components/animations/index.js +9 -8
  28. package/dist/components/animations/index.js.map +1 -1
  29. package/dist/components/character.ce.js +390 -314
  30. package/dist/components/character.ce.js.map +1 -1
  31. package/dist/components/dynamics/parse-value.js +42 -52
  32. package/dist/components/dynamics/parse-value.js.map +1 -1
  33. package/dist/components/dynamics/text.ce.js +71 -139
  34. package/dist/components/dynamics/text.ce.js.map +1 -1
  35. package/dist/components/gui/box.ce.js +26 -25
  36. package/dist/components/gui/box.ce.js.map +1 -1
  37. package/dist/components/gui/dialogbox/index.ce.js +202 -149
  38. package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
  39. package/dist/components/gui/gameover.ce.js +190 -138
  40. package/dist/components/gui/gameover.ce.js.map +1 -1
  41. package/dist/components/gui/hud/hud.ce.js +90 -33
  42. package/dist/components/gui/hud/hud.ce.js.map +1 -1
  43. package/dist/components/gui/index.js +14 -0
  44. package/dist/components/gui/menu/equip-menu.ce.js +478 -346
  45. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
  46. package/dist/components/gui/menu/exit-menu.ce.js +52 -33
  47. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
  48. package/dist/components/gui/menu/items-menu.ce.js +341 -226
  49. package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
  50. package/dist/components/gui/menu/main-menu.ce.js +414 -205
  51. package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
  52. package/dist/components/gui/menu/options-menu.ce.js +46 -26
  53. package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
  54. package/dist/components/gui/menu/skills-menu.ce.js +104 -50
  55. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
  56. package/dist/components/gui/mobile/index.js +18 -21
  57. package/dist/components/gui/mobile/index.js.map +1 -1
  58. package/dist/components/gui/mobile/mobile.ce.js +76 -15
  59. package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
  60. package/dist/components/gui/notification/notification.ce.js +62 -36
  61. package/dist/components/gui/notification/notification.ce.js.map +1 -1
  62. package/dist/components/gui/save-load.ce.js +386 -239
  63. package/dist/components/gui/save-load.ce.js.map +1 -1
  64. package/dist/components/gui/shop/shop.ce.js +649 -319
  65. package/dist/components/gui/shop/shop.ce.js.map +1 -1
  66. package/dist/components/gui/title-screen.ce.js +187 -145
  67. package/dist/components/gui/title-screen.ce.js.map +1 -1
  68. package/dist/components/index.js +4 -0
  69. package/dist/components/prebuilt/hp-bar.ce.js +114 -104
  70. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
  71. package/dist/components/prebuilt/index.js +2 -0
  72. package/dist/components/prebuilt/light-halo.ce.js +92 -74
  73. package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
  74. package/dist/components/scenes/canvas.ce.js +58 -42
  75. package/dist/components/scenes/canvas.ce.js.map +1 -1
  76. package/dist/components/scenes/draw-map.ce.js +87 -64
  77. package/dist/components/scenes/draw-map.ce.js.map +1 -1
  78. package/dist/components/scenes/event-layer.ce.js +26 -16
  79. package/dist/components/scenes/event-layer.ce.js.map +1 -1
  80. package/dist/core/inject.js +11 -10
  81. package/dist/core/inject.js.map +1 -1
  82. package/dist/core/setup.js +13 -13
  83. package/dist/core/setup.js.map +1 -1
  84. package/dist/index.js +44 -41
  85. package/dist/module.js +169 -168
  86. package/dist/module.js.map +1 -1
  87. package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js +209 -298
  88. package/dist/node_modules/.pnpm/@signe_di@2.8.3/node_modules/@signe/di/dist/index.js.map +1 -1
  89. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +430 -507
  90. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +1 -1
  91. package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js +2062 -2571
  92. package/dist/node_modules/.pnpm/@signe_room@2.8.3/node_modules/@signe/room/dist/index.js.map +1 -1
  93. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +8 -3
  94. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +1 -1
  95. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js +78 -101
  96. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/client/index.js.map +1 -1
  97. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js +264 -401
  98. package/dist/node_modules/.pnpm/@signe_sync@2.8.3/node_modules/@signe/sync/dist/index.js.map +1 -1
  99. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +9 -7
  100. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +1 -1
  101. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js +106 -165
  102. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -1
  103. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js +361 -461
  104. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -1
  105. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/index.js +2 -0
  106. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +3633 -4280
  107. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -1
  108. package/dist/presets/animation.js +37 -25
  109. package/dist/presets/animation.js.map +1 -1
  110. package/dist/presets/faceset.js +49 -22
  111. package/dist/presets/faceset.js.map +1 -1
  112. package/dist/presets/icon.js +13 -13
  113. package/dist/presets/icon.js.map +1 -1
  114. package/dist/presets/index.js +15 -14
  115. package/dist/presets/index.js.map +1 -1
  116. package/dist/presets/lpc.js +96 -93
  117. package/dist/presets/lpc.js.map +1 -1
  118. package/dist/presets/rmspritesheet.js +40 -39
  119. package/dist/presets/rmspritesheet.js.map +1 -1
  120. package/dist/services/AbstractSocket.js +10 -8
  121. package/dist/services/AbstractSocket.js.map +1 -1
  122. package/dist/services/keyboardControls.js +20 -18
  123. package/dist/services/keyboardControls.js.map +1 -1
  124. package/dist/services/loadMap.js +120 -36
  125. package/dist/services/loadMap.js.map +1 -1
  126. package/dist/services/mmorpg.js +128 -136
  127. package/dist/services/mmorpg.js.map +1 -1
  128. package/dist/services/save.js +74 -66
  129. package/dist/services/save.js.map +1 -1
  130. package/dist/services/standalone.js +165 -167
  131. package/dist/services/standalone.js.map +1 -1
  132. package/dist/utils/getEntityProp.js +49 -51
  133. package/dist/utils/getEntityProp.js.map +1 -1
  134. package/package.json +8 -8
  135. package/src/components/character.ce +1 -1
  136. package/src/components/scenes/draw-map.ce +3 -1
  137. package/dist/index.js.map +0 -1
@@ -1,316 +1,392 @@
1
- import { useProps, useDefineProps, computed, signal, on, animatedSignal, mount, tick, h, Container, loop, Sprite, cond } from 'canvasengine';
2
- import { combineLatest, map, startWith, pairwise, filter, lastValueFrom } from 'rxjs';
3
- import { Particle } from '@canvasengine/presets';
4
- import { Direction, ModulesToken } from '@rpgjs/common';
5
- import { RpgClientEngine } from '../RpgClientEngine.js';
6
- import { inject } from '../core/inject.js';
7
- import { RpgGui } from '../Gui/Gui.js';
8
-
1
+ import { inject } from "../core/inject.js";
2
+ import { RpgGui } from "../Gui/Gui.js";
3
+ import { RpgClientEngine } from "../RpgClientEngine.js";
4
+ import { Container, Sprite, animatedSignal, computed, cond, h, loop, mount, on, signal, tick, useDefineProps, useProps } from "canvasengine";
5
+ import { Particle } from "@canvasengine/presets";
6
+ import { Direction, ModulesToken } from "@rpgjs/common";
7
+ import { combineLatest, filter, lastValueFrom, map, pairwise, startWith } from "rxjs";
8
+ //#region src/components/character.ce
9
9
  function component($$props) {
10
- useProps($$props);
11
- const defineProps = useDefineProps($$props);
12
- var __assign = (this && this.__assign) || function () {
13
- __assign = Object.assign || function(t) {
14
- for (var s, i = 1, n = arguments.length; i < n; i++) {
15
- s = arguments[i];
16
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
17
- t[p] = s[p];
18
- }
19
- return t;
20
- };
21
- return __assign.apply(this, arguments);
22
- };
23
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
24
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
- return new (P || (P = Promise))(function (resolve, reject) {
26
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
- step((generator = generator.apply(thisArg, _arguments || [])).next());
30
- });
31
- };
32
- var __generator = (this && this.__generator) || function (thisArg, body) {
33
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
34
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
35
- function verb(n) { return function (v) { return step([n, v]); }; }
36
- function step(op) {
37
- if (f) throw new TypeError("Generator is already executing.");
38
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
39
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
40
- if (y = 0, t) op = [op[0] & 2, t.value];
41
- switch (op[0]) {
42
- case 0: case 1: t = op; break;
43
- case 4: _.label++; return { value: op[1], done: false };
44
- case 5: _.label++; y = op[1]; op = [0]; continue;
45
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
46
- default:
47
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
48
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
49
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
50
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
51
- if (t[2]) _.ops.pop();
52
- _.trys.pop(); continue;
53
- }
54
- op = body.call(thisArg, _);
55
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
56
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
57
- }
58
- };
59
- var _a = defineProps(), object = _a.object, id = _a.id;
60
- var client = inject(RpgClientEngine);
61
- var hooks = inject(ModulesToken);
62
- var guiService = inject(RpgGui);
63
- client.spritesheets;
64
- var playerId = client.playerId;
65
- var componentsBehind = client.spriteComponentsBehind;
66
- var componentsInFront = client.spriteComponentsInFront;
67
- var isMe = computed(function () { return id() === playerId; });
68
- var normalizeComponent = function (comp) {
69
- var componentRef;
70
- var propsValue;
71
- var dependenciesFn;
72
- // If it's a direct component reference
73
- if (typeof comp === 'function' || (comp && typeof comp === 'object' && !comp.component)) {
74
- componentRef = comp;
75
- propsValue = undefined;
76
- dependenciesFn = undefined;
77
- }
78
- // If it's a configuration object with component and props
79
- else if (comp && typeof comp === 'object' && comp.component) {
80
- componentRef = comp.component;
81
- // Support both "data" (legacy) and "props" (new) for backward compatibility
82
- propsValue = comp.props !== undefined ? comp.props : comp.data;
83
- dependenciesFn = comp.dependencies;
84
- }
85
- // Fallback: treat as direct component
86
- else {
87
- componentRef = comp;
88
- propsValue = undefined;
89
- dependenciesFn = undefined;
90
- }
91
- // Return props directly (object or function), not as computed
92
- // The computed will be created in the template when needed
93
- return {
94
- component: componentRef,
95
- props: typeof propsValue === 'function' ? propsValue(object) : propsValue || {},
96
- dependencies: dependenciesFn ? dependenciesFn(object) : []
97
- };
98
- };
99
- var normalizeComponents = function (components) {
100
- return components.map(function (comp) { return normalizeComponent(comp); });
101
- };
102
- var normalizedComponentsBehind = computed(function () {
103
- return normalizeComponents(componentsBehind());
104
- });
105
- var normalizedComponentsInFront = computed(function () {
106
- return normalizeComponents(componentsInFront());
107
- });
108
- var shouldFollowCamera = computed(function () {
109
- var cameraTargetId = client.cameraFollowTargetId();
110
- // If a target is explicitly set, only follow if this sprite is the target
111
- if (cameraTargetId !== null) {
112
- return id() === cameraTargetId;
113
- }
114
- // Otherwise, follow the current player (default behavior)
115
- return isMe();
116
- });
117
- var attachedGuis = computed(function () {
118
- return guiService.getAttachedGuis();
119
- });
120
- var shouldDisplayAttachedGui = computed(function () {
121
- return guiService.shouldDisplayAttachedGui(id());
122
- });
123
- var x = object.x, y = object.y, tint = object.tint, direction = object.direction, animationName = object.animationName, animationCurrentIndex = object.animationCurrentIndex, emitParticleTrigger = object.emitParticleTrigger, particleName = object.particleName; object.graphics; var hitbox = object.hitbox, isConnected = object.isConnected, graphicsSignals = object.graphicsSignals, flashTrigger = object.flashTrigger;
124
- var flashType = signal('alpha');
125
- var flashDuration = signal(300);
126
- var flashCycles = signal(1);
127
- var flashAlpha = signal(0.3);
128
- var flashTint = signal(0xffffff);
129
- on(flashTrigger, function (data) {
130
- if (data && typeof data === 'object') {
131
- if (data.type !== undefined)
132
- flashType.set(data.type);
133
- if (data.duration !== undefined)
134
- flashDuration.set(data.duration);
135
- if (data.cycles !== undefined)
136
- flashCycles.set(data.cycles);
137
- if (data.alpha !== undefined)
138
- flashAlpha.set(data.alpha);
139
- if (data.tint !== undefined)
140
- flashTint.set(data.tint);
141
- }
142
- });
143
- var flashConfig = computed(function () { return ({
144
- trigger: flashTrigger,
145
- type: flashType(),
146
- duration: flashDuration(),
147
- cycles: flashCycles(),
148
- alpha: flashAlpha(),
149
- tint: flashTint(),
150
- }); });
151
- var particleSettings = client.particleSettings;
152
- var canControls = function () { return isMe() && object.canMove(); };
153
- var keyboardControls = client.globalConfig.keyboardControls;
154
- var visible = computed(function () {
155
- if (object.type === 'event') {
156
- return true;
157
- }
158
- return isConnected();
159
- });
160
- var controls = signal({
161
- down: {
162
- repeat: true,
163
- bind: keyboardControls.down,
164
- keyDown: function () {
165
- if (canControls())
166
- client.processInput({ input: Direction.Down });
167
- },
168
- },
169
- up: {
170
- repeat: true,
171
- bind: keyboardControls.up,
172
- keyDown: function () {
173
- if (canControls())
174
- client.processInput({ input: Direction.Up });
175
- },
176
- },
177
- left: {
178
- repeat: true,
179
- bind: keyboardControls.left,
180
- keyDown: function () {
181
- if (canControls())
182
- client.processInput({ input: Direction.Left });
183
- },
184
- },
185
- right: {
186
- repeat: true,
187
- bind: keyboardControls.right,
188
- keyDown: function () {
189
- if (canControls())
190
- client.processInput({ input: Direction.Right });
191
- },
192
- },
193
- action: {
194
- bind: keyboardControls.action,
195
- keyDown: function () {
196
- if (canControls()) {
197
- client.processAction({ action: 'action' });
198
- }
199
- },
200
- },
201
- escape: {
202
- bind: keyboardControls.escape,
203
- keyDown: function () {
204
- if (canControls()) {
205
- client.processAction({ action: 'escape' });
206
- }
207
- },
208
- },
209
- gamepad: {
210
- enabled: true
211
- }
212
- });
213
- var smoothX = animatedSignal(x(), {
214
- duration: isMe() ? 0 : 0
215
- });
216
- var smoothY = animatedSignal(y(), {
217
- duration: isMe() ? 0 : 0,
218
- });
219
- var z = computed(function () {
220
- return object.y() + object.z();
221
- });
222
- var realAnimationName = signal(animationName());
223
- var xSubscription = x.observable.subscribe(function (value) {
224
- smoothX.set(value);
225
- });
226
- var ySubscription = y.observable.subscribe(function (value) {
227
- smoothY.set(value);
228
- });
229
- var sheet = function (graphicObject) {
230
- return {
231
- definition: graphicObject,
232
- playing: realAnimationName(),
233
- params: {
234
- direction: direction()
235
- },
236
- onFinish: function () {
237
- animationCurrentIndex.update(function (index) { return index + 1; });
238
- }
239
- };
240
- };
241
- var movementAnimations = ['walk', 'stand'];
242
- var epsilon = 0;
243
- var stateX$ = smoothX.animatedState.observable;
244
- var stateY$ = smoothY.animatedState.observable;
245
- var animationName$ = animationName.observable;
246
- var moving$ = combineLatest([stateX$, stateY$]).pipe(map(function (_a) {
247
- var sx = _a[0], sy = _a[1];
248
- var xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;
249
- var yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;
250
- return !xFinished || !yFinished; // moving if X or Y is not finished
251
- }), startWith(false));
252
- var animationChange$ = animationName$.pipe(startWith(animationName()), pairwise(), filter(function (_a) {
253
- var prev = _a[0], curr = _a[1];
254
- return prev !== curr;
255
- }));
256
- var animationMovementSubscription = combineLatest([animationChange$, moving$]).subscribe(function (_a) {
257
- var _b = _a[0]; _b[0]; var curr = _b[1], isMoving = _a[1];
258
- if (curr == 'stand' && !isMoving) {
259
- realAnimationName.set(curr);
260
- }
261
- else if (curr == 'walk' && isMoving) {
262
- realAnimationName.set(curr);
263
- }
264
- else if (!movementAnimations.includes(curr)) {
265
- realAnimationName.set(curr);
266
- }
267
- if (!isMoving && object.animationIsPlaying && object.animationIsPlaying()) {
268
- if (movementAnimations.includes(curr)) {
269
- if (typeof object.resetAnimationState === 'function') {
270
- object.resetAnimationState();
271
- }
272
- }
273
- }
274
- });
275
- var onBeforeDestroy = function () { return __awaiter(void 0, void 0, void 0, function () {
276
- return __generator(this, function (_a) {
277
- switch (_a.label) {
278
- case 0:
279
- animationMovementSubscription.unsubscribe();
280
- xSubscription.unsubscribe();
281
- ySubscription.unsubscribe();
282
- return [4 /*yield*/, lastValueFrom(hooks.callHooks("client-sprite-onDestroy", object))];
283
- case 1:
284
- _a.sent();
285
- return [4 /*yield*/, lastValueFrom(hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, object))];
286
- case 2:
287
- _a.sent();
288
- return [2 /*return*/];
289
- }
290
- });
291
- }); };
292
- mount(function (element) {
293
- hooks.callHooks("client-sprite-onAdd", object).subscribe();
294
- hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, object).subscribe();
295
- if (isMe())
296
- client.setKeyboardControls(element.directives.controls);
297
- });
298
- var onAttachedGuiFinish = function (gui, data) {
299
- guiService.guiClose(gui.name, data);
300
- };
301
- var onAttachedGuiInteraction = function (gui, name, data) {
302
- guiService.guiInteraction(gui.name, name, data);
303
- };
304
- tick(function () {
305
- hooks.callHooks("client-sprite-onUpdate").subscribe();
306
- });
307
- let $this = h(Container, { x: smoothX, y: smoothY, zIndex: z, viewportFollow: shouldFollowCamera, controls, onBeforeDestroy, visible }, [loop(normalizedComponentsBehind, compConfig => h(Container, null, h(compConfig.component, { object, ...compConfig.props }))), h(Particle, { emit: emitParticleTrigger, settings: particleSettings, zIndex: 1000, name: particleName }), h(Container, null, loop(graphicsSignals, graphicObj => h(Sprite, { sheet: computed(() => sheet(graphicObj)), direction, tint, hitbox, flash: flashConfig }))), loop(normalizedComponentsInFront, compConfig => h(Container, { dependencies: compConfig.dependencies }, h(compConfig.component, { object, ...compConfig.props }))), loop(attachedGuis, attachedGui => cond(shouldDisplayAttachedGui, () => h(Container, null, h(attachedGui.component, { ...attachedGui.data(), dependencies: attachedGui.dependencies, object: object, onFinish: (data) => {
308
- onAttachedGuiFinish(attachedGui, data);
309
- }, onInteraction: (name, data) => {
310
- onAttachedGuiInteraction(attachedGui, name, data);
311
- } }))))]);
312
- return $this
313
- }
314
-
10
+ useProps($$props);
11
+ const defineProps = useDefineProps($$props);
12
+ var __assign = this && this.__assign || function() {
13
+ __assign = Object.assign || function(t) {
14
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
15
+ s = arguments[i];
16
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
17
+ }
18
+ return t;
19
+ };
20
+ return __assign.apply(this, arguments);
21
+ };
22
+ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
23
+ function adopt(value) {
24
+ return value instanceof P ? value : new P(function(resolve) {
25
+ resolve(value);
26
+ });
27
+ }
28
+ return new (P || (P = Promise))(function(resolve, reject) {
29
+ function fulfilled(value) {
30
+ try {
31
+ step(generator.next(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ }
36
+ function rejected(value) {
37
+ try {
38
+ step(generator["throw"](value));
39
+ } catch (e) {
40
+ reject(e);
41
+ }
42
+ }
43
+ function step(result) {
44
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
45
+ }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
49
+ var __generator = this && this.__generator || function(thisArg, body) {
50
+ var _ = {
51
+ label: 0,
52
+ sent: function() {
53
+ if (t[0] & 1) throw t[1];
54
+ return t[1];
55
+ },
56
+ trys: [],
57
+ ops: []
58
+ }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
59
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
60
+ return this;
61
+ }), g;
62
+ function verb(n) {
63
+ return function(v) {
64
+ return step([n, v]);
65
+ };
66
+ }
67
+ function step(op) {
68
+ if (f) throw new TypeError("Generator is already executing.");
69
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
70
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
71
+ if (y = 0, t) op = [op[0] & 2, t.value];
72
+ switch (op[0]) {
73
+ case 0:
74
+ case 1:
75
+ t = op;
76
+ break;
77
+ case 4:
78
+ _.label++;
79
+ return {
80
+ value: op[1],
81
+ done: false
82
+ };
83
+ case 5:
84
+ _.label++;
85
+ y = op[1];
86
+ op = [0];
87
+ continue;
88
+ case 7:
89
+ op = _.ops.pop();
90
+ _.trys.pop();
91
+ continue;
92
+ default:
93
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
94
+ _ = 0;
95
+ continue;
96
+ }
97
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
98
+ _.label = op[1];
99
+ break;
100
+ }
101
+ if (op[0] === 6 && _.label < t[1]) {
102
+ _.label = t[1];
103
+ t = op;
104
+ break;
105
+ }
106
+ if (t && _.label < t[2]) {
107
+ _.label = t[2];
108
+ _.ops.push(op);
109
+ break;
110
+ }
111
+ if (t[2]) _.ops.pop();
112
+ _.trys.pop();
113
+ continue;
114
+ }
115
+ op = body.call(thisArg, _);
116
+ } catch (e) {
117
+ op = [6, e];
118
+ y = 0;
119
+ } finally {
120
+ f = t = 0;
121
+ }
122
+ if (op[0] & 5) throw op[1];
123
+ return {
124
+ value: op[0] ? op[1] : void 0,
125
+ done: true
126
+ };
127
+ }
128
+ };
129
+ var _a = defineProps(), object = _a.object, id = _a.id;
130
+ var client = inject(RpgClientEngine);
131
+ var hooks = inject(ModulesToken);
132
+ var guiService = inject(RpgGui);
133
+ client.spritesheets;
134
+ var playerId = client.playerId;
135
+ var componentsBehind = client.spriteComponentsBehind;
136
+ var componentsInFront = client.spriteComponentsInFront;
137
+ var isMe = computed(function() {
138
+ return id() === playerId;
139
+ });
140
+ var normalizeComponent = function(comp) {
141
+ var componentRef;
142
+ var propsValue;
143
+ var dependenciesFn;
144
+ if (typeof comp === "function" || comp && typeof comp === "object" && !comp.component) {
145
+ componentRef = comp;
146
+ propsValue = void 0;
147
+ dependenciesFn = void 0;
148
+ } else if (comp && typeof comp === "object" && comp.component) {
149
+ componentRef = comp.component;
150
+ propsValue = comp.props !== void 0 ? comp.props : comp.data;
151
+ dependenciesFn = comp.dependencies;
152
+ } else {
153
+ componentRef = comp;
154
+ propsValue = void 0;
155
+ dependenciesFn = void 0;
156
+ }
157
+ return {
158
+ component: componentRef,
159
+ props: typeof propsValue === "function" ? propsValue(object) : propsValue || {},
160
+ dependencies: dependenciesFn ? dependenciesFn(object) : []
161
+ };
162
+ };
163
+ var normalizeComponents = function(components) {
164
+ return components.map(function(comp) {
165
+ return normalizeComponent(comp);
166
+ });
167
+ };
168
+ var normalizedComponentsBehind = computed(function() {
169
+ return normalizeComponents(componentsBehind());
170
+ });
171
+ var normalizedComponentsInFront = computed(function() {
172
+ return normalizeComponents(componentsInFront());
173
+ });
174
+ var shouldFollowCamera = computed(function() {
175
+ var cameraTargetId = client.cameraFollowTargetId();
176
+ if (cameraTargetId !== null) return id() === cameraTargetId;
177
+ return isMe();
178
+ });
179
+ var attachedGuis = computed(function() {
180
+ return guiService.getAttachedGuis();
181
+ });
182
+ var shouldDisplayAttachedGui = computed(function() {
183
+ return guiService.shouldDisplayAttachedGui(id());
184
+ }), x = object.x, y = object.y, tint = object.tint, direction = object.direction, animationName = object.animationName, animationCurrentIndex = object.animationCurrentIndex, emitParticleTrigger = object.emitParticleTrigger, particleName = object.particleName;
185
+ object.graphics;
186
+ var hitbox = object.hitbox, isConnected = object.isConnected, graphicsSignals = object.graphicsSignals, flashTrigger = object.flashTrigger;
187
+ var flashType = signal("alpha");
188
+ var flashDuration = signal(300);
189
+ var flashCycles = signal(1);
190
+ var flashAlpha = signal(.3);
191
+ var flashTint = signal(16777215);
192
+ on(flashTrigger, function(data) {
193
+ if (data && typeof data === "object") {
194
+ if (data.type !== void 0) flashType.set(data.type);
195
+ if (data.duration !== void 0) flashDuration.set(data.duration);
196
+ if (data.cycles !== void 0) flashCycles.set(data.cycles);
197
+ if (data.alpha !== void 0) flashAlpha.set(data.alpha);
198
+ if (data.tint !== void 0) flashTint.set(data.tint);
199
+ }
200
+ });
201
+ var flashConfig = computed(function() {
202
+ return {
203
+ trigger: flashTrigger,
204
+ type: flashType(),
205
+ duration: flashDuration(),
206
+ cycles: flashCycles(),
207
+ alpha: flashAlpha(),
208
+ tint: flashTint()
209
+ };
210
+ });
211
+ var particleSettings = client.particleSettings;
212
+ var canControls = function() {
213
+ return isMe() && object.canMove();
214
+ };
215
+ var keyboardControls = client.globalConfig.keyboardControls;
216
+ var visible = computed(function() {
217
+ if (object.type === "event") return true;
218
+ return isConnected();
219
+ });
220
+ var controls = signal({
221
+ down: {
222
+ repeat: true,
223
+ bind: keyboardControls.down,
224
+ keyDown: function() {
225
+ if (canControls()) client.processInput({ input: Direction.Down });
226
+ }
227
+ },
228
+ up: {
229
+ repeat: true,
230
+ bind: keyboardControls.up,
231
+ keyDown: function() {
232
+ if (canControls()) client.processInput({ input: Direction.Up });
233
+ }
234
+ },
235
+ left: {
236
+ repeat: true,
237
+ bind: keyboardControls.left,
238
+ keyDown: function() {
239
+ if (canControls()) client.processInput({ input: Direction.Left });
240
+ }
241
+ },
242
+ right: {
243
+ repeat: true,
244
+ bind: keyboardControls.right,
245
+ keyDown: function() {
246
+ if (canControls()) client.processInput({ input: Direction.Right });
247
+ }
248
+ },
249
+ action: {
250
+ bind: keyboardControls.action,
251
+ keyDown: function() {
252
+ if (canControls()) client.processAction({ action: "action" });
253
+ }
254
+ },
255
+ escape: {
256
+ bind: keyboardControls.escape,
257
+ keyDown: function() {
258
+ if (canControls()) client.processAction({ action: "escape" });
259
+ }
260
+ },
261
+ gamepad: { enabled: true }
262
+ });
263
+ var smoothX = animatedSignal(x(), { duration: isMe() ? 0 : 0 });
264
+ var smoothY = animatedSignal(y(), { duration: isMe() ? 0 : 0 });
265
+ var z = computed(function() {
266
+ return object.y() + object.z();
267
+ });
268
+ var realAnimationName = signal(animationName());
269
+ var xSubscription = x.observable.subscribe(function(value) {
270
+ smoothX.set(value);
271
+ });
272
+ var ySubscription = y.observable.subscribe(function(value) {
273
+ smoothY.set(value);
274
+ });
275
+ var sheet = function(graphicObject) {
276
+ return {
277
+ definition: graphicObject,
278
+ playing: realAnimationName(),
279
+ params: { direction: direction() },
280
+ onFinish: function() {
281
+ animationCurrentIndex.update(function(index) {
282
+ return index + 1;
283
+ });
284
+ }
285
+ };
286
+ };
287
+ var movementAnimations = ["walk", "stand"];
288
+ var epsilon = 0;
289
+ var stateX$ = smoothX.animatedState.observable;
290
+ var stateY$ = smoothY.animatedState.observable;
291
+ var animationName$ = animationName.observable;
292
+ var moving$ = combineLatest([stateX$, stateY$]).pipe(map(function(_a) {
293
+ var sx = _a[0], sy = _a[1];
294
+ var xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;
295
+ var yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;
296
+ return !xFinished || !yFinished;
297
+ }), startWith(false));
298
+ var animationMovementSubscription = combineLatest([animationName$.pipe(startWith(animationName()), pairwise(), filter(function(_a) {
299
+ return _a[0] !== _a[1];
300
+ })), moving$]).subscribe(function(_a) {
301
+ var _b = _a[0];
302
+ _b[0];
303
+ var curr = _b[1], isMoving = _a[1];
304
+ if (curr == "stand" && !isMoving) realAnimationName.set(curr);
305
+ else if (curr == "walk" && isMoving) realAnimationName.set(curr);
306
+ else if (!movementAnimations.includes(curr)) realAnimationName.set(curr);
307
+ if (!isMoving && object.animationIsPlaying && object.animationIsPlaying()) {
308
+ if (movementAnimations.includes(curr)) {
309
+ if (typeof object.resetAnimationState === "function") object.resetAnimationState();
310
+ }
311
+ }
312
+ });
313
+ var onBeforeDestroy = function() {
314
+ return __awaiter(void 0, void 0, void 0, function() {
315
+ return __generator(this, function(_a) {
316
+ switch (_a.label) {
317
+ case 0:
318
+ animationMovementSubscription.unsubscribe();
319
+ xSubscription.unsubscribe();
320
+ ySubscription.unsubscribe();
321
+ return [4, lastValueFrom(hooks.callHooks("client-sprite-onDestroy", object))];
322
+ case 1:
323
+ _a.sent();
324
+ return [4, lastValueFrom(hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, object))];
325
+ case 2:
326
+ _a.sent();
327
+ return [2];
328
+ }
329
+ });
330
+ });
331
+ };
332
+ mount(function(element) {
333
+ hooks.callHooks("client-sprite-onAdd", object).subscribe();
334
+ hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, object).subscribe();
335
+ if (isMe()) client.setKeyboardControls(element.directives.controls);
336
+ });
337
+ var onAttachedGuiFinish = function(gui, data) {
338
+ guiService.guiClose(gui.name, data);
339
+ };
340
+ var onAttachedGuiInteraction = function(gui, name, data) {
341
+ guiService.guiInteraction(gui.name, name, data);
342
+ };
343
+ tick(function() {
344
+ hooks.callHooks("client-sprite-onUpdate").subscribe();
345
+ });
346
+ return h(Container, {
347
+ x: smoothX,
348
+ y: smoothY,
349
+ zIndex: z,
350
+ viewportFollow: shouldFollowCamera,
351
+ controls,
352
+ onBeforeDestroy,
353
+ visible
354
+ }, [
355
+ loop(normalizedComponentsBehind, (compConfig) => h(Container, null, h(compConfig.component, {
356
+ object,
357
+ ...compConfig.props
358
+ }))),
359
+ h(Particle, {
360
+ emit: emitParticleTrigger,
361
+ settings: particleSettings,
362
+ zIndex: 1e3,
363
+ name: particleName
364
+ }),
365
+ h(Container, null, loop(graphicsSignals, (graphicObj) => h(Sprite, {
366
+ sheet: computed(() => sheet(graphicObj)),
367
+ direction,
368
+ tint,
369
+ hitbox,
370
+ flash: flashConfig
371
+ }))),
372
+ loop(normalizedComponentsInFront, (compConfig) => h(Container, { dependencies: compConfig.dependencies }, h(compConfig.component, {
373
+ object,
374
+ ...compConfig.props
375
+ }))),
376
+ loop(attachedGuis, (attachedGui) => cond(shouldDisplayAttachedGui, () => h(Container, null, h(attachedGui.component, {
377
+ ...attachedGui.data(),
378
+ dependencies: attachedGui.dependencies,
379
+ object,
380
+ onFinish: (data) => {
381
+ onAttachedGuiFinish(attachedGui, data);
382
+ },
383
+ onInteraction: (name, data) => {
384
+ onAttachedGuiInteraction(attachedGui, name, data);
385
+ }
386
+ }))))
387
+ ]);
388
+ }
389
+ //#endregion
315
390
  export { component as default };
316
- //# sourceMappingURL=character.ce.js.map
391
+
392
+ //# sourceMappingURL=character.ce.js.map