@rpgjs/client 5.0.0-beta.1 → 5.0.0-beta.10

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 (200) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +19 -0
  3. package/dist/Game/AnimationManager.d.ts +1 -1
  4. package/dist/Game/AnimationManager.js +18 -9
  5. package/dist/Game/AnimationManager.js.map +1 -1
  6. package/dist/Game/AnimationManager.spec.d.ts +1 -0
  7. package/dist/Game/Event.js.map +1 -1
  8. package/dist/Game/Map.d.ts +9 -1
  9. package/dist/Game/Map.js +63 -5
  10. package/dist/Game/Map.js.map +1 -1
  11. package/dist/Game/Object.d.ts +47 -15
  12. package/dist/Game/Object.js +82 -38
  13. package/dist/Game/Object.js.map +1 -1
  14. package/dist/Game/Player.js.map +1 -1
  15. package/dist/Gui/Gui.d.ts +17 -4
  16. package/dist/Gui/Gui.js +78 -48
  17. package/dist/Gui/Gui.js.map +1 -1
  18. package/dist/Gui/Gui.spec.d.ts +1 -0
  19. package/dist/Gui/NotificationManager.js.map +1 -1
  20. package/dist/Resource.js +1 -1
  21. package/dist/Resource.js.map +1 -1
  22. package/dist/RpgClient.d.ts +57 -2
  23. package/dist/RpgClientEngine.d.ts +61 -6
  24. package/dist/RpgClientEngine.js +122 -14
  25. package/dist/RpgClientEngine.js.map +1 -1
  26. package/dist/Sound.js.map +1 -1
  27. package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.130.0}/helpers/decorate.js +1 -1
  28. package/dist/_virtual/{_@oxc-project_runtime@0.122.0 → _@oxc-project_runtime@0.130.0}/helpers/decorateMetadata.js +1 -1
  29. package/dist/components/animations/animation.ce.js +4 -5
  30. package/dist/components/animations/animation.ce.js.map +1 -1
  31. package/dist/components/animations/hit.ce.js +19 -25
  32. package/dist/components/animations/hit.ce.js.map +1 -1
  33. package/dist/components/animations/index.js +4 -4
  34. package/dist/components/animations/index.js.map +1 -1
  35. package/dist/components/character.ce.js +406 -226
  36. package/dist/components/character.ce.js.map +1 -1
  37. package/dist/components/dynamics/bar.ce.js +96 -0
  38. package/dist/components/dynamics/bar.ce.js.map +1 -0
  39. package/dist/components/dynamics/image.ce.js +23 -0
  40. package/dist/components/dynamics/image.ce.js.map +1 -0
  41. package/dist/components/dynamics/parse-value.d.ts +3 -0
  42. package/dist/components/dynamics/parse-value.js +54 -35
  43. package/dist/components/dynamics/parse-value.js.map +1 -1
  44. package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
  45. package/dist/components/dynamics/shape-utils.d.ts +16 -0
  46. package/dist/components/dynamics/shape-utils.js +73 -0
  47. package/dist/components/dynamics/shape-utils.js.map +1 -0
  48. package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
  49. package/dist/components/dynamics/shape.ce.js +83 -0
  50. package/dist/components/dynamics/shape.ce.js.map +1 -0
  51. package/dist/components/dynamics/text.ce.js +33 -56
  52. package/dist/components/dynamics/text.ce.js.map +1 -1
  53. package/dist/components/gui/box.ce.js +6 -8
  54. package/dist/components/gui/box.ce.js.map +1 -1
  55. package/dist/components/gui/dialogbox/index.ce.js +53 -60
  56. package/dist/components/gui/dialogbox/index.ce.js.map +1 -1
  57. package/dist/components/gui/gameover.ce.js +39 -63
  58. package/dist/components/gui/gameover.ce.js.map +1 -1
  59. package/dist/components/gui/hud/hud.ce.js +21 -30
  60. package/dist/components/gui/hud/hud.ce.js.map +1 -1
  61. package/dist/components/gui/menu/equip-menu.ce.js +110 -164
  62. package/dist/components/gui/menu/equip-menu.ce.js.map +1 -1
  63. package/dist/components/gui/menu/exit-menu.ce.js +6 -5
  64. package/dist/components/gui/menu/exit-menu.ce.js.map +1 -1
  65. package/dist/components/gui/menu/items-menu.ce.js +49 -67
  66. package/dist/components/gui/menu/items-menu.ce.js.map +1 -1
  67. package/dist/components/gui/menu/main-menu.ce.js +72 -90
  68. package/dist/components/gui/menu/main-menu.ce.js.map +1 -1
  69. package/dist/components/gui/menu/options-menu.ce.js +5 -4
  70. package/dist/components/gui/menu/options-menu.ce.js.map +1 -1
  71. package/dist/components/gui/menu/skills-menu.ce.js +12 -17
  72. package/dist/components/gui/menu/skills-menu.ce.js.map +1 -1
  73. package/dist/components/gui/mobile/index.js +2 -2
  74. package/dist/components/gui/mobile/index.js.map +1 -1
  75. package/dist/components/gui/mobile/mobile.ce.js +5 -4
  76. package/dist/components/gui/mobile/mobile.ce.js.map +1 -1
  77. package/dist/components/gui/notification/notification.ce.js +22 -24
  78. package/dist/components/gui/notification/notification.ce.js.map +1 -1
  79. package/dist/components/gui/save-load.ce.js +70 -248
  80. package/dist/components/gui/save-load.ce.js.map +1 -1
  81. package/dist/components/gui/shop/shop.ce.js +87 -125
  82. package/dist/components/gui/shop/shop.ce.js.map +1 -1
  83. package/dist/components/gui/title-screen.ce.js +42 -68
  84. package/dist/components/gui/title-screen.ce.js.map +1 -1
  85. package/dist/components/player-components-utils.d.ts +67 -0
  86. package/dist/components/player-components-utils.js +162 -0
  87. package/dist/components/player-components-utils.js.map +1 -0
  88. package/dist/components/player-components-utils.spec.d.ts +1 -0
  89. package/dist/components/player-components.ce.js +188 -0
  90. package/dist/components/player-components.ce.js.map +1 -0
  91. package/dist/components/prebuilt/hp-bar.ce.js +41 -44
  92. package/dist/components/prebuilt/hp-bar.ce.js.map +1 -1
  93. package/dist/components/prebuilt/light-halo.ce.js +35 -59
  94. package/dist/components/prebuilt/light-halo.ce.js.map +1 -1
  95. package/dist/components/scenes/canvas.ce.js +157 -21
  96. package/dist/components/scenes/canvas.ce.js.map +1 -1
  97. package/dist/components/scenes/draw-map.ce.js +19 -29
  98. package/dist/components/scenes/draw-map.ce.js.map +1 -1
  99. package/dist/components/scenes/event-layer.ce.js +9 -8
  100. package/dist/components/scenes/event-layer.ce.js.map +1 -1
  101. package/dist/core/inject.js +1 -1
  102. package/dist/core/inject.js.map +1 -1
  103. package/dist/core/setup.js +1 -1
  104. package/dist/core/setup.js.map +1 -1
  105. package/dist/decorators/spritesheet.d.ts +1 -0
  106. package/dist/decorators/spritesheet.js +11 -0
  107. package/dist/decorators/spritesheet.js.map +1 -0
  108. package/dist/index.d.ts +1 -0
  109. package/dist/index.js +21 -20
  110. package/dist/module.js +4 -1
  111. package/dist/module.js.map +1 -1
  112. package/dist/node_modules/.pnpm/{@signe_di@2.9.0 → @signe_di@3.0.1}/node_modules/@signe/di/dist/index.js +7 -117
  113. package/dist/node_modules/.pnpm/@signe_di@3.0.1/node_modules/@signe/di/dist/index.js.map +1 -0
  114. package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js +239 -0
  115. package/dist/node_modules/.pnpm/@signe_reactive@3.0.1/node_modules/@signe/reactive/dist/index.js.map +1 -0
  116. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js +13 -0
  117. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/chunk-EUXUH3YW.js.map +1 -0
  118. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js +696 -0
  119. package/dist/node_modules/.pnpm/@signe_room@3.0.1/node_modules/@signe/room/dist/index.js.map +1 -0
  120. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js +44 -0
  121. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/client/index.js.map +1 -0
  122. package/dist/node_modules/.pnpm/{@signe_sync@2.9.0 → @signe_sync@3.0.1}/node_modules/@signe/sync/dist/index.js +57 -141
  123. package/dist/node_modules/.pnpm/@signe_sync@3.0.1/node_modules/@signe/sync/dist/index.js.map +1 -0
  124. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-HAC622V3.js.map +1 -1
  125. package/dist/node_modules/.pnpm/partysocket@1.1.3/node_modules/partysocket/dist/chunk-S74YV6PU.js.map +1 -1
  126. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js +27 -27
  127. package/dist/node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.js.map +1 -1
  128. package/dist/presets/animation.js.map +1 -1
  129. package/dist/presets/faceset.js.map +1 -1
  130. package/dist/presets/icon.js.map +1 -1
  131. package/dist/presets/index.js.map +1 -1
  132. package/dist/presets/lpc.js.map +1 -1
  133. package/dist/presets/rmspritesheet.js.map +1 -1
  134. package/dist/services/AbstractSocket.js.map +1 -1
  135. package/dist/services/keyboardControls.js.map +1 -1
  136. package/dist/services/loadMap.d.ts +6 -0
  137. package/dist/services/loadMap.js +1 -1
  138. package/dist/services/loadMap.js.map +1 -1
  139. package/dist/services/mmorpg.js +9 -4
  140. package/dist/services/mmorpg.js.map +1 -1
  141. package/dist/services/save.js.map +1 -1
  142. package/dist/services/save.spec.d.ts +1 -0
  143. package/dist/services/standalone.js +1 -1
  144. package/dist/services/standalone.js.map +1 -1
  145. package/dist/utils/getEntityProp.js +4 -3
  146. package/dist/utils/getEntityProp.js.map +1 -1
  147. package/dist/utils/getEntityProp.spec.d.ts +1 -0
  148. package/dist/utils/readPropValue.d.ts +2 -0
  149. package/dist/utils/readPropValue.js +13 -0
  150. package/dist/utils/readPropValue.js.map +1 -0
  151. package/package.json +13 -14
  152. package/src/Game/AnimationManager.spec.ts +30 -0
  153. package/src/Game/AnimationManager.ts +22 -10
  154. package/src/Game/Map.ts +91 -2
  155. package/src/Game/Object.ts +148 -69
  156. package/src/Gui/Gui.spec.ts +273 -0
  157. package/src/Gui/Gui.ts +105 -50
  158. package/src/Resource.ts +1 -2
  159. package/src/RpgClient.ts +63 -2
  160. package/src/RpgClientEngine.ts +173 -25
  161. package/src/components/character.ce +422 -15
  162. package/src/components/dynamics/bar.ce +87 -0
  163. package/src/components/dynamics/image.ce +20 -0
  164. package/src/components/dynamics/parse-value.spec.ts +83 -0
  165. package/src/components/dynamics/parse-value.ts +111 -37
  166. package/src/components/dynamics/shape-utils.spec.ts +46 -0
  167. package/src/components/dynamics/shape-utils.ts +61 -0
  168. package/src/components/dynamics/shape.ce +89 -0
  169. package/src/components/dynamics/text.ce +34 -149
  170. package/src/components/gui/dialogbox/index.ce +15 -6
  171. package/src/components/player-components-utils.spec.ts +109 -0
  172. package/src/components/player-components-utils.ts +205 -0
  173. package/src/components/player-components.ce +221 -0
  174. package/src/components/scenes/canvas.ce +165 -6
  175. package/src/components/scenes/draw-map.ce +2 -15
  176. package/src/components/scenes/event-layer.ce +1 -2
  177. package/src/core/setup.ts +2 -2
  178. package/src/decorators/spritesheet.ts +8 -0
  179. package/src/index.ts +1 -0
  180. package/src/module.ts +5 -1
  181. package/src/services/loadMap.ts +2 -0
  182. package/src/services/mmorpg.ts +8 -2
  183. package/src/services/save.spec.ts +127 -0
  184. package/src/utils/getEntityProp.spec.ts +96 -0
  185. package/src/utils/getEntityProp.ts +4 -3
  186. package/src/utils/readPropValue.ts +16 -0
  187. package/dist/node_modules/.pnpm/@signe_di@2.9.0/node_modules/@signe/di/dist/index.js.map +0 -1
  188. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js +0 -457
  189. package/dist/node_modules/.pnpm/@signe_reactive@2.8.3/node_modules/@signe/reactive/dist/index.js.map +0 -1
  190. package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js +0 -463
  191. package/dist/node_modules/.pnpm/@signe_reactive@2.9.0/node_modules/@signe/reactive/dist/index.js.map +0 -1
  192. package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js +0 -2191
  193. package/dist/node_modules/.pnpm/@signe_room@2.9.0/node_modules/@signe/room/dist/index.js.map +0 -1
  194. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js +0 -10
  195. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/chunk-7QVYU63E.js.map +0 -1
  196. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js +0 -91
  197. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/client/index.js.map +0 -1
  198. package/dist/node_modules/.pnpm/@signe_sync@2.9.0/node_modules/@signe/sync/dist/index.js.map +0 -1
  199. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js +0 -14
  200. package/dist/node_modules/.pnpm/dset@3.1.4/node_modules/dset/dist/index.js.map +0 -1
