commit:27c3c52ba3014674a85507fb131534fb0235c1c0
author:Chip Black
committer:Chip Black
date:Thu Oct 18 00:29:50 2018 -0500
parents:8894f3d8b1c951fac63dc176f3ba000b338dd534
Integrate script engine with events
diff --git a/src/event.ts b/src/event.ts
line changes: +6/-3
index ca1ed27..a25bfdd
--- a/src/event.ts
+++ b/src/event.ts
@@ -1,4 +1,5 @@
 import { ID, generateID } from './id';
+import { Script } from './script';
 import gs from './gamestate';
 
 export enum GameEventType {
@@ -24,9 +25,11 @@ export class GameEvent {
         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() {

diff --git a/src/gamestate.ts b/src/gamestate.ts
line changes: +10/-1
index a9e75c0..089ab35
--- a/src/gamestate.ts
+++ b/src/gamestate.ts
@@ -68,12 +68,16 @@ class GameState {
         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) {
@@ -87,6 +91,11 @@ class GameState {
             this.actions.addAction('Edit Cell', () => this.map.editDescription());
         }
     }
+
+    enterCell() {
+        this.printCellText();
+        this.showCellActions();
+    }
 }
 
 // Create a default GameState object and export it