Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.unloadAPI("gxm")
- os.loadAPI("gxm")
- local tArgs = {...}
- formType = tArgs[1]
- local materialSlot = 16
- local materialSensitive = true
- gxm.relative()
- form = {}
- form.goStart = true
- form.chainList = {}
- local printTable = function(tab)
- for k, v in pairs(tab) do
- if type(v) == "table" then
- for p, o in pairs(v) do
- printString = type(p) == "string" and p.." - "..tostring(o) or o
- write(printString.." ")
- end
- print()
- else
- printString = type(k) == "string" and k.." - "..tostring(v) or v
- print(printString)
- end
- end
- end
- local isTable = function(tab)
- return type(tab) == "table"
- end
- local giveWarning = function(warning)
- print(warning)
- print("Exit - e")
- print("Show grid - g")
- print("Continue - any key.")
- while true do
- e, pressed = os.pullEvent()
- if pressed == keys.e then
- return false
- elseif pressed == keys.g then
- return "grid"
- else
- return true
- end
- end
- end
- local fillPatternTable = function(x, y, tableType, ...)
- local patternTable = {["warning"] = false}
- local function fillTable(num)
- for i = 1, y do
- patternTable[i] = {}
- for j = 1, x do
- patternTable[i][j] = num
- end
- end
- end
- if not tableType then
- fillTable(16)
- elseif tableType == "outlined" then
- fillTable(16)
- for i = 1, y do
- for j = 1, x do
- if j == 1 or j == x or i == 1 or i == y then
- patternTable[i][j] = 15
- end
- end
- end
- elseif tableType == "grid" then
- xOffset = arg[1]
- yOffset = arg[2]
- if (x-1) % xOffset ~= 0 then patternTable.warning = "Correction: -"..(x-1)%xOffset.." points in x axis."
- elseif (y-1) % yOffset ~= 0 then patternTable.warning = "Correction: -"..(y-1)%yOffset.." points in y axis." end
- fillTable(16)
- for i = 1, y do
- for j = 1, x, xOffset do
- patternTable[i][j] = 15
- end
- end
- for i = 1, y, yOffset do
- for j = 1, x do
- patternTable[i][j] = 15
- end
- end
- end
- return patternTable
- end
- form.goToStart = function(bool)
- form.goStart = bool
- end
- form.calculateFuel = function(pattern)
- local fuelRequired = 0
- pattern = pattern and pattern or form.pattern
- for c in string.gmatch(form.pattern, "[0-9]*[fbud]") do
- c = tonumber(c:match("[0-9]*"))
- fuelRequired = fuelRequired + (c or 1)
- end
- return fuelRequired
- end
- form.calculateBlocks = function(pattern)
- pattern = pattern and pattern or form.pattern
- local requiredBlocks = 0
- for _ in pattern:gmatch("[,;p-_^]") do
- requiredBlocks = requiredBlocks + 1
- end
- return requiredBlocks
- end
- form.calculateCost = function(pattern)
- return {["fuel"] = form.calculateFuel(pattern), ["blocks"] = form.calculateBlocks(pattern)}
- end
- -- Pattern generation --
- form.plane = function(xLen, yLen, outlined, horizontal, side, pattern)
- local alt = true
- local material =
- outlined and fillPatternTable(xLen, yLen, "outlined")
- or (type(pattern) == "table" and pattern.type == "uniformGrid") and fillPatternTable(xLen, yLen, "grid", pattern.offset, pattern.offset)
- or (type(pattern) == "table" and pattern.type == "grid") and fillPatternTable(xLen, yLen, pattern.type, pattern.xOffset, pattern.yOffset)
- or fillPatternTable(xLen, yLen)
- if material.warning then
- action = giveWarning(material.warning)
- if action == "grid" then
- printTable(material)
- elseif not action then
- return
- end
- end
- form.pattern =
- horizontal == "top" and "d"
- or not horizontal and "f"
- or "u"
- yLen = yLen or 1
- for y = 1, yLen do
- form.pattern =
- (not horizontal and side=="top") and form.pattern .. "d"..material[1][1].."p"
- or not horizontal and form.pattern .. "u"..material[1][1]..","
- or (y == 1 and horizontal ~= "top") and form.pattern.."f"..material[1][1]..","
- or (y == 1 and horizontal == "top") and form.pattern.."f"..material[1][1].."p"
- or (horizontal == "top" and side == "left") and form.pattern .. "lfrp"
- or horizontal == "top" and form.pattern .. "rflp"
- or (horizontal and side == "left") and form.pattern .. "lfr,"
- or horizontal and form.pattern .. "rfl,"
- for x = 1, xLen-1 do
- form.pattern =
- ((alt and side == "top") or (alt and horizontal == "top")) and form.pattern.."f"..material[y][x+1].."p"
- or (not alt and side == "top" or horizontal == "top") and form.pattern.."b"..material[y][x+1].."p"
- or alt and form.pattern.."f"..material[y][x+1]..","
- or form.pattern.."b"..material[y][x+1]..","
- end
- alt = not alt
- end
- if form.goStart then
- form.pattern =
- (not horizontal and yLen % 2 == 0 and not side == "top") and form.pattern .. "b" .. tostring(yLen) .. "d"
- or (not horizontal and side ~= "top") and form.pattern .. tostring(xLen) .. "b" .. tostring(yLen) .. "d"
- or (side == "left" and yLen % 2 == 0 and horizontal ~= "top") and form.pattern .. "br" .. tostring(yLen-1) .. "fld"
- or (side == "left" and horizontal ~= "top") and form.pattern .. tostring(xLen) .. "br" .. tostring(yLen-1) .. "fld"
- or (side == "left" and horizontal == "top" and yLen % 2 == 0) and form.pattern .. "br" .. tostring(yLen-1) .. "flu"
- or (side == "left" and horizontal == "top") and form.pattern .. tostring(xLen) .. "br" .. tostring(yLen-1) .. "flu"
- or (horizontal == "top" and yLen %2 == 0) and form.pattern .. "bl" .. tostring(yLen-1) .. "fru"
- or horizontal == "top" and form.pattern .. tostring(xLen) .. "bl" .. tostring(yLen-1) .. "fru"
- or (side == "top" and yLen % 2 == 0) and form.pattern .."b" .. tostring(yLen).."u"
- or side == "top" and form.pattern ..tostring(xLen) .."b" .. tostring(yLen).."u"
- or yLen % 2 == 0 and form.pattern .. "bl" .. tostring(yLen-1) .. "frd"
- or form.pattern .. tostring(xLen) .. "bl" .. tostring(yLen-1) .. "frd"
- end
- return form.pattern
- end
- form.line = function(length)
- return form.plane(length, 1)
- end
- form.horizontalLine = function(length)
- return form.plane(1, length)
- end
- form.wall = function(length, height, side, outline)
- outline = type(side) == "boolean" and side or outline
- return form.plane(length, height, outline, false, side)
- end
- form.gridWall = function(length, height, xGridOffset, yGridOffset, side)
- if type(yGridOffset == "string") then
- side = yGridOffset
- yGridOffset = xGridOffset
- elseif not yGridOffset then
- yGridOffset = xGridOffset
- end
- return form.plane(length, height, false, false, side, {["type"] = "grid", ["xOffset"] = xGridOffset, ["yOffset"] = yGridOffset})
- end
- form.floor = function(length, width, side, outlined)
- outlined = type(side) == "boolean" and side or outlined
- return form.plane(length, width, outlined, true, side or "right")
- end
- form.gridFloor = function(length, width, xGridOffset, yGridOffset)
- yGridOffset = yGridOffset or xGridOffset
- return form.plane(length, width, false, true, false, {["type"] = "grid", ["xOffset"] = xGridOffset, ["yOffset"] = yGridOffset})
- end
- form.roof = function(length, width, side, outlined)
- outlined = type(side) == "boolean" and side or outlined
- return form.plane(length, width, outlined, "top", side)
- end
- form.outlinedRoof = function(length, width, side)
- return form.plane(length, width, true, "top", side)
- end
- form.gridRoof = function(length, width, side, xGridOffset, yGridOffset)
- return form.plane(length, width, false, side, false, {["type"] = "grid", ["xOffset"] = xGridOffset, ["yOffset"] = yGrodPffset})
- end
- form.tunnel = function(length, xSize, ySize, outlined)
- outlined = type(ySize) == "boolean" and ySize or outlined
- ySize = type(ySize) == "boolean" and xSize or ySize
- form.goToStart(false)
- return
- (xSize % 2 == 0 and ySize % 2 == 0) and form.floor(length, xSize, outlined) .. "brfl" .. form.wall(length, ySize, outlined) .. "blfr" .. form.roof(length, xSize, "left", outlined) .. "blfr" .. form.wall(length, ySize, "top", outlined)
- or (xSize % 2 == 0 and ySize % 2 ~= 0) and form.floor(length, xSize, outlined) .. "brfl" .. form.wall(length, ySize, outlined) .. "flfl" .. form.roof(length, xSize, outlined) .. "brfl" .. form.wall(length, ySize, "top", outlined)
- or (xSize % 2 ~= 0 and ySize % 2 == 0) and form.floor(length, xSize, outlined) .. "frfr" .. form.wall(length, ySize, outlined) .. "brfl" .. form.roof(length, xSize, outlined) .. "frfr" .. form.wall(length, ySize, "top", outlined)
- or form.floor(length, xSize, outlined) .. "frfr" .. form.wall(length, xSize, outlined) .. "frfr" .. form.roof(length, xSize, "left", outlined) .. "flfl" .. form.wall(length, ySize, "top", outlined)
- end
- form.addToChain = function(...)
- print(...)
- end
- setMenu = function(x, y)
- local field = {}
- local x, y = 12, 4
- local lastc = " "
- local function clearLast()
- term.setCursorPos(x, y)
- term.write(" ")
- term.setCursorPos(x+3, y)
- term.write(" ")
- end
- w, h = term.getSize()
- term.clear()
- term.setCursorPos(x, y)
- term.write("[")
- term.setCursorPos(x+3, y)
- term.write("]")
- while true do
- for x, tab in pairs(field) do
- for y, v in pairs(tab) do
- term.setCursorPos(x+1, y)
- term.write(tostring(v))
- end
- end
- e, key = os.pullEvent()
- clearLast()
- if key == keys.down then
- y = y + 1
- elseif key == keys.up then
- y = y - 1
- elseif key == keys.right then
- x = x + 3
- elseif key == keys.left then
- x = x - 3
- elseif key == keys.enter then
- term.setCursorPos(x+1, y)
- term.write(" ")
- term.setCursorPos(x+1, y)
- input = read()
- if not field[x] then field[x] = {} end
- field[x][y] = tonumber(input)
- end
- if x < 6 then x = 6 end
- if y < 4 then y = 4 end
- if x > 24 then x = 24 end
- if y > 8 then y = 8 end
- term.setCursorPos(x, y)
- term.write("[")
- term.setCursorPos(x+3, y)
- term.write("]")
- end
- end
- gxm.exec(form.horizontalLine(5))
- --form.gridWall(9, 9, 4, 5)
- --printTable(fillPatternTable(12, 3, "grid", 2, 2))
- --form.gridWall(9, 9, 4)
- --printTable(form.calculateCost(form.gridFloor(9, 9, 4)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement