Do we need so many variants of position and area?

Place to post guides, observations, things related to modding that are not mods themselves.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Do we need so many variants of position and area?

Post by aubergine18 »

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}}
Would it be easier to make everything use a single format for position objects and a single format for table objects?

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
This would make working with positions, and especially areas, much easier as there's only ever one format for the objects. It's also consistent with the way prototype collision_box, selection_box, window_box, etc., are defined.

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
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding discussion”