Torque3D/Templates/BaseGame/game/tools/assetBrowser/scripts/utils.tscript
Areloch ae8eca48e1 Implementation of Subscenes, SceneGroups and Gamemodes
Standardizes Gamemodes to be an actual class with data and utility functions that can be parsed
Adds inspector field handling for selecting gamemodes
Updated Scene class to work with Gamemodes for the gamemode field
Updates editor suite elements to be able to create SubScenes, SceneGroups and Gamemodes
Adds ability to convert SimGroup to SubScene
Updates BaseUI's chooselevel menu to have gamemode selection and filters shown levels based on selected gamemode
2024-09-01 16:39:00 -05:00

253 lines
6.2 KiB
Plaintext

function testRpl()
{
ToolUtilityScripts::appendLineToFunction("data/prototyping/prototyping.tscript", "Prototyping", "onDestroyGameServer", "//AAAAAAAAAAAAAAAAAAAAA");
}
function Tools::appendLineToFunction(%file, %nameSpace, %functionName, %appendLine)
{
%fileOutput = new ArrayObject(){};
%fileObj = new FileObject(){};
%insideFunction = false;
%scopeDepth = 0;
if ( %fileObj.openForRead( %file ) )
{
while ( !%fileObj.isEOF() )
{
%line = %fileObj.readLine();
if(strIsMatchExpr("*function *(*)*", %line))
{
%fileOutput.add(%line);
%start = strpos(%line, "function ");
%end = strpos(%line, "(", %start);
%scannedFunctionName = "";
if(%start != -1 && %end != -1)
{
%scannedFunctionName = getSubStr(%line, %start + 9, %end-%start-9);
}
%matchesFunctionSig = false;
if(%nameSpace !$= "")
{
if(%scannedFunctionName $= (%nameSpace @ "::" @ %functionName))
%matchesFunctionSig = true;
}
else
{
if(%scannedFunctionName $= %functionName)
%matchesFunctionSig = true;
}
if(!%matchesFunctionSig)
continue;
%insideFunction = true;
if(strIsMatchExpr("*{*", %line))
{
%scopeDepth++;
}
if(strIsMatchExpr("*}*", %line))
{
%scopeDepth--;
}
}
else
{
if(%insideFunction && strIsMatchExpr("*{*", %line))
{
%scopeDepth++;
}
if(%insideFunction && strIsMatchExpr("*}*", %line))
{
%scopeDepth--;
if(%scopeDepth == 0) //we've fully backed out of the function scope, so resolve back to the parent
{
%insideFunction = false;
%fileOutput.add(%appendLine);
}
}
%fileOutput.add(%line);
}
}
%fileObj.close();
}
if ( %fileObj.openForWrite( %file ) )
{
for(%i=0; %i < %fileOutput.count(); %i++)
{
%line = %fileOutput.getKey(%i);
%fileObj.writeLine(%line);
}
%fileObj.close();
}
}
function Tools::findInFile(%file, %findText, %startingLineId)
{
if(%startingLineId $= "")
%startingLineId = 0;
%fileObj = new FileObject(){};
if ( %fileObj.openForRead( %file ) )
{
%lineId = 0;
while ( !%fileObj.isEOF() )
{
if(%lineId >= %startingLineId)
{
%line = %fileObj.readLine();
if(strIsMatchExpr(%findText, %line))
{
return %lineId;
}
}
%lineId++;
}
%fileObj.close();
}
return -1;
}
function Tools::findInFunction(%file, %nameSpace, %functionName, %findText)
{
%fileObj = new FileObject(){};
%insideFunction = false;
%scopeDepth = 0;
if ( %fileObj.openForRead( %file ) )
{
%lineId = -1;
while ( !%fileObj.isEOF() )
{
%line = %fileObj.readLine();
%lineId++;
if(strIsMatchExpr("*function *(*)*", %line))
{
%start = strpos(%line, "function ");
%end = strpos(%line, "(", %start);
%scannedFunctionName = "";
if(%start != -1 && %end != -1)
{
%scannedFunctionName = getSubStr(%line, %start + 9, %end-%start-9);
}
%matchesFunctionSig = false;
if(%nameSpace !$= "")
{
if(%scannedFunctionName $= (%nameSpace @ "::" @ %functionName))
%matchesFunctionSig = true;
}
else
{
if(%scannedFunctionName $= %functionName)
%matchesFunctionSig = true;
}
if(!%matchesFunctionSig)
continue;
%insideFunction = true;
if(strIsMatchExpr("*{*", %line))
{
%scopeDepth++;
}
if(strIsMatchExpr("*}*", %line))
{
%scopeDepth--;
}
}
else
{
if(%insideFunction && strIsMatchExpr("*{*", %line))
{
%scopeDepth++;
}
if(%insideFunction && strIsMatchExpr("*}*", %line))
{
%scopeDepth--;
if(%scopeDepth == 0) //we've fully backed out of the function scope, so resolve back to the parent
{
%insideFunction = false;
break;
}
}
if(%insideFunction && strIsMatchExpr(%findText, %line))
{
break;
}
}
}
%fileObj.close();
}
return %lineId;
}
function Tools::insertInFile(%file, %insertLineId, %insertText, %insertBefore)
{
%fileOutput = new ArrayObject(){};
%fileObj = new FileObject(){};
if ( %fileObj.openForRead( %file ) )
{
%lineId = 0;
while ( !%fileObj.isEOF() )
{
%line = %fileObj.readLine();
if(%insertLineId == %lineId)
{
if(!%insertBefore || %insertBefore $= "")
{
%fileOutput.add(%line);
%fileOutput.add(%insertText);
}
else
{
%fileOutput.add(%insertText);
%fileOutput.add(%line);
}
}
else
{
%fileOutput.add(%line);
}
%lineId++;
}
%fileObj.close();
}
if ( %fileObj.openForWrite( %file ) )
{
for(%i=0; %i < %fileOutput.count(); %i++)
{
%line = %fileOutput.getKey(%i);
%fileObj.writeLine(%line);
}
%fileObj.close();
}
}