@rpgjs/server 5.0.0-alpha.40 → 5.0.0-alpha.42

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.
@@ -1,5 +1,5 @@
1
1
  import { MockConnection, RoomMethods, RoomOnJoin } from '@signe/room';
2
- import { Hooks, RpgCommonMap, RpgShape, WorldMapsManager, WeatherState, WorldMapConfig } from '../../../common/src';
2
+ import { Hooks, RpgCommonMap, RpgShape, MapPhysicsInitContext, MapPhysicsEntityContext, WorldMapsManager, WeatherState, WorldMapConfig } from '../../../common/src';
3
3
  import { RpgPlayer, RpgEvent } from '../Player/Player';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { MapOptions } from '../decorators/map';
@@ -192,6 +192,10 @@ export declare class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoi
192
192
  autoSync: boolean;
193
193
  constructor(room: any);
194
194
  onStart(): Promise<void>;
195
+ protected emitPhysicsInit(context: MapPhysicsInitContext): void;
196
+ protected emitPhysicsEntityAdd(context: MapPhysicsEntityContext): void;
197
+ protected emitPhysicsEntityRemove(context: MapPhysicsEntityContext): void;
198
+ protected emitPhysicsReset(): void;
195
199
  private isPositiveNumber;
196
200
  private resolveTrustedMapDimensions;
197
201
  private normalizeEventMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpgjs/server",
3
- "version": "5.0.0-alpha.40",
3
+ "version": "5.0.0-alpha.42",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "publishConfig": {
@@ -11,9 +11,9 @@
11
11
  "license": "MIT",
12
12
  "description": "",
13
13
  "dependencies": {
14
- "@rpgjs/common": "5.0.0-alpha.40",
15
- "@rpgjs/physic": "5.0.0-alpha.40",
16
- "@rpgjs/testing": "5.0.0-alpha.40",
14
+ "@rpgjs/common": "5.0.0-alpha.42",
15
+ "@rpgjs/physic": "5.0.0-alpha.42",
16
+ "@rpgjs/testing": "5.0.0-alpha.42",
17
17
  "@rpgjs/database": "^4.3.0",
18
18
  "@signe/di": "^2.8.3",
19
19
  "@signe/reactive": "^2.8.3",
package/src/RpgServer.ts CHANGED
@@ -2,7 +2,7 @@ import { MapOptions } from "./decorators/map"
2
2
  import { RpgPlayer } from "./Player/Player"
3
3
  import { type RpgMap } from "./rooms/map"
4
4
  import { RpgServerEngine } from "./RpgServerEngine"
5
- import { WorldMapConfig, RpgShape } from "@rpgjs/common"
5
+ import { WorldMapConfig, RpgShape, type MapPhysicsInitContext, type MapPhysicsEntityContext } from "@rpgjs/common"
6
6
  import { RpgEvent } from "./Player/Player"
7
7
 
8
8
  type RpgClassMap<T> = new () => T
@@ -579,6 +579,48 @@ export interface RpgMapHooks {
579
579
  * ```
580
580
  */
581
581
  onLeave?: (player: RpgPlayer, map: RpgMap) => any
582
+
583
+ /**
584
+ * Called when the map physics world is initialized.
585
+ *
586
+ * This hook runs each time `loadPhysic()` prepares the physics world, after static
587
+ * map hitboxes are created and before dynamic player/event bodies are hydrated.
588
+ *
589
+ * @param {RpgMap} map - The map instance
590
+ * @param {MapPhysicsInitContext} context - Physics initialization context
591
+ * @returns {any}
592
+ * @memberof RpgMapHooks
593
+ */
594
+ onPhysicsInit?: (map: RpgMap, context: MapPhysicsInitContext) => any
595
+
596
+ /**
597
+ * Called when a dynamic character physics body is added to the map.
598
+ *
599
+ * @param {RpgMap} map - The map instance
600
+ * @param {MapPhysicsEntityContext} context - Added entity context
601
+ * @returns {any}
602
+ * @memberof RpgMapHooks
603
+ */
604
+ onPhysicsEntityAdd?: (map: RpgMap, context: MapPhysicsEntityContext) => any
605
+
606
+ /**
607
+ * Called when a dynamic character physics body is removed from the map.
608
+ *
609
+ * @param {RpgMap} map - The map instance
610
+ * @param {MapPhysicsEntityContext} context - Removed entity context
611
+ * @returns {any}
612
+ * @memberof RpgMapHooks
613
+ */
614
+ onPhysicsEntityRemove?: (map: RpgMap, context: MapPhysicsEntityContext) => any
615
+
616
+ /**
617
+ * Called when the map physics world is reset (before reload).
618
+ *
619
+ * @param {RpgMap} map - The map instance
620
+ * @returns {any}
621
+ * @memberof RpgMapHooks
622
+ */
623
+ onPhysicsReset?: (map: RpgMap) => any
582
624
  }
583
625
 
584
626
  export interface RpgServer {
package/src/rooms/map.ts CHANGED
@@ -1,5 +1,18 @@
1
1
  import { Action, MockConnection, Request, Room, RoomMethods, RoomOnJoin } from "@signe/room";
2
- import { Hooks, IceMovement, ModulesToken, ProjectileMovement, ProjectileType, RpgCommonMap, Direction, RpgCommonPlayer, RpgShape, findModules } from "@rpgjs/common";
2
+ import {
3
+ Hooks,
4
+ IceMovement,
5
+ ModulesToken,
6
+ ProjectileMovement,
7
+ ProjectileType,
8
+ RpgCommonMap,
9
+ Direction,
10
+ RpgCommonPlayer,
11
+ RpgShape,
12
+ findModules,
13
+ type MapPhysicsInitContext,
14
+ type MapPhysicsEntityContext,
15
+ } from "@rpgjs/common";
3
16
  import { WorldMapsManager, type WeatherState, type WorldMapConfig } from "@rpgjs/common";
4
17
  import { RpgPlayer, RpgEvent } from "../Player/Player";
5
18
  import { generateShortUUID, sync, type, users } from "@signe/sync";
@@ -279,6 +292,22 @@ export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
279
292
  return BaseRoom.prototype.onStart.call(this)
280
293
  }
281
294
 
295
+ protected emitPhysicsInit(context: MapPhysicsInitContext): void {
296
+ this.hooks.callHooks("server-map-onPhysicsInit", this, context).subscribe();
297
+ }
298
+
299
+ protected emitPhysicsEntityAdd(context: MapPhysicsEntityContext): void {
300
+ this.hooks.callHooks("server-map-onPhysicsEntityAdd", this, context).subscribe();
301
+ }
302
+
303
+ protected emitPhysicsEntityRemove(context: MapPhysicsEntityContext): void {
304
+ this.hooks.callHooks("server-map-onPhysicsEntityRemove", this, context).subscribe();
305
+ }
306
+
307
+ protected emitPhysicsReset(): void {
308
+ this.hooks.callHooks("server-map-onPhysicsReset", this).subscribe();
309
+ }
310
+
282
311
  private isPositiveNumber(value: unknown): value is number {
283
312
  return typeof value === "number" && Number.isFinite(value) && value > 0;
284
313
  }