Do we need so many variants of position and area?
Posted: Wed Oct 19, 2016 5:45 pm
Code: Select all
-- position formats:
(x, y) -- methods only
{x, y}
{x=x, y=y}
-- area formats:
{{x,y}, {x,y}}
{{x=x, y=y}, {x=x, y=y}}
{left_top = {x,y}, right_bottom = {x,y}}
{left_top = {x=x, y=y}, right_bottom = {x=x, y=y}}
Code: Select all
local x, y, lt, rb = 1, 2, 1, 2
pos = {3,4}
area = {{5,6}, {7,8}}
pos[x] -- pos[1] = 3
aera[rb][y] -- area[2][2] = 8
The downside is that code becomes slightly less legible (example: `foo[x]` or `foo[1]` instead of `foo.x`), but it will remove loads of branching code, particularly in reuseable library functions (eg. Factorio StdLib) and remote interfaces. It will also simplify documentation - all areas and positions will be same format. Methods that currently take an (x,y) will change to only accept {x,y}, etc. That's going to break many mods, but it's trivial type of thing to fix.
Maybe something to consider for 0.15?
Related discussion on github: https://github.com/Afforess/Factorio-St ... -254750890