Skip to content

Commit f830cff

Browse files
authored
491: PyAL: some recipes show no icon (#497)
This fixes #491, along with the incorrect overlay offsets.
2 parents 8047634 + b01c5f4 commit f830cff

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

Yafc.Parser/Data/FactorioDataDeserializer.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,15 @@ private unsafe Icon CreateIconFromSpec(Dictionary<(string mod, string path), Int
299299
};
300300

301301
if (icon.x != 0) {
302-
targetRect.x = MathUtils.Clamp(targetRect.x + MathUtils.Round(icon.x * iconSize / icon.size), 0, iconSize - targetRect.w);
302+
// These two formulas have variously multiplied icon.x (or icon.y) by a scaling factor of iconSize / icon.size,
303+
// iconSize * icon.scale, or iconSize. (const int iconSize = 32)
304+
// Presumably the scaling factor had a purpose, but I can't find it. Py and Vanilla objects (e.g. Recipe.Moss-1 and
305+
// Entity.lane-splitter) draw correctly after removing the scaling factor.
306+
targetRect.x = MathUtils.Clamp(targetRect.x + MathUtils.Round(icon.x), 0, iconSize - targetRect.w);
303307
}
304308

305309
if (icon.y != 0) {
306-
targetRect.y = MathUtils.Clamp(targetRect.y + MathUtils.Round(icon.y * iconSize / icon.size), 0, iconSize - targetRect.h);
310+
targetRect.y = MathUtils.Clamp(targetRect.y + MathUtils.Round(icon.y), 0, iconSize - targetRect.h);
307311
}
308312

309313
SDL.SDL_Rect srcRect = new SDL.SDL_Rect {
@@ -737,31 +741,30 @@ private void DeserializeLocation(LuaTable table, ErrorCollector collector) {
737741
target.locDescr = LocalisedStringParser.ParseKey(prototypeType + "-description." + target.name, []);
738742
}
739743

740-
_ = table.Get("icon_size", out float defaultIconSize);
741-
742744
if (table.Get("icon", out string? s)) {
743-
target.iconSpec = [new FactorioIconPart(s) { size = defaultIconSize }];
745+
target.iconSpec = [new FactorioIconPart(s) { size = table.Get("icon_size", 64f) }];
744746
}
745747
else if (table.Get("icons", out LuaTable? iconList)) {
746748
target.iconSpec = [.. iconList.ArrayElements<LuaTable>().Select(x => {
747749
if (!x.Get("icon", out string? path)) {
748750
throw new NotSupportedException($"One of the icon layers for {name} does not have a path.");
749751
}
750752

751-
FactorioIconPart part = new FactorioIconPart(path);
752-
_ = x.Get("icon_size", out part.size, defaultIconSize);
753-
_ = x.Get("scale", out part.scale, 1f);
753+
FactorioIconPart part = new(path) {
754+
size = x.Get("icon_size", 64f),
755+
scale = x.Get("scale", 1f)
756+
};
754757

755758
if (x.Get("shift", out LuaTable? shift)) {
756-
_ = shift.Get(1, out part.x);
757-
_ = shift.Get(2, out part.y);
759+
part.x = shift.Get<float>(1);
760+
part.y = shift.Get<float>(2);
758761
}
759762

760763
if (x.Get("tint", out LuaTable? tint)) {
761-
_ = tint.Get("r", out part.r, 1f);
762-
_ = tint.Get("g", out part.g, 1f);
763-
_ = tint.Get("b", out part.b, 1f);
764-
_ = tint.Get("a", out part.a, 1f);
764+
part.r = tint.Get("r", 1f);
765+
part.g = tint.Get("g", 1f);
766+
part.b = tint.Get("b", 1f);
767+
part.a = tint.Get("a", 1f);
765768
}
766769

767770
return part;

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Date:
2121
Features:
2222

2323
Fixes:
24-
24+
- Fix icon rendering.
2525
----------------------------------------------------------------------------------------------------------------------
2626
Version: 2.14.0
2727
Date: June 15th 2025

0 commit comments

Comments
 (0)