@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,218 +1,184 @@
1
- import { RpgCommonPlayer, ModulesToken } from '@rpgjs/common';
2
- import { trigger, signal } from 'canvasengine';
3
- import { map, filter, switchMap, from } from 'rxjs';
4
- import { inject } from '../core/inject.js';
5
- import { RpgClientEngine } from '../RpgClientEngine.js';
6
- import component from '../components/dynamics/text.ce.js';
7
-
8
- const DYNAMIC_COMPONENTS = {
9
- text: component
1
+ import { inject } from "../core/inject.js";
2
+ import component from "../components/dynamics/text.ce.js";
3
+ import { RpgClientEngine } from "../RpgClientEngine.js";
4
+ import { signal, trigger } from "canvasengine";
5
+ import { ModulesToken, RpgCommonPlayer } from "@rpgjs/common";
6
+ import { filter, from, map, switchMap } from "rxjs";
7
+ //#region src/Game/Object.ts
8
+ var DYNAMIC_COMPONENTS = { text: component };
9
+ var RpgClientObject = class extends RpgCommonPlayer {
10
+ constructor() {
11
+ super();
12
+ this.emitParticleTrigger = trigger();
13
+ this.particleName = signal("");
14
+ this.animationCurrentIndex = signal(0);
15
+ this.animationIsPlaying = signal(false);
16
+ this._param = signal({});
17
+ this.frames = [];
18
+ this.graphicsSignals = signal([]);
19
+ this._component = {};
20
+ this.flashTrigger = trigger();
21
+ this.hooks.callHooks("client-sprite-onInit", this).subscribe();
22
+ this._frames.observable.subscribe(({ items }) => {
23
+ if (!this.id) return;
24
+ this.frames = [...this.frames, ...items];
25
+ });
26
+ this.graphics.observable.pipe(map(({ items }) => items), filter((graphics) => graphics.length > 0), switchMap((graphics) => from(Promise.all(graphics.map((graphic) => this.engine.getSpriteSheet(graphic)))))).subscribe((sheets) => {
27
+ this.graphicsSignals.set(sheets);
28
+ });
29
+ this.componentsTop.observable.pipe(filter((value) => value !== null && value !== void 0), map((value) => typeof value === "string" ? JSON.parse(value) : value)).subscribe(({ components }) => {
30
+ for (const component of components) for (const [key, value] of Object.entries(component)) {
31
+ this._component = value;
32
+ console.log(value);
33
+ const type = value.type;
34
+ if (DYNAMIC_COMPONENTS[type]) this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);
35
+ }
36
+ });
37
+ this.engine.tick.pipe().subscribe(() => {
38
+ const frame = this.frames.shift();
39
+ if (frame) {
40
+ if (typeof frame.x !== "number" || typeof frame.y !== "number") return;
41
+ this.engine.scene.setBodyPosition(this.id, frame.x, frame.y, "top-left");
42
+ }
43
+ });
44
+ }
45
+ get hooks() {
46
+ return inject(ModulesToken);
47
+ }
48
+ get engine() {
49
+ return inject(RpgClientEngine);
50
+ }
51
+ /**
52
+ * Trigger a flash animation on this sprite
53
+ *
54
+ * This method triggers a flash effect using CanvasEngine's flash directive.
55
+ * The flash can be configured with various options including type (alpha, tint, or both),
56
+ * duration, cycles, and color.
57
+ *
58
+ * ## Design
59
+ *
60
+ * The flash uses a trigger system that is connected to the flash directive in the
61
+ * character component. This allows for flexible configuration and can be triggered
62
+ * from both server events and client-side code.
63
+ *
64
+ * @param options - Flash configuration options
65
+ * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
66
+ * @param options.duration - Duration of the flash animation in milliseconds (default: 300)
67
+ * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
68
+ * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
69
+ * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * // Simple flash with default settings (alpha flash)
74
+ * player.flash();
75
+ *
76
+ * // Flash with red tint
77
+ * player.flash({ type: 'tint', tint: 0xff0000 });
78
+ *
79
+ * // Flash with both alpha and tint
80
+ * player.flash({
81
+ * type: 'both',
82
+ * alpha: 0.5,
83
+ * tint: 0xff0000,
84
+ * duration: 200,
85
+ * cycles: 2
86
+ * });
87
+ *
88
+ * // Quick damage flash
89
+ * player.flash({
90
+ * type: 'tint',
91
+ * tint: 0xff0000,
92
+ * duration: 150,
93
+ * cycles: 1
94
+ * });
95
+ * ```
96
+ */
97
+ flash(options) {
98
+ const flashOptions = {
99
+ type: options?.type || "alpha",
100
+ duration: options?.duration ?? 300,
101
+ cycles: options?.cycles ?? 1,
102
+ alpha: options?.alpha ?? .3,
103
+ tint: options?.tint ?? 16777215
104
+ };
105
+ let tintValue = flashOptions.tint;
106
+ if (typeof tintValue === "string") tintValue = {
107
+ "white": 16777215,
108
+ "red": 16711680,
109
+ "green": 65280,
110
+ "blue": 255,
111
+ "yellow": 16776960,
112
+ "cyan": 65535,
113
+ "magenta": 16711935,
114
+ "black": 0
115
+ }[tintValue.toLowerCase()] ?? 16777215;
116
+ this.flashTrigger.start({
117
+ ...flashOptions,
118
+ tint: tintValue
119
+ });
120
+ }
121
+ /**
122
+ * Reset animation state when animation changes externally
123
+ *
124
+ * This method should be called when the animation changes due to movement
125
+ * or other external factors to ensure the animation system doesn't get stuck
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * // Reset when player starts moving
130
+ * player.resetAnimationState();
131
+ * ```
132
+ */
133
+ resetAnimationState() {
134
+ this.animationIsPlaying.set(false);
135
+ this.animationCurrentIndex.set(0);
136
+ if (this.animationSubscription) {
137
+ this.animationSubscription.unsubscribe();
138
+ this.animationSubscription = void 0;
139
+ }
140
+ }
141
+ setAnimation(animationName, graphicOrNbTimes, nbTimes) {
142
+ if (this.animationIsPlaying()) return;
143
+ this.animationIsPlaying.set(true);
144
+ const previousAnimationName = this.animationName();
145
+ const previousGraphics = this.graphics();
146
+ this.animationCurrentIndex.set(0);
147
+ let graphic;
148
+ let finalNbTimes = Infinity;
149
+ if (typeof graphicOrNbTimes === "number") finalNbTimes = graphicOrNbTimes;
150
+ else if (graphicOrNbTimes !== void 0) {
151
+ graphic = graphicOrNbTimes;
152
+ finalNbTimes = nbTimes ?? Infinity;
153
+ } else finalNbTimes = Infinity;
154
+ if (graphic !== void 0) if (Array.isArray(graphic)) this.graphics.set(graphic);
155
+ else this.graphics.set([graphic]);
156
+ if (this.animationSubscription) this.animationSubscription.unsubscribe();
157
+ this.animationSubscription = this.animationCurrentIndex.observable.subscribe((index) => {
158
+ if (index >= finalNbTimes) {
159
+ this.animationCurrentIndex.set(0);
160
+ this.animationName.set(previousAnimationName);
161
+ if (graphic !== void 0) this.graphics.set(previousGraphics);
162
+ this.animationIsPlaying.set(false);
163
+ if (this.animationSubscription) {
164
+ this.animationSubscription.unsubscribe();
165
+ this.animationSubscription = void 0;
166
+ }
167
+ }
168
+ });
169
+ this.animationName.set(animationName);
170
+ }
171
+ showComponentAnimation(id, params) {
172
+ inject(RpgClientEngine).getComponentAnimation(id).displayEffect(params, this);
173
+ }
174
+ isEvent() {
175
+ return this.type === "event";
176
+ }
177
+ isPlayer() {
178
+ return this.type === "player";
179
+ }
10
180
  };