@@ -1,146 +1,38 @@
1
1
  import { inject } from "../core/inject.js";
2
+ import { getCanMoveValue } from "../utils/readPropValue.js";
2
3
  import { RpgGui } from "../Gui/Gui.js";
3
4
  import { RpgClientEngine } from "../RpgClientEngine.js";
4
- import { Container, Sprite, animatedSignal, computed, cond, h, loop, mount, on, signal, tick, useDefineProps, useProps } from "canvasengine";
5
+ import __ce_component$1 from "./player-components.ce.js";
6
+ import { Container, Sprite, animatedSignal, computed, cond, effect, h, loop, mount, on, signal, tick, useDefineProps, useProps } from "canvasengine";
5
7
  import { Particle } from "@canvasengine/presets";
6
- import { Direction, ModulesToken } from "@rpgjs/common";
8
+ import { Animation, Direction, ModulesToken } from "@rpgjs/common";
7
9
  import { combineLatest, filter, lastValueFrom, map, pairwise, startWith } from "rxjs";
10
+ import { Assets } from "pixi.js";
8
11
  //#region src/components/character.ce
9
12
  function component($$props) {
10
13
  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);
14
+ const { object, id } = useDefineProps($$props)();
15
+ const client = inject(RpgClientEngine);
16
+ const hooks = inject(ModulesToken);
17
+ const guiService = inject(RpgGui);
133
18
  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;
