@@ -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 ;
0 commit comments