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/radial-gradient-material.js | 54 ++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'js/lib/rdge/materials/radial-gradient-material.js') diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index d19b44b7..87e20ad4 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js @@ -158,7 +158,8 @@ var RadialGradientMaterial = function RadialGradientMaterial() { this._propValues[ this._propNames[6] ] = this._colorStop3; this._propValues[ this._propNames[7] ] = this._colorStop4; - this.setProperty = function( prop, value ) { + this.setProperty = function( prop, value ) + { if (prop === "color") prop = "color1"; // make sure we have legitimate imput @@ -236,6 +237,57 @@ var RadialGradientMaterial = function RadialGradientMaterial() { } }; + this.exportJSON = function() + { + var jObj = + { + 'material' : this.getShaderName(), + 'name' : this.getName(), + + 'color1' : this.getColor1(), + 'color2' : this.getColor2(), + 'color3' : this.getColor3(), + 'color4' : this.getColor4(), + 'colorStop1' : this.getColorStop1(), + 'colorStop2' : this.getColorStop2(), + 'colorStop3' : this.getColorStop3(), + 'colorStop4' : this.getColorStop4() + }; + + return jObj; + }; + + this.importJSON = function( jObj ) + { + if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); + this.setName( jObj.name ); + + try + { + var color1 = jObj.color1, + color2 = jObj.color2, + color3 = jObj.color3, + color4 = jObj.color4, + colorStop1 = jObj.colorStop1, + colorStop2 = jObj.colorStop2, + colorStop3 = jObj.colorStop3, + colorStop4 = jObj.colorStop4; + + this.setProperty( "color1", color1 ); + this.setProperty( "color2", color2 ); + this.setProperty( "color3", color3 ); + this.setProperty( "color4", color4 ); + this.setProperty( "colorStop1", colorStop1 ); + this.setProperty( "colorStop2", colorStop2 ); + this.setProperty( "colorStop3", colorStop3 ); + this.setProperty( "colorStop4", colorStop4 ); + } + catch (e) + { + throw new Error( "could not import material: " + importStr ); + } + }; + this.export = function() { // every material needs the base type and instance name var exportStr = "material: " + this.getShaderName() + "\n"; -- cgit v1.2.3