refactor: clean up self entity trait juggling

This commit is contained in:
cha0s 2019-04-05 12:59:29 -04:00
parent e5f738202b
commit cbccd7b1ae

View File

@ -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(