Created
February 14, 2013 08:49
-
-
Save qoh/4951399 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function save_json_bricks( %path, %set, %data, %offset ) | |
{ | |
if ( !strLen( %offset ) ) | |
{ | |
%offset = "0 0 0"; | |
} | |
if ( !strLen( %data ) ) | |
{ | |
%data = js_object(); | |
} | |
else | |
{ | |
%type = js_type( %data ); | |
if ( %type !$= "object" ) | |
{ | |
if ( %type $= "array" ) | |
{ | |
%data.killTree(); | |
} | |
%data = js_object(); | |
} | |
} | |
for ( %max_color = 64 ; %max_color ; %max_color-- ) | |
{ | |
if ( getColorIDTable( %max_color - 1 ) !$= "1.000000 0.000000 1.000000 0.000000" ) | |
{ | |
break; | |
} | |
} | |
if ( %max_color ) | |
{ | |
%colors = %data.set( "colors", js_array() ); | |
for ( %i = 0 ; %i < %max_color ; %i++ ) | |
{ | |
%colors.append( getColorIDTable( %i ) ); | |
} | |
} | |
%count = %set.getCount(); | |
if ( %count ) | |
{ | |
%bricks = %data.set( "bricks", js_array() ); | |
for ( %i = 0 ; %i < %count ; %i++ ) | |
{ | |
%obj = %set.getObject( %i ); | |
%dat = js_object(); | |
%dat.set( "position", vectorSub( %obj.position, %offset ) ); | |
%dat.set( "datablock", %obj.getDataBlock().uiName ); | |
if ( strLen( %name = %obj.getName() ) >= 2 ) | |
{ | |
%dat.set( "name", getSubStr( %name, 1, strLen( %name ) ) ); | |
} | |
// @TODO: save items | |
if ( isObject( %obj.light ) ) | |
{ | |
%dat.set( "light", %obj.light.getDataBlock().uiName ); | |
} | |
if ( isObject( %obj.emitter ) ) | |
{ | |
%dat.set( "emitter", %obj.emitter.emitter.uiName ); | |
// @TODO: emitter directions | |
} | |
if ( %obj.printId != 0 ) | |
{ | |
%data.set( "print", printIdToName( %obj.printId ) ); | |
} | |
if ( %obj.angleId != 0 ) | |
{ | |
%dat.set( "rotation", %obj.angleId ); | |
} | |
if ( %obj.colorId != 0 ) | |
{ | |
%dat.set( "color", %obj.colorId ); | |
} | |
if ( %obj.colorFxId != 0 ) | |
{ | |
%dat.set( "color_fx", %obj.colorFxId ); | |
} | |
if ( %obj.shapeFxId != 0 ) | |
{ | |
%dat.set( "shape_fx", %obj.shapeFxId ); | |
} | |
if ( !%obj.isRendering() ) | |
{ | |
%dat.set( "rendering", false ); | |
} | |
if ( !%obj.isColliding() ) | |
{ | |
%dat.set( "colliding", false ); | |
} | |
if ( !%obj.isRayCasting() ) | |
{ | |
%dat.set( "raycasting", false ); | |
} | |
if ( %dat.numEvents ) | |
{ | |
%events = %dat.set( "events", js_array() ); | |
for ( %j = 0 ; %j < %dat.numEvents ; %j++ ) | |
{ | |
// @TODO: save events | |
} | |
} | |
%bricks.append( %dat ); | |
} | |
} | |
json_dump( %data, %path ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment