From c2e7ac9b6ba5ce08a3da3ddb0a3ea01d134c9ce8 Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Fri, 15 Oct 2021 23:38:52 +0200 Subject: [PATCH] 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 --- Source/Core/GZBuilder/Data/ScriptItem.cs | 9 +++++++-- Source/Core/General/MapManager.cs | 8 +++++--- Source/Core/ZDoom/Scripting/AcsParserSE.cs | 14 +++++++++++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Source/Core/GZBuilder/Data/ScriptItem.cs b/Source/Core/GZBuilder/Data/ScriptItem.cs index a2467abb..247b2598 100755 --- a/Source/Core/GZBuilder/Data/ScriptItem.cs +++ b/Source/Core/GZBuilder/Data/ScriptItem.cs @@ -11,12 +11,14 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data private readonly int cursorposition; private readonly bool isinclude; private readonly bool customname; + private readonly bool skip; internal string Name { get { return name; } } internal int Index { get { return index; } } internal int CursorPosition { get { return cursorposition; } } internal bool IsInclude { get { return isinclude; } } 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 internal ScriptItem(string name, int cursorposition, bool isinclude) @@ -27,10 +29,11 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data this.cursorposition = cursorposition; this.isinclude = isinclude; this.customname = true; + this.skip = false; } // Constructor for numbered script - internal ScriptItem(int index, string name, List argnames, int cursorposition, bool isinclude, bool customname) + internal ScriptItem(int index, string name, List argnames, int cursorposition, bool isinclude, bool customname, bool skip) { this.name = name; this.argnames = argnames; @@ -38,10 +41,11 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data this.cursorposition = cursorposition; this.isinclude = isinclude; this.customname = customname; + this.skip = skip; } // Constructor for named script - internal ScriptItem(string name, List argnames, int cursorposition, bool isinclude) + internal ScriptItem(string name, List argnames, int cursorposition, bool isinclude, bool skip) { this.name = name; this.argnames = argnames; @@ -49,6 +53,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data this.cursorposition = cursorposition; this.isinclude = isinclude; this.customname = true; + this.skip = skip; } internal static int SortByIndex(ScriptItem i1, ScriptItem i2) diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs index d67f3732..efd8ab33 100755 --- a/Source/Core/General/MapManager.cs +++ b/Source/Core/General/MapManager.cs @@ -2192,15 +2192,17 @@ namespace CodeImp.DoomBuilder parser.NamedScripts.Sort(ScriptItem.SortByName); 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) { - if(!namedscripts.ContainsKey(item.Name.ToLowerInvariant())) + if(!item.Skip && !namedscripts.ContainsKey(item.Name.ToLowerInvariant())) 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); } } diff --git a/Source/Core/ZDoom/Scripting/AcsParserSE.cs b/Source/Core/ZDoom/Scripting/AcsParserSE.cs index 1ee8ae5b..91a15d01 100755 --- a/Source/Core/ZDoom/Scripting/AcsParserSE.cs +++ b/Source/Core/ZDoom/Scripting/AcsParserSE.cs @@ -82,6 +82,7 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting public bool Parse(TextResourceData data, HashSet configincludes, bool processincludes, IncludeType includetype, bool clearerrors) { 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 //and must be included/imported separately @@ -124,6 +125,9 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting switch(token) { + case "$skip": + skipnextscript = true; + break; case "script": { SkipWhitespace(true); @@ -145,7 +149,9 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting if(AddArgumentsToScriptNames) scriptname += " " + GetArgumentNames(args); // 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 else @@ -187,7 +193,9 @@ namespace CodeImp.DoomBuilder.ZDoom.Scripting if(AddArgumentsToScriptNames) name += " " + GetArgumentNames(args); // 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); // 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;