@rpgjs/server 5.0.0-beta.5 → 5.0.0-beta.7

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.
@@ -48,6 +48,17 @@ afterEach(async () => {
48
48
 
49
49
 
50
50
  describe("Move Routes - Basic Movements", () => {
51
+ test("should create player physics body with rectangular RPG hitbox and speed", async () => {
52
+ const map = player.getCurrentMap() as any;
53
+ const entity = map.getBody(player.id);
54
+ const hitbox = player.hitbox();
55
+
56
+ expect(entity).toBeDefined();
57
+ expect(entity.width).toBe(hitbox.w);
58
+ expect(entity.height).toBe(hitbox.h);
59
+ expect(entity.radius).toBe(0);
60
+ expect(entity.maxLinearVelocity).toBe(player.speed() * 50);
61
+ });
51
62
 
52
63
  test("should move right using Direction enum", async () => {
53
64
  const initialX = player.x();
@@ -117,6 +128,59 @@ describe("Move Routes - Basic Movements", () => {
117
128
  });
118
129
  });
119
130
 
131
+ describe("Map Shapes", () => {
132
+ test("should create static obstacle body for map shape", async () => {
133
+ const map = player.getCurrentMap() as any;
134
+ const shape = map.createShape({
135
+ x: 40,
136
+ y: 56,
137
+ width: 24,
138
+ height: 32,
139
+ name: "test-obstacle",
140
+ });
141
+ const entity = map.physic.getEntityByUUID("shape-test-obstacle");
142
+
143
+ expect(shape.name).toBe("test-obstacle");
144
+ expect(entity).toBeDefined();
145
+ expect(entity.position.x).toBe(52);
146
+ expect(entity.position.y).toBe(72);
147
+ expect(entity.width).toBe(24);
148
+ expect(entity.height).toBe(32);
149
+ expect(entity.isStatic()).toBe(true);
150
+ });
151
+
152
+ test("should detect entities with moving hitbox sensor", async () => {
153
+ const map = player.getCurrentMap() as any;
154
+ const hitbox = player.hitbox();
155
+ const hitsPromise = new Promise<any[]>((resolve, reject) => {
156
+ let subscription: { unsubscribe: () => void };
157
+ const timeout = setTimeout(() => {
158
+ subscription.unsubscribe();
159
+ reject(new Error("moving hitbox did not detect player"));
160
+ }, 500);
161
+ subscription = map.createMovingHitbox([
162
+ {
163
+ x: player.x(),
164
+ y: player.y(),
165
+ width: hitbox.w,
166
+ height: hitbox.h,
167
+ },
168
+ ]).subscribe({
169
+ next: (hits: any[]) => {
170
+ clearTimeout(timeout);
171
+ subscription.unsubscribe();
172
+ resolve(hits);
173
+ },
174
+ error: reject,
175
+ });
176
+ map.physic.getZoneManager().update();
177
+ });
178
+
179
+ const hits = await hitsPromise;
180
+ expect(hits.map((hit) => hit.id)).toContain(player.id);
181
+ });
182
+ });
183
+
120
184
  describe("Move Routes - Move Helper Functions", () => {
121
185
  test("should move right using Move.right()", async () => {
122
186
  const initialX = player.x();
@@ -598,4 +662,4 @@ describe("Move Routes - Stuck Detection", () => {
598
662
  // Player should have moved successfully
599
663
  expect(player.x()).toBeGreaterThan(initialX);
600
664
  });
601
- });
665
+ });
@@ -396,6 +396,10 @@ describe('Map WorldMapsManager Integration', () => {
396
396
  const worldY = player.worldPositionY()
397
397
  expect(worldX).toBe(100)
398
398
  expect(worldY).toBe(200)
399
+ const entity = map?.physic.getEntityByUUID(player.id)
400
+ const hitbox = player.hitbox()
401
+ expect(entity?.position.x).toBe(100 + hitbox.w / 2)
402
+ expect(entity?.position.y).toBe(200 + hitbox.h / 2)
399
403
 
400
404
  // Change to map2 which is at worldX: 1024, worldY: 0
401
405
  await player.changeMap('map2', { x: 50, y: 100 })