Skip to content

Instantly share code, notes, and snippets.

@qoh
Created February 13, 2013 19:41
Show Gist options
  • Save qoh/4947485 to your computer and use it in GitHub Desktop.
Save qoh/4947485 to your computer and use it in GitHub Desktop.
function simGroup::createBrickFromJSON( %this, %data, %offset, %plant )
{
if ( %data.hasKey( "position" ) )
{
%position = vectorAdd( %data.get( "position" ), %offset );
}
else
{
return -1;
}
if ( %data.hasKey( "datablock" ) )
{
%datablock = $uiNameTable[ %data.get( "datablock" ) ];
if ( !isObject( %datablock ) )
{
return -1;
}
}
else
{
return -1;
}
%angleId = %data.get( "rotation", 0 );
%colorId = %data.get( "color", 0 );
switch ( %angleId )
{
case 0: %rotation = "1 0 0 0";
case 1: %rotation = "0 0 1 90";
case 2: %rotation = "0 0 1 180";
default: %rotation = "0 0 -1 90";
}
%obj = new fxDTSBrick()
{
datablock = %datablock;
position = %position;
rotation = %rotation;
angleId = %angleId;
colorId = %colorId;
orig_position = %position;
orig_angle = %angleId;
};
%this.add( %obj );
%obj.setColorFx( %data.get( "color_fx", 0 ) );
%obj.setShapeFx( %data.get( "shape_fx", 0 ) );
%obj.setRendering( %data.get( "rendering", true ) );
%obj.setColliding( %data.get( "colliding", true ) );
%obj.setRayCasting( %data.get( "raycasting", true ) );
if ( %data.hasKey( "events" ) )
{
%events = %data.get( "events" );
%amount = %events.size();
%obj.numPendingEvents = 0;
for ( %j = 0 ; %j < %amount ; %j++ )
{
%event = %events.get( %j );
if ( !%event.hasKey( "input" ) || !%event.hasKey( "target" ) || !%event.hasKey( "output" ) )
{
continue;
}
%obj.pendingEventEnabled[ %obj.numPendingEvents ] = %event.get( "enabled", true );
%obj.pendingEventDelay[ %obj.numPendingEvents ] = %event.get( "delay", 0 );
%obj.pendingEventInput[ %obj.numPendingEvents ] = %event.get( "input" );
%obj.pendingEventTarget[ %obj.numPendingEvents ] = %event.get( "target" );
%obj.pendingEventOutput[ %obj.numPendingEvents ] = %event.get( "output" );
if ( %event.hasKey( "args" ) )
{
%args = %event.get( "args" );
%size = %args.size();
%obj.pendingEventArgumentCount[ %obj.numPendingEvents ] = %size;
for ( %k = 0 ; %k < %size ; %k++ )
{
%obj.pendingEventArgument[ %obj.numPendingEvents, %k ] = %args.get( %k );
}
}
else
{
%obj.pendingEventArgumentCount[ %obj.numPendingEvents ] = 0;
}
%obj.numPendingEvents++;
}
}
if ( %plant )
{
%obj.jsbPlant();
if ( !isObject( %obj ) )
{
return -1;
}
}
return %obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment