From 8d8432115b105deff608c809e56ac9f979e57f43 Mon Sep 17 00:00:00 2001 From: JeffR Date: Thu, 24 Feb 2022 00:48:00 -0600 Subject: [PATCH 1/2] Adjusts formatting when parsing for object and function definitions in the project importer to be more accurate Adds handling for progrommatic new object delcarations where the class type is defined via () encapsulated code so the project import doesn't mangle it. --- .../scripts/projectImporter.tscript | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript b/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript index c149cf3f2..f7b86be34 100644 --- a/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript +++ b/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript @@ -476,7 +476,7 @@ function preprocessImportingFiles() { %line = $ProjectImporter::fileObject.readLine(); - if(strIsMatchExpr("* new*(*)*", %line)) + if(strIsMatchExpr("*new *(*)*", %line)) { %start = strpos(%line, "new "); %end = strpos(%line, "(", %start); @@ -486,6 +486,14 @@ function preprocessImportingFiles() %className = getSubStr(%line, %start + 4, %end-%start-4); } + if(%className $= "") + { + //we clearly have some unusual formatting, potentially a progromattic + //object block creation going on here. so we'll just skip it and move on + %currentFileSectionObject.add(%line); + continue; + } + %nameEnd = strpos(%line, ")", %end); %objectName = getSubStr(%line, %end+1, %nameEnd-%end-1); @@ -530,7 +538,7 @@ function preprocessImportingFiles() %insideObjectBlock = true; } } - else if(strIsMatchExpr("* datablock*(*)*", %line)) + else if(strIsMatchExpr("*datablock *(*)*", %line)) { %start = strpos(%line, "datablock "); %end = strpos(%line, "(", %start); @@ -584,7 +592,7 @@ function preprocessImportingFiles() %insideObjectBlock = true; } } - else if(strIsMatchExpr("* singleton*(*)*", %line)) + else if(strIsMatchExpr("*singleton *(*)*", %line)) { %start = strpos(%line, "singleton "); %end = strpos(%line, "(", %start); @@ -638,7 +646,7 @@ function preprocessImportingFiles() %insideObjectBlock = true; } } - else if(strIsMatchExpr("*function*(*)*", %line)) + else if(strIsMatchExpr("*function *(*)*", %line)) { %start = strpos(%line, "function "); %end = strpos(%line, "(", %start); From 7659b51ac93a04fb1c8f16b3eb94fa23a98c2822 Mon Sep 17 00:00:00 2001 From: JeffR Date: Thu, 24 Feb 2022 01:33:14 -0600 Subject: [PATCH 2/2] Added trimming of parsed object names to ensure whitespace before and after isn't accidentally processed as invalid characters Also made the classname validity check happen on the other creation keyword types Added logic so when processing an importing material definition that already has an asset, can handle it if the scriptPath doesn't have the extension in it already. --- .../pre40/T3Dpre4ProjectImporter.tscript | 6 +++++ .../scripts/projectImporter.tscript | 24 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Templates/BaseGame/game/tools/projectImporter/importers/pre40/T3Dpre4ProjectImporter.tscript b/Templates/BaseGame/game/tools/projectImporter/importers/pre40/T3Dpre4ProjectImporter.tscript index c6ac5c2b2..abbe166e0 100644 --- a/Templates/BaseGame/game/tools/projectImporter/importers/pre40/T3Dpre4ProjectImporter.tscript +++ b/Templates/BaseGame/game/tools/projectImporter/importers/pre40/T3Dpre4ProjectImporter.tscript @@ -1038,6 +1038,12 @@ function T3Dpre4ProjectImporter::processMaterialObject(%this, %fileObject, %obje %assetScriptPath = %assetDef.getScriptPath(); + if(fileExt(%assetScriptPath) $= "") + { + //try the default extension + %assetScriptPath = %assetScriptPath @ "." @ $TorqueScriptFileExtension; + } + if(isFile(%assetScriptPath) && isObject(%objectName)) { //Regular material in a companion file, so we'll want to write it to the diff --git a/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript b/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript index f7b86be34..13797d2a2 100644 --- a/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript +++ b/Templates/BaseGame/game/tools/projectImporter/scripts/projectImporter.tscript @@ -488,7 +488,7 @@ function preprocessImportingFiles() if(%className $= "") { - //we clearly have some unusual formatting, potentially a progromattic + //we clearly have some unusual formatting, potentially a programmatic //object block creation going on here. so we'll just skip it and move on %currentFileSectionObject.add(%line); continue; @@ -506,6 +506,8 @@ function preprocessImportingFiles() %objectName = getSubStr(%objectName, 0, %inheritanceSplit); } + %objectName = trim(%objectName); + %parentFileSectionObject = %currentFileSectionObject; %currentFileSectionObject = new ArrayObject(); @@ -548,6 +550,14 @@ function preprocessImportingFiles() %className = getSubStr(%line, %start + 10, %end-%start-10); } + if(%className $= "") + { + //we clearly have some unusual formatting, potentially a programmatic + //object block creation going on here. so we'll just skip it and move on + %currentFileSectionObject.add(%line); + continue; + } + %nameEnd = strpos(%line, ")", %end); %objectName = getSubStr(%line, %end+1, %nameEnd-%end-1); @@ -560,6 +570,8 @@ function preprocessImportingFiles() %objectName = getSubStr(%objectName, 0, %inheritanceSplit); } + %objectName = trim(%objectName); + %parentFileSectionObject = %currentFileSectionObject; %currentFileSectionObject = new ArrayObject(); @@ -602,6 +614,14 @@ function preprocessImportingFiles() %className = getSubStr(%line, %start + 10, %end-%start-10); } + if(%className $= "") + { + //we clearly have some unusual formatting, potentially a programmatic + //object block creation going on here. so we'll just skip it and move on + %currentFileSectionObject.add(%line); + continue; + } + %nameEnd = strpos(%line, ")", %end); %objectName = getSubStr(%line, %end+1, %nameEnd-%end-1); @@ -614,6 +634,8 @@ function preprocessImportingFiles() %objectName = getSubStr(%objectName, 0, %inheritanceSplit); } + %objectName = trim(%objectName); + %parentFileSectionObject = %currentFileSectionObject; %currentFileSectionObject = new ArrayObject();