Integrate script engine with events
import { ID, generateID } from './id';
+import { Script } from './script';
import gs from './gamestate';
export enum GameEventType {
this.title = '';
}
- execute() {
- const f = new Function('gs', this.script)
- f(gs);
+ async execute() {
+ const script = new Script(this.script);
+ gs.actions.clear();
+ await script.execute();
+ gs.showCellActions();
}
getCallback() {
this.enterCell();
}
- enterCell() {
+ printCellText() {
const cell = this.map.getCurrentCell();
gs.textView.clear();
gs.textView.print("You have entered the", cell.title);
gs.textView.print();
gs.textView.print(cell.description);
+ }
+
+ showCellActions() {
+ const cell = this.map.getCurrentCell();
this.actions.clear();
for (let [k, e] of cell.events) {
this.actions.addAction('Edit Cell', () => this.map.editDescription());
}
}
+
+ enterCell() {
+ this.printCellText();
+ this.showCellActions();
+ }
}
// Create a default GameState object and export it