[2.0.77] util.add_shift only supports array format

Bugs that are actually features.
User avatar
PennyJim
Fast Inserter
Fast Inserter
Posts: 175
Joined: Wed Jan 18, 2023 3:49 am
Contact:

[2.0.77] util.add_shift only supports array format

Post by PennyJim »

I was going through FMTK's annotations for util.lua and was comparing them to the actual functions.
I noticed the util.add_shift seems to only take the array form of the Vector type or Vector concept. It can only be assumed it was intended on being used in the shift of graphics definitions, and can subsequently fail in those applications.

The fix would be to rewrite it as something like this:

Code: Select all

function util.add_shift(a, b)
  if not (a and b) then
    return a or b
  end
  return {
    (a[1] or a.x) + (b[1] or b.x),
    (a[2] or a.y) + (b[2] or b.y)
  }
end
If you decide you're not going to change that in case it somehow breaks pre-existing uses of it. Please say so, so I can update the annotations accordingly to prevent people from accidentally give it the structured form of a Vector (if they're paying attention to type annotation).
User avatar
PennyJim
Fast Inserter
Fast Inserter
Posts: 175
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: [2.0.77] util.add_shift only supports array format

Post by PennyJim »

I'll add that util.sprite_load also only supports the array format for shift. Although, considering that it isn't expected to work on arbitrary prototype data, but instead special file inputs, I think that one's not that much of an issue. Would prefer the consistency though
Rseding91
Factorio Staff
Factorio Staff
Posts: 17238
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.77] util.add_shift only supports array format

Post by Rseding91 »

Thanks for the repeort however unless another developer decides they want to make these changes I'm going to decide this is fine to work how it does. The util library is not intended to be a bullet proof works on every possible kind of input provided set of functions. It was and is mainly made for base game and base game scenarios to use and if mods happen to find it useful that's also nice.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Not a bug”