11
- class RpgClientObject extends RpgCommonPlayer {
12
- constructor() {
13
- super();
14
- this.emitParticleTrigger = trigger();
15
- this.particleName = signal("");
16
- this.animationCurrentIndex = signal(0);
17
- this.animationIsPlaying = signal(false);
18
- this._param = signal({});
19
- this.frames = [];
20
- this.graphicsSignals = signal([]);
21
- this._component = {};
22
- // temporary component memory
23
- this.flashTrigger = trigger();
24
- this.hooks.callHooks("client-sprite-onInit", this).subscribe();
25
- this._frames.observable.subscribe(({ items }) => {
26
- if (!this.id) return;
27
- this.frames = [...this.frames, ...items];
28
- });
29
- this.graphics.observable.pipe(
30
- map(({ items }) => items),
31
- filter((graphics) => graphics.length > 0),
32
- switchMap((graphics) => from(Promise.all(graphics.map((graphic) => this.engine.getSpriteSheet(graphic)))))
33
- ).subscribe((sheets) => {
34
- this.graphicsSignals.set(sheets);
35
- });
36
- this.componentsTop.observable.pipe(
37
- filter((value) => value !== null && value !== void 0),
38
- map((value) => typeof value === "string" ? JSON.parse(value) : value)
39
- ).subscribe(({ components }) => {
40
- for (const component of components) {
41
- for (const [key, value] of Object.entries(component)) {
42
- this._component = value;
43
- console.log(value);
44
- const type = value.type;
45
- if (DYNAMIC_COMPONENTS[type]) {
46
- this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);
47
- }
48
- }
49
- }
50
- });
51
- this.engine.tick.pipe().subscribe(() => {
52
- const frame = this.frames.shift();
53
- if (frame) {
54
- if (typeof frame.x !== "number" || typeof frame.y !== "number") return;
55
- this.engine.scene.setBodyPosition(
56
- this.id,
57
- frame.x,
58
- frame.y,
59
- "top-left"
60
- );
61
- }
62
- });
63
- }
64
- get hooks() {
65
- return inject(ModulesToken);
66
- }
67
- get engine() {
68
- return inject(RpgClientEngine);
69
- }
70
- /**
71
- * Trigger a flash animation on this sprite
72
- *
73
- * This method triggers a flash effect using CanvasEngine's flash directive.
74
- * The flash can be configured with various options including type (alpha, tint, or both),
75
- * duration, cycles, and color.
76
- *
77
- * ## Design
78
- *
79
- * The flash uses a trigger system that is connected to the flash directive in the
80
- * character component. This allows for flexible configuration and can be triggered
81
- * from both server events and client-side code.
82
- *
83
- * @param options - Flash configuration options
84
- * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
85
- * @param options.duration - Duration of the flash animation in milliseconds (default: 300)
86
- * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
87
- * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
88
- * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
89
- *
90
- * @example
91
- * ```ts
92
- * // Simple flash with default settings (alpha flash)
93
- * player.flash();
94
- *
95
- * // Flash with red tint
96
- * player.flash({ type: 'tint', tint: 0xff0000 });
97
- *
98
- * // Flash with both alpha and tint
99
- * player.flash({
100
- * type: 'both',
101
- * alpha: 0.5,
102
- * tint: 0xff0000,
103
- * duration: 200,
104
- * cycles: 2
105
- * });
106
- *
107
- * // Quick damage flash
108
- * player.flash({
109
- * type: 'tint',
110
- * tint: 0xff0000,
111
- * duration: 150,
112
- * cycles: 1
113
- * });
114
- * ```
115
- */
116
- flash(options) {
117
- const flashOptions = {
118
- type: options?.type || "alpha",
119
- duration: options?.duration ?? 300,
120
- cycles: options?.cycles ?? 1,
121
- alpha: options?.alpha ?? 0.3,
122
- tint: options?.tint ?? 16777215
123
- };
124
- let tintValue = flashOptions.tint;
125
- if (typeof tintValue === "string") {
126
- const colorMap = {
127
- "white": 16777215,
128
- "red": 16711680,
129
- "green": 65280,
130
- "blue": 255,
131
- "yellow": 16776960,
132
- "cyan": 65535,
133
- "magenta": 16711935,
134
- "black": 0
135
- };
136
- tintValue = colorMap[tintValue.toLowerCase()] ?? 16777215;
137
- }
138
- this.flashTrigger.start({
139
- ...flashOptions,
140
- tint: tintValue
141
- });
142
- }
143
- /**
144
- * Reset animation state when animation changes externally
145
- *
146
- * This method should be called when the animation changes due to movement
147
- * or other external factors to ensure the animation system doesn't get stuck
148
- *
149
- * @example
150
- * ```ts
151
- * // Reset when player starts moving
152
- * player.resetAnimationState();
153
- * ```
154
- */
155
- resetAnimationState() {
156
- this.animationIsPlaying.set(false);
157
- this.animationCurrentIndex.set(0);
158
- if (this.animationSubscription) {
159
- this.animationSubscription.unsubscribe();
160
- this.animationSubscription = void 0;
161
- }
162
- }
163
- setAnimation(animationName, graphicOrNbTimes, nbTimes) {
164
- if (this.animationIsPlaying()) return;
165
- this.animationIsPlaying.set(true);
166
- const previousAnimationName = this.animationName();
167
- const previousGraphics = this.graphics();
168
- this.animationCurrentIndex.set(0);
169
- let graphic;
170
- let finalNbTimes = Infinity;
171
- if (typeof graphicOrNbTimes === "number") {
172
- finalNbTimes = graphicOrNbTimes;
173
- } else if (graphicOrNbTimes !== void 0) {
174
- graphic = graphicOrNbTimes;
175
- finalNbTimes = nbTimes ?? Infinity;
176
- } else {
177
- finalNbTimes = Infinity;
178
- }
179
- if (graphic !== void 0) {
180
- if (Array.isArray(graphic)) {
181
- this.graphics.set(graphic);
182
- } else {
183
- this.graphics.set([graphic]);
184
- }
185
- }
186
- if (this.animationSubscription) {
187
- this.animationSubscription.unsubscribe();
188
- }
189
- this.animationSubscription = this.animationCurrentIndex.observable.subscribe((index) => {
190
- if (index >= finalNbTimes) {
191
- this.animationCurrentIndex.set(0);
192
- this.animationName.set(previousAnimationName);
193
- if (graphic !== void 0) {
194
- this.graphics.set(previousGraphics);
195
- }
196
- this.animationIsPlaying.set(false);
197
- if (this.animationSubscription) {
198
- this.animationSubscription.unsubscribe();
199
- this.animationSubscription = void 0;
200
- }
201
- }
202
- });
203
- this.animationName.set(animationName);
204
- }
205
- showComponentAnimation(id, params) {
206
- const engine = inject(RpgClientEngine);
207
- engine.getComponentAnimation(id).displayEffect(params, this);
208
- }
209
- isEvent() {
210
- return this.type === "event";
211
- }
212
- isPlayer() {
213
- return this.type === "player";
214
- }
215
- }
216
-
181
+ //#endregion
217
182
  export { RpgClientObject };
