refactor: clean up self entity trait juggling
This commit is contained in:
parent
e5f738202b
commit
cbccd7b1ae
|
@ -50,15 +50,24 @@ const stateSynchronizer = new StateSynchronizer({
|
|||
worldTime,
|
||||
});
|
||||
room.on('entityAdded', (entity) => {
|
||||
entity.removeTrait('controllable');
|
||||
// Traits that only make sense for our self entity on the client.
|
||||
const selfEntityOnlyTraits = [
|
||||
'controllable',
|
||||
'followed',
|
||||
];
|
||||
for (const type of selfEntityOnlyTraits) {
|
||||
if (entity.is(type)) {
|
||||
entity.removeTrait(type);
|
||||
}
|
||||
}
|
||||
// Set self entity.
|
||||
if ('string' === typeof selfEntity) {
|
||||
if (entity === room.findEntity(selfEntity)) {
|
||||
selfEntity = entity;
|
||||
// Only self entity should be controllable.
|
||||
entity.addTrait('controllable');
|
||||
// Camera tracking.
|
||||
entity.addTrait('followed');
|
||||
// Add back our self entity traits.
|
||||
for (const type of selfEntityOnlyTraits) {
|
||||
entity.addTrait(type);
|
||||
}
|
||||
const {camera} = entity;
|
||||
camera.on('realPositionChanged', () => {
|
||||
roomView.position = Vector.round(
|
||||
|
|
Loading…
Reference in New Issue
Block a user