@rpgjs/common 4.2.1 → 5.0.0-alpha.0

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 (148) hide show
  1. package/dist/Physic.d.ts +619 -0
  2. package/dist/Player.d.ts +198 -0
  3. package/{lib → dist}/Utils.d.ts +19 -2
  4. package/dist/database/Item.d.ts +10 -0
  5. package/dist/database/index.d.ts +1 -0
  6. package/dist/index.d.ts +9 -0
  7. package/dist/index.js +16741 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/modules.d.ts +92 -0
  10. package/dist/movement/MovementManager.d.ts +84 -0
  11. package/dist/movement/MovementStrategy.d.ts +39 -0
  12. package/dist/movement/index.d.ts +12 -0
  13. package/dist/movement/strategies/CompositeMovement.d.ts +76 -0
  14. package/dist/movement/strategies/Dash.d.ts +52 -0
  15. package/dist/movement/strategies/IceMovement.d.ts +87 -0
  16. package/dist/movement/strategies/Knockback.d.ts +50 -0
  17. package/dist/movement/strategies/LinearMove.d.ts +43 -0
  18. package/dist/movement/strategies/LinearRepulsion.d.ts +55 -0
  19. package/dist/movement/strategies/Oscillate.d.ts +60 -0
  20. package/dist/movement/strategies/PathFollow.d.ts +78 -0
  21. package/dist/movement/strategies/ProjectileMovement.d.ts +138 -0
  22. package/dist/movement/strategies/SeekAvoid.d.ts +27 -0
  23. package/dist/rooms/Map.d.ts +109 -0
  24. package/dist/services/updateMap.d.ts +7 -0
  25. package/package.json +17 -17
  26. package/src/Physic.ts +1644 -0
  27. package/src/Player.ts +262 -26
  28. package/src/{gui/PrebuiltGui.ts → PrebuiltGui.ts} +1 -1
  29. package/src/Utils.ts +184 -123
  30. package/src/database/Item.ts +19 -0
  31. package/src/database/index.ts +1 -0
  32. package/src/index.ts +9 -25
  33. package/src/modules.ts +230 -0
  34. package/src/movement/MovementManager.ts +142 -0
  35. package/src/movement/MovementStrategy.ts +42 -0
  36. package/src/movement/index.ts +15 -0
  37. package/src/movement/strategies/CompositeMovement.ts +173 -0
  38. package/src/movement/strategies/Dash.ts +82 -0
  39. package/src/movement/strategies/IceMovement.ts +158 -0
  40. package/src/movement/strategies/Knockback.ts +81 -0
  41. package/src/movement/strategies/LinearMove.ts +58 -0
  42. package/src/movement/strategies/LinearRepulsion.ts +128 -0
  43. package/src/movement/strategies/Oscillate.ts +144 -0
  44. package/src/movement/strategies/PathFollow.ts +156 -0
  45. package/src/movement/strategies/ProjectileMovement.ts +322 -0
  46. package/src/movement/strategies/SeekAvoid.ts +123 -0
  47. package/src/rooms/Map.ts +272 -0
  48. package/src/services/updateMap.ts +9 -0
  49. package/tests/physic.spec.ts +454 -0
  50. package/tsconfig.json +8 -3
  51. package/vite.config.ts +21 -0
  52. package/CHANGELOG.md +0 -152
  53. package/LICENSE +0 -19
  54. package/browser/manifest.json +0 -7
  55. package/browser/rpg.common.js +0 -11357
  56. package/browser/rpg.common.umd.cjs +0 -11358
  57. package/lib/AbstractObject.d.ts +0 -322
  58. package/lib/AbstractObject.js +0 -872
  59. package/lib/AbstractObject.js.map +0 -1
  60. package/lib/Color.d.ts +0 -1
  61. package/lib/Color.js +0 -25
  62. package/lib/Color.js.map +0 -1
  63. package/lib/DefaultInput.d.ts +0 -2
  64. package/lib/DefaultInput.js +0 -26
  65. package/lib/DefaultInput.js.map +0 -1
  66. package/lib/Event.d.ts +0 -3
  67. package/lib/Event.js +0 -4
  68. package/lib/Event.js.map +0 -1
  69. package/lib/EventEmitter.d.ts +0 -10
  70. package/lib/EventEmitter.js +0 -61
  71. package/lib/EventEmitter.js.map +0 -1
  72. package/lib/Game.d.ts +0 -28
  73. package/lib/Game.js +0 -127
  74. package/lib/Game.js.map +0 -1
  75. package/lib/Hit.d.ts +0 -16
  76. package/lib/Hit.js +0 -65
  77. package/lib/Hit.js.map +0 -1
  78. package/lib/Inject.d.ts +0 -9
  79. package/lib/Inject.js +0 -17
  80. package/lib/Inject.js.map +0 -1
  81. package/lib/Logger.d.ts +0 -2
  82. package/lib/Logger.js +0 -7
  83. package/lib/Logger.js.map +0 -1
  84. package/lib/Map.d.ts +0 -174
  85. package/lib/Map.js +0 -263
  86. package/lib/Map.js.map +0 -1
  87. package/lib/Module.d.ts +0 -16
  88. package/lib/Module.js +0 -139
  89. package/lib/Module.js.map +0 -1
  90. package/lib/Player.d.ts +0 -26
  91. package/lib/Player.js +0 -19
  92. package/lib/Player.js.map +0 -1
  93. package/lib/Plugin.d.ts +0 -67
  94. package/lib/Plugin.js +0 -92
  95. package/lib/Plugin.js.map +0 -1
  96. package/lib/Scheduler.d.ts +0 -26
  97. package/lib/Scheduler.js +0 -90
  98. package/lib/Scheduler.js.map +0 -1
  99. package/lib/Shape.d.ts +0 -127
  100. package/lib/Shape.js +0 -261
  101. package/lib/Shape.js.map +0 -1
  102. package/lib/Utils.js +0 -181
  103. package/lib/Utils.js.map +0 -1
  104. package/lib/Vector2d.d.ts +0 -20
  105. package/lib/Vector2d.js +0 -63
  106. package/lib/Vector2d.js.map +0 -1
  107. package/lib/VirtualGrid.d.ts +0 -26
  108. package/lib/VirtualGrid.js +0 -68
  109. package/lib/VirtualGrid.js.map +0 -1
  110. package/lib/Worker.d.ts +0 -7
  111. package/lib/Worker.js +0 -13
  112. package/lib/Worker.js.map +0 -1
  113. package/lib/WorldMaps.d.ts +0 -105
  114. package/lib/WorldMaps.js +0 -184
  115. package/lib/WorldMaps.js.map +0 -1
  116. package/lib/gui/PrebuiltGui.js +0 -29
  117. package/lib/gui/PrebuiltGui.js.map +0 -1
  118. package/lib/index.d.ts +0 -25
  119. package/lib/index.js +0 -26
  120. package/lib/index.js.map +0 -1
  121. package/lib/transports/io.d.ts +0 -22
  122. package/lib/transports/io.js +0 -82
  123. package/lib/transports/io.js.map +0 -1
  124. package/lib/workers/move.d.ts +0 -1
  125. package/lib/workers/move.js +0 -57
  126. package/lib/workers/move.js.map +0 -1
  127. package/rpg.toml +0 -11
  128. package/src/AbstractObject.ts +0 -973
  129. package/src/Color.ts +0 -29
  130. package/src/DefaultInput.ts +0 -26
  131. package/src/Event.ts +0 -3
  132. package/src/EventEmitter.ts +0 -65
  133. package/src/Game.ts +0 -159
  134. package/src/Hit.ts +0 -70
  135. package/src/Inject.ts +0 -22
  136. package/src/Logger.ts +0 -7
  137. package/src/Map.ts +0 -335
  138. package/src/Module.ts +0 -144
  139. package/src/Plugin.ts +0 -100
  140. package/src/Scheduler.ts +0 -95
  141. package/src/Shape.ts +0 -302
  142. package/src/Vector2d.ts +0 -70
  143. package/src/VirtualGrid.ts +0 -78
  144. package/src/Worker.ts +0 -17
  145. package/src/WorldMaps.ts +0 -204
  146. package/src/transports/io.ts +0 -91
  147. package/src/workers/move.ts +0 -61
  148. /package/{lib/gui → dist}/PrebuiltGui.d.ts +0 -0
