diff --git a/app/default-objects/DefaultDungeons.ts b/app/default-objects/DefaultDungeons.ts index b2a4135..3915d28 100644 --- a/app/default-objects/DefaultDungeons.ts +++ b/app/default-objects/DefaultDungeons.ts @@ -7,6 +7,7 @@ export class DefaultDungeons { } static fromJSON(str: string) :DefaultDungeons { const obj = JSON.parse(str); + //console.log(obj); const retval = new DefaultDungeons(); retval.version = obj.version; retval.data = DefaultDungeonsData.fromObject(obj.data); @@ -30,8 +31,9 @@ export class DefaultDungeonsData { static fromObject(obj:any):DefaultDungeonsData { const data = new DefaultDungeonsData(); const keys = Object.keys(data); + console.log(obj); for(const key of keys){ - if(obj[key]) { + if(obj[key]!==undefined) { data[key].setFromObject(obj[key]); } } @@ -72,7 +74,7 @@ export class Dungeon { setFromObject(obj:any): void{ const keys = Object.keys(this); for(const key of keys) { - if(obj[key]) { + if(obj[key]!==undefined) { this[key] = obj[key]; } } diff --git a/app/default-objects/DefaultGameSaves.ts b/app/default-objects/DefaultGameSaves.ts index 368d255..bbee947 100644 --- a/app/default-objects/DefaultGameSaves.ts +++ b/app/default-objects/DefaultGameSaves.ts @@ -32,7 +32,7 @@ export class DefaultGameSavesData { const data = new DefaultGameSavesData(); const keys = Object.keys(data); for(const key of keys){ - if(obj[key]) { + if(obj[key]!==undefined) { data[key] = Game.fromObject(obj[key]); } } diff --git a/app/default-objects/DefaultItems.ts b/app/default-objects/DefaultItems.ts index 358e442..340d04b 100644 --- a/app/default-objects/DefaultItems.ts +++ b/app/default-objects/DefaultItems.ts @@ -50,7 +50,7 @@ export class DefaultItemsData { const data = new DefaultItemsData(); const keys = Object.keys(data); for(const key of keys){ - if(obj[key]) { + if(obj[key]!==undefined) { data[key] = obj[key]; } } diff --git a/app/default-objects/DefaultMap.ts b/app/default-objects/DefaultMap.ts index 70763bc..2f1dfd6 100644 --- a/app/default-objects/DefaultMap.ts +++ b/app/default-objects/DefaultMap.ts @@ -19,11 +19,11 @@ export abstract class DefaultMapData implements IDefaultMapData{ if(data[world][mapkey] !== null && typeof data[world][mapkey] ==='object' ) { const keys = Object.keys(data[world][mapkey]); for (const key of keys) { - if (obj[world] && obj[world][mapkey] && obj[world][mapkey][key]) { + if (obj[world] && obj[world][mapkey] && obj[world][mapkey][key]!==undefined) { data[world][mapkey][key] = obj[world][mapkey][key]; } } - } else if(obj[world] && obj[world][mapkey]) { + } else if(obj[world] && obj[world][mapkey]!==undefined) { data[world][mapkey] = obj[world][mapkey]; } return data; diff --git a/app/default-objects/DefaultSettings.ts b/app/default-objects/DefaultSettings.ts index 6beb7c2..5a05513 100644 --- a/app/default-objects/DefaultSettings.ts +++ b/app/default-objects/DefaultSettings.ts @@ -28,7 +28,7 @@ export class DefaultSettingsData { const data = new DefaultSettingsData(); const keys = Object.keys(data); for(const key of keys){ - if(obj[key]) { + if(obj[key]!==undefined) { data[key] = obj[key]; } } diff --git a/app/tests/default-objects/DefaultDungeons.spec.js b/app/tests/default-objects/DefaultDungeons.spec.js index de024d0..be16cb3 100644 --- a/app/tests/default-objects/DefaultDungeons.spec.js +++ b/app/tests/default-objects/DefaultDungeons.spec.js @@ -14,12 +14,13 @@ describe('DefaultDungeons', () => { expect(dungeons.data.ep.boss).toEqual(true); }); it('should load items from JSON even if json is incomplete', () => { - const json = {'version':'0.0.1', 'data':{'dp':{'boss':true, 'crystal':0, 'chests':4, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'toh':{'boss':false, 'crystal':0, 'chests':4, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'aga':{'boss':false, 'crystal':0, 'chests':0, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'pod':{'boss':false, 'crystal':0, 'chests':7, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'sp':{'boss':false, 'crystal':0, 'chests':8, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'sw':{'boss':false, 'crystal':0, 'chests':4, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'tt':{'boss':false, 'crystal':0, 'chests':6, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'ip':{'boss':false, 'crystal':0, 'chests':5, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'mm':{'boss':false, 'crystal':0, 'chests':4, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'tr':{'boss':false, 'crystal':0, 'chests':7, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'gt':{'boss':false, 'crystal':0, 'chests':22, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}}}; + const json = {'version':'0.0.1', 'data':{'dp':{'boss':true, 'crystal':0, 'chests':0, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'toh':{'boss':false, 'crystal':0, 'chests':4, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'aga':{'boss':false, 'crystal':0, 'chests':0, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'pod':{'boss':false, 'crystal':0, 'chests':7, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'sp':{'boss':false, 'crystal':0, 'chests':8, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'sw':{'boss':false, 'crystal':0, 'chests':4, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'tt':{'boss':false, 'crystal':0, 'chests':6, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'ip':{'boss':false, 'crystal':0, 'chests':5, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'mm':{'boss':false, 'crystal':0, 'chests':4, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'tr':{'boss':false, 'crystal':0, 'chests':7, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}, 'gt':{'boss':false, 'crystal':0, 'chests':22, 'map':false, 'compass':false, 'bosskey':false, 'smallkeys':0, 'medallion':0}}}; const dungeons = DefaultDungeons.fromJSON(JSON.stringify(json)); expect(dungeons.data.ep).toBeDefined(); expect(dungeons.data.ep.boss).toEqual(false); expect(dungeons.data.dp.boss).toEqual(true); + expect(dungeons.data.dp.chests).toEqual(0); }); it('should make a copy', () => { const dungeons1 = new DefaultDungeonsData();