avocado-old/packages/topdown/traits/roomed.trait.js
2020-06-23 11:19:59 -05:00

52 lines
872 B
JavaScript

import {Trait} from '@avocado/entity';
export default class Roomed extends Trait {
static behaviorTypes() {
return {
detachFromRoom: {
type: 'void',
label: 'Remove from room.',
},
attachToRoom: {
type: 'void',
label: 'Set into room $1.',
args: [
['room', {
type: 'room',
}],
],
},
};
}
static type() {
return 'roomed';
}
destroy() {
this.entity.detachFromRoom();
}
methods() {
return {
detachFromRoom: () => {
const room = this.entity.room;
if (!room) {
return;
}
this.entity.room = null;
this.entity.emit('removedFromRoom', room);
},
attachToRoom: (room) => {
this.entity.room = room;
this.entity.emit('addedToRoom');
},
};
}
}