From a0d23354802ebc6b437698acb4b18d3395d47cd1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 16 Mar 2012 12:26:30 -0700 Subject: Conversion to JSON based file IO for canvas2D and WebGL rendering --- js/lib/rdge/materials/pulse-material.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'js/lib/rdge/materials/pulse-material.js') diff --git a/js/lib/rdge/materials/pulse-material.js b/js/lib/rdge/materials/pulse-material.js index 81db36c6..1e2cd2a9 100644 --- a/js/lib/rdge/materials/pulse-material.js +++ b/js/lib/rdge/materials/pulse-material.js @@ -174,6 +174,38 @@ var PulseMaterial = function PulseMaterial() { } }; + // JSON export + this.exportJSON = function() + { + var world = this.getWorld(); + if (!world) + throw new Error( "no world in material.export, " + this.getName() ); + + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + 'texture' : this._propValues[this._propNames[0]] + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try { + this._propValues[this._propNames[0]] = jObj.texture; + } + catch (e) + { + throw new Error( "could not import material: " + jObj ); + } + } + + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; -- cgit v1.2.3