perf: inline entity from JSON

This commit is contained in:
cha0s 2019-05-04 11:39:43 -05:00
parent 86ae9ab3b1
commit 911843561c

View File

@ -1,10 +1,10 @@
import {Entity} from '@avocado/entity';
// Create an entity for a new connection.
export function createEntityForConnection(socket) {
let entity = new Entity();
// let entity = new Entity();
const x = Math.floor(Math.random() * 284) + 50;
const y = Math.floor(Math.random() * 284) + 50;
entity = entity.fromJSON({
const entity = new Entity({
traits: {
alive: {
state: {
@ -27,6 +27,7 @@ export function createEntityForConnection(socket) {
},
},
collider: {},
controllable: {},
directional: {
params: {
directionCount: 4,
@ -35,7 +36,7 @@ export function createEntityForConnection(socket) {
emitter: {},
existent: {},
followed: {},
visible: {},
informed: {},
mobile: {
state: {
speed: 100,
@ -56,11 +57,10 @@ export function createEntityForConnection(socket) {
},
},
},
visible: {},
vulnerable: {},
},
});
entity.addTrait('controllable');
entity.addTrait('informed');
// Embed socket.
entity.socket = socket;
return entity;