refactor: trait actions -> methods
This commit is contained in:
parent
d257ea4161
commit
8f7e8bb5f0
|
@ -28,10 +28,6 @@ export class Trait {
|
|||
this.state = this.state.merge(undefinedProperties);
|
||||
}
|
||||
|
||||
actions() {
|
||||
return {};
|
||||
}
|
||||
|
||||
destroy() {}
|
||||
|
||||
hooks() {
|
||||
|
@ -52,6 +48,10 @@ export class Trait {
|
|||
return {};
|
||||
}
|
||||
|
||||
methods() {
|
||||
return {};
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
params: this.params.toJS(),
|
||||
|
|
|
@ -27,7 +27,7 @@ function enumerateProperties(prototype) {
|
|||
export class Traits {
|
||||
|
||||
constructor(entity) {
|
||||
this.actions_PRIVATE = {};
|
||||
this.methods_PRIVATE = {};
|
||||
this.entity_PRIVATE = entity;
|
||||
this.hooks_PRIVATE = {};
|
||||
this.properties_PRIVATE = {};
|
||||
|
@ -104,10 +104,10 @@ export class Traits {
|
|||
listeners[eventName]
|
||||
);
|
||||
}
|
||||
// Proxy actions.
|
||||
const actions = instance.actions();
|
||||
for (const key in actions) {
|
||||
this.actions_PRIVATE[key] = actions[key];
|
||||
// Proxy methods.
|
||||
const methods = instance.methods();
|
||||
for (const key in methods) {
|
||||
this.methods_PRIVATE[key] = methods[key];
|
||||
}
|
||||
// Register hook listeners.
|
||||
const hooks = instance.hooks();
|
||||
|
@ -138,8 +138,8 @@ export class Traits {
|
|||
}
|
||||
|
||||
getProperty(property) {
|
||||
if (property in this.actions_PRIVATE) {
|
||||
return this.actions_PRIVATE[property];
|
||||
if (property in this.methods_PRIVATE) {
|
||||
return this.methods_PRIVATE[property];
|
||||
}
|
||||
if (property in this.properties_PRIVATE) {
|
||||
const instance = this.properties_PRIVATE[property].instance;
|
||||
|
@ -154,7 +154,7 @@ export class Traits {
|
|||
}
|
||||
|
||||
hasProperty(property) {
|
||||
if (property in this.actions_PRIVATE) {
|
||||
if (property in this.methods_PRIVATE) {
|
||||
return true;
|
||||
}
|
||||
if (property in this.properties_PRIVATE) {
|
||||
|
@ -213,9 +213,9 @@ export class Traits {
|
|||
|
||||
const instance = this.traits_PRIVATE[type];
|
||||
|
||||
const actions = instance.actions();
|
||||
for (const key in actions) {
|
||||
delete this.actions_PRIVATE[key];
|
||||
const methods = instance.methods();
|
||||
for (const key in methods) {
|
||||
delete this.methods_PRIVATE[key];
|
||||
}
|
||||
|
||||
const hooks = instance.hooks();
|
||||
|
|
|
@ -32,7 +32,7 @@ class ExistentBase extends Trait {
|
|||
this._isTicking = isTicking;
|
||||
}
|
||||
|
||||
actions() {
|
||||
methods() {
|
||||
return {
|
||||
|
||||
destroy: () => {
|
||||
|
|
|
@ -21,8 +21,9 @@ class MobileBase extends Trait {
|
|||
this.requestedMovement = [0, 0];
|
||||
}
|
||||
|
||||
actions() {
|
||||
methods() {
|
||||
return {
|
||||
|
||||
requestMovement: (vector) => {
|
||||
if (!this.isMobile) {
|
||||
return;
|
||||
|
@ -33,6 +34,7 @@ class MobileBase extends Trait {
|
|||
);
|
||||
this.entity.emit('movementRequest', this.requestedMovement);
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user