From 03296cf3d47f21cf0c1ea2683ba87aa2c24054f9 Mon Sep 17 00:00:00 2001 From: Dale McCoy <21223975+DaleStan@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:27:51 -0500 Subject: [PATCH] fix: Check for some item misbehavior in Py's synthetic items. --- Yafc.Parser/Data/FactorioDataDeserializer.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Yafc.Parser/Data/FactorioDataDeserializer.cs b/Yafc.Parser/Data/FactorioDataDeserializer.cs index d6648889..02be027b 100644 --- a/Yafc.Parser/Data/FactorioDataDeserializer.cs +++ b/Yafc.Parser/Data/FactorioDataDeserializer.cs @@ -511,9 +511,13 @@ private void CalculateItemWeights() { if (item.weight != 0) { continue; } + if (item.stackSize == 0) { + continue; // Py's synthetic items sometimes have a stack size of 0. + } + Recipe? recipe = allObjects.OfType().FirstOrDefault(r => r.name == item.name); // Hidden recipes appear to be ignored by Factorio; a pistol weighs 100g, not the 200kg that would be expected from its stack size. - if (recipe?.products.Length > 0 && !recipe.hidden) { + if (recipe?.products.Length > 0 && recipe.ingredients.Length > 0 && !recipe.hidden) { float weight = 0; foreach (Ingredient ingredient in recipe.ingredients) { if (ingredient.goods is Item i) { @@ -543,9 +547,11 @@ private void CalculateItemWeights() { item.weight = rocketCapacity / (rocketCapacity / item.weight / item.stackSize) / item.stackSize; } - foreach (Item product in dependencies[item]) { - if (product.weight == 0) { - queue.Enqueue(product); + if (dependencies.TryGetValue(item, out List? products)) { + foreach (Item product in dependencies[item]) { + if (product.weight == 0) { + queue.Enqueue(product); + } } } }