@@ -111,14 +111,33 @@ class CTRLBanksStore{ | |||
return Object.keys(Banks).length; | |||
} | |||
get json(){ | |||
get obj(){ | |||
var data = []; | |||
Object.keys(Banks).forEach((key) => { | |||
if (Banks.hasOwnProperty(key)){ | |||
data.push({name:key, data:Banks[key].bank.base64}); | |||
} | |||
}); | |||
return JSON.stringify(data); | |||
return data; | |||
} | |||
set obj(d){ | |||
if (!(d instanceof Array)) | |||
throw new TypeError("Expected Array object."); | |||
this.clear(); | |||
d.forEach((item) => { | |||
if (typeof(item) === typeof({})){ | |||
if ((name in item) && (data in item)){ | |||
this.createBank(item.name, item.data); | |||
} else { | |||
console.log("WARNING: Bank object missing required properties. Skipped."); | |||
} | |||
} | |||
}); | |||
} | |||
get json(){ | |||
return JSON.stringify(this.obj); | |||
} | |||
initialize(){ |
@@ -153,24 +153,19 @@ class CTRLPalettesStore{ | |||
}).bind(this)); | |||
} | |||
get json(){ | |||
get obj(){ | |||
var d = { | |||
cpi: CurrentPaletteIndex, | |||
pals: [] | |||
}; | |||
for (let i=0; i < Palettes.length; i++){ | |||
d.pals.push([Palettes[i][0], Palettes[i][1].json]); | |||
d.pals.push([Palettes[i][0].value, Palettes[i][1].json]); | |||
} | |||
return JSON.stringify(d); | |||
return d; | |||
} | |||
set json(j){ | |||
try { | |||
var d = JSON.parse(j); | |||
} catch (e) { | |||
throw e; | |||
} | |||
set obj(d){ | |||
if (d.hasOwnProperty("cpi") && d.hasOwnProperty("pals")){ | |||
if (Utils.isInt(d.cpi) && d.pals instanceof Array){ | |||
var newPalettes = [] | |||
@@ -189,10 +184,22 @@ class CTRLPalettesStore{ | |||
GlobalEvents.emit("set_app_palette", Palettes[CurrentPaletteIndex][1]); | |||
} | |||
} else { | |||
throw new TypeError("JSON Property Value types invalid."); | |||
throw new TypeError("Object Property Value types invalid."); | |||
} | |||
} else { | |||
throw new TypeError("JSON missing expected properties."); | |||
throw new TypeError("Object missing expected properties."); | |||
} | |||
} | |||
get json(){ | |||
return JSON.stringify(this.obj); | |||
} | |||
set json(j){ | |||
try { | |||
this.obj = JSON.parse(j); | |||
} catch (e) { | |||
throw e; | |||
} | |||
} | |||
@@ -22,21 +22,27 @@ export default class NESPalette extends EventCaller{ | |||
]; | |||
} | |||
get json(){ | |||
return JSON.stringify(([this.__BGColor]).concat(this.__palette)); | |||
get obj(){ | |||
return ([this.__BGColor]).concat(this.__palette); | |||
} | |||
set json(j){ | |||
try{ | |||
var d = JSON.parse(j); | |||
set obj(d){ | |||
if (!(d instanceof Array) || d.length !== 25) | |||
throw new TypeError("Invalid Object or value range."); | |||
try { | |||
this.set_palette(d); | |||
} catch (e) { | |||
throw e; | |||
} | |||
} | |||
if (!(d instanceof Array) || d.length !== 25) | |||
throw new TypeError("Invalid JSON or value range."); | |||
try { | |||
this.set_palette(d); | |||
get json(){ | |||
return JSON.stringify(this.obj); | |||
} | |||
set json(j){ | |||
try{ | |||
this.obj = JSON.parse(j); | |||
} catch (e) { | |||
throw e; | |||
} |