@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.
- package/dist/Physic.d.ts +619 -0
- package/dist/Player.d.ts +198 -0
- package/{lib → dist}/Utils.d.ts +19 -2
- package/dist/database/Item.d.ts +10 -0
- package/dist/database/index.d.ts +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +16741 -0
- package/dist/index.js.map +1 -0
- package/dist/modules.d.ts +92 -0
- package/dist/movement/MovementManager.d.ts +84 -0
- package/dist/movement/MovementStrategy.d.ts +39 -0
- package/dist/movement/index.d.ts +12 -0
- package/dist/movement/strategies/CompositeMovement.d.ts +76 -0
- package/dist/movement/strategies/Dash.d.ts +52 -0
- package/dist/movement/strategies/IceMovement.d.ts +87 -0
- package/dist/movement/strategies/Knockback.d.ts +50 -0
- package/dist/movement/strategies/LinearMove.d.ts +43 -0
- package/dist/movement/strategies/LinearRepulsion.d.ts +55 -0
- package/dist/movement/strategies/Oscillate.d.ts +60 -0
- package/dist/movement/strategies/PathFollow.d.ts +78 -0
- package/dist/movement/strategies/ProjectileMovement.d.ts +138 -0
- package/dist/movement/strategies/SeekAvoid.d.ts +27 -0
- package/dist/rooms/Map.d.ts +109 -0
- package/dist/services/updateMap.d.ts +7 -0
- package/package.json +17 -17
- package/src/Physic.ts +1644 -0
- package/src/Player.ts +262 -26
- package/src/{gui/PrebuiltGui.ts → PrebuiltGui.ts} +1 -1
- package/src/Utils.ts +184 -123
- package/src/database/Item.ts +19 -0
- package/src/database/index.ts +1 -0
- package/src/index.ts +9 -25
- package/src/modules.ts +230 -0
- package/src/movement/MovementManager.ts +142 -0
- package/src/movement/MovementStrategy.ts +42 -0
- package/src/movement/index.ts +15 -0
- package/src/movement/strategies/CompositeMovement.ts +173 -0
- package/src/movement/strategies/Dash.ts +82 -0
- package/src/movement/strategies/IceMovement.ts +158 -0
- package/src/movement/strategies/Knockback.ts +81 -0
- package/src/movement/strategies/LinearMove.ts +58 -0
- package/src/movement/strategies/LinearRepulsion.ts +128 -0
- package/src/movement/strategies/Oscillate.ts +144 -0
- package/src/movement/strategies/PathFollow.ts +156 -0
- package/src/movement/strategies/ProjectileMovement.ts +322 -0
- package/src/movement/strategies/SeekAvoid.ts +123 -0
- package/src/rooms/Map.ts +272 -0
- package/src/services/updateMap.ts +9 -0
- package/tests/physic.spec.ts +454 -0
- package/tsconfig.json +8 -3
- package/vite.config.ts +21 -0
- package/CHANGELOG.md +0 -152
- package/LICENSE +0 -19
- package/browser/manifest.json +0 -7
- package/browser/rpg.common.js +0 -11357
- package/browser/rpg.common.umd.cjs +0 -11358
- package/lib/AbstractObject.d.ts +0 -322
- package/lib/AbstractObject.js +0 -872
- package/lib/AbstractObject.js.map +0 -1
- package/lib/Color.d.ts +0 -1
- package/lib/Color.js +0 -25
- package/lib/Color.js.map +0 -1
- package/lib/DefaultInput.d.ts +0 -2
- package/lib/DefaultInput.js +0 -26
- package/lib/DefaultInput.js.map +0 -1
- package/lib/Event.d.ts +0 -3
- package/lib/Event.js +0 -4
- package/lib/Event.js.map +0 -1
- package/lib/EventEmitter.d.ts +0 -10
- package/lib/EventEmitter.js +0 -61
- package/lib/EventEmitter.js.map +0 -1
- package/lib/Game.d.ts +0 -28
- package/lib/Game.js +0 -127
- package/lib/Game.js.map +0 -1
- package/lib/Hit.d.ts +0 -16
- package/lib/Hit.js +0 -65
- package/lib/Hit.js.map +0 -1
- package/lib/Inject.d.ts +0 -9
- package/lib/Inject.js +0 -17
- package/lib/Inject.js.map +0 -1
- package/lib/Logger.d.ts +0 -2
- package/lib/Logger.js +0 -7
- package/lib/Logger.js.map +0 -1
- package/lib/Map.d.ts +0 -174
- package/lib/Map.js +0 -263
- package/lib/Map.js.map +0 -1
- package/lib/Module.d.ts +0 -16
- package/lib/Module.js +0 -139
- package/lib/Module.js.map +0 -1
- package/lib/Player.d.ts +0 -26
- package/lib/Player.js +0 -19
- package/lib/Player.js.map +0 -1
- package/lib/Plugin.d.ts +0 -67
- package/lib/Plugin.js +0 -92
- package/lib/Plugin.js.map +0 -1
- package/lib/Scheduler.d.ts +0 -26
- package/lib/Scheduler.js +0 -90
- package/lib/Scheduler.js.map +0 -1
- package/lib/Shape.d.ts +0 -127
- package/lib/Shape.js +0 -261
- package/lib/Shape.js.map +0 -1
- package/lib/Utils.js +0 -181
- package/lib/Utils.js.map +0 -1
- package/lib/Vector2d.d.ts +0 -20
- package/lib/Vector2d.js +0 -63
- package/lib/Vector2d.js.map +0 -1
- package/lib/VirtualGrid.d.ts +0 -26
- package/lib/VirtualGrid.js +0 -68
- package/lib/VirtualGrid.js.map +0 -1
- package/lib/Worker.d.ts +0 -7
- package/lib/Worker.js +0 -13
- package/lib/Worker.js.map +0 -1
- package/lib/WorldMaps.d.ts +0 -105
- package/lib/WorldMaps.js +0 -184
- package/lib/WorldMaps.js.map +0 -1
- package/lib/gui/PrebuiltGui.js +0 -29
- package/lib/gui/PrebuiltGui.js.map +0 -1
- package/lib/index.d.ts +0 -25
- package/lib/index.js +0 -26
- package/lib/index.js.map +0 -1
- package/lib/transports/io.d.ts +0 -22
- package/lib/transports/io.js +0 -82
- package/lib/transports/io.js.map +0 -1
- package/lib/workers/move.d.ts +0 -1
- package/lib/workers/move.js +0 -57
- package/lib/workers/move.js.map +0 -1
- package/rpg.toml +0 -11
- package/src/AbstractObject.ts +0 -973
- package/src/Color.ts +0 -29
- package/src/DefaultInput.ts +0 -26
- package/src/Event.ts +0 -3
- package/src/EventEmitter.ts +0 -65
- package/src/Game.ts +0 -159
- package/src/Hit.ts +0 -70
- package/src/Inject.ts +0 -22
- package/src/Logger.ts +0 -7
- package/src/Map.ts +0 -335
- package/src/Module.ts +0 -144
- package/src/Plugin.ts +0 -100
- package/src/Scheduler.ts +0 -95
- package/src/Shape.ts +0 -302
- package/src/Vector2d.ts +0 -70
- package/src/VirtualGrid.ts +0 -78
- package/src/Worker.ts +0 -17
- package/src/WorldMaps.ts +0 -204
- package/src/transports/io.ts +0 -91
- package/src/workers/move.ts +0 -61
- /package/{lib/gui → dist}/PrebuiltGui.d.ts +0 -0
package/dist/Player.d.ts
ADDED
|
@@ -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
|
+
}
|
package/{lib → dist}/Utils.d.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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';
|
package/dist/index.d.ts
ADDED
|
@@ -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';
|