commit:38fed509930b839d2cd63c7d64a958ba4a07c13f
author:Chip Black
committer:Chip Black
date:Sat Oct 27 20:30:07 2018 -0500
parents:dad934f94cba76d349e3f71f4be45d7cf13666a4
Move events back into cell
diff --git a/src/cell.ts b/src/cell.ts
line changes: +7/-8
index b12abed..ec906ab
--- a/src/cell.ts
+++ b/src/cell.ts
@@ -24,7 +24,7 @@ export interface CellProperties {
     id: ID
     title: string
     description: string
-    events: ID[]
+    events: GameEventProperties[]
     objects: ID[]
     // agents are not saved
 }
@@ -78,7 +78,7 @@ export class Cell extends Storable {
     store() {
         return Object.assign(<CellProperties>super.store(), {
             objects: Array.from(this.objects).map( ([id, obj]) => id),
-            events: Array.from(this.events).map( ([id, e]) => id),
+            events: Array.from(this.events).map( ([id, e]) => e.store()),
         });
     }
 
@@ -88,7 +88,7 @@ export class Cell extends Storable {
         this.title = properties.title;
         this.description = properties.description;
 
-        // At this point the objects and events should already be loaded in gamestate
+        // At this point the objects should already be loaded in gamestate
         this.objects = new Map();
         for (let id of properties.objects) {
             if (!gs.objects.has(id)) {
@@ -98,11 +98,10 @@ export class Cell extends Storable {
         }
 
         this.events = new Map();
-        for (let id of properties.events) {
-            if (!gs.events.has(id)) {
-                throw new Error('Event not found in gamestate:' + id);
-            }
-            this.events.set(id, gs.events.get(id));
+        for (let event of properties.events) {
+            const ge = new GameEvent();
+            ge.load(event);
+            this.events.set(event.id, ge);
         }
 
         // We assume that since this cell was saved, it is navigable

diff --git a/src/event.ts b/src/event.ts
line changes: +10/-2
index a25bfdd..6ba1257
--- a/src/event.ts
+++ b/src/event.ts
@@ -1,3 +1,4 @@
+import Storable from './storable';
 import { ID, generateID } from './id';
 import { Script } from './script';
 import gs from './gamestate';
@@ -10,15 +11,21 @@ export enum GameEventType {
 }
 
 export interface GameEventProperties {
+    id: ID
+    type: GameEventType
+    script: string
+    title: string
 }
 
-export class GameEvent {
+export class GameEvent extends Storable {
     id: ID
     type: GameEventType
     script: string
     title: string
+    saveProperties = ['id', 'type', 'script', 'title']
 
     constructor() {
+        super();
         this.id = generateID();
         this.type = GameEventType.Random;
         this.script = '';
@@ -37,9 +44,10 @@ export class GameEvent {
     }
 
     store() : GameEventProperties {
-        return {};
+        return <GameEventProperties>super.store()
     }
 
     load(properties: GameEventProperties) {
+        return super.load(properties);
     }
 }