Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pStorage
- local pSave
- local currentDirectionPrivate
- local api = {}
- local NAN = 0 / 0
- turtle_unhooked_turnLeft = installPreExecutionHook(turtle, "turnLeft", "smartGPS", function()
- if currentDirectionPrivate then
- setCurrentDirection(getCurrentDirection() - 1)
- end
- end)
- turtle_unhooked_turnRight = installPreExecutionHook(turtle, "turnRight", "smartGPS", function()
- if currentDirectionPrivate then
- setCurrentDirection(getCurrentDirection() + 1)
- end
- end)
- function api.moveTo(pos, direction)
- local path = findPath(gpsAdapter.locate(), pos)
- if not path then
- error("no path found")
- end
- local cleared = false
- while not followPath(path) do
- path = findPath(gpsAdapter.locate(), pos)
- while not path do
- if not cleared then
- resetCuboids()
- path = findPath(gpsAdapter.locate(), pos)
- cleared = true
- else
- error("no path found")
- end
- end
- end
- turnTowardsDirection(direction)
- pSave()
- end
- function api.locate()
- return toTurtiArray(gpsAdapter.locate())
- end
- function api.getDirection()
- return getCurrentDirection()
- end
- function api.setDirection(direction)
- turnTowardsDirection(direction)
- end
- function faceTowardAny(positions)
- local possiblePositions = {}
- for i, pos in ipairs(positions) do
- table.insert(possiblePositions, { pos[1] - 1, pos[2], pos[3] }) -- direction 0
- table.insert(possiblePositions, { pos[1], pos[2], pos[3] - 1 }) -- direction 1
- table.insert(possiblePositions, { pos[1] + 1, pos[2], pos[3] }) -- direction 2
- table.insert(possiblePositions, { pos[1], pos[2], pos[3] + 1 }) -- direction 3
- end
- local cleared = false
- while true do
- local path, index = findPathToAny(gpsAdapter.locate(), possiblePositions)
- if path then
- if followPath(path) then
- turnTowardsDirection((index - 1) % 4)
- return math.floor((index - 1) / 4)
- end
- else
- if not cleared then
- resetCuboids()
- cleared = true
- else
- error("no path found")
- end
- end
- end
- end
- function api.faceToward(pos)
- local possiblePositions = {
- { pos[1] - 1, pos[2], pos[3] }, -- direction 0
- { pos[1], pos[2], pos[3] - 1 }, -- direction 1
- { pos[1] + 1, pos[2], pos[3] }, -- direction 2
- { pos[1], pos[2], pos[3] + 1 } -- direction 3
- }
- while true do
- local path, index = findPathToAny(gpsAdapter.locate(), possiblePositions)
- if path then
- if followPath(path) then
- turnTowardsDirection(index - 1)
- return
- end
- else
- if not cleared then
- resetCuboids()
- cleared = true
- else
- error("no path found")
- end
- end
- end
- end
- function api.faceTowardAny(...)
- return faceTowardAny({ ... })
- end
- function api.getPosInDirection(pos, direction)
- return toTurtiArray(getPosInDirection(pos, direction))
- end
- --[[function followPathOld(path)
- for i = 2, #path do
- local direction = getDirectionFromPoints(path[i - 1], path[i])
- if not moveInDirection(direction) then
- markAsObstructed(path[i])
- return false
- end
- end
- return true
- end]]
- function getPosInDirection(pos, direction, count)
- if not count then
- count = 1
- end
- if direction == 0 then
- return { pos[1] + count, pos[2], pos[3] }
- elseif direction == 1 then
- return { pos[1], pos[2], pos[3] + count }
- elseif direction == 2 then
- return { pos[1] - count, pos[2], pos[3] }
- elseif direction == 3 then
- return { pos[1], pos[2], pos[3] - count }
- elseif direction == 4 then
- return { pos[1], pos[2] + count, pos[3] }
- elseif direction == 5 then
- return { pos[1], pos[2] - count, pos[3] }
- end
- end
- function moveInDirection(direction, count)
- if count == 0 then
- return 0
- end
- if direction == 4 then
- for i = 1, count do
- if not turtle.up() then
- return i - 1
- end
- end
- elseif direction == 5 then
- for i = 1, count do
- if not turtle.down() then
- return i - 1
- end
- end
- else
- turnTowardsDirection(direction)
- for i = 1, count do
- if not turtle.forward() then
- return i - 1
- end
- end
- end
- return count
- end
- function getCurrentDirection()
- if currentDirectionPrivate then
- return currentDirectionPrivate
- end
- local directionShift = 0
- local currentPos = gpsAdapter.locate()
- local testY = 3
- local currentY = 0
- for y = 1, testY do
- for i = 0, 5 do
- if turtle.forward() then
- currentDirectionPrivate = getDirectionFromPoints(currentPos, gpsAdapter.locate())
- turtle.back()
- break
- end
- turtle_unhooked_turnLeft()
- directionShift = directionShift + 1
- end
- if currentDirectionPrivate then
- break
- end
- if turtle.up() then
- currentY = currentY + 1
- else
- break
- end
- end
- while currentY > 0 do
- turtle.down()
- currentY = currentY - 1
- end
- if currentDirectionPrivate then
- for _ = 1, directionShift do
- turtle.turnRight()
- end
- return currentDirectionPrivate
- end
- for y = 1, testY do
- for i = 0, 5 do
- if turtle.forward() then
- currentDirectionPrivate = getDirectionFromPoints(currentPos, gpsAdapter.locate())
- turtle.back()
- break
- end
- turtle_unhooked_turnLeft()
- directionShift = directionShift + 1
- end
- if currentDirectionPrivate then
- break
- end
- if turtle.down() then
- currentY = currentY - 1
- else
- break
- end
- end
- while currentY < 0 do
- turtle.up()
- currentY = currentY + 1
- end
- if not currentDirectionPrivate then
- error("turtle is trapped!")
- end
- for _ = 1, directionShift do
- turtle.turnRight()
- end
- return currentDirectionPrivate
- end
- function setCurrentDirection(cD)
- while cD > 3 do
- cD = cD - 4
- end
- while cD < 0 do
- cD = cD + 4
- end
- currentDirectionPrivate = cD
- end
- function turnTowardsDirection(direction)
- while direction > 3 do
- direction = direction - 4
- end
- while direction < 0 do
- direction = direction + 4
- end
- if direction == 4 or direction == 5 then
- return
- end
- local turnLeftDirection = getCurrentDirection() + 3
- if turnLeftDirection > 3 then
- turnLeftDirection = turnLeftDirection - 4
- end
- if turnLeftDirection == direction then
- turtle.turnLeft()
- end
- while getCurrentDirection() ~= direction do
- turtle.turnRight()
- end
- end
- function getDirectionFromPoints(pos1, pos2)
- if pos2[1] == pos1[1] + 1 then
- return 0
- elseif pos2[3] == pos1[3] + 1 then
- return 1
- elseif pos2[1] == pos1[1] - 1 then
- return 2
- elseif pos2[3] == pos1[3] - 1 then
- return 3
- elseif pos2[2] == pos1[2] + 1 then
- return 4
- elseif pos2[2] == pos1[2] - 1 then
- return 5
- else
- printTable(pos1)
- printTable(pos2)
- error("cannot determine direction from points")
- end
- end
- function yield()
- if not test then
- os.queueEvent("randomEvent")
- os.pullEvent()
- end
- end
- function followPath(path)
- local directions = { 0, 4, 1, 2, 5, 3 }
- for i = 2, #path do
- local pos1 = path[i - 1][1]
- local pos2 = path[i][1]
- local axes = {}
- for iA = 1, 3 do
- if iA ~= path[i - 1][2] then
- table.insert(axes, iA)
- end
- end
- table.insert(axes, path[i - 1][2])
- printTable(path[i - 1])
- printTable(path[i])
- local pos = pos1
- for _, axis in ipairs(axes) do
- local dirP = directions[axis]
- local dirN = directions[axis + 3]
- local count = math.abs(pos2[axis] - pos1[axis])
- if pos2[axis] > pos1[axis] then
- local moved = moveInDirection(dirP, count)
- if moved ~= count then
- markAsObstructed(getPosInDirection(pos, dirP, moved + 1))
- return false
- end
- pos = getPosInDirection(pos1, dirP, moved)
- elseif pos2[axis] < pos1[axis] then
- local moved = moveInDirection(dirN, count)
- if moved ~= count then
- markAsObstructed(getPosInDirection(pos, dirN, moved + 1))
- return false
- end
- pos = getPosInDirection(pos1, dirN, moved)
- end
- end
- end
- return true
- end
- function findPath(start, destination)
- local startNode = { start, findCuboidContainingPos(start) }
- local destinationNode = { destination, findCuboidContainingPos(destination) }
- if startNode[2] == destinationNode[2] then
- return { { startNode[1], 3 }, { destinationNode[1], 3 } }
- end
- local openNodesQueue = {}
- local openNodes = {}
- local closedNodes = {}
- table.insert(openNodesQueue, { node = startNode, identifier = nodeToIdentifier(startNode), f = 0, g = 0, pre = nil })
- openNodes[openNodesQueue[1].identifier] = openNodesQueue[1]
- while (true) do
- table.sort(openNodesQueue, function(a, b)
- return a.f < b.f
- end)
- if #openNodesQueue > 10000 then
- return nil
- end
- local currentNode = table.remove(openNodesQueue, 1)
- if not currentNode then
- return nil
- end
- if posEquals(currentNode.node[1], destination) then
- return getPathFromNode(currentNode)
- end
- closedNodes[currentNode.identifier] = true
- aStarExpandNode(currentNode, openNodesQueue, openNodes, closedNodes, destinationNode)
- end
- end
- function aStarExpandNode(currentEntry, openNodesQueue, openNodes, closedNodes, destinationNode)
- for _, successorNode in ipairs(getSuccessorNodes(currentEntry.node, destinationNode)) do
- local identifier = nodeToIdentifier(successorNode)
- if not closedNodes[identifier] then
- local g = currentEntry.g + getPointDistance(currentEntry.node[1], successorNode[1])
- if openNodes[identifier] and g > openNodes[identifier].g then
- else
- local f = g + getPointDistance(successorNode[1], destinationNode[1])
- if openNodes[identifier] then
- local entry = openNodes[identifier]
- entry.g = g
- entry.f = f
- entry.pre = currentEntry
- else
- local entry = { node = successorNode, identifier = identifier, f = f, g = g, pre = currentEntry }
- table.insert(openNodesQueue, entry)
- openNodes[identifier] = entry
- end
- end
- end
- end
- end
- function getSuccessorNodes(currentNode, destinationNode)
- local pos = currentNode[1]
- local cuboid = currentNode[2]
- local successors = {}
- for _, connectedCuboid in ipairs(cuboid[7]) do
- local successorPos = getClosestPositionInCuboid(pos, connectedCuboid)
- table.insert(successors, { successorPos, connectedCuboid })
- if connectedCuboid == destinationNode[2] then
- table.insert(successors, destinationNode)
- end
- end
- return successors
- end
- function getClosestPositionInCuboid(pos, cuboid)
- return { putNumInRange(pos[1], cuboid[1], cuboid[4]), putNumInRange(pos[2], cuboid[2], cuboid[5]), putNumInRange(pos[3], cuboid[3], cuboid[6]) }
- end
- function putNumInRange(num, min, max)
- if min == min and num < min then
- return min
- elseif max == max and max <= num then
- return max - 1
- else
- return num
- end
- end
- --[[
- function aStarExpandNode(currentNode, openNodesQueue, openNodes, closedNodes, destination)
- for i, successor in ipairs(getSuccessors(currentNode)) do
- local identifier = posToIdentifier(successor)
- if not closedNodes[identifier] then
- local g = currentNode.g + 1
- if openNodes[identifier] and g > openNodes[identifier].g then
- else
- local f = g + aStarH(successor, destination)
- if openNodes[identifier] then
- local entry = openNodes[identifier]
- entry.g = g
- entry.f = f
- entry.pre = currentNode
- else
- local entry = { pos = successor, identifier = identifier, f = f, g = g, pre = currentNode }
- table.insert(openNodesQueue, entry)
- openNodes[identifier] = entry
- end
- end
- end
- end
- end
- ]]
- function getPathFromNode(node)
- local path = {}
- local nextNode
- local currentNode = node
- while currentNode do
- if nextNode then
- local overlappingDirection = getOverlappingCuboidDirection(nextNode.node[2], currentNode.node[2])
- table.insert(path, 1, {getPosInDirection(nextNode.node[1], overlappingDirection), 1})
- table.insert(path, 1, { currentNode.node[1], getOverlappingCuboidAxis(currentNode.node[2], nextNode.node[2]) })
- else
- table.insert(path, 1, { currentNode.node[1] })
- end
- nextNode = currentNode
- currentNode = currentNode.pre
- end
- return path
- end
- function nodeToIdentifier(node)
- local pos = node[1]
- return pos[1] .. "_" .. pos[2] .. "_" .. pos[3] .. "_" .. node[2][8]
- end
- function getPointDistance(p1, p2)
- return math.abs(p2[1] - p1[1]) + math.abs(p2[2] - p1[2]) + math.abs(p2[3] - p1[3])
- end
- --[[function findPath(start, destination)
- local openNodesQueue = {}
- local openNodes = {}
- local closedNodes = {}
- table.insert(openNodesQueue, { pos = start, identifier = posToIdentifier(start), f = 0, g = 0, pre = nil })
- openNodes[openNodesQueue[1].identifier] = openNodesQueue[1]
- while (true) do
- table.sort(openNodesQueue, function(a, b)
- return a.f < b.f
- end)
- if #openNodesQueue > 1000 then
- return nil
- end
- yield()
- local currentNode = table.remove(openNodesQueue, 1)
- if not currentNode then
- return nil
- end
- if posEquals(currentNode.pos, destination) then
- return getPathFromNode(currentNode)
- end
- closedNodes[currentNode.identifier] = true
- aStarExpandNode(currentNode, openNodesQueue, openNodes, closedNodes, destination)
- end
- end
- function getPathFromNode(endNode)
- local path = {}
- local currentNode = endNode
- while currentNode do
- table.insert(path, 1, currentNode.pos)
- currentNode = currentNode.pre
- end
- return path
- end
- function aStarExpandNode(currentNode, openNodesQueue, openNodes, closedNodes, destination)
- for i, successor in ipairs(getSuccessors(currentNode)) do
- local identifier = posToIdentifier(successor)
- if not closedNodes[identifier] then
- local g = currentNode.g + 1
- if openNodes[identifier] and g > openNodes[identifier].g then
- else
- local f = g + aStarH(successor, destination)
- if openNodes[identifier] then
- local entry = openNodes[identifier]
- entry.g = g
- entry.f = f
- entry.pre = currentNode
- else
- local entry = { pos = successor, identifier = identifier, f = f, g = g, pre = currentNode }
- table.insert(openNodesQueue, entry)
- openNodes[identifier] = entry
- end
- end
- end
- end
- end
- function aStarH(start, destination)
- return math.abs(destination[1] - start[1]) + math.abs(destination[2] - start[2]) + math.abs(destination[3] - start[3])
- end
- function getSuccessors(node)
- local pos = node.pos
- local x = pos[1]
- local y = pos[2]
- local z = pos[3]
- local potentialSuccessors = {
- { x + 1, y, z },
- { x - 1, y, z },
- { x, y + 1, z },
- { x, y - 1, z },
- { x, y, z + 1 },
- { x, y, z - 1 }
- }
- local successors = {}
- for i, v in ipairs(potentialSuccessors) do
- if not isObstructed(v) then
- table.insert(successors, v)
- end
- end
- return successors
- end
- function posToIdentifier(pos)
- return pos[1] .. ":" .. pos[2] .. ":" .. pos[3]
- end]]
- --[[function findPathToAny(start, destinations)
- local allOpenNodesQueues = {}
- local allOpenNodes = {}
- local allClosedNodes = {}
- local activeRoutes = {}
- for i, destination in pairs(destinations) do
- local openNodesQueue = {}
- local openNodes = {}
- table.insert(openNodesQueue, { pos = start, identifier = posToIdentifier(start), f = 0, g = 0, pre = nil })
- openNodes[openNodesQueue[1].identifier] = openNodesQueue[1]
- table.insert(allOpenNodesQueues, openNodesQueue)
- table.insert(allOpenNodes, openNodes)
- table.insert(allClosedNodes, {})
- table.insert(activeRoutes, true)
- end
- while (true) do
- local anyActive = false
- for i = 1, #activeRoutes do
- if activeRoutes[i] then
- anyActive = true
- local openNodesQueue = allOpenNodesQueues[i]
- local openNodes = allOpenNodes[i]
- local closedNodes = allClosedNodes[i]
- table.sort(openNodesQueue, function(a, b)
- return a.f < b.f
- end)
- yield()
- if #openNodesQueue > 1000 then
- activeRoutes[i] = false
- else
- local currentNode = table.remove(openNodesQueue, 1)
- if not currentNode then
- activeRoutes[i] = false
- else
- if posEquals(currentNode.pos, destinations[i]) then
- return getPathFromNode(currentNode), i
- end
- closedNodes[currentNode.identifier] = true
- aStarExpandNode(currentNode, openNodesQueue, openNodes, closedNodes, destinations[i])
- end
- end
- end
- end
- if not anyActive then
- return false
- end
- end
- end]]
- function posEquals(pos1, pos2)
- return pos1[1] == pos2[1] and pos1[2] == pos2[2] and pos1[3] == pos2[3]
- end
- --[[function isObstructed(pos)
- local blocks = pStorage.blocks
- if not blocks then
- return false
- end
- blocks = blocks[pos[1]]--[[
- if not blocks then
- return false
- end
- blocks = blocks[pos[2]]--[[
- if not blocks then
- return false
- end
- blocks = blocks[pos[3]]--[[
- if not blocks then
- return false
- end
- return true
- end]]
- function resetCuboids()
- print("reset cuboids")
- pStorage.cuboids = { { NAN, NAN, NAN, NAN, NAN, NAN, {}, 1 } }
- end
- function markAsObstructed(pos)
- local cuboid = findCuboidContainingPos(pos)
- local newCuboids = splitCuboidAtPos(cuboid, pos)
- local numNewCuboids = #newCuboids
- -- delete
- for _, connectedCuboid in pairs(cuboid[7]) do
- removeValue(connectedCuboid[7], cuboid)
- for _, c in pairs(newCuboids) do
- if areCuboidsAdjacent(c, connectedCuboid) then
- connectCuboids(connectedCuboid, c)
- end
- end
- end
- if numNewCuboids == 0 then
- table.remove(pStorage.cuboids, cuboid[8])
- reindexCuboids()
- return
- end
- pStorage.cuboids[cuboid[8]] = newCuboids[1]
- newCuboids[1][8] = cuboid[8]
- local numCuboids = #pStorage.cuboids
- for i = 2, numNewCuboids do
- newCuboids[i][8] = numCuboids + i - 1
- table.insert(pStorage.cuboids, newCuboids[i])
- end
- logCuboids()
- end
- function logCuboids()
- local txt = getTableSaveText(pStorage)
- local f = fs.open("out", "w")
- f.write(txt)
- f.close()
- end
- function connectCuboids(c1, c2)
- table.insert(c1[7], c2)
- table.insert(c2[7], c1)
- end
- function getOverlappingCuboidAxis(c1, c2)
- if c1[1] == c2[4] or c1[4] == c2[1] then
- return 1
- elseif c1[2] == c2[5] or c1[5] == c2[2] then
- return 2
- elseif c1[3] == c2[6] or c1[6] == c2[3] then
- return 3
- end
- printCuboidCoordinates(c1)
- printCuboidCoordinates(c2)
- error("invalid cuboids")
- end
- function getOverlappingCuboidDirection(c1, c2)
- if c1[4] == c2[1] then
- return 0
- elseif c1[6] == c2[3] then
- return 1
- elseif c1[5] == c2[2] then
- return 4
- elseif c1[1] == c2[4] then
- return 2
- elseif c1[3] == c2[6] then
- return 3
- elseif c1[2] == c2[5] then
- return 5
- end
- printCuboidCoordinates(c1)
- printCuboidCoordinates(c2)
- error("invalid cuboids")
- end
- function printCuboidCoordinates(c)
- print(c[1], c[2], c[3], c[4], c[5], c[6], "|", c[8])
- end
- function areCuboidsAdjacent(c1, c2)
- local sum1 = 0
- local sum2 = 0
- if rangesOverlap(c1[1], c1[4], c2[1], c2[4]) then
- sum1 = sum1 + 1
- elseif c1[1] == c2[4] or c1[4] == c2[1] then
- sum2 = sum2 + 1
- end
- if rangesOverlap(c1[2], c1[5], c2[2], c2[5]) then
- sum1 = sum1 + 1
- elseif c1[2] == c2[5] or c1[5] == c2[2] then
- sum2 = sum2 + 1
- end
- if rangesOverlap(c1[3], c1[6], c2[3], c2[6]) then
- sum1 = sum1 + 1
- elseif c1[3] == c2[6] or c1[6] == c2[3] then
- sum2 = sum2 + 1
- end
- if sum1 > 2 then
- printCuboidCoordinates(c1)
- printCuboidCoordinates(c2)
- error("impossible case " .. sum1 .. ", " .. sum2)
- end
- return sum1 == 2 and sum2 == 1
- end
- function isNan(v)
- return v ~= v
- end
- function rangesOverlap(p1x1, p1x2, p2x1, p2x2)
- if isNan(p1x1) and isNan(p1x2) then
- return true
- elseif isNan(p2x1) and isNan(p2x2) then
- return true
- elseif isNan(p1x1) and isNan(p2x1) then
- return true
- elseif isNan(p1x2) and isNan(p2x2) then
- return true
- end
- if isNan(p1x1) then
- p1x1 = p2x1
- elseif isNan(p2x1) then
- p2x1 = p1x1
- end
- if isNan(p1x2) then
- p1x2 = p2x2
- elseif isNan(p2x2) then
- p2x2 = p1x2
- end
- return math.max(p1x2, p2x2) - math.min(p1x1, p2x1) < p2x2 - p2x1 + p1x2 - p1x1
- end
- function reindexCuboids()
- for i = 1, #pStorage.cuboids do
- pStorage.cuboids[i][8] = i
- end
- end
- function splitCuboidAtPos(cuboid, pos)
- local x1 = cuboid[1]
- local y1 = cuboid[2]
- local z1 = cuboid[3]
- local x2 = cuboid[4]
- local y2 = cuboid[5]
- local z2 = cuboid[6]
- local pX = pos[1]
- local pY = pos[2]
- local pZ = pos[3]
- local cuboidYM = { x1, y1, z1, x2, pY, z2, {}, 1 }
- local cuboidYP = { x1, pY + 1, z1, x2, y2, z2, {}, 2 }
- local cuboidXM = { x1, pY, z1, pX, pY + 1, z2, {}, 3 }
- local cuboidXP = { pX + 1, pY, z1, x2, pY + 1, z2, {}, 4 }
- local cuboidZM = { pX, pY, z1, pX + 1, pY + 1, pZ, {}, 5 }
- local cuboidZP = { pX, pY, pZ + 1, pX + 1, pY + 1, z2, {}, 6 }
- local allCuboids = { cuboidXM, cuboidXP, cuboidYM, cuboidYP, cuboidZM, cuboidZP }
- local partners = { cuboidYP, cuboidYM, cuboidXP, cuboidXM, cuboidZP, cuboidZM }
- local cuboids = {}
- for _, c in pairs(allCuboids) do
- if not isEmptyCuboid(c) then
- table.insert(cuboids, c)
- for _, cP in pairs(allCuboids) do
- if c ~= cP and partners[c[8]] ~= cP then
- table.insert(cP[7], c)
- end
- end
- end
- end
- return cuboids
- end
- function findCuboidContainingPos(pos)
- -- TODO pass cuboid that might contain pos (from turtle position)
- for _, cuboid in ipairs(pStorage.cuboids) do
- printCuboidCoordinates(cuboid)
- if isPointInCuboid(pos, cuboid) then
- return cuboid
- end
- end
- printTable(pos)
- error("c")
- error("cuboid containing position not found!")
- end
- function isPointInCuboid(pos, cuboid)
- if (pos[1] < cuboid[1]) and (cuboid[1] == cuboid[1]) then
- return false
- elseif (cuboid[4] <= pos[1]) and (cuboid[4] == cuboid[4]) then
- return false
- elseif (pos[2] < cuboid[2]) and (cuboid[2] == cuboid[2]) then
- return false
- elseif (cuboid[5] <= pos[2]) and (cuboid[5] == cuboid[5]) then
- return false
- elseif (pos[3] < cuboid[3]) and (cuboid[3] == cuboid[3]) then
- return false
- elseif (cuboid[6] <= pos[3]) and (cuboid[6] == cuboid[6]) then
- return false
- end
- return true
- end
- function isEmptyCuboid(cuboid)
- return cuboid[1] == cuboid[4] or cuboid[2] == cuboid[5] or cuboid[3] == cuboid[6]
- end
- function getAtKeyOrCreateTable(tbl, key)
- local v = tbl[key]
- if not v then
- v = {}
- tbl[key] = v
- end
- return v
- end
- function removeValue(tbl, value)
- for i, v in pairs(tbl) do
- if v == value then
- table.remove(tbl, i)
- return
- end
- end
- end
- return {
- name = 'smartGPS',
- api = api,
- onInitPersistentStorage = function(_pStorage, _pSave)
- pStorage = _pStorage
- if not pStorage.cuboids then
- resetCuboids()
- end
- pSave = _pSave
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement