Skip to content

Commit

Permalink
Refactor OutTheWindow_Utils.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
quarantin committed Dec 26, 2021
1 parent e5d01f1 commit bbbf49d
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions media/lua/client/OutTheWindow/OutTheWindow_Utils.lua
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
local function getNorth(window)
return window.getNorth and window:getNorth() or window:isNorthHoppable()
end

local function getOppositeSquare(window, x, y, z)
return getNorth(window) and getSquare(x, y - 1, z) or getSquare(x - 1, y, z)
end
return {
getDropSquare = function(player, window)

local function getDropSquare(player, window)
local sq1, sq2, selected

local dropSquare, floorSquare, oppositeSquare
local playerSquare = player:getSquare()
local px, py, pz = playerSquare:getX(), playerSquare:getY(), playerSquare:getZ()

local playerSquare = player:getSquare()
local windowSquare = window:getSquare()
local x, y, z = windowSquare:getX(), windowSquare:getY(), windowSquare:getZ()
local oppositeSquare = getOppositeSquare(window, x, y, z)
local windowSquare = window:getSquare()
local wx, wy, wz = windowSquare:getX(), windowSquare:getY(), windowSquare:getZ()

if getNorth(window) then
dropSquare = getSquare(x, y + 1, z)
else
dropSquare = getSquare(x + 1, y, z)
end

local dropSquare = playerSquare:equals(windowSquare) and oppositeSquare or dropSquare
if window.getNorth and window:getNorth() or window:isNorthHoppable() then
sq1 = getSquare(wx, wy + 1, wz)
sq2 = getSquare(wx, wy - 1, wz)
selected = (py >= wy) and sq2 or sq1
else
sq1 = getSquare(wx + 1, wy, wz)
sq2 = getSquare(wx - 1, wy, wz)
selected = (px >= wx) and sq2 or sq1
end

x = dropSquare:getX()
y = dropSquare:getY()
x = selected:getX()
y = selected:getY()

for z = dropSquare:getZ(), 0, -1 do
floorSquare = getSquare(x, y, z)
if floorSquare:isSolidFloor() then
return floorSquare
for z = selected:getZ(), 0, -1 do
local floorSquare = getSquare(x, y, z)
if floorSquare:isSolidFloor() then
return floorSquare
end
end
end

error('This should never happen!')
end

return {
getDropSquare = getDropSquare,
error('This should never happen!')
end
}

0 comments on commit bbbf49d

Please sign in to comment.