Script editor: added support for the //$Skip editor in scripts. Adding this line will not add the next script to the drop down list of available scripts for the ACS actions in the thing and linedef editor dialogs. Resolves #636

This commit is contained in:
biwa 2021-10-15 23:38:52 +02:00
parent cbe231c853
commit c2e7ac9b6b
3 changed files with 23 additions and 8 deletions

View file

@ -11,12 +11,14 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
private readonly int cursorposition; private readonly int cursorposition;
private readonly bool isinclude; private readonly bool isinclude;
private readonly bool customname; private readonly bool customname;
private readonly bool skip;
internal string Name { get { return name; } } internal string Name { get { return name; } }
internal int Index { get { return index; } } internal int Index { get { return index; } }
internal int CursorPosition { get { return cursorposition; } } internal int CursorPosition { get { return cursorposition; } }
internal bool IsInclude { get { return isinclude; } } internal bool IsInclude { get { return isinclude; } }
internal bool HasCustomName { get { return customname; } } internal bool HasCustomName { get { return customname; } }
internal bool Skip { get { return skip; } } // Used to not display the script in the list of scripts in the action control
// Constructor for misc usage // Constructor for misc usage
internal ScriptItem(string name, int cursorposition, bool isinclude) internal ScriptItem(string name, int cursorposition, bool isinclude)
@ -27,10 +29,11 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
this.cursorposition = cursorposition; this.cursorposition = cursorposition;
this.isinclude = isinclude; this.isinclude = isinclude;
this.customname = true; this.customname = true;
this.skip = false;
} }
// Constructor for numbered script // Constructor for numbered script
internal ScriptItem(int index, string name, List<string> argnames, int cursorposition, bool isinclude, bool customname) internal ScriptItem(int index, string name, List<string> argnames, int cursorposition, bool isinclude, bool customname, bool skip)
{ {
this.name = name; this.name = name;
this.argnames = argnames; this.argnames = argnames;
@ -38,10 +41,11 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
this.cursorposition = cursorposition; this.cursorposition = cursorposition;
this.isinclude = isinclude; this.isinclude = isinclude;
this.customname = customname; this.customname = customname;
this.skip = skip;
} }
// Constructor for named script // Constructor for named script
internal ScriptItem(string name, List<string> argnames, int cursorposition, bool isinclude) internal ScriptItem(string name, List<string> argnames, int cursorposition, bool isinclude, bool skip)
{ {
this.name = name; this.name = name;
this.argnames = argnames; this.argnames = argnames;
@ -49,6 +53,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
this.cursorposition = cursorposition; this.cursorposition = cursorposition;
this.isinclude = isinclude; this.isinclude = isinclude;
this.customname = true; this.customname = true;
this.skip = skip;
} }
internal static int SortByIndex(ScriptItem i1, ScriptItem i2) internal static int SortByIndex(ScriptItem i1, ScriptItem i2)

View file

@ -2192,15 +2192,17 @@ namespace CodeImp.DoomBuilder
parser.NamedScripts.Sort(ScriptItem.SortByName); parser.NamedScripts.Sort(ScriptItem.SortByName);
parser.NumberedScripts.Sort(ScriptItem.SortByIndex); parser.NumberedScripts.Sort(ScriptItem.SortByIndex);
// Add scripts, but only those the user didn't want to skip (using the //$Skip editor key)
foreach(ScriptItem item in parser.NamedScripts) foreach(ScriptItem item in parser.NamedScripts)
{ {
if(!namedscripts.ContainsKey(item.Name.ToLowerInvariant())) if(!item.Skip && !namedscripts.ContainsKey(item.Name.ToLowerInvariant()))
namedscripts.Add(item.Name.ToLowerInvariant(), item); namedscripts.Add(item.Name.ToLowerInvariant(), item);
} }
foreach(ScriptItem item in parser.NumberedScripts) // Add scripts, but only those the user didn't want to skip (using the //$Skip editor key)
foreach (ScriptItem item in parser.NumberedScripts)
{ {
if(!numberedscripts.ContainsKey(item.Index)) if(!item.Skip && !numberedscripts.ContainsKey(item.Index))
numberedscripts.Add(item.Index, item); numberedscripts.Add(item.Index, item);
} }
} }

View file

@ -82,6 +82,7 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting
public bool Parse(TextResourceData data, HashSet<string> configincludes, bool processincludes, IncludeType includetype, bool clearerrors) public bool Parse(TextResourceData data, HashSet<string> configincludes, bool processincludes, IncludeType includetype, bool clearerrors)
{ {
string source = data.Filename.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); string source = data.Filename.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
bool skipnextscript = false;
//INFO: files included or imported inside a library are not visible to the code outside it //INFO: files included or imported inside a library are not visible to the code outside it
//and must be included/imported separately //and must be included/imported separately
@ -124,6 +125,9 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting
switch(token) switch(token)
{ {
case "$skip":
skipnextscript = true;
break;
case "script": case "script":
{ {
SkipWhitespace(true); SkipWhitespace(true);
@ -145,7 +149,9 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting
if(AddArgumentsToScriptNames) scriptname += " " + GetArgumentNames(args); if(AddArgumentsToScriptNames) scriptname += " " + GetArgumentNames(args);
// Add to collection // Add to collection
namedscripts.Add(new ScriptItem(scriptname, argnames, startpos, includetype != IncludeType.NONE)); namedscripts.Add(new ScriptItem(scriptname, argnames, startpos, includetype != IncludeType.NONE, skipnextscript));
skipnextscript = false;
} }
// Should be numbered script // Should be numbered script
else else
@ -187,7 +193,9 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting
if(AddArgumentsToScriptNames) name += " " + GetArgumentNames(args); if(AddArgumentsToScriptNames) name += " " + GetArgumentNames(args);
// Add to collection // Add to collection
numberedscripts.Add(new ScriptItem(n, name, argnames, startpos, includetype != IncludeType.NONE, customname)); numberedscripts.Add(new ScriptItem(n, name, argnames, startpos, includetype != IncludeType.NONE, customname, skipnextscript));
skipnextscript = false;
} }
} }
} }
@ -210,7 +218,7 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting
if(AddArgumentsToScriptNames) funcname += GetArgumentNames(args); if(AddArgumentsToScriptNames) funcname += GetArgumentNames(args);
// Add to collection // Add to collection
functions.Add(new ScriptItem(funcname, argnames, startpos, includetype != IncludeType.NONE)); functions.Add(new ScriptItem(funcname, argnames, startpos, includetype != IncludeType.NONE, false));
} }
break; break;