[2.0.77] util.add_shift only supports array format

Post your bugs and problems so we can fix them.
User avatar
PennyJim
Fast Inserter
Fast Inserter
Posts: 171
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: 171
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
Post Reply

Return to “Bug Reports”