diff --git a/modules/corelib/classes/callbackevent.lua b/modules/corelib/classes/callbackevent.lua deleted file mode 100644 index 8bcadf1f..00000000 --- a/modules/corelib/classes/callbackevent.lua +++ /dev/null @@ -1,44 +0,0 @@ ---[[ - @Authors: Ben Dol (BeniS) - @Details: CallbackEvent class shell for callback events -]] - -CallbackEvent = newclass("CallbackEvent") - -CallbackEvent.create = function(id, callback) - local event = CallbackEvent.internalCreate() - - event.id = id - event.callback = callback - - return event -end - --- gets/sets - ---@RequiredBy:Queue -function CallbackEvent:getId() - return self.id -end - ---@RequiredBy:Queue -function CallbackEvent:setId(id) - self.id = id -end - ---@RequiredBy:Queue -function CallbackEvent:getCallback() - return self.callback -end - ---@RequiredBy:Queue -function CallbackEvent:setCallback(callback) - self.callback = callback -end - --- logic - ---@RequiredBy:Queue -function CallbackEvent:start() - -- Do nothing by default -end diff --git a/modules/corelib/classes/queue.lua b/modules/corelib/classes/queue.lua deleted file mode 100644 index 7bb11edb..00000000 --- a/modules/corelib/classes/queue.lua +++ /dev/null @@ -1,70 +0,0 @@ ---[[ - @Authors: Ben Dol (BeniS) - @Details: Queue class for event queuing. -]] - -Queue = newclass("Queue") - -Queue.create = function(callback) - local obj = Queue.internalCreate() - - obj.queue = {} - obj.callback = callback - - return obj -end - --- gets/sets - -function Queue:getQueue() - return self.queue -end - -function Queue:setQueue(queue) - self.queue = queue -end - -function Queue:getCallback() - return self.callback -end - -function Queue:setCallback(callback) - self.callback = callback -end - --- logic - -function Queue:add(item) - table.insert(self.queue, item) -end - -function Queue:start() - local compiled = function() self:finished() end - for k,event in pairs(self.queue) do - print("Compiling " .. tostring(event:getId())) - local snip = compiled - compiled = function() - local realCallback = event:getCallback() - event:setCallback(function() - print("Event compiled callback called") - realCallback() - -- next queue item - snip() - end) - print("Event started from queue chain") - event:start() - end - end - -- Start the queue chain - print("Start compiled chain") - compiled() -end - -function Queue:finished() - print("Queue:finished") - local done = function() - local callback = self:getCallback() - if callback then callback() end - end - done() -end \ No newline at end of file diff --git a/modules/gamelib/position.lua b/modules/gamelib/position.lua index 3a428795..b41a0fa3 100644 --- a/modules/gamelib/position.lua +++ b/modules/gamelib/position.lua @@ -22,4 +22,16 @@ end function Position.isInRange(pos1, pos2, xRange, yRange) return math.abs(pos1.x-pos2.x) <= xRange and math.abs(pos1.y-pos2.y) <= yRange and pos1.z == pos2.z; +end + +function Position.isValid(pos) + return not (pos.x == 65535 and pos.y == 65535 and pos.z == 255) +end + +function Position.distance(pos1, pos2) + return math.sqrt(math.pow((pos2.x - pos1.x), 2) + math.pow((pos2.y - pos1.y), 2)) +end + +function Position.manhattanDistance(pos1, pos2) + return math.abs(pos2.x - pos1.x) + math.abs(pos2.y - pos1.y) end \ No newline at end of file