Store globals as an array
*/
-interface ObjectBag {
- [id: string]: GameObjectProperties
-}
-
interface Globals {
- objects: ObjectBag
+ objects: GameObjectProperties[]
}
class GameState {
}
storeGlobals(): Globals {
- const objects: ObjectBag = {}
+ const objects: GameObjectProperties[] = [];
for (let [k, o] of this.objects) {
- console.log('storeGlobals', k, o);
- objects[k] = o.store();
+ objects.push(o.store());
}
return { objects };
loadGlobals(globals: Globals) {
if (globals.objects) {
- for (let k of Object.keys(globals.objects)) {
+ for (let o of globals.objects) {
const obj = new GameObject();
- obj.load(globals.objects[k]);
+ obj.load(o);
this.addObject(obj);
}
}
localStorage['map'] = JSON.stringify(gs.map.store());
console.log(localStorage['map']);
localStorage['globals'] = JSON.stringify(gs.storeGlobals());
- console.log(localStorage['objects']);
+ console.log(localStorage['globals']);
break;
case 'KeyL':
gs.map.load(JSON.parse(localStorage['map']));