@rpgjs/server 5.0.0-alpha.13 → 5.0.0-alpha.14
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/RpgServer.d.ts +3 -0
- package/dist/index.js +3845 -645
- package/dist/index.js.map +1 -1
- package/dist/rooms/map.d.ts +3 -0
- package/package.json +9 -8
- package/src/RpgServer.ts +4 -0
- package/src/rooms/map.ts +41 -5
package/dist/rooms/map.d.ts
CHANGED
|
@@ -48,7 +48,10 @@ export declare class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoi
|
|
|
48
48
|
dataIsReady$: BehaviorSubject<void>;
|
|
49
49
|
globalConfig: any;
|
|
50
50
|
damageFormulas: any;
|
|
51
|
+
constructor();
|
|
52
|
+
get isStandalone(): boolean;
|
|
51
53
|
onJoin(player: RpgPlayer, conn: MockConnection): void;
|
|
54
|
+
onLeave(player: RpgPlayer, conn: MockConnection): void;
|
|
52
55
|
get hooks(): Hooks;
|
|
53
56
|
get widthPx(): number;
|
|
54
57
|
get heightPx(): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/server",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.14",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,16 +11,17 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"description": "",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@rpgjs/common": "5.0.0-alpha.
|
|
14
|
+
"@rpgjs/common": "5.0.0-alpha.14",
|
|
15
15
|
"@rpgjs/database": "^4.3.0",
|
|
16
|
-
"@signe/di": "^2.4.
|
|
17
|
-
"@signe/reactive": "^2.4.
|
|
18
|
-
"@signe/room": "^2.4.
|
|
19
|
-
"@signe/sync": "^2.4.
|
|
20
|
-
"rxjs": "^7.8.2"
|
|
16
|
+
"@signe/di": "^2.4.6",
|
|
17
|
+
"@signe/reactive": "^2.4.6",
|
|
18
|
+
"@signe/room": "^2.4.6",
|
|
19
|
+
"@signe/sync": "^2.4.6",
|
|
20
|
+
"rxjs": "^7.8.2",
|
|
21
|
+
"zod": "^4.0.17"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"vite": "^7.1.
|
|
24
|
+
"vite": "^7.1.2",
|
|
24
25
|
"vite-plugin-dts": "^4.5.4"
|
|
25
26
|
},
|
|
26
27
|
"type": "module",
|
package/src/RpgServer.ts
CHANGED
package/src/rooms/map.ts
CHANGED
|
@@ -10,6 +10,26 @@ import { finalize, lastValueFrom } from "rxjs";
|
|
|
10
10
|
import { Subject } from "rxjs";
|
|
11
11
|
import { BehaviorSubject } from "rxjs";
|
|
12
12
|
import { COEFFICIENT_ELEMENTS, DAMAGE_CRITICAL, DAMAGE_PHYSIC, DAMAGE_SKILL } from "../presets";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Zod schema for validating map update request body
|
|
17
|
+
*
|
|
18
|
+
* This schema ensures that the required fields are present and properly typed
|
|
19
|
+
* when updating a map configuration.
|
|
20
|
+
*/
|
|
21
|
+
const MapUpdateSchema = z.object({
|
|
22
|
+
/** Configuration object for the map (optional) */
|
|
23
|
+
config: z.any().optional(),
|
|
24
|
+
/** Damage formulas configuration (optional) */
|
|
25
|
+
damageFormulas: z.any().optional(),
|
|
26
|
+
/** Unique identifier for the map (required) */
|
|
27
|
+
id: z.string(),
|
|
28
|
+
/** Width of the map in pixels (required) */
|
|
29
|
+
width: z.number(),
|
|
30
|
+
/** Height of the map in pixels (required) */
|
|
31
|
+
height: z.number(),
|
|
32
|
+
});
|
|
13
33
|
|
|
14
34
|
/**
|
|
15
35
|
* Interface representing hook methods available for map events
|
|
@@ -55,8 +75,7 @@ export type EventPosOption = {
|
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
@Room({
|
|
58
|
-
path: "map-{id}"
|
|
59
|
-
throttleSync: 0
|
|
78
|
+
path: "map-{id}"
|
|
60
79
|
})
|
|
61
80
|
export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
|
|
62
81
|
@users(RpgPlayer) players = signal({});
|
|
@@ -67,7 +86,17 @@ export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
|
|
|
67
86
|
globalConfig: any = {}
|
|
68
87
|
damageFormulas: any = {}
|
|
69
88
|
|
|
70
|
-
|
|
89
|
+
constructor() {
|
|
90
|
+
super();
|
|
91
|
+
this.hooks.callHooks("server-map-onStart", this).subscribe();
|
|
92
|
+
this.throttleSync = this.isStandalone ? 0 : 100;
|
|
93
|
+
this.throttleStorage = this.isStandalone ? 0 : 1000;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get isStandalone() {
|
|
97
|
+
return typeof window !== 'undefined'
|
|
98
|
+
}
|
|
99
|
+
|
|
71
100
|
onJoin(player: RpgPlayer, conn: MockConnection) {
|
|
72
101
|
player.map = this;
|
|
73
102
|
player.context = context;
|
|
@@ -92,6 +121,13 @@ export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
|
|
|
92
121
|
).subscribe();
|
|
93
122
|
}
|
|
94
123
|
|
|
124
|
+
onLeave(player: RpgPlayer, conn: MockConnection) {
|
|
125
|
+
this.physic.removeHitbox(player.id)
|
|
126
|
+
this.hooks
|
|
127
|
+
.callHooks("server-player-onLeaveMap", player, this)
|
|
128
|
+
.subscribe();
|
|
129
|
+
}
|
|
130
|
+
|
|
95
131
|
get hooks() {
|
|
96
132
|
return inject<Hooks>(context, ModulesToken);
|
|
97
133
|
}
|
|
@@ -147,8 +183,8 @@ export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
|
|
|
147
183
|
|
|
148
184
|
@Request({
|
|
149
185
|
path: "/map/update",
|
|
150
|
-
method: "POST"
|
|
151
|
-
})
|
|
186
|
+
method: "POST"
|
|
187
|
+
}, MapUpdateSchema as any)
|
|
152
188
|
async updateMap(request: Request) {
|
|
153
189
|
const map = await request.json()
|
|
154
190
|
this.data.set(map)
|