From 9be6741d13685a2e2792b266dc084f61a890b886 Mon Sep 17 00:00:00 2001 From: Dale McCoy <21223975+DaleStan@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:46:47 -0500 Subject: [PATCH] fix: Yafc can now tolerate non-module items that spoil into modules. --- Yafc.Model/Data/DataClasses.cs | 10 ++++++++++ Yafc.Parser/Data/FactorioDataDeserializer.cs | 6 +++++- changelog.txt | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Yafc.Model/Data/DataClasses.cs b/Yafc.Model/Data/DataClasses.cs index 9e357f19..76e4c2ef 100644 --- a/Yafc.Model/Data/DataClasses.cs +++ b/Yafc.Model/Data/DataClasses.cs @@ -315,6 +315,16 @@ public virtual bool HasSpentFuel([MaybeNullWhen(false)] out Item spent) { } public class Item : Goods { + /// + /// The prototypes in this array will be loaded in order, before any other prototypes. + /// This should correspond to the prototypes for subclasses of item, with more derived classes listed before their base classes. + /// e.g. If ItemWithHealth and ModuleWithHealth C# classes were added, all prototypes for both classes must be listed here. + /// Ignoring style restrictions, the prototypes could be listed in any order, provided all ModuleWithHealth prototype(s) are listed before "module". + /// + /// This forces modules to be loaded before other items, since deserialization otherwise creates Item objects for all spoil results. + /// It does not protect against modules that spoil into other modules, but one hopes people won't do that. + internal static string[] ExplicitPrototypeLoadOrder { get; } = ["module"]; + public Item? fuelResult { get; internal set; } public int stackSize { get; internal set; } public Entity? placeResult { get; internal set; } diff --git a/Yafc.Parser/Data/FactorioDataDeserializer.cs b/Yafc.Parser/Data/FactorioDataDeserializer.cs index 19981f46..baa02e1d 100644 --- a/Yafc.Parser/Data/FactorioDataDeserializer.cs +++ b/Yafc.Parser/Data/FactorioDataDeserializer.cs @@ -117,7 +117,11 @@ public Project LoadData(string projectPath, LuaTable data, LuaTable prototypes, raw = (LuaTable?)data["raw"] ?? throw new ArgumentException("Could not load data.raw from data argument", nameof(data)); LuaTable itemPrototypes = (LuaTable?)prototypes?["item"] ?? throw new ArgumentException("Could not load prototypes.item from data argument", nameof(prototypes)); - foreach (object prototypeName in itemPrototypes.ObjectElements.Keys) { + foreach (object prototypeName in Item.ExplicitPrototypeLoadOrder.Intersect(itemPrototypes.ObjectElements.Keys)) { + DeserializePrototypes(raw, (string)prototypeName, DeserializeItem, progress, errorCollector); + } + + foreach (object prototypeName in itemPrototypes.ObjectElements.Keys.Except(Item.ExplicitPrototypeLoadOrder)) { DeserializePrototypes(raw, (string)prototypeName, DeserializeItem, progress, errorCollector); } diff --git a/changelog.txt b/changelog.txt index 0e19147a..3416475e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -22,6 +22,7 @@ Date: They can be toggled on/off in the LMB of the recipe. Bugfixes: - Fixed counts are hidden on disabled recipes, since editing them won't work properly. + - Accomodate modules as spoilage results. ---------------------------------------------------------------------------------------------------------------------- Version: 2.1.0 Date: October 29th 2024