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

68 lines
1.4 KiB
JavaScript
Raw Normal View History

import {Entity} from '@avocado/entity';
2019-03-27 15:51:58 -05:00
// Create an entity for a new connection.
export function createEntityForConnection(socket) {
let entity = new Entity();
2019-04-22 14:18:02 -05:00
const x = Math.floor(Math.random() * 284) + 50;
const y = Math.floor(Math.random() * 284) + 50;
2019-03-27 15:51:58 -05:00
entity = entity.fromJSON({
traits: {
2019-04-22 21:03:28 -05:00
alive: {
state: {
2019-04-23 03:42:13 -05:00
life: 100,
maxLife: 100,
2019-04-22 21:03:28 -05:00
},
},
2019-03-27 15:51:58 -05:00
animated: {
params: {
animations: {
idle: {
offset: [0, -12],
uri: '/idle.animation.json',
},
moving: {
offset: [0, -12],
uri: '/moving.animation.json',
},
}
},
},
2019-04-08 15:20:43 -05:00
collider: {},
2019-03-27 15:51:58 -05:00
directional: {
params: {
directionCount: 4,
},
},
2019-04-22 18:20:38 -05:00
emitter: {},
2019-03-27 15:51:58 -05:00
existent: {},
2019-04-05 11:59:14 -05:00
followed: {},
2019-04-14 18:42:23 -05:00
visible: {},
2019-03-27 15:51:58 -05:00
mobile: {
state: {
speed: 100,
},
},
2019-04-08 13:32:52 -05:00
physical: {},
positioned: {
state: {
2019-04-22 14:18:02 -05:00
x: x * 4,
y: y * 4,
2019-04-08 13:32:52 -05:00
},
},
shaped: {
2019-03-27 15:51:58 -05:00
params: {
shape: {
2019-04-13 03:19:41 -05:00
type: 'circle',
radius: 4,
2019-04-08 13:32:52 -05:00
},
2019-03-27 15:51:58 -05:00
},
},
vulnerable: {},
2019-03-27 15:51:58 -05:00
},
});
entity.addTrait('controllable');
entity.addTrait('informed');
// Embed socket.
entity.socket = socket;
return entity;
}