Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created November 19, 2015 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesu/afdd8825e7c79ba8cb05 to your computer and use it in GitHub Desktop.
Save jamesu/afdd8825e7c79ba8cb05 to your computer and use it in GitHub Desktop.
Tool to compile torque shapes
function onStart()
{
}
function onExit()
{
}
function parseArgs()
{
for (%i = 2; %i < $Game::argc; %i++)
{
// Grab the argument.
%arg = $Game::argv[%i];
// Grab the next argument for those args that require parameters.
%nextArg = $Game::argv[%i + 1];
// Check if there is another argument.
%hasNextArg = $Game::argc - %i > 1;
// Handle the argument.
switch$ (%arg)
{
case "-o":
$outFile = %nextArg;
$argUsed[%i++]++;
// Display the command line help.
case "-help":
$displayHelp = true;
$argUsed[%i]++;
default:
$inFile = ($inFile $= "") ? %arg : $inFile;
$argUsed[%i]++;
}
}
}
package Help
{
function onExit()
{
// When the help is being displayed, the game never started up, so with this we make sure
// no superfluous shutdown and cleanup takes place.
}
};
function displayHelp()
{
// Activate the Help Package.
activatePackage(Help);
error(
"TGB command line options:\n"@
" -log <logmode> Logging behavior; see main.cs comments for details\n"@
" -game <game_name> Reset list of mods to only contain <game_name>\n"@
" -mod <mod_name> Add <mod_name> to list of mods\n"@
" -console Open a separate console\n"@
" -jSave <file_name> Record a journal\n"@
" -jPlay <file_name> Play back a journal\n"@
" -jDebug <file_name> Play back a journal and issue an int3 at the end\n"@
" -help Display this help message\n"
);
}
function onExit()
{
}
function onGameWarmedUp()
{
}
function updateTSShapeLoadProgress()
{
}
function doQuit(%status)
{
schedule(0, 0, "quit", %status);
}
/*
ConsoleFunction(compileTorqueShape, bool, 3, 3, "in, out")
{
Torque::Path path = argv[1];
Torque::Path destPath = argv[2];
// Execute the shape script if it exists
Torque::Path scriptPath(path);
scriptPath.setExtension("cs");
// Don't execute the script if we're already doing so!
StringTableEntry currentScript = Platform::stripBasePath(CodeBlock::getCurrentCodeBlockFullPath());
if (!scriptPath.getFullPath().equal(currentScript))
{
Torque::Path scriptPathDSO(scriptPath);
scriptPathDSO.setExtension("cs.dso");
if (Torque::FS::IsFile(scriptPathDSO) || Torque::FS::IsFile(scriptPath))
{
String evalCmd = "exec(\"" + scriptPath + "\");";
String instantGroup = Con::getVariable("InstantGroup");
Con::setIntVariable("InstantGroup", RootGroupId);
Con::evaluate((const char*)evalCmd.c_str(), false, scriptPath.getFullPath());
Con::setVariable("InstantGroup", instantGroup.c_str());
}
}
// Attempt to load the shape
TSShape * ret = 0;
bool readSuccess = false;
const String extension = path.getExtension();
if ( extension.equal( "dae", String::NoCase ) || extension.equal( "kmz", String::NoCase ) )
{
// Attempt to load the DAE file
ret = loadColladaShapeTOOL(path);
readSuccess = (ret != NULL);
}
else
{
return false;
}
if( !readSuccess )
{
Con::errorf( "compileTorqueShape - Error reading '%s'", path.getFullPath().c_str() );
return false;
}
FileStream outFile;
if (outFile.open(destPath, Torque::FS::File::Write))
{
ret->write(&outFile);
}
else
{
Con::errorf("compileTorqueShape - Couldn't save to shape %s!", argv[2]);
}
delete ret;
return true;
}
*/
function onStart()
{
enableWinConsole(1);
echo("Compiling shape" SPC $inFile SPC "to" SPC $outFile);
if ($inFile $= "" || $outFile $= "")
return doQuit(1);
%ret = compileTorqueShape($inFile, $outFile);
doQuit(%ret ? 0 : 1);
}
parseArgs();
onStart();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment