refactor: better socket/entity interface

This commit is contained in:
cha0s 2019-03-21 00:29:44 -05:00
parent aa74dc06e4
commit a7a342cc36
2 changed files with 2 additions and 2 deletions

View File

@ -31,9 +31,7 @@ function createConnectionListener(avocadoServer) {
// Create and track a new entity for the connection. // Create and track a new entity for the connection.
const entity = createEntityForConnection(); const entity = createEntityForConnection();
entityList.addEntity(entity); entityList.addEntity(entity);
entity.addTrait('informed');
entity.socket = socket; entity.socket = socket;
socket.entity = entity;
// Listen for events. // Listen for events.
socket.on('message', createMessageListener(avocadoServer, socket)); socket.on('message', createMessageListener(avocadoServer, socket));
socket.on('disconnect', createDisconnectionListener(avocadoServer, socket)); socket.on('disconnect', createDisconnectionListener(avocadoServer, socket));
@ -84,6 +82,7 @@ function createEntityForConnection() {
}, },
existent: {}, existent: {},
graphical: {}, graphical: {},
informed: {},
mobile: { mobile: {
state: { state: {
speed: 400, speed: 400,

View File

@ -71,6 +71,7 @@ class InformedBase extends Trait {
} }
set socket(socket) { set socket(socket) {
socket.entity = this.entity;
this._socket = socket; this._socket = socket;
} }