@rpgjs/server 5.0.0-alpha.26 → 5.0.0-alpha.27
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/Player/MoveManager.d.ts +62 -1
- package/dist/Player/Player.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1419 -173
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/Player/MoveManager.ts +654 -112
- package/src/Player/Player.ts +18 -1
- package/src/index.ts +2 -1
- package/src/rooms/map.ts +2 -2
- package/tests/change-map.spec.ts +2 -2
- package/tests/event.spec.ts +80 -0
- package/tests/item.spec.ts +2 -2
- package/tests/move.spec.ts +601 -0
- package/tests/random-move.spec.ts +65 -0
package/src/Player/Player.ts
CHANGED
|
@@ -369,7 +369,16 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
369
369
|
// Skip collision check for teleportation (allow teleporting through walls)
|
|
370
370
|
const entity = this.map.physic.getEntityByUUID(this.id);
|
|
371
371
|
if (entity) {
|
|
372
|
-
this.
|
|
372
|
+
const hitbox = typeof this.hitbox === "function" ? this.hitbox() : this.hitbox;
|
|
373
|
+
const width = hitbox?.w ?? 32;
|
|
374
|
+
const height = hitbox?.h ?? 32;
|
|
375
|
+
|
|
376
|
+
// Convert top-left position to center position for physics engine
|
|
377
|
+
// positions.x/y are TOP-LEFT coordinates, but physic.teleport expects CENTER coordinates
|
|
378
|
+
const centerX = positions.x + width / 2;
|
|
379
|
+
const centerY = positions.y + height / 2;
|
|
380
|
+
|
|
381
|
+
this.map.physic.teleport(entity, { x: centerX, y: centerY });
|
|
373
382
|
}
|
|
374
383
|
}
|
|
375
384
|
this.x.set(positions.x)
|
|
@@ -1108,6 +1117,10 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
1108
1117
|
}, this)
|
|
1109
1118
|
}
|
|
1110
1119
|
}
|
|
1120
|
+
|
|
1121
|
+
isEvent(): boolean {
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1111
1124
|
}
|
|
1112
1125
|
|
|
1113
1126
|
export class RpgEvent extends RpgPlayer {
|
|
@@ -1126,6 +1139,10 @@ export class RpgEvent extends RpgPlayer {
|
|
|
1126
1139
|
if (!map) return;
|
|
1127
1140
|
map.removeEvent(this.id);
|
|
1128
1141
|
}
|
|
1142
|
+
|
|
1143
|
+
override isEvent(): boolean {
|
|
1144
|
+
return true;
|
|
1145
|
+
}
|
|
1129
1146
|
}
|
|
1130
1147
|
|
|
1131
1148
|
|
package/src/index.ts
CHANGED
|
@@ -12,4 +12,5 @@ export * from "@signe/reactive";
|
|
|
12
12
|
export * from "./Gui";
|
|
13
13
|
export { RpgShape, RpgModule } from "@rpgjs/common";
|
|
14
14
|
export * from "./decorators/event";
|
|
15
|
-
export * from "./decorators/map";
|
|
15
|
+
export * from "./decorators/map";
|
|
16
|
+
export * from "./Player/MoveManager";
|
package/src/rooms/map.ts
CHANGED
|
@@ -222,6 +222,7 @@ export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
|
|
|
222
222
|
if (isTest) {
|
|
223
223
|
this.autoSync = false;
|
|
224
224
|
this.setAutoTick(false);
|
|
225
|
+
this.autoTickEnabled = false;
|
|
225
226
|
this.throttleSync = 0;
|
|
226
227
|
this.throttleStorage = 0;
|
|
227
228
|
}
|
|
@@ -1320,8 +1321,7 @@ export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
|
|
|
1320
1321
|
eventInstance.map = this;
|
|
1321
1322
|
eventInstance.context = context;
|
|
1322
1323
|
|
|
1323
|
-
eventInstance.
|
|
1324
|
-
eventInstance.y.set(y);
|
|
1324
|
+
await eventInstance.teleport({ x, y });
|
|
1325
1325
|
|
|
1326
1326
|
this.events()[id] = eventInstance;
|
|
1327
1327
|
|
package/tests/change-map.spec.ts
CHANGED
|
@@ -67,6 +67,6 @@ test('Player can change map', async () => {
|
|
|
67
67
|
expect(newMap).toBeDefined()
|
|
68
68
|
expect(newMap?.id).toBe('map2')
|
|
69
69
|
|
|
70
|
-
expect(player.x()).toBe(200
|
|
71
|
-
expect(player.y()).toBe(200
|
|
70
|
+
expect(player.x()).toBe(200)
|
|
71
|
+
expect(player.y()).toBe(200)
|
|
72
72
|
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { beforeEach, test, expect, afterEach } from 'vitest'
|
|
2
|
+
import { testing, TestingFixture } from '@rpgjs/testing'
|
|
3
|
+
import { defineModule, createModule } from '@rpgjs/common'
|
|
4
|
+
import { RpgPlayer, RpgServer, Move } from '../src'
|
|
5
|
+
import { RpgClient } from '../../client/src'
|
|
6
|
+
|
|
7
|
+
const Event = () => {
|
|
8
|
+
return {
|
|
9
|
+
name: "EV-1",
|
|
10
|
+
onInit() {
|
|
11
|
+
this.setGraphic("hero");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Define server module with two maps
|
|
17
|
+
const serverModule = defineModule<RpgServer>({
|
|
18
|
+
maps: [
|
|
19
|
+
{
|
|
20
|
+
id: 'map1',
|
|
21
|
+
events: [{ event: Event(), x: 100, y: 150 }]
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
player: {
|
|
25
|
+
async onConnected(player) {
|
|
26
|
+
await player.changeMap('map1', { x: 100, y: 126 })
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// Define client module
|
|
32
|
+
const clientModule = defineModule<RpgClient>({
|
|
33
|
+
// Client-side logic
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
let player: RpgPlayer
|
|
37
|
+
let client: any
|
|
38
|
+
let fixture: TestingFixture
|
|
39
|
+
|
|
40
|
+
beforeEach(async () => {
|
|
41
|
+
const myModule = createModule('TestModule', [{
|
|
42
|
+
server: serverModule,
|
|
43
|
+
client: clientModule
|
|
44
|
+
}])
|
|
45
|
+
|
|
46
|
+
fixture = await testing(myModule)
|
|
47
|
+
client = await fixture.createClient()
|
|
48
|
+
player = client.player
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
fixture.clear()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('Player to touch event', async () => {
|
|
56
|
+
player = await client.waitForMapChange('map1')
|
|
57
|
+
const map = player.getCurrentMap()
|
|
58
|
+
const event = map?.getEvents()[0]
|
|
59
|
+
expect(event).toBeDefined()
|
|
60
|
+
expect(event?.name()).toBe("EV-1")
|
|
61
|
+
expect(event?.x()).toBe(100)
|
|
62
|
+
expect(event?.y()).toBe(150)
|
|
63
|
+
await fixture.waitUntil(
|
|
64
|
+
player.moveRoutes([
|
|
65
|
+
Move.tileDown(2),
|
|
66
|
+
], {
|
|
67
|
+
onStuck: () => false
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
expect(event?.x()).toBe(100)
|
|
71
|
+
expect(event?.y()).toBe(150)
|
|
72
|
+
await fixture.waitUntil(
|
|
73
|
+
event!.moveRoutes([
|
|
74
|
+
Move.down()
|
|
75
|
+
])
|
|
76
|
+
)
|
|
77
|
+
expect(event?.x()).toBe(100)
|
|
78
|
+
expect(event?.y()).toBe(150 + event!.speed())
|
|
79
|
+
|
|
80
|
+
})
|
package/tests/item.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { beforeEach, test, expect, afterEach, describe, vi } from "vitest";
|
|
2
|
-
import { testing, waitForSyncComplete } from "@rpgjs/testing";
|
|
2
|
+
import { testing, waitForSyncComplete, TestingFixture } from "@rpgjs/testing";
|
|
3
3
|
import { defineModule, createModule } from "@rpgjs/common";
|
|
4
4
|
import { RpgPlayer, RpgServer } from "../src";
|
|
5
5
|
import { RpgClient } from "../../client/src";
|
|
@@ -57,7 +57,7 @@ const TestNoPriceItem = {
|
|
|
57
57
|
|
|
58
58
|
let player: RpgPlayer;
|
|
59
59
|
let clientTesting: any;
|
|
60
|
-
let fixture:
|
|
60
|
+
let fixture: TestingFixture;
|
|
61
61
|
|
|
62
62
|
// Define server module with items in database
|
|
63
63
|
const serverModule = defineModule<RpgServer>({
|