@hytopia.com/examples 1.0.18 → 1.0.19
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.
|
@@ -77,7 +77,7 @@ export default class GameManager {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
private _selectWorldForPlayer = async (player: Player): Promise<World | undefined> => {
|
|
80
|
-
const gamePlayer =
|
|
80
|
+
const gamePlayer = GamePlayer.getOrCreate(player);
|
|
81
81
|
return gamePlayer.currentRegion?.world ?? this._startRegion.world;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -88,13 +88,15 @@ export default class GamePlayer {
|
|
|
88
88
|
this.hotbar.onSelectedItemChanged = this._onHotbarSelectedItemChanged;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
public static
|
|
91
|
+
public static getOrCreate(player: Player): GamePlayer {
|
|
92
92
|
let gamePlayer = this._instances.get(player.id);
|
|
93
|
+
|
|
93
94
|
if (!gamePlayer) {
|
|
94
95
|
gamePlayer = new GamePlayer(player);
|
|
95
|
-
|
|
96
|
+
gamePlayer.load();
|
|
96
97
|
this._instances.set(player.id, gamePlayer);
|
|
97
98
|
}
|
|
99
|
+
|
|
98
100
|
return gamePlayer;
|
|
99
101
|
}
|
|
100
102
|
|
|
@@ -342,8 +344,8 @@ export default class GamePlayer {
|
|
|
342
344
|
this.player.joinWorld(region.world);
|
|
343
345
|
}
|
|
344
346
|
|
|
345
|
-
public
|
|
346
|
-
const serializedGamePlayerData =
|
|
347
|
+
public load(): void {
|
|
348
|
+
const serializedGamePlayerData = this.player.getPersistedData();
|
|
347
349
|
|
|
348
350
|
if (serializedGamePlayerData) { // Existing player, load their state
|
|
349
351
|
this._loadFromSerializedData(serializedGamePlayerData as SerializedGamePlayerData);
|
|
@@ -140,9 +140,8 @@ export default class GameRegion {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
protected
|
|
144
|
-
|
|
145
|
-
const gamePlayer = await GamePlayer.getOrCreate(player);
|
|
143
|
+
protected onPlayerJoin(player: Player) {
|
|
144
|
+
const gamePlayer = GamePlayer.getOrCreate(player);
|
|
146
145
|
|
|
147
146
|
// Set the current region for the player
|
|
148
147
|
gamePlayer.setCurrentRegion(this);
|
|
@@ -153,11 +152,6 @@ export default class GameRegion {
|
|
|
153
152
|
const gamePlayerEntity = new GamePlayerEntity(gamePlayer);
|
|
154
153
|
|
|
155
154
|
gamePlayerEntity.spawn(this._world, spawnPoint, Quaternion.fromEuler(0, spawnFacingAngle, 0));
|
|
156
|
-
|
|
157
|
-
// Since we're using an async onPlayerJoin, we need to explicitly set the camera
|
|
158
|
-
// since the camera attachment logic as of SDK 0.6.7 only checks for an entity
|
|
159
|
-
// the first tick after a player joins a world in order to auto attach the camera.
|
|
160
|
-
player.camera.setAttachedToEntity(gamePlayerEntity);
|
|
161
155
|
|
|
162
156
|
// Make the camera look at the correct spawn facing angle.
|
|
163
157
|
// Calculate look direction based on facing angle (identity direction is -z, consistent with threejs)
|
|
@@ -200,8 +194,8 @@ export default class GameRegion {
|
|
|
200
194
|
// The HYTOPIA SDK handles resynchronization of all persisted state back to the player client such as
|
|
201
195
|
// their entity, scene ui states, etc, but anything that uses ephemeral state (Such as UI) we need
|
|
202
196
|
// to handle reloading for them manually here.
|
|
203
|
-
protected
|
|
204
|
-
const gamePlayer =
|
|
197
|
+
protected onPlayerReconnected(player: Player) {
|
|
198
|
+
const gamePlayer = GamePlayer.getOrCreate(player);
|
|
205
199
|
gamePlayer.onPlayerReconnected();
|
|
206
200
|
}
|
|
207
201
|
}
|
package/package.json
CHANGED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"health": 120,
|
|
3
|
-
"currentRegionId": "stalkhaven",
|
|
4
|
-
"skillExperience": [
|
|
5
|
-
[
|
|
6
|
-
"exploration",
|
|
7
|
-
225
|
|
8
|
-
],
|
|
9
|
-
[
|
|
10
|
-
"combat",
|
|
11
|
-
162
|
|
12
|
-
],
|
|
13
|
-
[
|
|
14
|
-
"agility",
|
|
15
|
-
20
|
|
16
|
-
]
|
|
17
|
-
],
|
|
18
|
-
"backpack": {
|
|
19
|
-
"items": []
|
|
20
|
-
},
|
|
21
|
-
"hotbar": {
|
|
22
|
-
"items": [
|
|
23
|
-
{
|
|
24
|
-
"position": 0,
|
|
25
|
-
"itemId": "dull_sword"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"position": 2,
|
|
29
|
-
"itemId": "toy_sword"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"position": 3,
|
|
33
|
-
"itemId": "gold",
|
|
34
|
-
"quantity": 82
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"position": 1,
|
|
38
|
-
"itemId": "ratkin_tail"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"position": 4,
|
|
42
|
-
"itemId": "ratkin_tooth"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"position": 5,
|
|
46
|
-
"itemId": "ratkin_eyes",
|
|
47
|
-
"quantity": 3
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"position": 6,
|
|
51
|
-
"itemId": "ratkin_bones",
|
|
52
|
-
"quantity": 3
|
|
53
|
-
}
|
|
54
|
-
]
|
|
55
|
-
},
|
|
56
|
-
"questLog": {
|
|
57
|
-
"quests": [
|
|
58
|
-
{
|
|
59
|
-
"questId": "welcome-to-stalkhaven",
|
|
60
|
-
"state": "completed",
|
|
61
|
-
"objectiveProgress": {
|
|
62
|
-
"talk-to-mark": 1
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"questId": "exploring-stalkhaven",
|
|
67
|
-
"state": "completed",
|
|
68
|
-
"objectiveProgress": {
|
|
69
|
-
"talk-to-mycelis": 1,
|
|
70
|
-
"talk-to-finn": 1,
|
|
71
|
-
"talk-to-sporn": 1,
|
|
72
|
-
"talk-to-mark": 1
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"questId": "tested-mettle",
|
|
77
|
-
"state": "active",
|
|
78
|
-
"objectiveProgress": {
|
|
79
|
-
"kill-5-ratkin": 5,
|
|
80
|
-
"dodge-3-times": 3,
|
|
81
|
-
"talk-to-mark": 0
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
"questId": "dip-duck-dodge",
|
|
86
|
-
"state": "active",
|
|
87
|
-
"objectiveProgress": {
|
|
88
|
-
"dodge": 0,
|
|
89
|
-
"talk-to-sporn": 0
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
]
|
|
93
|
-
},
|
|
94
|
-
"storage": {
|
|
95
|
-
"items": []
|
|
96
|
-
},
|
|
97
|
-
"wearables": {
|
|
98
|
-
"items": [
|
|
99
|
-
{
|
|
100
|
-
"position": 1,
|
|
101
|
-
"itemId": "adventurer_tunic"
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
},
|
|
105
|
-
"currentRegionSpawnFacingAngle": 0,
|
|
106
|
-
"currentRegionSpawnPoint": {
|
|
107
|
-
"x": 1,
|
|
108
|
-
"y": 2,
|
|
109
|
-
"z": 40
|
|
110
|
-
}
|
|
111
|
-
}
|