Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- external info --
- local tArgs = { ... }
- local retPath = tArgs[1]
- --if #tArgs <= 0 then retPath = "disk/OS/OS" end
- function prevApp()
- shell.run(retPath)
- end
- -- BluPrint --
- local filename = "/programFiles/bluprints/test"
- local running = true
- local layer = 1
- local termW, termH = term.getSize()
- local offsW, offsH = 0, 0
- local doResize = false
- --blocks[height][length][width]
- local blocks = {
- [1] = {
- [1 ] = { 0,0,0,0,0,0,0,0,0,0 },
- [2 ] = { 0,0,0,0,0,0,0,0,0,0 },
- [3 ] = { 0,0,0,0,0,0,0,0,0,0 },
- [4 ] = { 0,0,0,0,0,0,0,0,0,0 },
- [5 ] = { 0,0,0,0,0,0,0,0,0,0 },
- }
- }
- --dim for bluprint
- local height = #blocks
- local length = #blocks[1]
- local width = #blocks[1][1]
- local pallet = {
- [0] = colours.blue,
- [1] = colours.white,
- [2] = colours.orange,
- [3] = colours.magenta,
- [4] = colours.lightBlue,
- [5] = colours.yellow,
- [6] = colours.green,
- [7] = colours.pink,
- [8] = colours.grey,
- [9] = colours.lime,
- [10] = colours.cyan,
- [11] = colours.purple,
- [12] = colours.brown,
- }
- local paint = 1
- function save()
- file = fs.open(filename, "w")
- file.write(textutils.serialize(blocks))
- file.close()
- end
- function load()
- file = fs.open(filename, "r")
- data = file.readAll()
- file.close()
- blocks = textutils.unserialize(data)
- height = #blocks
- length = #blocks[1]
- width = #blocks[1][1]
- end
- local controls = {
- ["save"] = {
- ["name"] = "[SAVE]",
- ["x"] = 40,
- ["y"] = 17,
- ["l"] = 5,
- run = function() save() end
- },
- ["load"] = {
- ["name"] = "[LOAD]",
- ["x"] = 42,
- ["y"] = 18,
- ["l"] = 5,
- run = function() load() end
- },
- ["exit"] = {
- ["name"] = "[EXIT]",
- ["x"] = 44,
- ["y"] = 19,
- ["l"] = 5,
- run = function() running = false end
- },
- ["wid+"] = {
- ["name"] = "[+]",
- ["x"] = 41,
- ["y"] = 2,
- ["l"] = 2,
- run = function() width = width + 1 doResize = true end
- },
- ["wid-"] = {
- ["name"] = "[-]",
- ["x"] = 47,
- ["y"] = 2,
- ["l"] = 2,
- run = function() width = width - 1 doResize = true end
- },
- ["len+"] = {
- ["name"] = "[+]",
- ["x"] = 41,
- ["y"] = 5,
- ["l"] = 2,
- run = function() length = length + 1 doResize = true end
- },
- ["len-"] = {
- ["name"] = "[-]",
- ["x"] = 47,
- ["y"] = 5,
- ["l"] = 2,
- run = function() length = length - 1 doResize = true end
- },
- ["hit+"] = {
- ["name"] = "[+]",
- ["x"] = 41,
- ["y"] = 9,
- ["l"] = 2,
- run = function() height = height + 1 doResize = true end
- },
- ["hit-"] = {
- ["name"] = "[-]",
- ["x"] = 47,
- ["y"] = 9,
- ["l"] = 2,
- run = function() height = height - 1 doResize = true end
- },
- ["lay+"] = {
- ["name"] = "[+]",
- ["x"] = 41,
- ["y"] = 13,
- ["l"] = 2,
- run = function() layer = layer + 1 end
- },
- ["lay-"] = {
- ["name"] = "[-]",
- ["x"] = 47,
- ["y"] = 13,
- ["l"] = 2,
- run = function() layer = layer - 1 end
- }
- }
- -- HELPER FUNCTIONS --
- function clear()
- term.setBackgroundColour(colours.black)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function pos(x, y)
- term.setCursorPos(x, y)
- end
- function posCol(x, y, col)
- term.setCursorPos(x, y)
- term.setBackgroundColour(col)
- write(" ")
- end
- function posWrt(x, y, text, textCol)
- term.setCursorPos(x, y)
- term.setTextColour(textCol)
- write(text)
- end
- -- DEPENDANT FUNCTIONS --
- function drawPallet()
- for i=1, #pallet do
- posCol(termW, i, pallet[i])
- end
- end
- function drawCanvas()
- for x=1, width+2 do
- posCol(x + offsW, 1 + offsH, colours.red)
- posCol(x + offsW, length+2 + offsH, colours.red)
- end
- for y=1, length+2 do
- posCol(1 + offsW, y + offsH, colours.red)
- posCol(width+2 + offsW, y + offsH, colours.red)
- end
- --[[
- for x=2 + offsW, width+1 + offsW do
- for y=2 + offsH, length+1 + offsH do
- posCol(x, y, colours.blue)
- end
- end
- ]]
- for x=1, width do
- for y=1, length do
- posCol(x+1 + offsW, y+1 + offsH, pallet[blocks[layer][y][x]])
- end
- end
- end
- function drawControls()
- for y=1, termH do
- for x=termW-12, termW do
- posCol(x, y, colours.lightGrey)
- end
- end
- posWrt(41, 1, "WIDTH "..width, colours.black)
- posWrt(41, 4, "LENGTH "..length, colours.black)
- posWrt(41, 8, "HEIGHT "..height, colours.black)
- posWrt(41, 12, "LAYER "..layer, colours.black)
- for i, control in pairs(controls) do
- x = control.x
- y = control.y
- name = control.name
- posWrt(x, y, name, colours.black)
- end
- end
- debugInfo = ""
- function resize()
- temp = { } -- temp table
- -- inserting all the height levels
- for h=1, height do table.insert( temp , { } ) end
- -- inserting all the lengths
- for h=1, height do
- for l=1, length do table.insert( temp[h], { } ) end
- end
- -- inserting all the width and defaulting them to 0
- for h=1, height do
- for l=1, length do
- for w=1, width do table.insert( temp[h][l] , 0 ) end
- end
- end
- -- if the canvas size is increasing
- if #blocks <= height then
- if #blocks[1] <= length then
- if #blocks[1][1] <= width then
- for h=1, #blocks do
- for l=1, #blocks[1] do
- for w=1, #blocks[1][1] do
- -- fill in data from blocks
- temp[h][l][w] = blocks[h][l][w]
- end
- end
- end
- end
- end
- end
- --if the canvas size is decreasing
- if #blocks >= height then
- if #blocks[1] >= length then
- if #blocks[1][1] >= width then
- for h=1, #temp do
- for l=1, #temp[1] do
- for w=1, #temp[1][1] do
- -- fill in data from blocks but not the last value
- temp[h][l][w] = blocks[h][l][w]
- end
- end
- end
- end
- end
- end
- -- overwrite blocks with the new dimensions
- blocks = temp
- end
- function doClick(event)
- xPos = event[3]
- yPos = event[4]
- --debugInfo = event[1].." "..xPos.." "..yPos
- for i, control in pairs(controls) do
- x = control.x y = control.y
- l = control.x + control.l
- name = control.name
- if xPos >= x and xPos <= l and yPos == y then
- control.run()
- if name == "[SAVE]" then debugInfo = "SAVED FILE "..filename end
- if name == "[LOAD]" then debugInfo = "LOADD FILE "..filename end
- end
- end
- if width <= 0 then width = 1 end
- if length <= 0 then length = 1 end
- if height <= 0 then height = 1 end
- if layer <= 0 then layer = 1 end
- if layer >= height then layer = height end
- if doResize then resize() end
- if xPos == termW and yPos <= #pallet then
- paint = yPos
- end
- if xPos >= 39 then return end
- if (xPos) >= (2 + offsW) and (xPos) <= (#blocks[1][1]+1 + offsW) then
- if (yPos) >= (2 + offsH) and (yPos) <= (#blocks[1]+1 + offsH) then
- if event[2] == 1 then
- blocks[layer][yPos-1 - offsH][xPos-1 - offsW] = paint
- else
- blocks[layer][yPos-1 - offsH][xPos-1 - offsW] = 0
- end
- end
- end
- end
- function doKeyPress(event)
- key = event[2]
- if key == keys.right then offsW = offsW + 1 end
- if key == keys.left then offsW = offsW - 1 end
- if key == keys.up then offsH = offsH - 1 end
- if key == keys.down then offsH = offsH + 1 end
- if key == keys.one then paint = 1 end
- if key == keys.two then paint = 2 end
- if key == keys.three then paint = 3 end
- if key == keys.four then paint = 4 end
- if key == keys.five then paint = 5 end
- if key == keys.six then paint = 6 end
- if key == keys.seven then paint = 7 end
- if key == keys.eight then paint = 8 end
- if key == keys.nine then paint = 9 end
- if key == keys.zero then paint = 10 end
- if key == keys.q then layer = layer + 1 end
- if key == keys.a then layer = layer - 1 end
- if layer <= 0 then layer = 1 end
- if layer >= height then layer = height end
- end
- -- PROGRAM FUNCTIONS --
- function draw()
- clear()
- --posWrt(15, 11, paint, pallet[1])
- drawCanvas()
- drawControls()
- drawPallet()
- term.setBackgroundColour(colours.black)
- posWrt(1, 19, debugInfo, colours.white)
- end
- function update()
- --sleep(2)
- --running = false
- while true do
- event = { os.pullEvent() }
- if event[1] == "mouse_click" then
- debugInfo = event[1].." "..event[3].." "..event[4]
- doClick(event)
- break
- end
- if event[1] == "key" then
- debugInfo = event[1].." "..event[2]
- doKeyPress(event)
- break
- end
- end
- end
- -- RUN FUNCTION --
- function run()
- clear()
- while running do
- draw()
- update()
- end
- clear()
- prevApp()
- end
- function startup()
- clear()
- fs.makeDir("/programFiles/bluprints")
- list = fs.list("/programFiles/bluprints")
- print("If you would like to load a file just type in the name below")
- print()
- print("LIST OF ALL AVAILABLE FILES")
- textutils.pagedTabulate( list )
- filename = read()
- filename = "/programFiles/bluprints/"..filename
- if fs.exists(filename) then
- load()
- else
- save()
- end
- end
- startup()
- run()
Advertisement
Add Comment
Please, Sign In to add comment