diff options
author | hwc487 | 2012-03-16 12:26:30 -0700 |
---|---|---|
committer | hwc487 | 2012-03-16 12:26:30 -0700 |
commit | a0d23354802ebc6b437698acb4b18d3395d47cd1 (patch) | |
tree | a0081c079c9fc557e10a828db9adeed5a91d5a72 /js/lib/rdge/materials/pulse-material.js | |
parent | 57d4a82977a1f0e809511fe894886f88581d9615 (diff) | |
download | ninja-a0d23354802ebc6b437698acb4b18d3395d47cd1.tar.gz |
Conversion to JSON based file IO for canvas2D and WebGL rendering
Diffstat (limited to 'js/lib/rdge/materials/pulse-material.js')
-rw-r--r-- | js/lib/rdge/materials/pulse-material.js | 32 |
1 files changed, 32 insertions, 0 deletions
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() { | |||
174 | } | 174 | } |
175 | }; | 175 | }; |
176 | 176 | ||
177 | // JSON export | ||
178 | this.exportJSON = function() | ||
179 | { | ||
180 | var world = this.getWorld(); | ||
181 | if (!world) | ||
182 | throw new Error( "no world in material.export, " + this.getName() ); | ||
183 | |||
184 | var jObj = | ||
185 | { | ||
186 | 'material' : this.getShaderName(), | ||
187 | 'name' : this.getName(), | ||
188 | 'texture' : this._propValues[this._propNames[0]] | ||
189 | }; | ||
190 | |||
191 | return jObj; | ||
192 | }; | ||
193 | |||
194 | this.importJSON = function( jObj ) | ||
195 | { | ||
196 | if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); | ||
197 | this.setName( jObj.name ); | ||
198 | |||
199 | try { | ||
200 | this._propValues[this._propNames[0]] = jObj.texture; | ||
201 | } | ||
202 | catch (e) | ||
203 | { | ||
204 | throw new Error( "could not import material: " + jObj ); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | |||
177 | this.export = function() { | 209 | this.export = function() { |
178 | // every material needs the base type and instance name | 210 | // every material needs the base type and instance name |
179 | var exportStr = "material: " + this.getShaderName() + "\n"; | 211 | var exportStr = "material: " + this.getShaderName() + "\n"; |