diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript index d53e8a4cb..536ef79d5 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.tscript @@ -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) { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gameMode.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gameMode.tscript index ae5e59b3e..b953b18da 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gameMode.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gameMode.tscript @@ -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) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript index bd88e1274..eeb4fa1ef 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.tscript @@ -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; } diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/newAsset.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/newAsset.tscript index ea05ecfb6..3a55dc43e 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/newAsset.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/newAsset.tscript @@ -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(); } diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/popupMenus.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/popupMenus.tscript index ad34a83f5..107cf1104 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/popupMenus.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/popupMenus.tscript @@ -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);