Skip to content

Commit

Permalink
Fix pyhard spoilage loading error (#344)
Browse files Browse the repository at this point in the history
Pyhard added spoiling recipes where the spoil result is a module. This
was not expected and caused loading errors
(#313 (comment)).
I fixed it by forcibly loading modules before anything else.
  • Loading branch information
shpaass authored Nov 5, 2024
2 parents 6afd3de + 9be6741 commit 48cc872
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Yafc.Model/Data/DataClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ public virtual bool HasSpentFuel([MaybeNullWhen(false)] out Item spent) {
}

public class Item : Goods {
/// <summary>
/// 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".
/// </summary>
/// <remarks>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.</remarks>
internal static string[] ExplicitPrototypeLoadOrder { get; } = ["module"];

public Item? fuelResult { get; internal set; }
public int stackSize { get; internal set; }
public Entity? placeResult { get; internal set; }
Expand Down
6 changes: 5 additions & 1 deletion Yafc.Parser/Data/FactorioDataDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 48cc872

Please sign in to comment.