218
- //# sourceMappingURL=Object.js.map
183
+
184
+ //# sourceMappingURL=Object.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Object.js","sources":["../../src/Game/Object.ts"],"sourcesContent":["import { Hooks, ModulesToken, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { trigger, signal, effect } from \"canvasengine\";\nimport { filter, from, map, Subscription, switchMap } from \"rxjs\";\nimport { inject } from \"../core/inject\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport TextComponent from \"../components/dynamics/text.ce\";\n\nconst DYNAMIC_COMPONENTS = {\n text: TextComponent,\n}\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 frames: { x: number; y: number; ts: number }[] = [];\n graphicsSignals = signal<any[]>([]);\n _component = {} // temporary component memory\n flashTrigger = trigger();\n\n constructor() {\n super();\n this.hooks.callHooks(\"client-sprite-onInit\", this).subscribe();\n\n this._frames.observable.subscribe(({ items }) => {\n if (!this.id) return;\n //if (this.id == this.engine.playerIdSignal()!) return;\n this.frames = [...this.frames, ...items];\n });\n\n this.graphics.observable\n .pipe(\n map(({ items }) => items),\n filter(graphics => graphics.length > 0),\n switchMap(graphics => from(Promise.all(graphics.map(graphic => this.engine.getSpriteSheet(graphic)))))\n )\n .subscribe((sheets) => { \n this.graphicsSignals.set(sheets);\n });\n\n this.componentsTop.observable\n .pipe(\n filter(value => value !== null && value !== undefined),\n map((value) => typeof value === 'string' ? JSON.parse(value) : value),\n )\n .subscribe(({components}) => {\n for (const component of components) {\n for (const [key, value] of Object.entries(component)) {\n this._component = value as any; // temporary component memory\n console.log(value)\n const type = (value as any).type as keyof typeof DYNAMIC_COMPONENTS;\n if (DYNAMIC_COMPONENTS[type]) {\n this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);\n }\n }\n }\n });\n\n this.engine.tick\n .pipe\n //throttleTime(10)\n ()\n .subscribe(() => {\n const frame = this.frames.shift();\n if (frame) {\n if (typeof frame.x !== \"number\" || typeof frame.y !== \"number\") return;\n this.engine.scene.setBodyPosition(\n this.id,\n frame.x,\n frame.y,\n \"top-left\"\n );\n }\n });\n }\n\n get hooks() {\n return inject<Hooks>(ModulesToken);\n }\n\n get engine() {\n return inject(RpgClientEngine);\n }\n\n private animationSubscription?: Subscription;\n\n /**\n * Trigger a flash animation on this sprite\n * \n * This method triggers a flash effect using CanvasEngine's flash directive.\n * The flash can be configured with various options including type (alpha, tint, or both),\n * duration, cycles, and color.\n * \n * ## Design\n * \n * The flash uses a trigger system that is connected to the flash directive in the\n * character component. This allows for flexible configuration and can be triggered\n * from both server events and client-side code.\n * \n * @param options - Flash configuration options\n * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')\n * @param options.duration - Duration of the flash animation in milliseconds (default: 300)\n * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)\n * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)\n * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)\n * \n * @example\n * ```ts\n * // Simple flash with default settings (alpha flash)\n * player.flash();\n * \n * // Flash with red tint\n * player.flash({ type: 'tint', tint: 0xff0000 });\n * \n * // Flash with both alpha and tint\n * player.flash({ \n * type: 'both', \n * alpha: 0.5, \n * tint: 0xff0000,\n * duration: 200,\n * cycles: 2\n * });\n * \n * // Quick damage flash\n * player.flash({ \n * type: 'tint', \n * tint: 0xff0000, \n * duration: 150,\n * cycles: 1\n * });\n * ```\n */\n flash(options?: {\n type?: 'alpha' | 'tint' | 'both';\n duration?: number;\n cycles?: number;\n alpha?: number;\n tint?: number | string;\n }): void {\n const flashOptions = {\n type: options?.type || 'alpha',\n duration: options?.duration ?? 300,\n cycles: options?.cycles ?? 1,\n alpha: options?.alpha ?? 0.3,\n tint: options?.tint ?? 0xffffff,\n };\n \n // Convert color name to hex if needed\n let tintValue = flashOptions.tint;\n if (typeof tintValue === 'string') {\n // Common color name to hex mapping\n const colorMap: Record<string, number> = {\n 'white': 0xffffff,\n 'red': 0xff0000,\n 'green': 0x00ff00,\n 'blue': 0x0000ff,\n 'yellow': 0xffff00,\n 'cyan': 0x00ffff,\n 'magenta': 0xff00ff,\n 'black': 0x000000,\n };\n tintValue = colorMap[tintValue.toLowerCase()] ?? 0xffffff;\n }\n \n this.flashTrigger.start({\n ...flashOptions,\n tint: tintValue,\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): void;\n /**\n * Set a custom animation with temporary graphic change\n *\n * Plays a custom animation for the specified number of repetitions and temporarily\n * changes the player's graphic (sprite sheet) during the animation. The graphic\n * is automatically reset when the animation finishes.\n *\n * @param animationName - Name of the animation to play\n * @param graphic - The graphic(s) to temporarily use during the animation\n * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)\n *\n * @example\n * ```ts\n * // Play attack animation with temporary graphic change\n * player.setAnimation('attack', 'hero_attack', 3);\n * ```\n */\n setAnimation(animationName: string, graphic?: string | string[], nbTimes?: number): void;\n setAnimation(animationName: string, graphicOrNbTimes?: string | string[] | number, nbTimes?: number): void {\n if (this.animationIsPlaying()) return;\n this.animationIsPlaying.set(true);\n const previousAnimationName = this.animationName();\n const previousGraphics = this.graphics();\n this.animationCurrentIndex.set(0);\n\n let graphic: string | string[] | undefined;\n let finalNbTimes: number = Infinity;\n\n // Handle overloads\n if (typeof graphicOrNbTimes === 'number') {\n // setAnimation(animationName, nbTimes)\n finalNbTimes = graphicOrNbTimes;\n } else if (graphicOrNbTimes !== undefined) {\n // setAnimation(animationName, graphic, nbTimes)\n graphic = graphicOrNbTimes;\n finalNbTimes = nbTimes ?? Infinity;\n } else {\n // setAnimation(animationName) - nbTimes remains Infinity\n finalNbTimes = Infinity;\n }\n\n // Temporarily change graphic if provided\n if (graphic !== undefined) {\n if (Array.isArray(graphic)) {\n this.graphics.set(graphic);\n } else {\n this.graphics.set([graphic]);\n }\n }\n\n // Clean up any existing subscription\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n }\n\n this.animationSubscription =\n this.animationCurrentIndex.observable.subscribe((index) => {\n if (index >= finalNbTimes) {\n this.animationCurrentIndex.set(0);\n this.animationName.set(previousAnimationName);\n // Reset graphic to previous value if it was changed\n if (graphic !== undefined) {\n this.graphics.set(previousGraphics);\n }\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 \n isEvent(): boolean {\n return this.type === 'event';\n }\n\n isPlayer(): boolean {\n return this.type === 'player';\n }\n}\n"],"names":["TextComponent"],"mappings":";;;;;;;AAOA,MAAM,kBAAA,GAAqB;AAAA,EACzB,IAAA,EAAMA;AACR,CAAA;AAEO,MAAe,wBAAwB,eAAA,CAAgB;AAAA,EAY5D,WAAA,GAAc;AACZ,IAAA,KAAA,EAAM;AAXR,IAAA,IAAA,CAAA,mBAAA,GAAsB,OAAA,EAAQ;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,IAAA,IAAA,CAAA,MAAA,GAAS,MAAA,CAAO,EAAE,CAAA;AAClB,IAAA,IAAA,CAAA,MAAA,GAAiD,EAAC;AAClD,IAAA,IAAA,CAAA,eAAA,GAAkB,MAAA,CAAc,EAAE,CAAA;AAClC,IAAA,IAAA,CAAA,UAAA,GAAa,EAAC;AACd;AAAA,IAAA,IAAA,CAAA,YAAA,GAAe,OAAA,EAAQ;AAIrB,IAAA,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,sBAAA,EAAwB,IAAI,EAAE,SAAA,EAAU;AAE7D,IAAA,IAA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AAK,QAAA,CAAS,IAAI,gBAAgB,CAAA;AAAA,QACpC;AACA,QAAA,IAAA,CAAK,kBAAA,CAAmB,IAAI,KAAK,CAAA;AACjC,QAAA,IAAI,KAAK,qBAAA,EAAuB;AAC9B,UAAA,IAAA,CAAK,sBAAsB,WAAA,EAAY;AACvC,UAAA,IAAA,CAAK,qBAAA,GAAwB,MAAA;AAAA,QAC/B;AAAA,MACF;AAAA,IACF,CAAC,CAAA;AACH,IAAA,IAAA,CAAK,aAAA,CAAc,IAAI,aAAa,CAAA;AAAA,EACtC;AAAA,EAEA,sBAAA,CAAuB,IAAY,MAAA,EAAa;AAC9C,IAAA,MAAM,MAAA,GAAS,OAAO,eAAe,CAAA;AACrC,IAAA,MAAA,CAAO,qBAAA,CAAsB,EAAE,CAAA,CAAE,aAAA,CAAc,QAAQ,IAAI,CAAA;AAAA,EAC7D;AAAA,EAEA,OAAA,GAAmB;AACjB,IAAA,OAAO,KAAK,IAAA,KAAS,OAAA;AAAA,EACvB;AAAA,EAEA,QAAA,GAAoB;AAClB,IAAA,OAAO,KAAK,IAAA,KAAS,QAAA;AAAA,EACvB;AACF;;;;"}
1
+ {"version":3,"file":"Object.js","names":[],"sources":["../../src/Game/Object.ts"],"sourcesContent":["import { Hooks, ModulesToken, RpgCommonPlayer } from \"@rpgjs/common\";\nimport { trigger, signal, effect } from \"canvasengine\";\nimport { filter, from, map, Subscription, switchMap } from \"rxjs\";\nimport { inject } from \"../core/inject\";\nimport { RpgClientEngine } from \"../RpgClientEngine\";\nimport TextComponent from \"../components/dynamics/text.ce\";\n\nconst DYNAMIC_COMPONENTS = {\n text: TextComponent,\n}\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 frames: { x: number; y: number; ts: number }[] = [];\n graphicsSignals = signal<any[]>([]);\n _component = {} // temporary component memory\n flashTrigger = trigger();\n\n constructor() {\n super();\n this.hooks.callHooks(\"client-sprite-onInit\", this).subscribe();\n\n this._frames.observable.subscribe(({ items }) => {\n if (!this.id) return;\n //if (this.id == this.engine.playerIdSignal()!) return;\n this.frames = [...this.frames, ...items];\n });\n\n this.graphics.observable\n .pipe(\n map(({ items }) => items),\n filter(graphics => graphics.length > 0),\n switchMap(graphics => from(Promise.all(graphics.map(graphic => this.engine.getSpriteSheet(graphic)))))\n )\n .subscribe((sheets) => { \n this.graphicsSignals.set(sheets);\n });\n\n this.componentsTop.observable\n .pipe(\n filter(value => value !== null && value !== undefined),\n map((value) => typeof value === 'string' ? JSON.parse(value) : value),\n )\n .subscribe(({components}) => {\n for (const component of components) {\n for (const [key, value] of Object.entries(component)) {\n this._component = value as any; // temporary component memory\n console.log(value)\n const type = (value as any).type as keyof typeof DYNAMIC_COMPONENTS;\n if (DYNAMIC_COMPONENTS[type]) {\n this.engine.addSpriteComponentInFront(DYNAMIC_COMPONENTS[type]);\n }\n }\n }\n });\n\n this.engine.tick\n .pipe\n //throttleTime(10)\n ()\n .subscribe(() => {\n const frame = this.frames.shift();\n if (frame) {\n if (typeof frame.x !== \"number\" || typeof frame.y !== \"number\") return;\n this.engine.scene.setBodyPosition(\n this.id,\n frame.x,\n frame.y,\n \"top-left\"\n );\n }\n });\n }\n\n get hooks() {\n return inject<Hooks>(ModulesToken);\n }\n\n get engine() {\n return inject(RpgClientEngine);\n }\n\n private animationSubscription?: Subscription;\n\n /**\n * Trigger a flash animation on this sprite\n * \n * This method triggers a flash effect using CanvasEngine's flash directive.\n * The flash can be configured with various options including type (alpha, tint, or both),\n * duration, cycles, and color.\n * \n * ## Design\n * \n * The flash uses a trigger system that is connected to the flash directive in the\n * character component. This allows for flexible configuration and can be triggered\n * from both server events and client-side code.\n * \n * @param options - Flash configuration options\n * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')\n * @param options.duration - Duration of the flash animation in milliseconds (default: 300)\n * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)\n * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)\n * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)\n * \n * @example\n * ```ts\n * // Simple flash with default settings (alpha flash)\n * player.flash();\n * \n * // Flash with red tint\n * player.flash({ type: 'tint', tint: 0xff0000 });\n * \n * // Flash with both alpha and tint\n * player.flash({ \n * type: 'both', \n * alpha: 0.5, \n * tint: 0xff0000,\n * duration: 200,\n * cycles: 2\n * });\n * \n * // Quick damage flash\n * player.flash({ \n * type: 'tint', \n * tint: 0xff0000, \n * duration: 150,\n * cycles: 1\n * });\n * ```\n */\n flash(options?: {\n type?: 'alpha' | 'tint' | 'both';\n duration?: number;\n cycles?: number;\n alpha?: number;\n tint?: number | string;\n }): void {\n const flashOptions = {\n type: options?.type || 'alpha',\n duration: options?.duration ?? 300,\n cycles: options?.cycles ?? 1,\n alpha: options?.alpha ?? 0.3,\n tint: options?.tint ?? 0xffffff,\n };\n \n // Convert color name to hex if needed\n let tintValue = flashOptions.tint;\n if (typeof tintValue === 'string') {\n // Common color name to hex mapping\n const colorMap: Record<string, number> = {\n 'white': 0xffffff,\n 'red': 0xff0000,\n 'green': 0x00ff00,\n 'blue': 0x0000ff,\n 'yellow': 0xffff00,\n 'cyan': 0x00ffff,\n 'magenta': 0xff00ff,\n 'black': 0x000000,\n };\n tintValue = colorMap[tintValue.toLowerCase()] ?? 0xffffff;\n }\n \n this.flashTrigger.start({\n ...flashOptions,\n tint: tintValue,\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): void;\n /**\n * Set a custom animation with temporary graphic change\n *\n * Plays a custom animation for the specified number of repetitions and temporarily\n * changes the player's graphic (sprite sheet) during the animation. The graphic\n * is automatically reset when the animation finishes.\n *\n * @param animationName - Name of the animation to play\n * @param graphic - The graphic(s) to temporarily use during the animation\n * @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)\n *\n * @example\n * ```ts\n * // Play attack animation with temporary graphic change\n * player.setAnimation('attack', 'hero_attack', 3);\n * ```\n */\n setAnimation(animationName: string, graphic?: string | string[], nbTimes?: number): void;\n setAnimation(animationName: string, graphicOrNbTimes?: string | string[] | number, nbTimes?: number): void {\n if (this.animationIsPlaying()) return;\n this.animationIsPlaying.set(true);\n const previousAnimationName = this.animationName();\n const previousGraphics = this.graphics();\n this.animationCurrentIndex.set(0);\n\n let graphic: string | string[] | undefined;\n let finalNbTimes: number = Infinity;\n\n // Handle overloads\n if (typeof graphicOrNbTimes === 'number') {\n // setAnimation(animationName, nbTimes)\n finalNbTimes = graphicOrNbTimes;\n } else if (graphicOrNbTimes !== undefined) {\n // setAnimation(animationName, graphic, nbTimes)\n graphic = graphicOrNbTimes;\n finalNbTimes = nbTimes ?? Infinity;\n } else {\n // setAnimation(animationName) - nbTimes remains Infinity\n finalNbTimes = Infinity;\n }\n\n // Temporarily change graphic if provided\n if (graphic !== undefined) {\n if (Array.isArray(graphic)) {\n this.graphics.set(graphic);\n } else {\n this.graphics.set([graphic]);\n }\n }\n\n // Clean up any existing subscription\n if (this.animationSubscription) {\n this.animationSubscription.unsubscribe();\n }\n\n this.animationSubscription =\n this.animationCurrentIndex.observable.subscribe((index) => {\n if (index >= finalNbTimes) {\n this.animationCurrentIndex.set(0);\n this.animationName.set(previousAnimationName);\n // Reset graphic to previous value if it was changed\n if (graphic !== undefined) {\n this.graphics.set(previousGraphics);\n }\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 \n isEvent(): boolean {\n return this.type === 'event';\n }\n\n isPlayer(): boolean {\n return this.type === 'player';\n }\n}\n"],"mappings":";;;;;;;AAOA,IAAM,qBAAqB,EACzB,MAAM,WACP;AAED,IAAsB,kBAAtB,cAA8C,gBAAgB;CAY5D,cAAc;AACZ,SAAO;6BAXa,SAAS;sBAChB,OAAO,GAAG;+BACD,OAAO,EAAE;4BACZ,OAAO,MAAM;gBACzB,OAAO,EAAE,CAAC;gBAC8B,EAAE;yBACjC,OAAc,EAAE,CAAC;oBACtB,EAAE;sBACA,SAAS;AAItB,OAAK,MAAM,UAAU,wBAAwB,KAAK,CAAC,WAAW;AAE9D,OAAK,QAAQ,WAAW,WAAW,EAAE,YAAY;AAC/C,OAAI,CAAC,KAAK,GAAI;AAEd,QAAK,SAAS,CAAC,GAAG,KAAK,QAAQ,GAAG,MAAM;IACxC;AAEF,OAAK,SAAS,WACb,KACC,KAAK,EAAE,YAAY,MAAM,EACzB,QAAO,aAAY,SAAS,SAAS,EAAE,EACvC,WAAU,aAAY,KAAK,QAAQ,IAAI,SAAS,KAAI,YAAW,KAAK,OAAO,eAAe,QAAQ,CAAC,CAAC,CAAC,CAAC,CACvG,CACA,WAAW,WAAW;AACrB,QAAK,gBAAgB,IAAI,OAAO;IAChC;AAEF,OAAK,cAAc,WAClB,KACC,QAAO,UAAS,UAAU,QAAQ,UAAU,KAAA,EAAU,EACtD,KAAK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AAK,sBAAsB,aAAa;AACxC,QAAK,wBAAwB,KAAA;;;CA0CjC,aAAa,eAAuB,kBAA+C,SAAwB;AACzG,MAAI,KAAK,oBAAoB,CAAE;AAC/B,OAAK,mBAAmB,IAAI,KAAK;EACjC,MAAM,wBAAwB,KAAK,eAAe;EAClD,MAAM,mBAAmB,KAAK,UAAU;AACxC,OAAK,sBAAsB,IAAI,EAAE;EAEjC,IAAI;EACJ,IAAI,eAAuB;AAG3B,MAAI,OAAO,qBAAqB,SAE9B,gBAAe;WACN,qBAAqB,KAAA,GAAW;AAEzC,aAAU;AACV,kBAAe,WAAW;QAG1B,gBAAe;AAIjB,MAAI,YAAY,KAAA,EACd,KAAI,MAAM,QAAQ,QAAQ,CACxB,MAAK,SAAS,IAAI,QAAQ;MAE1B,MAAK,SAAS,IAAI,CAAC,QAAQ,CAAC;AAKhC,MAAI,KAAK,sBACP,MAAK,sBAAsB,aAAa;AAG1C,OAAK,wBACH,KAAK,sBAAsB,WAAW,WAAW,UAAU;AACzD,OAAI,SAAS,cAAc;AACzB,SAAK,sBAAsB,IAAI,EAAE;AACjC,SAAK,cAAc,IAAI,sBAAsB;AAE7C,QAAI,YAAY,KAAA,EACd,MAAK,SAAS,IAAI,iBAAiB;AAErC,SAAK,mBAAmB,IAAI,MAAM;AAClC,QAAI,KAAK,uBAAuB;AAC9B,UAAK,sBAAsB,aAAa;AACxC,UAAK,wBAAwB,KAAA;;;IAGjC;AACJ,OAAK,cAAc,IAAI,cAAc;;CAGvC,uBAAuB,IAAY,QAAa;AAC/B,SAAO,gBAAgB,CAC/B,sBAAsB,GAAG,CAAC,cAAc,QAAQ,KAAK;;CAG9D,UAAmB;AACjB,SAAO,KAAK,SAAS;;CAGvB,WAAoB;AAClB,SAAO,KAAK,SAAS"}
@@ -1,11 +1,12 @@
1
- import { RpgClientObject } from './Object.js';
2
-
3
- class RpgClientPlayer extends RpgClientObject {
4
- constructor() {
5
- super(...arguments);
6
- this.type = "player";
7
- }
8
- }
9
-
1
+ import { RpgClientObject } from "./Object.js";
2
+ //#region src/Game/Player.ts
3
+ var RpgClientPlayer = class extends RpgClientObject {
4
+ constructor(..._args) {
5
+ super(..._args);
6
+ this.type = "player";
7
+ }
8
+ };
9
+ //#endregion
10
10
  export { RpgClientPlayer };
11
- //# sourceMappingURL=Player.js.map
11
+
12
+ //# sourceMappingURL=Player.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Player.js","sources":["../../src/Game/Player.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\";\n\nexport class RpgClientPlayer extends RpgClientObject {\n type = 'player'\n} "],"names":[],"mappings":";;AAEO,MAAM,wBAAwB,eAAA,CAAgB;AAAA,EAA9C,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AACH,IAAA,IAAA,CAAA,IAAA,GAAO,QAAA;AAAA,EAAA;AACX;;;;"}
1
+ {"version":3,"file":"Player.js","names":[],"sources":["../../src/Game/Player.ts"],"sourcesContent":["import { RpgClientObject } from \"./Object\";\n\nexport class RpgClientPlayer extends RpgClientObject {\n type = 'player'\n} "],"mappings":";;AAEA,IAAa,kBAAb,cAAqC,gBAAgB;;;cAC1C"}