[0.18.10] Game accepts items that don't conform to the prototype definition

Bugs that are actually features.
Post Reply
User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 726
Joined: Sun Mar 13, 2016 9:48 am
Contact:

[0.18.10] Game accepts items that don't conform to the prototype definition

Post by DRY411S »

At https://wiki.factorio.com/Types/IconSpecification there are 2 options.


There is at least one mod out there that implements something like this:

Code: Select all

icon = "__base__/graphics/icons/foo.png",
icons = {
  {
    icon = "__base__/graphics/icons/foo2.png",
    icon_size = 32
  },
  {
    icon = "__base__/graphics/icons/foo3.png",
    icon_size = 32
    tint = { a = 0.75,  b = 0, g = 0, r = 0 }
  },
  {
    icon = "__base__/graphics/icons/foo4.png",
    icon_size = 32
    tint = { a = 0.75, b = 0.5, g = 0.5, r = 0.5 }
  }
}
The specification mandates that if icon is specified, then icon_size is mandatory and must also be present. It is however possible to implement the above where the specification has not been followed, and icon_size is missing when icon is present.

Mods should use 1 IconSpecification option or another, not all of one and part of another. It appears that the game base code recognises the IconSpecification Option 1, and 'forgives' the bad implementation of Option 2.

I would like the base game to reject mod code like the above that does not conform to specification

[EDIT]. Sorry my example code is wrong. It was missing the icon_size completely!
Last edited by DRY411S on Sun Mar 15, 2020 9:58 am, edited 1 time in total.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by Optera »

Correct me if I misread your post.
You defined prototype.icon and prototype.icons, but not prototype.icon_size

With icons set, icon and icon_size are ignored entirely.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 726
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by DRY411S »

Optera wrote: ↑
Sun Mar 15, 2020 6:19 am
Correct me if I misread your post.
You defined prototype.icon and prototype.icons, but not prototype.icon_size
It wasn't me, it was somebody else. :)
Optera wrote: ↑
Sun Mar 15, 2020 6:19 am
With icons set, icon and icon_size are ignored entirely.
That isn't what the specification says. It says there are 2 options. It doesn't say that if Option 1 is used then an incorrect implementation of Option 2 is ignored. :)

My issue with this is that I have to put code in my mod that identifies when other mods have incorrectly implemented off specification. I would rather the base game code errored on the off-specification mods instead of mine crashing. :D

[Edit] I've also contacted mod authors and asked them to use the correct specification. If they have stuff in their mods that the game is ignoroing, they should remove it.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2916
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by Optera »

I too have mods that have to handle this weirdness, but haven't had any problems with ignoring icon in presence of icons

Code: Select all

if icons then
--use icons
elseif icon and icon_size
-- use icon and icon_size
else 
-- error
end
The specification could be clearer, but I'm fairly certain that's how the base works too.

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by posila »

Can't reproduce.
icon_size_missing.png
icon_size_missing.png (8.62 KiB) Viewed 1778 times

Code: Select all

  {
    type = "item",
    name = "fast-transport-belt",
    --icon_size = 64, icon_mipmaps = 4,
    icon = "__base__/graphics/icons/foo.png",
    icons = {
      {
        icon = "__base__/graphics/icons/foo2.png"
      },
      {
        icon = "__base__/graphics/icons/foo3.png",
        tint = { a = 0.75,  b = 0, g = 0, r = 0 }
      },
      {
        icon = "__base__/graphics/icons/foo4.png",
        tint = { a = 0.75, b = 0.5, g = 0.5, r = 0.5 }
      }
    },
    subgroup = "belt",
    order = "a[transport-belt]-b[fast-transport-belt]",
    place_result = "fast-transport-belt",
    stack_size = 100
  },

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 726
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by DRY411S »

posila wrote: ↑
Sun Mar 15, 2020 9:05 am
Can't reproduce.

icon_size_missing.png

Code: Select all

  {
    type = "item",
    name = "fast-transport-belt",
    --icon_size = 64, icon_mipmaps = 4,
    icon = "__base__/graphics/icons/foo.png",
    icons = {
      {
        icon = "__base__/graphics/icons/foo2.png"
      },
      {
        icon = "__base__/graphics/icons/foo3.png",
        tint = { a = 0.75,  b = 0, g = 0, r = 0 }
      },
      {
        icon = "__base__/graphics/icons/foo4.png",
        tint = { a = 0.75, b = 0.5, g = 0.5, r = 0.5 }
      }
    },
    subgroup = "belt",
    order = "a[transport-belt]-b[fast-transport-belt]",
    place_result = "fast-transport-belt",
    stack_size = 100
  },
