silphius/app/ecs/components/interlocutor.js
2024-09-05 16:52:22 -05:00

29 lines
745 B
JavaScript

import Component from '@/ecs/component.js';
export default class Interlocutor extends Component {
mergeDiff(original, update) {
const merged = {};
if (original.dialogue || 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});
}
};
}
}