Fixed logic for parsing registerDatablock paths to trim script extensions during import conversion

Fixed creation of materialAsset from AB to properly generate companion script file
Fixed logic in project import that if we import in a legacy module script, we get rid of the newly generated one in favor of the old one
This commit is contained in:
Areloch 2021-08-07 02:36:38 -05:00
parent bdf32f4f7b
commit 2f5f585aaf
5 changed files with 60 additions and 24 deletions

View file

@ -3127,19 +3127,47 @@ Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
return "";
}
if (!isInPlace && Platform::isFile(qualifiedFromCSFile))
if (!isInPlace)
{
if(!dPathCopy(qualifiedFromCSFile, qualifiedToCSFile, !isReimport))
if (Platform::isFile(qualifiedFromCSFile))
{
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", qualifiedFromCSFile);
if (!dPathCopy(qualifiedFromCSFile, qualifiedToCSFile, !isReimport))
{
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", qualifiedFromCSFile);
activityLog.push_back(importLogBuffer);
}
else
{
//We successfully copied the original constructor file, so no extra work required
makeNewConstructor = false;
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Successfully copied original TSShape Constructor file %s", qualifiedFromCSFile);
activityLog.push_back(importLogBuffer);
}
}
}
else
{
//We're doing an in-place import, so double check we've already got a constructor file in the expected spot
if (Platform::isFile(qualifiedFromCSFile))
{
//Yup, found it, we're good to go
makeNewConstructor = false;
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", qualifiedFromCSFile);
activityLog.push_back(importLogBuffer);
}
else
{
//We successfully copied the original constructor file, so no extra work required
makeNewConstructor = false;
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Successfully copied original TSShape Constructor file %s", qualifiedFromCSFile);
activityLog.push_back(importLogBuffer);
//Didn't work, but it's possible it's using the old .cs extension when our extension variable is set to something else, so check that one as well just to be sure
Torque::Path constrFilePath = qualifiedFromCSFile;
constrFilePath.setExtension("cs");
if (Platform::isFile(constrFilePath.getFullPath().c_str()))
{
//Yup, found it, we're good to go
makeNewConstructor = false;
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", constrFilePath.getFullPath().c_str());
activityLog.push_back(importLogBuffer);
}
}
}
}

View file

@ -8,18 +8,21 @@ function AssetBrowser::createMaterialAsset(%this)
%assetPath = AssetBrowser.dirHandler.currentAddress @ "/";
%tamlpath = %assetPath @ %assetName @ ".asset.taml";
%sgfPath = %assetPath @ %assetName @ ".sgf";
%scriptPath = %assetPath @ %assetName @ "." @ $TorqueScriptFileExtension;
%asset = new MaterialAsset()
{
AssetName = %assetName;
versionId = 1;
shaderData = "";
shaderGraph = %sgfPath;
materialDefinitionName = %assetName;
scriptFile = %assetName @ "." @ $TorqueScriptFileExtension;
};
TamlWrite(%asset, %tamlpath);
%mat = new Material(%assetName);
%mat.save(%scriptPath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
@ -43,18 +46,6 @@ function AssetBrowser::editMaterialAsset(%this, %assetDef)
MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName );
AssetBrowser.hideDialog();
//
//
/*%assetDef.materialDefinitionName.reload();
$Tools::materialEditorList = "";
EWorldEditor.clearSelection();
MaterialEditorGui.currentObject = 0;
MaterialEditorGui.currentMode = "asset";
MaterialEditorGui.currentMaterial = %assetDef.materialDefinitionName;
MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName);
EditorGui.setEditor(MaterialEditorPlugin);
AssetBrowser.hideDialog();*/
}
//Renames the asset

View file

@ -340,7 +340,7 @@ function MaterialEditorGui::prepareActiveObject( %this, %override )
{
%fieldName = %obj.getField(%i);
if( %obj.getFieldType(%fieldName) !$= "TypeMaterialAssetId" && %obj.getFieldType(%fieldName) !$= "TypeMaterialName")
if( %obj.getFieldType(%fieldName) !$= "TypeMaterialAssetId" /*&& %obj.getFieldType(%fieldName) !$= "TypeMaterialName"*/)
continue;
if( !%canSupportMaterial )

View file

@ -505,7 +505,7 @@ function T3Dpre4ProjectImporter::beginCodeFilesImport(%this)
}
}
}
else if(strIsMatchExpr("*datablock*(*)*", %line))
else if(strIsMatchExpr("*datablock*(*)*", %line) && (strPos(%line, "registerDatablock") == -1))
{
%className = findObjectClass(%line, "datablock");

View file

@ -263,6 +263,23 @@ function ProjectImportWizardPage4::openPage(%this)
$ProjectImporter::importTool.copyFiles();
else
ProjectImportWindow.nextStep();
//if we gen'd a new module setup, double check we didn't copy over a module script file under a legacy extension
if(!$ProjectImporter::useExistingModule)
{
%newModuleName = $ProjectImporter::moduleName;
%moduleFilePath = "data/" @ %newModuleName;
if($TorqueScriptFileExtension !$= "cs")
{
%moduleScriptFilePath = %moduleFilePath @ "/" @ %newModuleName @ ".cs";
if(isFile(%moduleScriptFilePath))
{
//yep, that exists, so we'll assume it was the file we wanted, so remove the generated one
fileDelete(%moduleFilePath @ "/" @ %newModuleName @ "." @ $TorqueScriptFileExtension);
}
}
}
}
function ProjectImportWizardPage4::processPage(%this)