Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m = {} --Coordinate arrays: [level][x][y] 0 is solid, 1 is clear, 2 is unknown, any higher is a turtle
- u = {} --Array for loading
- am = {} --Array for coordinates of options
- lid=0
- cid=0
- cx=32 --Cursor position
- cy=32
- lvl=1
- done=true
- menu=0
- option=1
- mo = {} --Number of options for each menu
- tm=0
- material = 1
- name = ""
- shut = 0
- change = 0
- db = 0
- function ia() --Initialise our coordinate arrays
- for i=1, 12 do
- m[i] = {}
- for j=1, 64 do
- m[i][j] = {}
- for k=1, 64 do
- m[i][j][k] = 0
- end
- end
- end
- for i=1,49152 do
- u[i] = 0
- end
- for i=1,3 do
- am[i] = {}
- for j=3,47 do
- am[i][j] = {}
- for k=2,3 do
- am[i][j][k] = 0
- end
- end
- end
- for i=4,13 do
- am[1][i][2] = 1
- end
- for i=16,25 do
- am[1][i][2] = 2
- end
- for i=28,36 do
- am[1][i][2] = 3
- end
- for i=39,43 do
- am[1][i][2] = 4
- end
- for i=4,8 do
- am[1][i][3] = 5
- end
- for i=3,6 do
- am[2][i][2] = 1
- end
- for i=8,11 do
- am[2][i][2] = 2
- end
- for i=13,16 do
- am[2][i][2] = 3
- end
- for i=18,21 do
- am[2][i][2] = 4
- end
- for i=18,21 do
- am[2][i][2] = 5
- end
- for i=23,26 do
- am[2][i][2] = 6
- end
- for i=28,31 do
- am[2][i][2] = 7
- end
- for i=33,36 do
- am[2][i][2] = 8
- end
- for i=38,42 do
- am[2][i][2] = 9
- end
- for i=12,13 do
- am[3][i][2] = 1
- end
- for i=37,39 do
- am[3][i][2] = 2
- end
- if fs.exists("disk/builder/maps/") == false then
- fs.makeDir("disk/builder/maps/")
- end
- mo[1] = 6 --main menu
- mo[2] = 2 --quit
- mo[5] = 2 --save before quit
- mo[6] = 2 --cancel without saving
- end
- function cu(id, l, xv, yv) --Sends the value of a coordinate
- local j = "7:"..tostring(l)..":"..tostring(xv)..":"..tostring(yv)..":"..tostring(m[l][xv][yv])..":;"
- rednet.send(id, j)
- end
- function du()
- term.clear()
- term.setCursorPos(1,1)
- if menu == 5 then
- term.write("======================Save?=======================")
- elseif menu == 6 then
- term.write("=====================Cancel?======================")
- else
- term.write("==================================================")
- end
- term.setCursorPos(1,3)
- term.write("==================================================")
- for xv = 1, 50 do
- for yv = 4, 18 do
- term.setCursorPos(xv,yv)
- if cx+xv-25 >= 1 and cy+yv-9 >= 1 and cx+xv-25 <= 64 and cy+yv-9 <= 64 then
- cm = m[lvl][cx+xv-25][cy+yv-9]
- if cm ~= 0 then
- term.write(tostring(cm))
- else
- term.write(" ")
- end
- else
- term.write("!")
- end
- end
- end
- if cid == 0 then
- term.setCursorPos(25,9)
- term.write("x")
- end
- if menu == 0 then
- term.setCursorPos(34,2)
- term.write("x: "..tostring(cx))
- term.setCursorPos(41,2)
- term.write("z: "..tostring(cy))
- end
- term.setCursorPos(1,19)
- if db == 1 then
- term.write("File doesn't exist")
- end
- if menu == 0 then
- term.setCursorPos(1,2)
- term.write("| Layer: ")
- term.setCursorPos(10,2)
- term.write(tostring(lvl))
- term.setCursorPos(15,2)
- term.write("material: "..tostring(material))
- term.setCursorPos(50,2)
- term.write("|")
- elseif menu == 1 then
- term.setCursorPos(1,2)
- term.write("| Load Save Send Help Quit Exit |")
- term.setCursorPos(-2+7*option,2)
- term.write(">")
- elseif menu == 2 or menu == 5 or menu == 6 then
- term.setCursorPos(1,2)
- term.write("| No Yes |")
- if option == 1 then
- term.setCursorPos(11,2)
- else
- term.setCursorPos(36,2)
- end
- term.write(">")
- elseif menu == 3 then
- term.setCursorPos(1,2)
- term.write("| File Name: |")
- term.setCursorPos(14,2)
- term.setCursorBlink(true)
- load(read())
- term.setCursorBlink(false)
- menu=0
- option=1
- du()
- elseif menu == 4 then
- term.setCursorPos(1,2)
- term.write("| Project Name: |")
- term.setCursorPos(17,2)
- term.setCursorBlink(true)
- term.setCursorBlink(false)
- name = read()
- if name ~= "" then
- save()
- if shut == 1 then
- tm=1
- end
- menu = 0
- else
- menu = 6
- end
- du()
- option=1
- menu=0
- end
- end
- function leer(m,l)
- local i = 1
- local p = ""
- repeat
- repeat
- if m:sub(l,l) ~= ":" then
- p=p..m:sub(l,l)
- l=l+1
- end
- until m:sub(l,l) == ":"
- u[i] = tonumber(p)
- p=""
- l=l+1
- i=i+1
- until m:sub(l,l) == ";"
- end
- function save()
- local file = fs.open("disk/builder/maps/"..name, "w")
- for i=1,12 do
- for xv=1,64 do
- for yv=1,64 do
- if m[i][xv][yv] ~= 0 then
- file.write(tostring(i)..":"..tostring(xv)..":"..tostring(yv)..":"..tostring(m[i][xv][yv]..":"))
- end
- end
- end
- end
- file.write(";")
- file.close()
- end
- function load(f)
- if f ~= "" then
- if fs.exists("disk/builder/maps/" .. f) then
- ia()
- local file = fs.open("disk/builder/maps/" .. f, "r")
- local data = file.readAll()
- file.close()
- if data ~= "" and data ~= ";" then
- leer(data,1)
- local j=0
- repeat
- if u[1+4*j] ~= 0 then
- m[u[1+4*j]][u[2+4*j]][u[3+4*j]]=u[4+4*j]
- u[1+4*j], u[2+4*j], u[3+4*j], u[4+4*j]=0,0,0,0
- end
- j=j+1
- term.setCursorPos(1,19)
- term.write(tostring(j))
- until u[1+4*j] == 0
- end
- else
- db = 1
- end
- name = f
- end
- end
- function kr()
- if mo[menu] >= option + 1 then
- option = option + 1
- du()
- end
- end
- function kl()
- if option ~= 1 then
- option = option-1
- du()
- end
- end
- function enter()
- if menu == 1 then
- if option == 1 then
- menu=3
- elseif option == 2 then
- option=1
- if name == "" then
- menu=4
- else
- save()
- end
- elseif option == 5 then
- option=1
- menu=2
- elseif option == 6 then
- option=1
- menu=0
- end
- elseif menu == 2 then
- if option == 1 then
- option=1
- menu=1
- else
- if change == 1 then
- option=1
- menu=5
- else
- option = 1
- tm = 1
- menu = 0
- end
- end
- elseif menu == 5 then
- if option == 2 then
- if name == "" then
- menu=4
- shut=1
- else
- save()
- end
- else
- option=1
- tm=1
- menu=0
- end
- elseif menu == 6 then
- if option == 1 then
- menu = 4
- else
- option = 1
- menu = 0
- end
- end
- end
- if fs.isDir("disk") == false then
- print("Please insert a disk.")
- local event, side = os.pullEvent("disk")
- end
- term.clear()
- term.setCursorBlink(false)
- ia()
- du()
- repeat
- local event, a, b, c = os.pullEvent()
- if event == "key" then
- if a == 1 and menu ~= 0 then
- option = 1
- menu = 0
- du()
- end
- if a == 200 and menu == 0 then
- if cy ~= 1 then
- cy = cy-1
- du()
- end
- end
- if a == 208 and menu == 0 then
- if cy ~= 64 then
- cy =cy+1
- du()
- end
- end
- if a == 205 then
- if menu ~= 0 then
- kr()
- elseif cx ~= 64 then
- cx=cx+1
- du()
- end
- end
- if a == 203 then
- if menu ~= 0 then
- kl()
- elseif cx ~= 1 then
- cx=cx-1
- du()
- end
- end
- if a == 14 and menu == 0 then
- m[lvl][cx][cy] = 0
- change = 1
- du()
- end
- if a == 24 and menu == 0 then
- cx = 1
- cy = 1
- du()
- end
- if a == 28 then
- if menu == 0 then
- menu = 1
- else
- enter()
- end
- du()
- end
- if a == 57 and menu == 0 then
- m[lvl][cx][cy] = material
- change = 1
- du()
- end
- if a == 12 and lvl ~= 1 and menu == 0 then
- lvl=lvl-1
- du()
- end
- if a == 207 and menu == 0 then
- tm = 1
- end
- if a == 13 and lvl ~= 12 and menu == 0 then
- lvl=lvl+1
- du()
- end
- if a >= 2 and a <= 10 and menu == 0 then
- material=a-1
- du()
- end
- end
- if event == "mouse_drag" and menu == 0 then
- if cx+b-25 >= 1 and cx+b-25 <= 64 and cy+c-9 >= 1 and cy+c-9 <= 64 then
- if a == 1 then
- m[lvl][cx+b-25][cy+c-9] = material
- else
- m[lvl][cx+b-25][cy+c-9] = 0
- end
- change = 1
- du()
- end
- end
- if event == "mouse_click" and menu == 0 then
- if cx+b-25 >= 1 and cx+b-25 <= 64 and cy+c-9 >= 1 and cy+c-9 <= 64 then
- if a == 1 then
- m[lvl][cx+b-25][cy+c-9] = material
- else
- m[lvl][cx+b-25][cy+c-9] = 0
- end
- change = 1
- du()
- end
- end
- if event == "mouse_scroll" and menu == 0 then
- if material + a ~= 0 and material + a ~= 10 then
- material = material + a
- end
- du()
- end
- if event == "disk_eject" then
- term.setCursorPos(1,19)
- term.write("Please enter disk.")
- local event, side = os.pullEvent("disk")
- du()
- end
- until tm == 1
- term.setCursorPos(1,1)
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment