Afforess / Factorio-Stdlib

Factorio Standard Library Project
ISC License
162 stars 45 forks source link

Player force #96

Closed Nexela closed 7 years ago

Nexela commented 7 years ago

Adds Player and Force events, and a few other small things. Still need to write tests for it but stuff seems to be working.

Afforess commented 7 years ago

Looks fine but at some point I'd really like tests for the queue - implementing data structures without proper testing is just asking for bugs.

Nexela commented 7 years ago

Tests for Queue, Area, and Position are on my todo list. Area and Position have been tweaked to allow them to be used as objects. Area and Position are not pushed yet because I still need more core testing

local position1 = Position.to_table(entity.position) local position2 = Position.to_table(entity2.position) [x] game.print(tostring(position1)) -- prints {x = X, y = Y} [x] position1 == position2 -- false (unless it is true :)) [x] position1 + position2 -- modifies position1 by adding position2 to it [x] position1:add(position2) -- same as above [x] local position3 = position1:add(position2) -- same as above with position3 being a reference to position1 [x] position1:translate(0, 1) --return position1 moved 1 tile north

Some things still left on my todo .new() to remove the refrences and create new tables

Choumiko commented 7 years ago

[x] position1 + position2 -- modifies position1 by adding position2 to it [x] position1:add(position2) -- same as above [x] local position3 = position1:add(position2) -- same as above with position3 being a reference to position1

Not sure i like the idea of an addition changing one of the operands, if i understand correctly each of these operations would mutate position1 ? To me addition/subtraction are pure mathematical/functional and therefore shouldn't mess with the operands? Also (at least for the operator overwriting) it would make addition non commutative, since position1 + position2 -- {1,1} + {2,2} position1 + position3 -- {3,3} + {0,1} = {3,4} would lead to a different result than position2 + position1 -- {2,2} + {1,1} position1 + position3 -- {1,1} + {0,1} = {1,2}

Hope that makes sense, but as long as Position.add(pos1, pos2) still work as it does now i'm fine with it. Just recently started changing FARL to use Position, so i don't wanna touch it again too soon ;)

Nexela commented 7 years ago

Conversation moved to #97

Afforess commented 7 years ago

@Nexela Are you done with your changes here?

Nexela commented 7 years ago

Not quite, Need to figure out the error in player and write the tests but am on vacation with the kids for another day.

Nexela commented 7 years ago

I am going to clean up this PR this week and probably remove the player/force until such a time that I can write decent tests for it.

Afforess commented 7 years ago

I am strongly tempted to just give @Nexela push rights to the repository.