Selaa lähdekoodia

leverage writeapppend to add any new info requested.
filter out pre-existing callback defines

AzaezelX 1 vuosi sitten
vanhempi
commit
caa93e2179

+ 73 - 10
Templates/BaseGame/game/data/Prototyping/UI/classPrototyping.tscript

@@ -90,9 +90,8 @@ function setProtoTypeFilePath(%targetPath)
    classPrototyping-->targetPath.text = %targetPath;
    classPrototyping-->targetPath.text = %targetPath;
 }
 }
 
 
-function classPrototyping::writeResults(%this)
+function classPrototyping::readExistingLayout(%this)
 {
 {
-    %namespaceUsed = "";
     for (%i=0; %i<%this.classCount; %i++)
     for (%i=0; %i<%this.classCount; %i++)
     {
     {
         %inheritanceOrder = %this.classCount-(%i+1);
         %inheritanceOrder = %this.classCount-(%i+1);
@@ -100,18 +99,63 @@ function classPrototyping::writeResults(%this)
         if (%obj.isStateOn())
         if (%obj.isStateOn())
             %namespaceUsed = getWord(%this.classlist,%inheritanceOrder);
             %namespaceUsed = getWord(%this.classlist,%inheritanceOrder);
     }
     }
+    
 	%file = new FileObject();
 	%file = new FileObject();
     %filename = classPrototyping-->targetPath.text @"/"@ %namespaceUsed @"."@ $TorqueScriptFileExtension;
     %filename = classPrototyping-->targetPath.text @"/"@ %namespaceUsed @"."@ $TorqueScriptFileExtension;
-	if(%file.openForWrite(%filename))
+    
+    if (!isObject(%this.callbacksDefined))
+        %this.callbacksDefined = new arrayobject();
+    %this.callbacksDefined.empty();
+    %this.reportedCommands = false;
+    %this.reportedVariables = false;
+    %this.callbackBlockDefined = false;
+    
+    %key=0;
+	if(%file.openForRead(%filename))
     {
     {
-        for (%i=0; %i<%this.methodCount; %i++)
+        while (!%file.isEof())
         {
         {
-            %obj = "ProtoMethodSelect"@ %i;
-            if (%obj.isStateOn())
-                %file.writeLine(strreplace(%this.methodArray.getValue(%i),%this.instanceName,%namespaceUsed));
+            %line = %file.readLine();
+            
+            //have we already reported commands?
+            if (startsWith(%line,"/* Available Commands:") )
+                %this.reportedCommands = true;
+                
+            //have we already reported variables?
+            if (startsWith(%line,"/* HardCoded Variables") )
+                %this.reportedVariables = true;
+                
+            if (startsWith(%line,"/*--- Callbacks ---*/") )
+                %this.callbackBlockDefined = true;
+            
+            //get list of methods already existing
+            if (startswith(%line,"function "@ %namespaceUsed) )
+            {
+                %methodName = strreplace(%line,"::"," ");
+                %methodName = getWord(strreplace(%methodName,"("," "),2);
+                %this.callbacksDefined.add(%key++,%methodName);
+            }
         }
         }
-    
-        if (ReportCommands.isStateOn())
+    }
+	%file.delete();
+}
+
+function classPrototyping::writeResults(%this)
+{
+    %namespaceUsed = "";
+    for (%i=0; %i<%this.classCount; %i++)
+    {
+        %inheritanceOrder = %this.classCount-(%i+1);
+        %obj = "ProtoClassSelect"@ %i;
+        if (%obj.isStateOn())
+            %namespaceUsed = getWord(%this.classlist,%inheritanceOrder);
+    }
+    %this.readExistingLayout();
+	%file = new FileObject();
+    %filename = classPrototyping-->targetPath.text @"/"@ %namespaceUsed @"."@ $TorqueScriptFileExtension;
+	if(%file.openForAppend(%filename))
+    {
+        if (ReportCommands.isStateOn() && %this.reportedCommands == false)
         {
         {
             %this.commandArray = getMethodSigsNS(%this.nameSpaceUsed,true);
             %this.commandArray = getMethodSigsNS(%this.nameSpaceUsed,true);
             %this.commandCount = %this.commandArray.count();
             %this.commandCount = %this.commandArray.count();
@@ -123,7 +167,7 @@ function classPrototyping::writeResults(%this)
             %file.writeLine("*/");
             %file.writeLine("*/");
         }
         }
     
     
-        if (ReportVariables.isStateOn())
+        if (ReportVariables.isStateOn() && %this.reportedVariables == false)
         {
         {
             %file.writeLine("/* HardCoded Variables");
             %file.writeLine("/* HardCoded Variables");
             for (%i=0; %i< getFieldCountNS(%this.nameSpaceUsed); %i++)
             for (%i=0; %i< getFieldCountNS(%this.nameSpaceUsed); %i++)
@@ -132,6 +176,25 @@ function classPrototyping::writeResults(%this)
             }
             }
             %file.writeLine("*/");
             %file.writeLine("*/");
         }
         }
+        
+        if (%this.callbackBlockDefined == false)
+            %file.writeLine("\n/*--- Callbacks ---*/\n");
+            
+        for (%i=0; %i<%this.methodCount; %i++)
+        {
+            %obj = "ProtoMethodSelect"@ %i;
+            if (%obj.isStateOn())
+            {
+                %methodDef = getRecord(%this.methodArray.getValue(%i),0);
+                %methodName = strreplace(%methodDef,"::"," ");
+                %methodName = getWord(strreplace(%methodName,"("," "),2);
+                if (%this.callbacksDefined.countValue(%methodName)==0)
+                {
+                    echo(%methodName @ "not found. defining...");
+                    %file.writeLine("\n" @ strreplace(%this.methodArray.getValue(%i),%this.instanceName,%namespaceUsed));
+                }
+            }
+        }
     }
     }
 	else
 	else
 	{
 	{