@@ -0,0 +1,198 @@
1
+ import { Item } from './database';
2
+ import { Observable } from 'rxjs';
3
+ import * as Matter from 'matter-js';
4
+ export declare enum Direction {
5
+ Up = "up",
6
+ Down = "down",
7
+ Left = "left",
8
+ Right = "right"
9
+ }
10
+ export declare enum Animation {
11
+ Stand = "stand",
12
+ Walk = "walk",
13
+ Attack = "attack",
14
+ Defense = "defense",
15
+ Skill = "skill"
16
+ }
17
+ export interface Hitbox {
18
+ w: number;
19
+ h: number;
20
+ }
21
+ export interface ShowAnimationParams {
22
+ graphic?: string | string[];
23
+ animationName: string;
24
+ loop?: boolean;
25
+ }
26
+ export interface AttachShapeOptions {
27
+ /** Width of the shape in pixels */
28
+ width: number;
29
+ /** Height of the shape in pixels */
30
+ height: number;
31
+ /** Circle radius in pixels (for zone shapes) */
32
+ radius?: number;
33
+ /** Vision aperture in degrees. 360 = full circle, <360 = cone */
34
+ angle?: number;
35
+ /** Facing direction used when angle < 360 */
36
+ direction?: Direction;
37
+ /** If true, walls (static hitboxes) stop vision */
38
+ limitedByWalls?: boolean;
39
+ /** Indicate where the shape is placed relative to the player */
40
+ positioning?: 'center' | 'top' | 'bottom' | 'left' | 'right';
41
+ /** The name of the shape */
42
+ name?: string;
43
+ /** An object to retrieve information when interacting with the shape */
44
+ properties?: object;
45
+ }
46
+ export declare class RpgCommonPlayer {
47
+ id: string;
48
+ x: import('@signe/reactive').WritableSignal<number>;
49
+ y: import('@signe/reactive').WritableSignal<number>;
50
+ z: import('@signe/reactive').WritableSignal<number>;
51
+ tint: import('@signe/reactive').WritableSignal<string>;
52
+ direction: import('@signe/reactive').WritableSignal<Direction>;
53
+ speed: import('@signe/reactive').WritableSignal<number>;
54
+ graphics: import('@signe/reactive').WritableArraySignal<any>;
55
+ canMove: import('@signe/reactive').WritableSignal<boolean>;
56
+ hitbox: import('@signe/reactive').WritableObjectSignal<Hitbox>;
57
+ _gold: import('@signe/reactive').WritableSignal<number>;
58
+ animationName: import('@signe/reactive').WritableSignal<string>;
59
+ _hp: import('@signe/reactive').WritableSignal<number>;
60
+ _sp: import('@signe/reactive').WritableSignal<number>;
61
+ _exp: import('@signe/reactive').WritableSignal<number>;
62
+ _level: import('@signe/reactive').WritableSignal<number>;
63
+ _class: import('@signe/reactive').WritableObjectSignal<{}>;
64
+ items: import('@signe/reactive').WritableArraySignal<Item[]>;
65
+ equipments: import('@signe/reactive').WritableArraySignal<any[]>;
66
+ states: import('@signe/reactive').WritableArraySignal<any[]>;
67
+ skills: import('@signe/reactive').WritableArraySignal<any[]>;
68
+ _effects: import('@signe/reactive').WritableArraySignal<any[]>;
69
+ _through: import('@signe/reactive').WritableSignal<boolean>;
70
+ _throughOtherPlayer: import('@signe/reactive').WritableSignal<boolean>;
71
+ _throughEvent: import('@signe/reactive').WritableSignal<boolean>;
72
+ _frequency: import('@signe/reactive').WritableSignal<number>;
73
+ private _intendedDirection;
74
+ /**
75
+ * Change the player's facing direction
76
+ *
77
+ * Updates the direction the player is facing, which affects animations
78
+ * and directional abilities. This should be called when the player
79
+ * intends to move in a specific direction, not when they are pushed
80
+ * by physics or sliding.
81
+ *
82
+ * @param direction - The new direction to face
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * // Player presses right arrow key
87
+ * player.changeDirection(Direction.Right);
88
+ * ```
89
+ */
90
+ changeDirection(direction: Direction): void;
91
+ /**
92
+ * Get the current facing direction
93
+ *
94
+ * @returns Current direction the player is facing
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const currentDirection = player.getDirection();
99
+ * if (currentDirection === Direction.Up) {
100
+ * // Player is facing up
101
+ * }
102
+ * ```
103
+ */
104
+ getDirection(): Direction;
105
+ /**
106
+ * Set the intended movement direction
107
+ *
108
+ * This should be called when the player intends to move in a direction,
109
+ * typically from input handling. This direction will be used to update
110
+ * the player's facing direction regardless of physics interactions.
111
+ *
112
+ * @param direction - The intended movement direction, or null if not moving
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * // Player presses down arrow key
117
+ * player.setIntendedDirection(Direction.Down);
118
+ *
119
+ * // Player releases all movement keys
120
+ * player.setIntendedDirection(null);
121
+ * ```
122
+ */
123
+ setIntendedDirection(direction: Direction | null): void;
124
+ /**
125
+ * Get the intended movement direction
126
+ *
127
+ * @returns The direction the player intends to move, or null if not moving
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const intended = player.getIntendedDirection();
132
+ * if (intended === Direction.Left) {
133
+ * // Player is trying to move left
134
+ * }
135
+ * ```
136
+ */
137
+ getIntendedDirection(): Direction | null;
138
+ /**
139
+ * Apply physics body position to player coordinates
140
+ *
141
+ * Synchronizes the player's position with their physics body after
142
+ * physics calculations. This method no longer automatically changes
143
+ * the player's direction based on position changes, as direction
144
+ * should be controlled by intended movement instead.
145
+ *
146
+ * @param body - The Matter.js physics body
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * // Called automatically by physics system
151
+ * player.applyPhysic(body);
152
+ * ```
153
+ */
154
+ applyPhysic(body: Matter.Body): void;
155
+ _showAnimation(params: ShowAnimationParams): void;
156
+ /**
157
+ * Create a temporary and moving hitbox relative to the player's position
158
+ *
159
+ * Creates a temporary hitbox that moves through multiple positions sequentially,
160
+ * with all coordinates being relative to the player's current position.
161
+ * For example, you can use it for player attacks, spells, or area effects
162
+ * that should follow the player's position.
163
+ *
164
+ * The method creates a zone sensor that moves through the specified hitbox positions
165
+ * at the given speed, detecting collisions with other players and events at each step.
166
+ *
167
+ * @param hitboxes - Array of hitbox positions relative to player position
168
+ * @param options - Configuration options for the movement
169
+ * @param map - Reference to the map instance for physics access
170
+ * @returns Observable that emits arrays of hit entities and completes when movement is finished
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * // Create a forward attack relative to player position
175
+ * player.createMovingHitbox([
176
+ * { x: 0, y: -32, width: 32, height: 32 }, // In front of player
177
+ * { x: 0, y: -64, width: 32, height: 32 } // Further in front
178
+ * ], { speed: 2 }, map).subscribe({
179
+ * next(hits) {
180
+ * // hits contains other RpgPlayer or RpgEvent objects that were hit
181
+ * console.log('Hit entities:', hits);
182
+ * },
183
+ * complete() {
184
+ * console.log('Attack finished');
185
+ * }
186
+ * });
187
+ * ```
188
+ */
189
+ createMovingHitbox(hitboxes: Array<{
190
+ x: number;
191
+ y: number;
192
+ width: number;
193
+ height: number;
194
+ }>, options?: {
195
+ speed?: number;
196
+ }): Observable<any[]>;
197
+ getCurrentMap(): any;
198
+ }
@@ -1,4 +1,4 @@
1
- import { constructor } from "@rpgjs/types";
1
+ export type Constructor<T = {}> = new (...args: any[]) => T;
2
2
  export declare function random(min: number, max: number): number;