Put icon_size in the icons { } table

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by posila »

Code: Select all

  {
    type = "item",
    name = "fast-transport-belt",
    --icon_size = 64, icon_mipmaps = 4,
    icon = "__base__/graphics/icons/foo.png",
    icons = {
      icon_size = 64,
      {
        icon = "__base__/graphics/icons/foo2.png"
      },
      {
        icon = "__base__/graphics/icons/foo3.png",
        tint = { a = 0.75,  b = 0, g = 0, r = 0 }
      },
      {
        icon = "__base__/graphics/icons/foo4.png",
        tint = { a = 0.75, b = 0.5, g = 0.5, r = 0.5 }
      }
    },
    subgroup = "belt",
    order = "a[transport-belt]-b[fast-transport-belt]",
    place_result = "fast-transport-belt",
    stack_size = 100
  },
Same error

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 726
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by DRY411S »

posila wrote: ↑
Sun Mar 15, 2020 9:38 am

Code: Select all

  {
    type = "item",
    name = "fast-transport-belt",
    --icon_size = 64, icon_mipmaps = 4,
    icon = "__base__/graphics/icons/foo.png",
    icons = {
      icon_size = 64,
      {
        icon = "__base__/graphics/icons/foo2.png"
      },
      {
        icon = "__base__/graphics/icons/foo3.png",
        tint = { a = 0.75,  b = 0, g = 0, r = 0 }
      },
      {
        icon = "__base__/graphics/icons/foo4.png",
        tint = { a = 0.75, b = 0.5, g = 0.5, r = 0.5 }
      }
    },
    subgroup = "belt",
    order = "a[transport-belt]-b[fast-transport-belt]",
    place_result = "fast-transport-belt",
    stack_size = 100
  },
Same error
I'm really sorry, I pasted the wrong sample code at the start of the topic. I have corrected it. The code should have included icon_size entries for every icon in the icons table.

OK. Please place the icon_size inside every icon entry in the icons table, so:

Code: Select all

  {
    type = "item",
    name = "fast-transport-belt",
    --icon_size = 64, icon_mipmaps = 4,
    icon = "__base__/graphics/icons/foo.png",
    icons = {
      {
        icon = "__base__/graphics/icons/foo2.png",
      icon_size = 64
      },
      {
        icon = "__base__/graphics/icons/foo3.png",
      icon_size = 64,
        tint = { a = 0.75,  b = 0, g = 0, r = 0 }
      },
      {
        icon = "__base__/graphics/icons/foo4.png",
      icon_size = 64,
        tint = { a = 0.75, b = 0.5, g = 0.5, r = 0.5 }
      }
    },
    subgroup = "belt",
    order = "a[transport-belt]-b[fast-transport-belt]",
    place_result = "fast-transport-belt",
    stack_size = 100
  },
That is the construct I am seeing that is not throwing an error. It appears in this mod >>> https://mods.factorio.com/mod/team_competition

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by posila »

I see. That's a valid definition. I have added information about icons taking priority over icon into the wiki page.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 726
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by DRY411S »

posila wrote: ↑
Sun Mar 15, 2020 10:03 am
I see. That's a valid definition. I have added information about icons taking priority over icon into the wiki page.
Ok thanks. I can amend my mod with confidence now.

User avatar
DRY411S
Filter Inserter
Filter Inserter
Posts: 726
Joined: Sun Mar 13, 2016 9:48 am
Contact:

Re: [0.18.10] Game accepts items that don't conform to the prototype definition

Post by DRY411S »

Optera wrote: ↑
Sun Mar 15, 2020 6:41 am
I too have mods that have to handle this weirdness, but haven't had any problems with ignoring icon in presence of icons

Code: Select all

if icons then
--use icons
elseif icon and icon_size
-- use icon and icon_size
else 
-- error
end
The specification could be clearer, but I'm fairly certain that's how the base works too.
You still need to use icon_size though if it is present, since it does not have to be contained in icons

Post Reply

Return to β€œNot a bug”