humus-old/server/create-entity-for-connection.js
2019-04-05 12:59:14 -04:00

57 lines
1.1 KiB
JavaScript

import {create as createEntity} from '@avocado/entity';
// Create an entity for a new connection.
export function createEntityForConnection(socket) {
let entity = createEntity();
entity = entity.fromJSON({
traits: {
animated: {
params: {
animations: {
idle: {
offset: [0, -12],
uri: '/idle.animation.json',
},
moving: {
offset: [0, -12],
uri: '/moving.animation.json',
},
}
},
},
directional: {
params: {
directionCount: 4,
},
},
existent: {},
followed: {},
graphical: {},
mobile: {
state: {
speed: 100,
},
},
physical: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [8, 8],
}
}
},
positioned: {
state: {
x: 100,
y: 100,
},
},
},
});
entity.addTrait('controllable');
entity.addTrait('informed');
// Embed socket.
entity.socket = socket;
return entity;
}