Skip to content

Commit

Permalink
[FACTORIO 2.0] Added 8 new directions into defines.direction.
Browse files Browse the repository at this point in the history
If mods are storing any direction values in their storage, they will need to migrate them by multiplying by 2.
  • Loading branch information
hgschmie committed Oct 23, 2024
1 parent 0deb061 commit 0fcbe67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions stdlib/area/direction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Direction.southwest = defines.direction.southwest
-- @tparam defines.direction direction the direction
-- @treturn defines.direction the opposite direction
function Direction.opposite(direction)
return (direction + 4) % 8
return (direction + 8) % 16
end

--- Returns the next direction.
Expand All @@ -40,7 +40,7 @@ end
-- @tparam[opt=false] boolean eight_way true to get the next direction in 8-way (note: not many prototypes support 8-way)
-- @treturn defines.direction the next direction
function Direction.next(direction, eight_way)
return (direction + (eight_way and 1 or 2)) % 8
return (direction + (eight_way and 2 or 4)) % 16
end

--- Returns the previous direction.
Expand All @@ -49,14 +49,14 @@ end
-- @tparam[opt=false] boolean eight_way true to get the previous direction in 8-way (note: not many prototypes support 8-way)
-- @treturn defines.direction the next direction
function Direction.previous(direction, eight_way)
return (direction + (eight_way and -1 or -2)) % 8
return (direction + (eight_way and -2 or -4)) % 16
end

--- Returns an orientation from a direction.
-- @tparam defines.direction direction
-- @treturn float
function Direction.to_orientation(direction)
return direction / 8
return direction / 16
end

--- Returns a vector from a direction.
Expand Down Expand Up @@ -101,7 +101,7 @@ do
end

function Direction.next_direction(direction, reverse, eight_way)
return (direction + (eight_way and ((reverse and -1) or 1) or ((reverse and -2) or 2))) % 8
return (direction + (eight_way and ((reverse and -2) or 2) or ((reverse and -4) or 4))) % 16
end
end

Expand Down
20 changes: 10 additions & 10 deletions stdlib/area/orientation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ local Orientation = {
setmetatable(Orientation, Orientation)

--- north orientation
Orientation.north = defines.direction.north / 8
Orientation.north = defines.direction.north / 16
--- east orientation
Orientation.east = defines.direction.east / 8
Orientation.east = defines.direction.east / 16
--- west orientation
Orientation.west = defines.direction.west / 8
Orientation.west = defines.direction.west / 16
--- south orientation
Orientation.south = defines.direction.south / 8
Orientation.south = defines.direction.south / 16
--- northeast orientation
Orientation.northeast = defines.direction.northeast / 8
Orientation.northeast = defines.direction.northeast / 16
--- northwest orientation
Orientation.northwest = defines.direction.northwest / 8
Orientation.northwest = defines.direction.northwest / 16
--- southeast orientation
Orientation.southeast = defines.direction.southeast / 8
Orientation.southeast = defines.direction.southeast / 16
--- southwest orientation
Orientation.southwest = defines.direction.southwest / 8
Orientation.southwest = defines.direction.southwest / 16

local floor = math.floor

Expand All @@ -32,8 +32,8 @@ local floor = math.floor
-- @tparam[opt=false] boolean eight_way
-- @treturn defines.direction
function Orientation.to_direction(orientation, eight_way)
local ways = eight_way and 8 or 4
local mod = eight_way and 1 or 2
local ways = eight_way and 16 or 8
local mod = eight_way and 2 or 4
return floor(orientation * ways + 0.5) % ways * mod
end

Expand Down

0 comments on commit 0fcbe67

Please sign in to comment.