19
+ const componentsBehind = client.spriteComponentsBehind;
20
+ const componentsInFront = client.spriteComponentsInFront;
21
+ const readProp = (value) => typeof value === "function" ? value() : value;
22
+ const isCurrentPlayer = () => {
23
+ const playerId = client.playerIdSignal();
24
+ const currentPlayer = playerId ? client.sceneMap?.players?.()?.[playerId] : void 0;
25
+ return readProp(id) === playerId || readProp(object?.id) === playerId || object === currentPlayer || object === client.sceneMap?.getCurrentPlayer?.();
26
+ };
27
+ const isMe = computed(isCurrentPlayer);
28
+ const shadowsEnabled = computed(() => {
29
+ const lighting = client.sceneMap?.lighting?.();
30
+ return Boolean(lighting?.shadows?.enabled || (lighting?.spots?.length ?? 0) > 0);
139
31
  });
140
- var normalizeComponent = function(comp) {
141
- var componentRef;
142
- var propsValue;
143
- var dependenciesFn;
32
+ const normalizeComponent = (comp) => {
33
+ let componentRef;
34
+ let propsValue;
35
+ let dependenciesFn;
144
36
  if (typeof comp === "function" || comp && typeof comp === "object" && !comp.component) {
145
37
  componentRef = comp;
146
38
  propsValue = void 0;
@@ -160,36 +52,33 @@ function component($$props) {
160
52
  dependencies: dependenciesFn ? dependenciesFn(object) : []
161
53
  };
162
54
  };
163
- var normalizeComponents = function(components) {
164
- return components.map(function(comp) {
165
- return normalizeComponent(comp);
166
- });
55
+ const normalizeComponents = (components) => {
56
+ return components.map((comp) => normalizeComponent(comp));
167
57
  };
168
- var normalizedComponentsBehind = computed(function() {
58
+ const normalizedComponentsBehind = computed(() => {
169
59
  return normalizeComponents(componentsBehind());
170
60
  });
171
- var normalizedComponentsInFront = computed(function() {
61
+ const normalizedComponentsInFront = computed(() => {
172
62
  return normalizeComponents(componentsInFront());
173
63
  });
174
- var shouldFollowCamera = computed(function() {
175
- var cameraTargetId = client.cameraFollowTargetId();
64
+ const shouldFollowCamera = computed(() => {
65
+ const cameraTargetId = client.cameraFollowTargetId();
176
66
  if (cameraTargetId !== null) return id() === cameraTargetId;
177
67
  return isMe();
178
68
  });
179
- var attachedGuis = computed(function() {
69
+ const attachedGuis = computed(() => {
180
70
  return guiService.getAttachedGuis();
181
71
  });
182
- var shouldDisplayAttachedGui = computed(function() {
72
+ const shouldDisplayAttachedGui = computed(() => {
183
73
  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) {
74
+ });
75
+ const { x, y, tint, direction, animationName, animationCurrentIndex, emitParticleTrigger, particleName, graphics, hitbox, isConnected, graphicsSignals, flashTrigger } = object;
76
+ const flashType = signal("alpha");
77
+ const flashDuration = signal(300);
78
+ const flashCycles = signal(1);
79
+ const flashAlpha = signal(.3);
80
+ const flashTint = signal(16777215);
81
+ on(flashTrigger, (data) => {
193
82
  if (data && typeof data === "object") {
194
83
  if (data.type !== void 0) flashType.set(data.type);
195
84
  if (data.duration !== void 0) flashDuration.set(data.duration);
@@ -198,109 +87,360 @@ function component($$props) {
198
87
  if (data.tint !== void 0) flashTint.set(data.tint);
199
88
  }
200
89
  });
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() {
90
+ const flashConfig = computed(() => ({
91
+ trigger: flashTrigger,
92
+ type: flashType(),
93
+ duration: flashDuration(),
94
+ cycles: flashCycles(),
95
+ alpha: flashAlpha(),
96
+ tint: flashTint()
97
+ }));
98
+ const particleSettings = client.particleSettings;
99
+ const canControls = () => isMe() && getCanMoveValue(object);
100
+ const keyboardControls = client.globalConfig.keyboardControls;
101
+ const visible = computed(() => {
217
102
  if (object.isEvent()) return true;
218
103
  return isConnected();
219
104
  });
220
- var controls = signal({
105
+ const controls = {
221
106
  down: {
222
107
  repeat: true,
223
108
  bind: keyboardControls.down,
224
- keyDown: function() {
109
+ keyDown() {
225
110
  if (canControls()) client.processInput({ input: Direction.Down });
226
111
  }
227
112
  },
228
113
  up: {
229
114
  repeat: true,
230
115
  bind: keyboardControls.up,
231
- keyDown: function() {
116
+ keyDown() {
232
117
  if (canControls()) client.processInput({ input: Direction.Up });
233
118
  }
234
119
  },
235
120
  left: {
236
121
  repeat: true,
237
122
  bind: keyboardControls.left,
238
- keyDown: function() {
123
+ keyDown() {
239
124
  if (canControls()) client.processInput({ input: Direction.Left });
240
125
  }
241
126
  },
242
127
  right: {
243
128
  repeat: true,
244
129
  bind: keyboardControls.right,
245
- keyDown: function() {
130
+ keyDown() {
246
131
  if (canControls()) client.processInput({ input: Direction.Right });
247
132
  }
248
133
  },
249
134
  action: {
250
135
  bind: keyboardControls.action,
251
- keyDown: function() {
136
+ keyDown() {
252
137
  if (canControls()) client.processAction({ action: "action" });
253
138
  }
254
139
  },
255
140
  escape: {
256
141
  bind: keyboardControls.escape,
257
- keyDown: function() {
142
+ keyDown() {
258
143
  if (canControls()) client.processAction({ action: "escape" });
259
144
  }
260
145
  },
261
146
  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() {
147
+ };
148
+ const smoothX = animatedSignal(x(), { duration: isMe() ? 0 : 0 });
149
+ const smoothY = animatedSignal(y(), { duration: isMe() ? 0 : 0 });
150
+ const z = computed(() => {
266
151
  return object.y() + object.z();
267
152
  });
268
- var realAnimationName = signal(animationName());
269
- var xSubscription = x.observable.subscribe(function(value) {
153
+ const realAnimationName = signal(animationName());
154
+ const xSubscription = x.observable.subscribe((value) => {
270
155
  smoothX.set(value);
271
156
  });
272
- var ySubscription = y.observable.subscribe(function(value) {
157
+ const ySubscription = y.observable.subscribe((value) => {
273
158
  smoothY.set(value);
274
159
  });
275
- var sheet = function(graphicObject) {
160
+ const sheet = (graphicObject) => {
276
161
  return {
277
162
  definition: graphicObject,
278
163
  playing: realAnimationName(),
279
164
  params: { direction: direction() },
280
- onFinish: function() {
281
- animationCurrentIndex.update(function(index) {
282
- return index + 1;
283
- });
165
+ onFinish() {
166
+ animationCurrentIndex.update((index) => index + 1);
284
167
  }
285
168
  };
286
169
  };
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;
170
+ const graphicScale = (graphicObject) => {
171
+ const scale = graphicObject?.scale;
172
+ if (Array.isArray(scale)) return scale;
173
+ if (typeof scale === "number") return [scale, scale];
174
+ if (scale && typeof scale === "object") {
175
+ const x = typeof scale.x === "number" ? scale.x : 1;
176
+ return [x, typeof scale.y === "number" ? scale.y : x];
177
+ }
178
+ };
179
+ const shadowCaster = (graphicObject) => {
180
+ const box = hitbox();
181
+ const bounds = graphicBounds();
182
+ const scale = graphicScale(graphicObject);
183
+ const scaleY = Array.isArray(scale) && typeof scale[1] === "number" ? Math.abs(scale[1]) : 1;
184
+ const height = Math.max(bounds?.height ?? box?.h ?? 32, box?.h ?? 32) * scaleY;
185
+ return {
186
+ enabled: shadowsEnabled,
187
+ height,
188
+ footAnchor: {
189
+ x: .5,
190
+ y: 1
191
+ },
192
+ footOffset: {
193
+ x: 0,
194
+ y: 2
195
+ },
196
+ alpha: .5,
197
+ blur: 3.5,
198
+ gradientPower: 2,
199
+ hardness: .42,
200
+ minLength: Math.max(6, (box?.h ?? 32) * .25),
201
+ maxLength: Math.max(90, height * 1.8),
202
+ contactAlpha: .3,
203
+ contactScale: .3
204
+ };
205
+ };
206
+ const imageDimensions = signal({});
207
+ const loadingImageDimensions = /* @__PURE__ */ new Set();
208
+ const toPositiveNumber = (value) => {
209
+ const number = typeof value === "number" ? value : parseFloat(value);
210
+ return Number.isFinite(number) && number > 0 ? number : void 0;
211
+ };
212
+ const toFiniteNumber = (value, fallback = 0) => {
213
+ const number = typeof value === "number" ? value : parseFloat(value);
214
+ return Number.isFinite(number) ? number : fallback;
215
+ };
216
+ const clampRatio = (value) => Math.min(1, Math.max(0, value));
217
+ const normalizePair = (value, fallback = [1, 1]) => {
218
+ if (Array.isArray(value)) {
219
+ const x = toFiniteNumber(value[0], fallback[0]);
220
+ return [x, toFiniteNumber(value[1] ?? value[0], x)];
221
+ }
222
+ if (typeof value === "number") return [value, value];
223
+ if (value && typeof value === "object") {
224
+ const x = toFiniteNumber(value.x, fallback[0]);
225
+ return [x, toFiniteNumber(value.y ?? value.x, x)];
226
+ }
227
+ return fallback;
228
+ };
229
+ const normalizeAnchor = (value) => {
230
+ if (!Array.isArray(value)) return void 0;
231
+ const [x, y] = normalizePair(value, [0, 0]);
232
+ return [clampRatio(x), clampRatio(y)];
233
+ };
234
+ const resolveImageSource = (image) => {
235
+ if (typeof image === "string") return image;
236
+ if (typeof image?.default === "string") return image.default;
237
+ };
238
+ const parentTextureOptions = (graphicObject) => {
239
+ return [
240
+ "width",
241
+ "height",
242
+ "framesHeight",
243
+ "framesWidth",
244
+ "rectWidth",
245
+ "rectHeight",
246
+ "offset",
247
+ "image",
248
+ "sound",
249
+ "spriteRealSize",
250
+ "scale",
251
+ "anchor",
252
+ "pivot",
253
+ "x",
254
+ "y",
255
+ "opacity"
256
+ ].reduce((options, prop) => {
257
+ if (graphicObject?.[prop] !== void 0) options[prop] = graphicObject[prop];
258
+ return options;
259
+ }, {});
260
+ };
261
+ const resolveTextureOptions = (graphicObject) => {
262
+ const textures = graphicObject?.textures ?? {};
263
+ const texture = textures[realAnimationName()] ?? textures[Animation.Stand] ?? Object.values(textures)[0] ?? {};
264
+ return {
265
+ ...parentTextureOptions(graphicObject),
266
+ ...texture
267
+ };
268
+ };
269
+ const resolveFirstAnimationFrame = (textureOptions) => {
270
+ const animations = textureOptions?.animations;
271
+ if (!animations) return {};
272
+ try {
273
+ const frames = typeof animations === "function" ? animations({ direction: direction() }) : animations;
274
+ if (!Array.isArray(frames)) return {};
275
+ const firstGroup = frames[0];
276
+ return Array.isArray(firstGroup) ? firstGroup[0] ?? {} : firstGroup ?? {};
277
+ } catch {
278
+ return {};
279
+ }
280
+ };
281
+ const optionValue = (prop, frame, textureOptions, graphicObject) => {
282
+ return frame?.[prop] ?? textureOptions?.[prop] ?? graphicObject?.[prop];
283
+ };
284
+ const resolveFrameSize = (textureOptions, dimensions) => {
285
+ const framesWidth = toPositiveNumber(textureOptions?.framesWidth) ?? 1;
286
+ const framesHeight = toPositiveNumber(textureOptions?.framesHeight) ?? 1;
287
+ const imageSource = resolveImageSource(textureOptions?.image);
288
+ const loadedSize = imageSource ? dimensions[imageSource] : void 0;
289
+ const fullWidth = toPositiveNumber(textureOptions?.width) ?? loadedSize?.width;
290
+ const fullHeight = toPositiveNumber(textureOptions?.height) ?? loadedSize?.height;
291
+ return {
292
+ width: toPositiveNumber(textureOptions?.rectWidth) ?? toPositiveNumber(textureOptions?.spriteWidth) ?? (fullWidth ? fullWidth / framesWidth : void 0),
293
+ height: toPositiveNumber(textureOptions?.rectHeight) ?? toPositiveNumber(textureOptions?.spriteHeight) ?? (fullHeight ? fullHeight / framesHeight : void 0)
294
+ };
295
+ };
296
+ const resolveHitboxAnchor = (spriteWidth, spriteHeight, realSize, box) => {
297
+ if (!spriteWidth || !spriteHeight || !box) return [0, 0];
298
+ const resolvedHeight = toPositiveNumber(typeof realSize === "number" ? realSize : realSize?.height) ?? spriteHeight;
299
+ const gap = Math.max(0, (spriteHeight - resolvedHeight) / 2);
300
+ const hitboxTopLeftX = clampRatio((spriteWidth - box.w) / 2 / spriteWidth);
301
+ const hitboxTopLeftY = clampRatio((spriteHeight - box.h - gap) / spriteHeight);
302
+ const hitboxCenterX = clampRatio(hitboxTopLeftX + box.w / 2 / spriteWidth);
303
+ const hitboxCenterY = clampRatio(hitboxTopLeftY + box.h / 2 / spriteHeight);
304
+ const footY = clampRatio((spriteHeight - gap) / spriteHeight);
305
+ switch (box.anchorMode ?? "top-left") {
306
+ case "center": return [hitboxCenterX, hitboxCenterY];
307
+ case "foot": return [hitboxCenterX, footY];
308
+ default: return [hitboxTopLeftX, hitboxTopLeftY];
309
+ }
310
+ };
311
+ const loadImageDimensions = (image) => {
312
+ const source = resolveImageSource(image);
313
+ if (!source || imageDimensions()[source] || loadingImageDimensions.has(source)) return;
314
+ loadingImageDimensions.add(source);
315
+ Assets.load(source).then((texture) => {
316
+ const width = toPositiveNumber(texture?.width);
317
+ const height = toPositiveNumber(texture?.height);
318
+ if (!width || !height) return;
319
+ imageDimensions.update((dimensions) => ({
320
+ ...dimensions,
321
+ [source]: {
322
+ width,
323
+ height
324
+ }
325
+ }));
326
+ }).catch(() => {}).finally(() => {
327
+ loadingImageDimensions.delete(source);
328
+ });
329
+ };
330
+ effect(() => {
331
+ const sources = /* @__PURE__ */ new Set();
332
+ graphicsSignals().forEach((graphicObject) => {
333
+ const baseImage = resolveImageSource(graphicObject?.image);
334
+ if (baseImage) sources.add(baseImage);
335
+ Object.values(graphicObject?.textures ?? {}).forEach((textureOptions) => {
336
+ const image = resolveImageSource(textureOptions?.image ?? graphicObject?.image);
337
+ if (image) sources.add(image);
338
+ });
339
+ });
340
+ sources.forEach((source) => loadImageDimensions(source));
341
+ });
342
+ const hitboxBounds = computed(() => {
343
+ const box = hitbox();
344
+ const width = box?.w ?? 0;
345
+ const height = box?.h ?? 0;
346
+ return {
347
+ left: 0,
348
+ top: 0,
349
+ right: width,
350
+ bottom: height,
351
+ width,
352
+ height,
353
+ centerX: width / 2,
354
+ centerY: height / 2
355
+ };
356
+ });
357
+ const graphicBounds = computed(() => {
358
+ const box = hitbox();
359
+ const fallback = hitboxBounds();
360
+ const dimensions = imageDimensions();
361
+ const graphics = graphicsSignals();
362
+ let bounds = null;
363
+ graphics.forEach((graphicObject) => {
364
+ const textureOptions = resolveTextureOptions(graphicObject);
365
+ const frame = resolveFirstAnimationFrame(textureOptions);
366
+ const size = resolveFrameSize(textureOptions, dimensions);
367
+ const spriteWidth = size.width ?? box?.w;
368
+ const spriteHeight = size.height ?? box?.h;
369
+ if (!spriteWidth || !spriteHeight) return;
370
+ const anchor = normalizeAnchor(optionValue("anchor", frame, textureOptions, graphicObject)) ?? resolveHitboxAnchor(spriteWidth, spriteHeight, optionValue("spriteRealSize", frame, textureOptions, graphicObject), box);
371
+ const scale = normalizePair(optionValue("scale", frame, textureOptions, graphicObject) ?? graphicScale(graphicObject));
372
+ const x = toFiniteNumber(optionValue("x", frame, textureOptions, graphicObject), 0);
373
+ const y = toFiniteNumber(optionValue("y", frame, textureOptions, graphicObject), 0);
374
+ const leftEdge = -anchor[0] * spriteWidth * scale[0];
375
+ const rightEdge = (1 - anchor[0]) * spriteWidth * scale[0];
376
+ const topEdge = -anchor[1] * spriteHeight * scale[1];
377
+ const bottomEdge = (1 - anchor[1]) * spriteHeight * scale[1];
378
+ const graphic = {
379
+ left: x + Math.min(leftEdge, rightEdge),
380
+ top: y + Math.min(topEdge, bottomEdge),
381
+ right: x + Math.max(leftEdge, rightEdge),
382
+ bottom: y + Math.max(topEdge, bottomEdge)
383
+ };
384
+ bounds = bounds ? {
385
+ left: Math.min(bounds.left, graphic.left),
386
+ top: Math.min(bounds.top, graphic.top),
387
+ right: Math.max(bounds.right, graphic.right),
388
+ bottom: Math.max(bounds.bottom, graphic.bottom)
389
+ } : graphic;
390
+ });
391
+ if (!bounds) return fallback;
392
+ const width = bounds.right - bounds.left;
393
+ const height = bounds.bottom - bounds.top;
394
+ return {
395
+ ...bounds,
396
+ width,
397
+ height,
398
+ centerX: bounds.left + width / 2,
399
+ centerY: bounds.top + height / 2
400
+ };
401
+ });
402
+ const movementAnimations = ["walk", "stand"];
403
+ const epsilon = 0;
404
+ const stateX$ = smoothX.animatedState.observable;
405
+ const stateY$ = smoothY.animatedState.observable;
406
+ const animationName$ = animationName.observable;
407
+ const moving$ = combineLatest([stateX$, stateY$]).pipe(map(([sx, sy]) => {
408
+ const xFinished = Math.abs(sx.value.current - sx.value.end) <= epsilon;
409
+ const yFinished = Math.abs(sy.value.current - sy.value.end) <= epsilon;
296
410
  return !xFinished || !yFinished;
297
411
  }), 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];
412
+ const animationChange$ = animationName$.pipe(startWith(animationName()), pairwise(), filter(([prev, curr]) => prev !== curr));
413
+ let beforeRemovePromise = null;
414
+ let beforeRemoveTransitionValue = null;
415
+ const resolveRemoveContext = () => {
416
+ if (!object._removeTransition) return null;
417
+ const value = object._removeTransition();
418
+ if (!value || typeof value !== "string") return null;
419
+ try {
420
+ const context = JSON.parse(value);
421
+ if (!context || typeof context !== "object" || !context.active) return null;
422
+ context.__transitionValue = value;
423
+ return context;
424
+ } catch {
425
+ return null;
426
+ }
427
+ };
428
+ const withTimeout = (promise, timeoutMs = 0) => {
429
+ if (!timeoutMs || timeoutMs <= 0) return promise;
430
+ return Promise.race([promise, new Promise((resolve) => setTimeout(resolve, timeoutMs))]);
431
+ };
432
+ const runBeforeRemove = () => {
433
+ const context = resolveRemoveContext();
434
+ if (!context) return Promise.resolve();
435
+ if (beforeRemovePromise && beforeRemoveTransitionValue === context.__transitionValue) return beforeRemovePromise;
436
+ beforeRemoveTransitionValue = context.__transitionValue;
437
+ beforeRemovePromise = withTimeout(lastValueFrom(hooks.callHooks("client-sprite-onBeforeRemove", object, context)), context.timeoutMs);
438
+ return beforeRemovePromise;
439
+ };
440
+ const removeTransitionSubscription = object._removeTransition?.observable?.subscribe(() => {
441
+ if (resolveRemoveContext()) runBeforeRemove();
442
+ });
443
+ const animationMovementSubscription = combineLatest([animationChange$, moving$]).subscribe(([[prev, curr], isMoving]) => {
304
444
  if (curr == "stand" && !isMoving) realAnimationName.set(curr);
305
445
  else if (curr == "walk" && isMoving) realAnimationName.set(curr);
306
446
  else if (!movementAnimations.includes(curr)) realAnimationName.set(curr);
@@ -310,37 +450,50 @@ function component($$props) {
310
450
  }
311
451
  }
312
452
  });
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
- }
453
+ const waitForTemporaryAnimationEnd = (maxDuration = 1200) => {
454
+ if (!object.animationIsPlaying || !object.animationIsPlaying()) return Promise.resolve();
455
+ return new Promise((resolve) => {
456
+ let finished = false;
457
+ let timeout;
458
+ let subscription;
459
+ const finish = () => {
460
+ if (finished) return;
461
+ finished = true;
462
+ clearTimeout(timeout);
463
+ subscription?.unsubscribe();
464
+ resolve();
465
+ };
466
+ timeout = setTimeout(finish, maxDuration);
467
+ subscription = object.animationIsPlaying.observable.subscribe((isPlaying) => {
468
+ if (!isPlaying) finish();
329
469
  });
470
+ if (finished) subscription.unsubscribe();
330
471
  });
331
472
  };
332
- mount(function(element) {
473
+ const onBeforeDestroy = async () => {
474
+ await runBeforeRemove();
475
+ await waitForTemporaryAnimationEnd();
476
+ removeTransitionSubscription?.unsubscribe();
477
+ animationMovementSubscription.unsubscribe();
478
+ xSubscription.unsubscribe();
479
+ ySubscription.unsubscribe();
480
+ await lastValueFrom(hooks.callHooks("client-sprite-onDestroy", object));
481
+ await lastValueFrom(hooks.callHooks("client-sceneMap-onRemoveSprite", client.sceneMap, object));
482
+ };
483
+ mount((element) => {
333
484
  hooks.callHooks("client-sprite-onAdd", object).subscribe();
334
485
  hooks.callHooks("client-sceneMap-onAddSprite", client.sceneMap, object).subscribe();
335
- if (isMe()) client.setKeyboardControls(element.directives.controls);
486
+ effect(() => {
487
+ if (isCurrentPlayer()) client.setKeyboardControls(element.directives.controls);
488
+ });
336
489
  });
337
- var onAttachedGuiFinish = function(gui, data) {
490
+ const onAttachedGuiFinish = (gui, data) => {
338
491
  guiService.guiClose(gui.name, data);
339
492
  };
340
- var onAttachedGuiInteraction = function(gui, name, data) {
493
+ const onAttachedGuiInteraction = (gui, name, data) => {
341
494
  guiService.guiInteraction(gui.name, name, data);
342
495
  };
343
- tick(function() {
496
+ tick(() => {
344
497
  hooks.callHooks("client-sprite-onUpdate").subscribe();
345
498
  });
346
499
  return h(Container, {
@@ -356,19 +509,45 @@ function component($$props) {
356
509
  object,
357
510
  ...compConfig.props
358
511
  }))),
512
+ h(__ce_component$1, {
513
+ object,
514
+ position: "bottom",
515
+ graphicBounds
516
+ }),
517
+ h(__ce_component$1, {
518
+ object,
519
+ position: "left",
520
+ graphicBounds
521
+ }),
359
522
  h(Particle, {
360
523
  emit: emitParticleTrigger,
361
524
  settings: particleSettings,
362
525
  zIndex: 1e3,
363
526
  name: particleName
364
527
  }),
365
- h(Container, null, loop(graphicsSignals, (graphicObj) => h(Sprite, {
528
+ h(Container, null, loop(graphicsSignals, (graphicObj) => h(Container, { scale: computed(() => graphicScale(graphicObj)) }, h(Sprite, {
366
529
  sheet: computed(() => sheet(graphicObj)),
367
530
  direction,
368
531
  tint,
369
532
  hitbox,
533
+ shadowCaster: computed(() => shadowCaster(graphicObj)),
370
534
  flash: flashConfig
371
- }))),
535
+ })))),
536
+ h(__ce_component$1, {
537
+ object,
538
+ position: "center",
539
+ graphicBounds
540
+ }),
541
+ h(__ce_component$1, {
542
+ object,
543
+ position: "right",
544
+ graphicBounds
545
+ }),
546
+ h(__ce_component$1, {
547
+ object,
548
+ position: "top",
549
+ graphicBounds
550
+ }),
372
551
  loop(normalizedComponentsInFront, (compConfig) => h(Container, { dependencies: compConfig.dependencies }, h(compConfig.component, {
373
552
  object,
374
553
  ...compConfig.props
@@ -386,7 +565,8 @@ function component($$props) {
386
565
  }))))
387
566
  ]);
388
567
  }
568
+ var __ce_component = component;
389
569
  //#endregion
390
- export { component as default };
570
+ export { __ce_component as default };
391
571
 
392
572
  //# sourceMappingURL=character.ce.js.map