Adds functionality to duplicate an existing asset, currently works with image and level. Other types to follow.

Adds editor setting for default target module, as well as if duplication of an asset should prompt for a new name, or proceed automatically with a default naming behavior.
Shifts collada loader logic back to collada from assimp until the oddities with the assimp DAE import configs is ironed out.
This commit is contained in:
Areloch 2020-04-05 01:28:34 -05:00
parent 7125171d87
commit 32d8acd1b3
7 changed files with 240 additions and 16 deletions

View file

@ -2143,7 +2143,7 @@ template<> void *Resource<TSShape>::create(const Torque::Path &path)
ret = new TSShape;
readSuccess = ret->read(&stream);
}
/*else if ( extension.equal( "dae", String::NoCase ) || extension.equal( "kmz", String::NoCase ) )
else if ( extension.equal( "dae", String::NoCase ) || extension.equal( "kmz", String::NoCase ) )
{
#ifdef TORQUE_COLLADA
// Attempt to load the DAE file
@ -2164,7 +2164,7 @@ template<> void *Resource<TSShape>::create(const Torque::Path &path)
ret = new TSShape;
readSuccess = ret->read(&stream);
#endif
}*/
}
else
{
//Con::errorf( "Resource<TSShape>::create - '%s' has an unknown file format", path.getFullPath().c_str() );

View file

@ -0,0 +1,118 @@
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(AssetBrowser_assetNameEdit) {
position = "0 0";
extent = "1024 768";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiDefaultNonModalProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "1";
Enabled = "1";
new GuiWindowCtrl() {
text = "Set Asset Name";
resizeWidth = "1";
resizeHeight = "0";
canMove = "1";
canClose = "1";
canMinimize = "0";
canMaximize = "0";
canCollapse = "0";
edgeSnap = "1";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "362 334";
extent = "355 99";
minExtent = "48 92";
horizSizing = "center";
vertSizing = "center";
profile = "ToolsGuiWindowProfile";
visible = "1";
active = "1";
command = "Canvas.popDialog(AssetBrowser_assetNameEdit);";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
new GuiButtonCtrl() {
text = "Select";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "207 68";
extent = "71 22";
minExtent = "8 2";
horizSizing = "left";
vertSizing = "top";
profile = "ToolsGuiButtonProfile";
visible = "1";
active = "1";
command = "Canvas.popDialog(AssetBrowser_assetNameEdit); eval(AssetBrowser_assetNameEdit.callback);";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiButtonCtrl() {
text = "Cancel";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "284 68";
extent = "64 22";
minExtent = "8 2";
horizSizing = "left";
vertSizing = "top";
profile = "ToolsGuiButtonProfile";
visible = "1";
active = "1";
command = "Canvas.popDialog(AssetBrowser_assetNameEdit);";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiTextEditCtrl(AssetBrowser_assetNameEditTxt) {
historySize = "0";
tabComplete = "0";
sinkAllKeyEvents = "0";
password = "0";
passwordMask = "*";
maxLength = "1024";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "8 38";
extent = "341 18";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "height";
profile = "ToolsGuiTextEditProfile";
visible = "1";
active = "1";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
};
};
};
//--- OBJECT WRITE END ---

View file

@ -66,6 +66,7 @@ function initializeAssetBrowser()
exec("./guis/newFolder.gui");
exec("./guis/assetImportLog.gui");
exec("./guis/looseFileAudit.gui");
exec("./guis/assetNameEdit.gui");
exec("./scripts/assetBrowser.cs");
exec("./scripts/popupMenus.cs");

View file

@ -212,6 +212,24 @@ function AssetBrowser::renameImageAsset(%this, %assetDef, %newAssetName)
renameAssetFile(%assetDef, %newAssetName);
}
//Duplicates the asset
function AssetBrowser::duplicateImageAsset(%this, %assetDef, %newAssetName)
{
%duplicatedAsset = duplicateAssetFile(%assetDef, %newAssetName);
%newFilename = duplicateAssetLooseFile(%assetDef.imageFile, %newAssetName);
if(!%newFilename $= "")
return;
%module = AssetBrowser.dirHandler.getModuleFromAddress(%duplicatedAsset);
%dupAssetDef = AssetDatabase.acquireAsset(%module.ModuleId @ ":" @ %newAssetName);
%dupAssetDef.imageFile = fileName(%newFilename);
%dupAssetDef.saveAsset();
}
//Deletes the asset
function AssetBrowser::deleteImageAsset(%this, %assetDef)
{

View file

@ -86,6 +86,24 @@ function AssetBrowser::renameLevelAsset(%this, %assetDef, %newAssetName)
renameAssetFile(%assetDef, %newAssetName);
}
//Duplicates the asset
function AssetBrowser::duplicateLevelAsset(%this, %assetDef, %newAssetName)
{
%duplicatedAsset = duplicateAssetFile(%assetDef, %newAssetName);
%newFilename = duplicateAssetLooseFile(%assetDef.LevelFile, %newAssetName);
if(!%newFilename $= "")
return;
%module = AssetBrowser.dirHandler.getModuleFromAddress(%duplicatedAsset);
%dupAssetDef = AssetDatabase.acquireAsset(%module.ModuleId @ ":" @ %newAssetName);
%dupAssetDef.LevelFile = fileName(%newFilename);
%dupAssetDef.saveAsset();
}
//Deletes the asset
function AssetBrowser::deleteLevelAsset(%this, %assetDef)
{

View file

@ -260,26 +260,89 @@ function moveAssetLooseFile(%file, %destinationPath)
//------------------------------------------------------------
function AssetBrowser::duplicateAsset(%this, %targetModule)
function AssetBrowser::duplicateAsset(%this)
{
if(%targetModule $= "")
{
//we need a module to duplicate to first
Canvas.pushDialog(AssetBrowser_selectModule);
AssetBrowser_selectModule.callback = "AssetBrowser.duplicateAsset";
return;
}
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId);
//this acts as a redirect based on asset type and will enact the appropriate function
//so for a GameObjectAsset, it'll become %this.duplicateGameObjectAsset(%assetDef, %targetModule);
//and call to the tools/assetBrowser/scripts/assetTypes/gameObject.cs file for implementation
if(%this.isMethod("duplicate"@%assetType))
eval(%this @ ".duplicate"@%assetType@"("@%assetDef@","@%targetModule@");");
%trailingNum = getTrailingNumber(%assetDef.assetName);
if(%trailingNum != -1)
{
%trailingNum++;
%newName = stripTrailingNumber(%assetDef.assetName) @ (%trailingNum);
}
else
{
%newName = stripTrailingNumber(%assetDef.assetName) @ "1";
}
AssetBrowser_assetNameEditTxt.text = %newName;
AssetBrowser_assetNameEdit.callback = "AssetBrowser.doDuplicateAsset();";
if(EditorSettings.value("AssetManagement/Assets/promptOnRename", "1") == 1)
Canvas.pushDialog(AssetBrowser_assetNameEdit);
else
eval(AssetBrowser_assetNameEdit.callback);
}
function AssetBrowser::doDuplicateAsset(%this)
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId);
if(AssetBrowser_assetNameEditTxt.text !$= "" && AssetBrowser_assetNameEditTxt.text !$= %assetDef.assetName)
{
//this acts as a redirect based on asset type and will enact the appropriate function
//so for a GameObjectAsset, it'll become %this.duplicateGameObjectAsset(%assetDef, %targetModule);
//and call to the tools/assetBrowser/scripts/assetTypes/gameObject.cs file for implementation
if(%this.isMethod("duplicate"@%assetType))
eval(%this @ ".duplicate"@%assetType@"("@%assetDef@","@AssetBrowser_assetNameEditTxt.text@");");
AssetBrowser.refresh();
}
}
function duplicateAssetFile(%assetDef, %newAssetName)
{
%assetPath = makeFullPath(AssetDatabase.getAssetFilePath(%assetDef.getAssetId()));
%assetFilepath = filePath(%assetPath);
%assetFileExt = fileExt(%assetPath);
%newAssetPath = %assetFilepath @ "/" @ %newAssetName @ ".asset.taml";
%copiedSuccess = pathCopy(%assetPath, %newAssetPath);
if(!%copiedSuccess)
return "";
replaceInFile(%newAssetPath, %assetDef.assetName, %newAssetName);
%module = AssetBrowser.dirHandler.getModuleFromAddress(%newAssetPath);
//Add with the new file
AssetDatabase.addDeclaredAsset(%module, %newAssetPath);
return %newAssetPath;
}
function duplicateAssetLooseFile(%file, %newFilename)
{
%filePath = filePath(%file);
%fileExt = fileExt(%file);
%newPath = %filePath @ "/" @ %newFilename @ %fileExt;
%copiedSuccess = pathCopy(%file, %newPath);
if(!%copiedSuccess)
return "";
return %newPath;
}
//------------------------------------------------------------
function AssetBrowser::deleteAsset(%this)
{
//Find out what type it is

View file

@ -444,6 +444,11 @@ function ESettingsWindow::getAssetManagementSettings(%this)
SettingsInspector.addSettingsField("AssetManagement/Modules/coreModulePath", "Core Module Path", "string", "");
SettingsInspector.addSettingsField("AssetManagement/Modules/gameDataModulePath", "Game Data Module Path", "string", "");
SettingsInspector.addSettingsField("AssetManagement/Modules/moduleExtension", "Module Extension", "string", "");
%moduleList = ModuleDatabase.findModules(true);
%moduleList = strreplace(%moduleList, " ", ",");
SettingsInspector.addSettingsField("AssetManagement/Modules/DefaultModule", "Default Module", "list", %moduleList);
SettingsInspector.endGroup();
SettingsInspector.startGroup("Assets");
@ -480,6 +485,7 @@ function ESettingsWindow::getAssetEditingSettings(%this)
SettingsInspector.addSettingsField("Assets/Browser/showFolders", "Show Folders in Tiles view in Asset Browser", "bool", "");
SettingsInspector.addSettingsField("Assets/Browser/showEmptyFolders", "Show Empty Folders in Tiles view in Asset Browser", "bool", "");
SettingsInspector.addSettingsField("Assets/Browser/previewTileSize", "Asset Preview Tile Size", "bool", "");
SettingsInspector.addSettingsField("AssetManagement/Assets/promptOnRename", "Prompt on Rename", "bool", "");
SettingsInspector.endGroup();
}