NHSE/NHSE.Core/Editing/Batch/ItemProcessor.cs
Kurt b88c518d5c
Update FieldItemEditor for 3.0.0 (#716)
Updates the Field Item Editor to render layers based on the entire map, and the per-patch positioning of each layer.
Import/export will gracefully handle upgrade/downgrade, and viewport import/export will gracefully update tiles rather than a per-acre basis.

Performance has also been slightly improved; no allocation is done anymore when updating the image.
2026-01-25 16:55:38 -06:00

48 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace NHSE.Core;
public sealed class ItemProcessor(BatchMutator<Item> mut) : BatchProcessor<Item>(mut)
{
protected override bool CanModify(Item item) => true;
protected override bool Finalize(Item item) => true;
/// <summary>
/// Initializes the <see cref="StringInstruction"/> list with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
/// </summary>
/// <param name="il">Instructions to initialize.</param>
public static void ScreenStrings(IEnumerable<StringInstruction> il)
{
foreach (var i in il.Where(i => !i.PropertyValue.All(char.IsDigit)))
{
string pv = i.PropertyValue;
if (pv.StartsWith('$') && pv.Contains(','))
i.SetRandomRange(pv);
SetInstructionScreenedValue(i);
}
}
/// <summary>
/// Initializes the <see cref="StringInstruction"/> with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
/// </summary>
/// <param name="i">Instruction to initialize.</param>
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(ReadOnlySpan<StringInstructionSet> sets)
{
foreach (var set in sets)
{
ScreenStrings(set.Filters);
ScreenStrings(set.Instructions);
}
}
}