silphius/app/ecs/components/interlocutor.js
2024-07-20 05:07:39 -05:00

29 lines
724 B
JavaScript

import Component from '@/ecs/component.js';
export default class Interlocutor extends Component {
mergeDiff(original, update) {
const merged = {};
if (update.dialogue) {
merged.dialogue = {
...original.dialogue,
...update.dialogue,
}
}
return merged;
}
instanceFromSchema() {
const Component = this;
return class InterlocutorInstance extends super.instanceFromSchema() {
dialogues = {};
id = 0;
destroy() {
for (const key in this.dialogues) {
this.dialogues[key].onClose();
}
}
dialogue(specification) {
Component.markChange(this.entity, 'dialogue', {[this.id++]: specification});
}
};
}
}