humus-old/server/create-entity-for-connection.js

59 lines
1.2 KiB
JavaScript

import {Entity} from '@avocado/entity';
// Create an entity for a new connection.
export function createEntityForConnection(socket) {
let entity = new Entity();
entity = entity.fromJSON({
traits: {
animated: {
params: {
animations: {
idle: {
offset: [0, -12],
uri: '/idle.animation.json',
},
moving: {
offset: [0, -12],
uri: '/moving.animation.json',
},
}
},
},
collider: {},
directional: {
params: {
directionCount: 4,
},
},
existent: {},
followed: {},
visible: {},
mobile: {
state: {
speed: 100,
},
},
physical: {},
positioned: {
state: {
x: 400,
y: 400,
},
},
shaped: {
params: {
shape: {
type: 'circle',
radius: 4,
},
},
},
vulnerable: {},
},
});
entity.addTrait('controllable');
entity.addTrait('informed');
// Embed socket.
entity.socket = socket;
return entity;
}