3
3
  export declare function isBrowser(): boolean;
4
4
  export declare function isFunction(val: unknown): boolean;
@@ -14,7 +14,22 @@ export declare function intersection([start1, end1]: [number, number], [start2,
14
14
  export declare function capitalize(s: unknown): string;
15
15
  export declare function camelToKebab(str: string): string;
16
16
  export declare function arrayEquals(a: any[], b: any[]): boolean;
17
- export declare function applyMixins(derivedCtor: constructor<any>, baseCtors: constructor<any>[]): void;
17
+ /**
18
+ * Combines multiple mixins into one
19
+ *
20
+ * @param mixins - Array of mixin functions to combine
21
+ * @returns A single mixin function that applies all mixins
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const AllMixins = combineMixins([WithStats, WithInventory, WithComponentManager]);
26
+ * class MyClass extends AllMixins(BaseClass) {
27
+ * // MyClass now has all capabilities from all mixins
28
+ * }
29
+ * ```
30
+ */
31
+ export declare function combineMixins(mixins: Array<(<T extends Constructor>(Base: T) => any)>): <T extends Constructor>(Base: T) => T;
32
+ export declare function applyMixins(derivedCtor: any, baseCtors: any[]): void;
18
33
  export declare function generateUID(): string;
19
34
  export declare function createConstructor<T>(...propNames: any[]): T;
20
35
  export declare function sharedArrayBuffer(): any;
@@ -30,6 +45,7 @@ export declare function preciseNow(): number;
30
45
  export declare function round(num: number, decimals?: number): number;
31
46
  export declare function set(obj: any, path: any, value: any, onlyPlainObject?: boolean): any;
32
47
  export declare function elementToPositionAbsolute(element: HTMLElement): void;
48
+ export declare function mergeObjectWithMethods<T, S>(target: T, source: S): T & S;
33
49
  declare const _default: {
34
50
  random: typeof random;
35
51
  isBrowser: typeof isBrowser;
@@ -59,5 +75,6 @@ declare const _default: {
59
75
  round: typeof round;
60
76
  camelToKebab: typeof camelToKebab;
61
77
  elementToPositionAbsolute: typeof elementToPositionAbsolute;
78
+ mergeObjectWithMethods: typeof mergeObjectWithMethods;
62
79
  };
63
80
  export default _default;
@@ -0,0 +1,10 @@
1
+ import { RpgCommonPlayer } from '../Player';
2
+ export declare class Item {
3
+ id: import('@signe/reactive').WritableSignal<string>;
4
+ name: import('@signe/reactive').WritableSignal<string>;
5
+ description: import('@signe/reactive').WritableSignal<string>;
6
+ price: import('@signe/reactive').WritableSignal<number>;
7
+ quantity: import('@signe/reactive').WritableSignal<number>;
8
+ onAdd: (player: RpgCommonPlayer) => void;
9
+ constructor(data: any);
10
+ }
@@ -0,0 +1 @@
1
+ export * from './Item';
@@ -0,0 +1,9 @@
1
+ export * from './Player';
2
+ export * from './rooms/Map';
3
+ export * from './modules';
4
+ export * from './services/updateMap';
5
+ export * from './Utils';
6
+ export * from './PrebuiltGui';
7
+ export * from './movement';
8
+ export * as Matter from 'matter-js';
9
+ export * from './database';