Fixes issue of not being able to create GameModes or blank MaterialAssets from the Asset Browser

This commit is contained in:
JeffR 2025-06-17 19:08:45 -05:00
parent 46bcd183f7
commit d35a305149
5 changed files with 124 additions and 21 deletions

View file

@ -72,7 +72,7 @@ function AssetBrowser::callAssetTypeFunc(%this, %type, %function, %param0, %para
{
%group = ABAssetTypesList.getKey(%i);
%typeData = ABAssetTypesList.getValue(%i);
if(getField(%typeData, 0) $= %type)
{
%typeGroup = %group;
@ -80,7 +80,7 @@ function AssetBrowser::callAssetTypeFunc(%this, %type, %function, %param0, %para
break;
}
}
%paramOffset = 0;
%isStaticCall = false;
%command = "";
@ -246,6 +246,26 @@ function AssetBrowser::callAssetTypeFunc(%this, %type, %function, %param0, %para
return %return;
}
function AssetBrowser::getAssetTypeGroup(%typeName)
{
%typeGroup = "";
%typeData = "";
for(%i=0; %i < ABAssetTypesList.count(); %i++)
{
%group = ABAssetTypesList.getKey(%i);
%typeData = ABAssetTypesList.getValue(%i);
if(getField(%typeData, 0) $= %typeName)
{
%typeGroup = %group;
%typeData = %typeData;
break;
}
}
return %typeGroup;
}
//
function AssetBrowser::initialize(%this)
{

View file

@ -1,4 +1,4 @@
AssetBrowser::registerObjectType("GameModeType", "Gamemode Objects", "Gamemode");
AssetBrowser::registerObjectType("GameModeType", "Gamemode Objects", "GameMode");
function GameModeType::setupCreateNew()
{
@ -7,7 +7,99 @@ function GameModeType::setupCreateNew()
function GameModeType::onCreateNew()
{
%moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
%assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/";
%scriptPath = %assetPath @ %assetName @ "." @ $TorqueScriptFileExtension;
%fullScriptPath = makeFullPath(%scriptPath);
%file = new FileObject();
%templateFile = new FileObject();
%postFXTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "gameMode." @ $TorqueScriptFileExtension @ ".template";
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 @ "\");";
%moduleScriptPath = makeFullPath(%moduleDef.ModuleScriptFilePath);
echo("Attempting exec insert for file: " @ %moduleScriptPath);
%lineIdx = Tools::findInFile(%moduleScriptPath, "*function*" @ %moduleName @ "::initClient*");
if(%lineIdx != -1)
{
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);
}
}
%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;
}
function GameModeType::buildBrowserElement(%this, %className, %previewData)

View file

@ -1,10 +1,10 @@
AssetBrowser::registerAssetType("MaterialAsset", "Materials");
function MaterialAsset::createMaterialAsset(%this)
function MaterialAsset::onCreateNew()
{
%assetName = AssetBrowser.newAssetSettings.assetName;
%assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetPath = NewAssetTargetAddress.getText() @ "/";
@ -30,7 +30,7 @@ function MaterialAsset::createMaterialAsset(%this)
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.refresh();
$CurrentAssetBrowser.refresh();
return %tamlpath;
}

View file

@ -255,8 +255,10 @@ function CreateNewAsset()
Canvas.popDialog(AssetBrowser_newAsset);
%assetTypeGroup = AssetBrowser::getAssetTypeGroup(%assetType);
//Load it
if(!AssetDatabase.isDeclaredAsset(%moduleName @ ":" @ %assetName))
if(%assetTypeGroup $= "Asset" && !AssetDatabase.isDeclaredAsset(%moduleName @ ":" @ %assetName))
{
%moduleDef = ModuleDatabase.findModule(%moduleName,1);
AssetDatabase.addDeclaredAsset(%moduleDef, %assetFilePath);
@ -270,18 +272,7 @@ function CreateNewAsset()
%callbackCommand = "" @ AssetBrowser_newAsset.callbackFunc @ "(\"" @ %moduleName @ ":" @ %assetName @ "\");";
eval(%callbackCommand);
}
//Update the selection to immediately jump to the new asset
/*AssetBrowser-->filterTree.clearSelection();
%ModuleItem = AssetBrowser-->filterTree.findItemByName(%moduleName);
%assetTypeId = AssetBrowser-->filterTree.findChildItemByName(%ModuleItem, %assetType);
AssetBrowser-->filterTree.selectItem(%assetTypeId);
%selectedItem = AssetBrowser-->filterTree.getSelectedItem();
AssetBrowser-->filterTree.scrollVisibleByObjectId(%selectedItem);
AssetBrowser-->filterTree.buildVisibleTree(); */
AssetBrowser.refresh();
}

View file

@ -134,7 +134,7 @@ function AssetBrowser::buildPopupMenus(%this)
item[ 0 ] = "Create Script" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"ScriptAsset\", AssetBrowser.selectedModule);";
item[ 1 ] = "Create State Machine" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"StateMachineAsset\", AssetBrowser.selectedModule);";
item[ 2 ] = "-";
item[ 3 ] = "Create Game Mode" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"GameMode\", AssetBrowser.selectedModule);";
item[ 3 ] = "Create Game Mode" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"GameModeType\", AssetBrowser.selectedModule);";
//item[ 3 ] = "Create Game Object" TAB "" TAB "AssetBrowser.createNewGameObjectAsset(\"NewGameObject\", AssetBrowser.selectedModule);";
};
//%this.AddNewScriptAssetPopup.insertSubMenu(0, "Create Component", AddNewComponentAssetPopup);