feat: room changing!
This commit is contained in:
parent
667573ce63
commit
74a5342ae7
|
@ -24,11 +24,20 @@ export default (latus) => class Universe extends JsonResource {
|
|||
#tps;
|
||||
|
||||
addPlayer({entity, socket, user}) {
|
||||
const room = this.room(entity.currentRoom);
|
||||
room.addEntityToLayer(entity, 0);
|
||||
entity.startInforming(room);
|
||||
const player = new Player({entity, socket, user});
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
entity.universe = this;
|
||||
const player = new Player({
|
||||
entity,
|
||||
socket,
|
||||
user,
|
||||
});
|
||||
this.#players.push(player);
|
||||
setTimeout(() => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
entity.setPosition([20, 20]);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
entity.currentRoom = 'rooms/town.room.json';
|
||||
}, 5000);
|
||||
return player;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,15 +3,50 @@ import {StateProperty, Trait} from '@avocado/traits';
|
|||
import {compose} from '@latus/core';
|
||||
|
||||
const decorate = compose(
|
||||
StateProperty('currentRoom'),
|
||||
StateProperty('currentRoom', {
|
||||
track: true,
|
||||
}),
|
||||
);
|
||||
|
||||
export default () => class Universed extends decorate(Trait) {
|
||||
|
||||
#universe;
|
||||
|
||||
static defaultState() {
|
||||
return {
|
||||
currentRoom: 'rooms/town.room.json',
|
||||
};
|
||||
}
|
||||
|
||||
onCurrentRoomChanged(oldRoom) {
|
||||
if (!this.#universe) {
|
||||
return;
|
||||
}
|
||||
if (oldRoom) {
|
||||
const room = this.#universe.room(oldRoom);
|
||||
this.entity.stopInforming(room);
|
||||
room.removeEntityFromLayer(this.entity, 0);
|
||||
}
|
||||
if (this.entity.currentRoom) {
|
||||
const room = this.#universe.room(this.entity.currentRoom);
|
||||
room.addEntityToLayer(this.entity, 0);
|
||||
this.entity.startInforming(room);
|
||||
}
|
||||
}
|
||||
|
||||
listeners() {
|
||||
return {
|
||||
|
||||
currentRoomChanged: (oldRoom) => {
|
||||
this.onCurrentRoomChanged(oldRoom);
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
set universe(universe) {
|
||||
this.#universe = universe;
|
||||
this.onCurrentRoomChanged();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user