From 6ce7f0b85fd3a413afbab4f7b3f3c638e9ac57a0 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 21 Mar 2021 12:04:43 -0700 Subject: [PATCH] Add item display name -> item ID autodetect --- NHSE.Core/Editing/Batch/BatchProcessor.cs | 14 ++++++- NHSE.Core/Editing/Batch/ItemProcessor.cs | 42 +++++++++++++++++++- NHSE.WinForms/Subforms/SysBot/BatchEditor.cs | 9 +---- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/NHSE.Core/Editing/Batch/BatchProcessor.cs b/NHSE.Core/Editing/Batch/BatchProcessor.cs index bd8f21c..a69d460 100644 --- a/NHSE.Core/Editing/Batch/BatchProcessor.cs +++ b/NHSE.Core/Editing/Batch/BatchProcessor.cs @@ -71,5 +71,17 @@ public void Execute(IList lines, IEnumerable data) Process(pk, set.Filters, set.Instructions); } } + + protected abstract void Initialize(StringInstructionSet[] sets); + + public void Process(StringInstructionSet[] sets, IReadOnlyList items) + { + Initialize(sets); + foreach (var s in sets) + { + foreach (var i in items) + Process(i, s.Filters, s.Instructions); + } + } } -} \ No newline at end of file +} diff --git a/NHSE.Core/Editing/Batch/ItemProcessor.cs b/NHSE.Core/Editing/Batch/ItemProcessor.cs index 09bef22..c9d7b50 100644 --- a/NHSE.Core/Editing/Batch/ItemProcessor.cs +++ b/NHSE.Core/Editing/Batch/ItemProcessor.cs @@ -1,4 +1,7 @@ -namespace NHSE.Core +using System.Collections.Generic; +using System.Linq; + +namespace NHSE.Core { public class ItemProcessor : BatchProcessor { @@ -8,5 +11,42 @@ public ItemProcessor(BatchMutator mut) : base(mut) protected override bool CanModify(Item item) => true; protected override bool Finalize(Item item) => true; + + /// + /// Initializes the list with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index. + /// + /// Instructions to initialize. + public void ScreenStrings(IEnumerable il) + { + foreach (var i in il.Where(i => !i.PropertyValue.All(char.IsDigit))) + { + string pv = i.PropertyValue; + if (pv.StartsWith("$") && pv.Contains(",")) + i.SetRandRange(pv); + + SetInstructionScreenedValue(i); + } + } + + /// + /// Initializes the with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index. + /// + /// Instruction to initialize. + private static void SetInstructionScreenedValue(StringInstruction i) + { + switch (i.PropertyName) + { + case nameof(Item.ItemId) or nameof(Item.ExtensionItemId): i.SetScreenedValue(GameInfo.Strings.itemlistdisplay); return; + } + } + + protected override void Initialize(StringInstructionSet[] sets) + { + foreach (var set in sets) + { + ScreenStrings(set.Filters); + ScreenStrings(set.Instructions); + } + } } } diff --git a/NHSE.WinForms/Subforms/SysBot/BatchEditor.cs b/NHSE.WinForms/Subforms/SysBot/BatchEditor.cs index 8add301..1c582aa 100644 --- a/NHSE.WinForms/Subforms/SysBot/BatchEditor.cs +++ b/NHSE.WinForms/Subforms/SysBot/BatchEditor.cs @@ -116,13 +116,8 @@ private void RunBatchEdit(StringInstructionSet[] sets) { if (finished) return; - - foreach (var s in sets) - { - foreach (var i in Items) - Processor.Process(i, s.Filters, s.Instructions); - } - + // don't bother reporting progress... + Processor.Process(sets, Items); finished = true; };