refactor: raw JS params
This commit is contained in:
parent
c148bc2456
commit
91ffcb890f
|
@ -27,7 +27,7 @@ export class Behaved extends decorate(Trait) {
|
|||
this._context.add('entity', this.entity);
|
||||
this._currentRoutine = undefined;
|
||||
this._isBehaving = true;
|
||||
const routinesJSON = this.params.get('routines').toJS();
|
||||
const routinesJSON = this.params.routines;
|
||||
this._routines = (new Routines()).fromJSON(routinesJSON);
|
||||
this._routines.context = this._context;
|
||||
this.updateCurrentRoutine();
|
||||
|
|
|
@ -207,6 +207,9 @@ export class Entity extends decorate(Resource) {
|
|||
if (!hasTrait(type)) {
|
||||
return;
|
||||
}
|
||||
if ('params' in step.value) {
|
||||
step.value.params = step.value.params.toJS();
|
||||
}
|
||||
this.addTrait(type, step.value);
|
||||
instance = this._traits[type];
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as I from 'immutable';
|
||||
import merge from 'lodash.merge';
|
||||
|
||||
import {compose, Property} from '@avocado/core';
|
||||
import {Vector} from '@avocado/math';
|
||||
|
@ -17,7 +18,7 @@ export class Trait extends decorate(class {}) {
|
|||
const ctor = this.constructor;
|
||||
this.isDirty = true;
|
||||
this._memoizedListeners = undefined;
|
||||
this.params = I.fromJS(ctor.defaultParams()).merge(I.fromJS(params));
|
||||
this.params = Object.assign({}, ctor.defaultParams(), params);
|
||||
this.state = I.fromJS(ctor.defaultState()).merge(I.fromJS(state));
|
||||
this.initializeSynchronizedChildren();
|
||||
}
|
||||
|
@ -69,7 +70,7 @@ export class Trait extends decorate(class {}) {
|
|||
|
||||
toJSON() {
|
||||
return {
|
||||
params: this.params.toJS(),
|
||||
params: this.params,
|
||||
state: this.state.toJS(),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -25,12 +25,12 @@ export class Directional extends decorate(Trait) {
|
|||
}
|
||||
|
||||
initialize() {
|
||||
this.directionCount = this.params.get('directionCount');
|
||||
this.directionCount = this.params.directionCount;
|
||||
}
|
||||
|
||||
listeners() {
|
||||
const listeners = {};
|
||||
if (this.params.get('trackMovement')) {
|
||||
if (this.params.trackMovement) {
|
||||
listeners.movementRequest = (vector) => {
|
||||
this.entity.direction = Vector.toDirection(vector, this.directionCount);
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ class ExistentBase extends Trait {
|
|||
}
|
||||
|
||||
initialize() {
|
||||
this._isTicking = this.params.get('isTicking');
|
||||
this._isTicking = this.params.isTicking;
|
||||
}
|
||||
|
||||
methods() {
|
||||
|
|
|
@ -34,7 +34,7 @@ export class Spawner extends decorate(Trait) {
|
|||
|
||||
initialize() {
|
||||
this.children = [];
|
||||
this.spawnJSONs = this.params.get('spawns').toJS();
|
||||
this.spawnJSONs = this.params.spawns;
|
||||
}
|
||||
|
||||
listeners() {
|
||||
|
|
|
@ -27,7 +27,7 @@ export class Pictured extends decorate(Trait) {
|
|||
|
||||
initialize() {
|
||||
this._cachedAabbs = {};
|
||||
this._images = this.params.get('images').toJS();
|
||||
this._images = this.params.images;
|
||||
this.sprites = undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ export class Visible extends decorate(Trait) {
|
|||
initialize() {
|
||||
if (hasGraphics) {
|
||||
this._container = new Container();
|
||||
const filter = this.params.get('filter');
|
||||
const filter = this.params.filter;
|
||||
if (filter) {
|
||||
this._container.setFilter(filter);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ export class Visible extends decorate(Trait) {
|
|||
}
|
||||
this._rawVisibleAabb = [0, 0, 0, 0];
|
||||
this.scheduledBoundingBoxUpdate = true;
|
||||
this.trackPosition = this.params.get('trackPosition');
|
||||
this.trackPosition = this.params.trackPosition;
|
||||
const scale = this.entity.visibleScale;
|
||||
this._visibleScale = [scale.get(0), scale.get(1)];
|
||||
this.onZIndexChanged();
|
||||
|
|
|
@ -24,10 +24,10 @@ export class Collider extends decorate(Trait) {
|
|||
}
|
||||
|
||||
initialize() {
|
||||
this._collisionGroup = this.params.get('collisionGroup');
|
||||
this._collidesWithGroups = this.params.get('collidesWithGroups').toJS();
|
||||
this._collisionGroup = this.params.collisionGroup;
|
||||
this._collidesWithGroups = this.params.collidesWithGroups;
|
||||
this._isCollidingWith = [];
|
||||
this._isSensor = this.params.get('isSensor');
|
||||
this._isSensor = this.params.isSensor;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
|
|
@ -16,7 +16,7 @@ export class Shaped extends decorate(Trait) {
|
|||
}
|
||||
|
||||
initialize() {
|
||||
this._shape = shapeFromJSON(this.params.get('shape').toJS());
|
||||
this._shape = shapeFromJSON(this.params.shape);
|
||||
this.shapeView = undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ export class Audible extends Trait {
|
|||
}
|
||||
|
||||
initialize() {
|
||||
this._sounds = this.params.get('sounds').toJS();
|
||||
this._sounds = this.params.sounds;
|
||||
this.sounds = {};
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class AnimatedBase extends Trait {
|
|||
}
|
||||
|
||||
initialize() {
|
||||
this._animations = this.params.get('animations').toJS();
|
||||
this._animations = this.params.animations;
|
||||
this.animations = {};
|
||||
this.animationViews = undefined;
|
||||
this.animationsPromise = undefined;
|
||||
|
|
|
@ -12,7 +12,7 @@ export class Followed extends Trait {
|
|||
|
||||
initialize() {
|
||||
const camera = new Camera();
|
||||
camera.viewSize = this.params.get('viewSize').toJS();
|
||||
camera.viewSize = this.params.viewSize;
|
||||
this._camera = camera;
|
||||
this.updatePosition();
|
||||
this.onRoomSizeChanged();
|
||||
|
|
Loading…
Reference in New Issue
Block a user