Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------
- -- BY UPZONE --
- ---------------
- os.loadAPI("builder\\apis\\Button")
- os.loadAPI("builder\\apis\\Colors")
- os.loadAPI("builder\\apis\\Paint")
- term.clear()
- term.setCursorPos(1, 1)
- local args = {...}
- if args[1] == "-help" then
- print("Color Legend:")
- Paint.pixel(2, 3, " ", Colors.black, Colors.yellow)
- term.setCursorPos(4, 3)
- term.write("= Yellow represents Blocks which are placed last")
- term.setCursorPos(6, 4)
- term.write("(e.g. Torches)")
- term.setCursorPos(4, 5)
- term.write("= Black represents nothing/empty slot")
- term.setCursorPos(1, 6)
- return
- end
- local width = 5
- local maxWidth = 23
- local height = 5
- local maxHeight = 15
- local layer = 1
- local maxLayer = 99
- local running = true
- local layers = {}
- function updateLayer()
- layer = 0
- layers = {}
- layerInc()
- -- reset
- Paint.fill(26, 2, 50, 18, Colors.black)
- -- draw layers border
- startX = 49 - width
- startY = 2
- endX = 50
- endY = 3 + height
- Paint.border(startX, startY, endX, endY, Colors.white)
- end
- function updateNumbers()
- -- width
- term.setCursorPos(14, 2)
- if width < 10 then
- term.write("0")
- end
- term.write(width)
- -- height
- term.setCursorPos(14, 4)
- if height < 10 then
- term.write("0")
- end
- term.write(height)
- -- layer
- term.setCursorPos(14, 6)
- if layer < 10 then
- term.write("0")
- end
- term.write(layer)
- end
- function widthDec()
- if width == 1 then
- return
- end
- width = width - 1
- updateLayer()
- updateNumbers()
- end
- function widthInc()
- if width == maxWidth then
- return
- end
- width = width + 1
- updateLayer()
- updateNumbers()
- end
- function heightDec()
- if height == 1 then
- return
- end
- height = height - 1
- updateLayer()
- updateNumbers()
- end
- function heightInc()
- if height == maxHeight then
- return
- end
- height = height + 1
- updateLayer()
- updateNumbers()
- end
- function layerDec()
- if layer == 1 then
- return
- end
- layer = layer - 1
- drawLayer(layer)
- updateNumbers()
- end
- function drawLayer(level)
- baseX = 49 - width
- baseY = 2
- for y = 1, height do
- for x = 1, width do
- Paint.pixel(baseX + x, baseY + y, " ", Colors.black, layers[layer][((y-1) * width) + x])
- end
- end
- end
- function layerInc()
- if layer == maxLayer then
- return
- end
- layer = layer + 1
- if layers[layer] == nil then
- layers[layer] = {}
- for i = 1, width * height do
- layers[layer][i] = Colors.black
- end
- end
- drawLayer(layer)
- updateNumbers()
- end
- function cleanupLayers()
- countLayer = 0
- for i, k in ipairs(layers) do
- countLayer = countLayer + 1
- end
- for i = countLayer, 1, -1 do
- hasOnlyBlacks = true
- for k, v in ipairs(layers[i]) do
- if v ~= Colors.black then
- hasOnlyBlacks = false
- break
- end
- end
- if hasOnlyBlacks then
- layers[i] = nil
- else
- break
- end
- end
- end
- function save()
- term.clear()
- term.setCursorPos(1, 1)
- if not fs.exists("builder\\templates\\") then
- shell.run("mkdir templates")
- end
- term.write("Filename: ")
- fileName = read()
- if fs.exists("builder\\templates\\" .. fileName) then
- repeat
- print("A file with this name already exists, please choose a different one")
- term.write("Filename: ")
- fileName = read()
- until not fs.exists(fileName)
- end
- cleanupLayers()
- f = fs.open("builder\\templates\\" .. fileName, "w")
- f.write(math.floor(width))
- f.write(":")
- f.write(math.floor(height))
- f.write(":")
- for k, v in ipairs(inventoryFields) do
- f.write(v[3])
- end
- f.write(":")
- curLayer = 1
- while layers[curLayer] ~= nil do
- for i = 1, width * height do
- f.write(layers[curLayer][i])
- end
- curLayer = curLayer + 1
- end
- f.close()
- running = false
- end
- function exit()
- running = false
- end
- buttons = {
- Button.create("<", 12, 2, 1, 1, widthDec, Colors.white, Colors.red, Colors.white, Colors.lime),
- Button.create(">", 17, 2, 1, 1, widthInc, Colors.white, Colors.red, Colors.white, Colors.lime),
- Button.create("<", 12, 4, 1, 1, heightDec, Colors.white, Colors.red, Colors.white, Colors.lime),
- Button.create(">", 17, 4, 1, 1, heightInc, Colors.white, Colors.red, Colors.white, Colors.lime),
- Button.create("<", 12, 6, 1, 1, layerDec, Colors.white, Colors.red, Colors.white, Colors.lime),
- Button.create(">", 17, 6, 1, 1, layerInc, Colors.white, Colors.red, Colors.white, Colors.lime),
- Button.create("Save", 12, 16, 6, 3, save, Colors.white, Colors.red, Colors.white, Colors.lime),
- Button.create("Exit", 19, 16, 6, 3, exit, Colors.white, Colors.red, Colors.white, Colors.lime)
- }
- inventoryFields = {
- { 3, 11, Colors.black }, { 5, 11, Colors.black }, { 7, 11, Colors.black }, { 9, 11, Colors.black },
- { 3, 13, Colors.black }, { 5, 13, Colors.black }, { 7, 13, Colors.black }, { 9, 13, Colors.black },
- { 3, 15, Colors.black }, { 5, 15, Colors.black }, { 7, 15, Colors.black }, { 9, 15, Colors.black },
- { 3, 17, Colors.black }, { 5, 17, Colors.black }, { 7, 17, Colors.black }, { 9, 17, Colors.black }
- }
- currentColorField = { 23, 11, Colors.black }
- function drawButtonsControls()
- for i, btn in ipairs(buttons) do
- btn:draw()
- end
- end
- function drawInventory()
- for slot, field in ipairs(inventoryFields) do
- Paint.pixel(field[1], field[2], " ", Colors.black, field[3])
- end
- end
- function drawText()
- term.setCursorPos(2, 2)
- term.write("Width:")
- term.setCursorPos(2, 4)
- term.write("Height:")
- term.setCursorPos(2, 6)
- term.write("Layer:")
- term.setCursorPos(2, 8)
- term.write("Inventory")
- term.setCursorPos(12, 11)
- term.write("Current:")
- end
- function updateCurrentColor()
- Paint.pixel(currentColorField[1], currentColorField[2], " ", Colors.black, currentColorField[3])
- end
- function drawingPitchClicked(x, y)
- pitchX = x - (49 - width)
- pitchY = y - 2
- if pitchX < 1 or pitchX > width or pitchY < 1 or pitchY > height then
- return
- end
- layers[layer][((pitchY-1) * width) + pitchX] = currentColorField[3]
- Paint.pixel(x, y, " ", Colors.black, currentColorField[3])
- end
- function initialize()
- Paint.fill(2, 10, 10, 18, Colors.white)
- Paint.border(22, 10, 24, 12, Colors.white)
- drawText()
- drawButtonsControls()
- drawInventory()
- updateNumbers()
- updateLayer()
- end
- initialize()
- while running do
- event, side, xPos, yPos = os.pullEvent("mouse_click")
- for i, btn in ipairs(buttons) do
- if btn:intersects(xPos, yPos) then
- btn:raiseOnClick()
- end
- end
- for i, field in ipairs(inventoryFields) do
- if xPos == field[1] and yPos == field[2] then
- inventoryFields[i][3] = currentColorField[3]
- drawInventory()
- end
- end
- if xPos == currentColorField[1] and yPos == currentColorField[2] then
- currentColorField[3] = Colors.change(currentColorField[3])
- updateCurrentColor()
- end
- drawingPitchClicked(xPos, yPos)
- end
- term.clear()
- term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement