Adds utility function and method to be able to enact a load of subscenes at a specific world position

Adds loadIf conditional logic to evaluate if a subscene is 'allowed' to load when tested
Adds isAlwaysActive to GameMode to be able to flag a gamemode as being defaulted to on and used automatically
Updated GetGameModesList function to return an arrayObject of the gamemodes found
Overhauled CallGameModeFunction to utilize the gamemodes list with active/alwaysActive modes being called against, rather than level-scanning
Updated ChooseLevelMenu to be able to toggle on/off multiple gamemodes with an image indicator if it's active or not
This commit is contained in:
JeffR 2024-10-04 00:10:26 -05:00
parent 20a01d9f02
commit e4d07c7e8d
14 changed files with 259 additions and 198 deletions

View file

@ -1,96 +1,35 @@
function AssetBrowser::createGameMode(%this)
AssetBrowser::registerObjectType("GameModeType", "Gamemode Objects", "Gamemode");
function GameModeType::setupCreateNew()
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
%assetName = AssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/";
%scriptPath = %assetPath @ %assetName @ "." @ $TorqueScriptFileExtension;
%fullScriptPath = makeFullPath(%scriptPath);
}
%file = new FileObject();
%templateFile = new FileObject();
%postFXTemplateCodeFilePath = %this.templateFilesPath @ "gameMode." @ $TorqueScriptFileExtension @ ".template";
function GameModeType::onCreateNew()
{
if(%file.openForWrite(%fullScriptPath) && %templateFile.openForRead(%postFXTemplateCodeFilePath))
{
while( !%templateFile.isEOF() )
{
%line = %templateFile.readline();
%line = strreplace( %line, "@@", %assetName );
%file.writeline(%line);
}
%file.close();
%templateFile.close();
}
else
{
%file.close();
%templateFile.close();
warnf("createGameMode - Something went wrong and we couldn't write the gameMode script file!");
}
}
%localScriptPath = strReplace(%scriptPath, "data/" @ %moduleName @ "/", "./");
%execLine = " %this.queueExec(\"" @ %localScriptPath @ "\");";
function GameModeType::buildBrowserElement(%this, %className, %previewData)
{
//echo("DatablockObjectType::buildBrowserElement() - " @ %datablock @ ", " @ %name @ ", " @ %previewData);
%previewData.assetName = %this.getName();
%previewData.assetPath = %this.getFileName();
%moduleScriptPath = makeFullPath(%moduleDef.ModuleScriptFilePath @ "." @ $TorqueScriptFileExtension);
%previewData.previewImage = "ToolsModule:genericAssetIcon_image";
echo("Attempting exec insert for file: " @ %moduleScriptPath);
//Lets see if we have a icon for specifically for this datablock type
%dataClass = %this.getClassName();
%dataClass = strreplace(%dataClass, "Data", "");
%lineIdx = Tools::findInFile(%moduleScriptPath, "*function*" @ %moduleName @ "::initClient*");
if(%lineIdx != -1)
%previewImage = "tools/classIcons/" @ %dataClass @ ".png";
if(isFile(%previewImage))
{
echo("INIT CLIENT FUNCTION LINE FOUND ON: " @ %lineIdx);
%insertLineIdx = Tools::findInFunction(%moduleScriptPath, %moduleName, "initClient", "*//--FILE EXEC END--*");
echo("FILE EXEC END LINE FOUND ON: " @ %insertLineIdx);
if(%insertLineIdx == -1)
{
//If there are not 'blocking' comments, then just slap the exec on the end of the function def
//as it doesn't really matter now
Tools::appendLineToFunction(%moduleScriptPath, %moduleName, "initClient", %execLine);
}
else
{
Tools::insertInFile(%moduleScriptPath, %insertLineIdx, %execLine, true);
}
%previewData.previewImage = %previewImage;
}
%lineIdx = Tools::findInFile(%moduleScriptPath, "*function*" @ %moduleName @ "::initServer*");
if(%lineIdx != -1)
{
echo("INIT SERVER FUNCTION LINE FOUND ON: " @ %lineIdx);
%insertLineIdx = Tools::findInFunction(%moduleScriptPath, %moduleName, "initServer", "*//--FILE EXEC END--*");
echo("FILE EXEC END LINE FOUND ON: " @ %insertLineIdx);
if(%insertLineIdx == -1)
{
//If there are not 'blocking' comments, then just slap the exec on the end of the function def
//as it doesn't really matter now
Tools::appendLineToFunction(%moduleScriptPath, %moduleName, "initServer", %execLine);
}
else
{
Tools::insertInFile(%moduleScriptPath, %insertLineIdx, %execLine, true);
}
}
//and we'll go ahead and force execute the script file so the gamemode is 'available' for use immediately
exec(%scriptPath);
if(isObject(%assetName))
{
//it's possible it got moved to an instant group upon execution, so we'll just
//shove it back to the RootGroup by force to be 100% sure
RootGroup.add(%assetName);
}
return %scriptPath;
//%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %this;
%previewData.tooltip = "\nGameMode Name: " @ %previewData.assetName @
"\nPath: " @ %previewData.assetPath;
}