70 lines
1.1 KiB
Lua
70 lines
1.1 KiB
Lua
local Direction = require("lib.direction")
|
|
|
|
---@class Position
|
|
---@field x number
|
|
---@field y number
|
|
---@field z number
|
|
---@field dir Direction
|
|
local Position = {}
|
|
Position.__index = Position
|
|
|
|
---@return Position
|
|
function Position:Empty()
|
|
local t = {}
|
|
setmetatable(t, Position)
|
|
|
|
t.x = 0
|
|
t.y = 0
|
|
t.z = 0
|
|
t.dir = Direction.NORTH
|
|
|
|
return t
|
|
end
|
|
|
|
---@param x number
|
|
---@param y number
|
|
---@param z number
|
|
---@param dir Direction
|
|
---@return Position
|
|
function Position:Create(x, y, z, dir)
|
|
local t = {}
|
|
setmetatable(t, Position)
|
|
|
|
t.x = x
|
|
t.y = y
|
|
t.z = z
|
|
t.dir = dir or Direction.NORTH
|
|
|
|
return t
|
|
end
|
|
|
|
---@param other Position
|
|
---@return Position
|
|
function Position:Copy(other)
|
|
local t = {}
|
|
setmetatable(t, Position)
|
|
|
|
t.x = other.x
|
|
t.y = other.y
|
|
t.z = other.z
|
|
t.dir = other.dir
|
|
|
|
return t
|
|
end
|
|
|
|
---@param other Position
|
|
function Position:Add(other)
|
|
self.x = self.x + other.x
|
|
self.y = self.y + other.y
|
|
self.z = self.z + other.z
|
|
end
|
|
|
|
---@param other Position
|
|
function Position:Subtract(other)
|
|
self.x = self.x - other.x
|
|
self.y = self.y - other.y
|
|
self.z = self.z - other.z
|
|
end
|
|
|
|
return Position
|