Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fs=require('filesystem')
- local shell=require('shell')
- local event = require('event')
- local term = require('term')
- local c = require('component')
- local gpu = c.gpu
- local serialization = require('serialization')
- local unicode=require('unicode')
- local name
- local h=4
- bun ={'Delete chest','Delete craft',' Exit '} bun1={' Enter name ','Select chest',' Exit '}
- men=1 men2=3 men3=10 men4=3 men5=3 men6=4
- plk='▌' plk2='▀' abl={} abl2={} lc={} lcp={}
- local b={'1','2','3','5','6','7','9','10','11','12','13'}
- local m= c.tunnel
- local bench={'╔═════╦═════╦═════╗','║ ║ ║ ║','╠═════╬═════╬═════╣','╚═════╩═════╩═════╝'} h=3
- function getxy() _,_,_,k2,_=event.pull('key_up') return k2 end
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
- function helps() gpu.set(34,1,'▬▬▬▬▬[Help]▬▬▬▬▬') gpu.set(34,2,'Для перемещения ') gpu.set(34,3,'по меню исполь- ') gpu.set(34,4,'зуйте стрелки. ') gpu.set(34,5,'Выбрать: Enter .') gpu.set(34,6,'▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬') gpu.set(34,7,'Программа созда-') gpu.set(34,8,'на для личного ') gpu.set(34,9,'пользования. ') gpu.set(34,10,'[Авторы]: ') gpu.set(34,11,' MeXaN1cK ') gpu.set(34,12,'PandaDoddo72rus') gpu.set(34,13,' (vah) ') gpu.set(34,14,'▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬') gpu.set(34,15,' |hil.su| ') gpu.set(34,16,'▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬') end
- local b1={"╔═══════════════════════════╗",' Add chest',' Add craft','Chest list',' Delete ',' Exit ','╚═══════════════════════════╝'}
- function pal6(men6) if men6==1 then term.setCursor(13,16) io.write(plk) elseif men6==2 then term.setCursor(25,16) io.write(plk) elseif men6==3 then term.setCursor(30,16) io.write(plk) elseif men6==4 then term.setCursor(45,16) io.write(plk) end end
- function pal4(men4) if men4==1 then gpu.set(32,4,plk) gpu.set(32,5,plk) gpu.set(32,6,plk) elseif men4==2 then gpu.set(32,7,plk) gpu.set(32,8,plk) gpu.set(32,9,plk) elseif men4==3 then gpu.set(32,10,plk) gpu.set(32,11,plk) gpu.set(32,12,plk) end end
- function pal3(men3) yap=plk2..plk2..plk2 if men3==1 then term.setCursor(3,2) io.write(yap) elseif men3==2 then term.setCursor(9,2) io.write(yap) elseif men3==3 then term.setCursor(15,2) io.write(yap) elseif men3==4 then term.setCursor(3,5) io.write(yap) elseif men3==5 then term.setCursor(9,5) io.write(yap) elseif men3==6 then term.setCursor(15,5) io.write(yap) elseif men3==7 then term.setCursor(3,8) io.write(yap) elseif men3==8 then term.setCursor(9,8) io.write(yap) elseif men3==9 then term.setCursor(15,8) io.write(yap) elseif men3==10 then for i=1,8 do term.setCursor(i,14) io.write(plk2) end elseif men3==11 then for i=9,20 do term.setCursor(i,14) io.write(plk2) end end end
- function pal2(men2) if men2==1 then term.setCursor(18,16) io.write(plk) elseif men2==2 then term.setCursor(30,16) io.write(plk) elseif men2==3 then term.setCursor(45,16) io.write(plk) end end
- function pal(men) if men==1 then gpu.set(32,1,plk) gpu.set(32,2,plk) gpu.set(32,3,plk) elseif men==2 then gpu.set(32,4,plk) gpu.set(32,5,plk) gpu.set(32,6,plk) elseif men==3 then gpu.set(32,7,plk) gpu.set(32,8,plk) gpu.set(32,9,plk) elseif men==4 then gpu.set(32,10,plk) gpu.set(32,11,plk) gpu.set(32,12,plk) elseif men==5 then gpu.set(32,13,plk) gpu.set(32,14,plk) gpu.set(32,15,plk) end end
- function selectChest()
- item=nil item1=nil et2=true
- while et2 do
- term.clear() helps() pal4(men5) term.setCursor(1,4) for i=1,3 do print(b1[1]) print('║ '.. bun1[i] ..' ║') print(b1[7]) end p2=getxy()
- if p2==200 then men5=men5-1 if men5<1 then men5=1 end
- elseif p2==208 then men5=men5+1 if men5>3 then men5=3 end
- elseif p2==28 then
- if men5==1 then term.clear() term.setCursor(15,7) io.write('Chest name: ') item=tostring(io.read()) term.clear() getxy() et2=false
- elseif men5==2 then
- ab1=loadTbl('chests.txt') for i=1,#ab1 do abl[i]=ab1[i] end page1=1 k1=1 j1=14 et1=true oldPage1=0
- while et1 do
- gpu.fill(1,15,50,2,' ') term.setCursor(2,16) io.write('Page: ',page1) term.setCursor(14,16) io.write('<Back|Next>') term.setCursor(46,16) io.write('Exit') term.setCursor(31,16) io.write('Select[#]') pal6(men6) term.setCursor(1,1)
- if oldPage1 ~= page1 then
- gpu.fill(1,1,50,14,' ')
- for i=k1,j1 do
- os.sleep(0.000001)
- if ab1[#ab1]~=nil then
- if ab1[i]~=nil then
- ab2='['..i..']'..'["'..abl[i]..'"]='
- os.sleep(0.000001)
- ab3=loadTbl('/chests/'..ab1[i]..'.txt')
- ab2=ab2..ab3['x']..','..ab3['y']..','..ab3['z']
- print(ab2)
- end oldPage1=page1 else term.setCursor(15,7) io.write('Пусто!') break
- end end end p2=getxy()
- if p2==203 then men6=men6-1 if men6<1 then men6=1 end
- elseif p2==205 then men6=men6+1 if men6>4 then men6=4 end elseif p2==28 then
- if men6==1 then if k1~=1 then k1=k1-14 j1=j1-14 page1=page1-1 end
- elseif men6==2 then k1=k1+14 j1=j1+14 page1=page1+1 elseif men6==3 then
- gpu.fill(1,16,50,1,' ') term.setCursor(1,16) io.write('Position: > ') item1=tonumber(io.read()) getxy() item=abl[item1] et1=false et2=false
- elseif men6==4 then term.clear() et1=false end end end
- elseif men5==3 then et2=false end end
- end return item end
- function delFile()
- et4=true
- while et4 do
- term.clear() helps() pal4(men4) term.setCursor(1,4)
- for i=1,3 do print(b1[1]) print('║ '.. bun[i] ..' ║') print(b1[7]) end
- p2=getxy()
- if p2==200 then men4=men4-1 if men4<1 then men4=1 end
- elseif p2==208 then men4=men4+1 if men4>3 then men4=3 end
- elseif p2==28 then
- if men4==1 then
- term.clear()
- io.write("Enter chestname: ") chn=tostring(io.read())
- chn1=loadTbl("chests.txt")
- for i=1,#chn1 do
- if chn1[i]==chn then delo1=1 break else delo1=0 end
- end
- if delo1==0 then gpu.set(15,7,'Cannot find this name!') os.sleep(2)
- else
- for i=1,#chn1 do
- if chn1[i]==chn then chn1[i]=del end
- saveTbl(chn1,'chests.txt')
- end
- getxy()
- term.clear()
- fs.remove('/chests/'..chn..".txt")
- gpu.set(15,7,'Chest: '..chn..' deleted!')
- os.sleep(1.7)
- for i=1,#chn1 do
- if chn1[i]==chn then chn1[i]=del end
- end
- saveTbl(chn1,"chests.txt")
- end
- elseif men4==2 then
- term.clear()
- io.write("Enter name of craft: ") chn2=tostring(io.read())
- chn3=loadTbl("craftNames.txt")
- for i=1,#chn3 do
- if chn3[i]==chn2..'.txt' then delo=1 break else delo=0 end
- end
- if delo==0 then io.write("Cannot find this name!") os.sleep(2)
- else
- fs.remove('/crafts/'..chn2..".txt")
- for i=1,#chn3 do
- if chn3[i]==chn2 then chn3[i]=del end
- end
- term.clear()
- gpu.set(15,7,'Craft: '..chn2..' deleted!')
- os.sleep(1.7)
- saveTbl(chn3,"craftNames.txt")
- m.send('del'..chn2)
- end
- getxy()
- elseif men4==3 then term.clear() et4=false end end
- end end
- function menu()
- term.clear()
- helps()
- for i=1,5 do print(b1[1]) print('║ ' .. b1[i+1] ..' ║') print(b1[7]) end
- pal(men)
- p2=getxy()
- if p2==208 then men=men+1 if men>5 then men=5 end
- elseif p2==200 then men=men-1 if men<1 then men=1 end
- elseif p2==28 then
- if men==1 then term.clear() addChest()
- elseif men==2 then term.clear() addCraft()
- elseif men==3 then term.clear() chestList()
- elseif men==4 then term.clear() delFile()
- elseif men==5 then term.clear() os.exit() end
- end
- end
- function chestList()
- ab1=loadTbl('chests.txt')
- for i=1,#ab1 do abl[i]=ab1[i] end
- page=1
- k=1 j=14
- et3=true
- oldPage=0
- while et3 do
- gpu.fill(1,15,50,2,' ')
- term.setCursor(2,16) io.write('Page: ',page)
- term.setCursor(19,16) io.write('<Back|Next>')
- term.setCursor(46,16) io.write('Exit') pal2(men2)
- term.setCursor(1,1)
- if oldPage ~= page then
- gpu.fill(1,1,50,14,' ')
- for i=k,j do
- os.sleep(0.000001)
- if ab1[#ab1]~=nil then
- if ab1[i]~=nil then
- ab2='["'..abl[i]..'"]='
- os.sleep(0.000001)
- ab3=loadTbl('/chests/'..ab1[i]..'.txt')
- ab2=ab2..ab3['x']..','..ab3['y']..','..ab3['z']
- print(ab2)
- end
- oldPage=page
- else
- term.setCursor(15,7) io.write('Пусто!') break
- end end end
- p2=getxy()
- if p2==203 then men2=men2-1 if men2<1 then men2=1 end
- elseif p2==205 then men2=men2+1 if men2>3 then men2=3 end
- elseif p2==28 then
- if men2==1 then if k~=1 then k=k-14 j=j-14 page=page-1 end
- elseif men2==2 then k=k+14 j=j+14 page=page+1
- elseif men2==3 then term.clear() et3=false end end
- end
- end
- function addChest()
- term.setCursor(15,7) io.write('Enter name: ') chname=tostring(io.read())
- term.clear() term.setCursor(15,6) io.write("Enter X: ") x=tonumber(io.read())
- term.setCursor(15,7) io.write("Enter Y: ") y=tonumber(io.read())
- term.setCursor(15,8) io.write("Enter Z: ") z=tonumber(io.read())
- ch2=loadTbl('chests.txt')
- ch2[#ch2+1]=chname
- saveTbl(ch2,'chests.txt')
- ch1=io.open('/chests/'..chname..'.txt','w')
- ch1:write('{["x"]='..x..',["y"]='..y..',["z"]='..z..'}')
- ch1:close()
- getxy()
- end
- function addCraft()
- lc={}
- et=true
- term.clear() term.setCursor(15,7) io.write('Enter craft: ') name=tostring(io.read())
- term.clear() term.setCursor(15,7) io.write('Enter min: ') ma=tostring(io.read())
- term.clear()
- newCraft=name..'.txt' newCraft=tostring(newCraft)
- cn=loadTbl('craftNames.txt') if #cn ==nil then cn[#cn]=newCraft saveTbl(cn,'craftNames.txt') else cn[#cn+1]=newCraft saveTbl(cn,'craftNames.txt') end
- getxy()
- while et do
- ben()
- pal3(men3)
- p2=getxy()
- if p2==205 then men3=men3+1 if men3>11 then men3=11 end
- elseif p2==203 then men3=men3-1 if men3<1 then men3=1 end
- elseif p2==200 then men3=men3-3 if men3<1 then men3=1 end
- elseif p2==208 then men3=men3+3 if men3>11 then men3=11 end
- elseif p2==28 then
- if men3==10 then os.sleep(1) term.clear() et=false
- elseif men3==11 then
- fil=io.open('/crafts/'..newCraft,'w') fil:write('{') fil:close()
- fil=io.open('/crafts/'..newCraft,'a')
- for j=1,9 do
- if lc[j] ~= nil then toi='["'.. b[j] ..'"]=' .. '"' .. lc[j] ..'"'
- else toi='["'..b[j]..'"]='..'"empty"' end
- lcp[j]=toi
- end
- for k=1,#lcp do
- if k==#lcp then fil:write(lcp[k]) fil:write(',["min"]='..ma..'}') elseif k~=#lcp then fil:write(lcp[k]) fil:write(',') end
- end
- fil:close()
- m.send('add'..name)
- et=false
- else
- item=selectChest()
- lc[men3]=item
- term.clear() ben() pal3(men3)
- end end end end
- function ben()
- term.clear()
- print(bench[1]) print(bench[2]) print(bench[2]) print(bench[3]) print(bench[2]) print(bench[2]) print(bench[3]) print(bench[2]) print(bench[2]) print(bench[4])
- term.setCursor(1,11) io.write('┎╼╼╼╼╼╼┒┎╼╼╼╼╼╼╼╼╼┒')
- term.setCursor(1,12) io.write('┃ back ┃┃ success ┃')
- term.setCursor(1,13) io.write('┖╼╼╼╼╼╼┚┖╼╼╼╼╼╼╼╼╼┚')
- term.setCursor(2,3) if lc[1]~= nil then io.write(unicode.sub(lc[1],1,5)) end
- term.setCursor(8,3) if lc[2]~= nil then io.write(unicode.sub(lc[2],1,5)) end
- term.setCursor(14,3) if lc[3]~=nil then io.write(unicode.sub(lc[3],1,5)) end
- term.setCursor(2,6) if lc[4]~=nil then io.write(unicode.sub(lc[4],1,5)) end
- term.setCursor(8,6) if lc[5]~=nil then io.write(unicode.sub(lc[5],1,5)) end
- term.setCursor(14,6) if lc[6]~=nil then io.write(unicode.sub(lc[6],1,5)) end
- term.setCursor(2,9) if lc[7]~=nil then io.write(unicode.sub(lc[7],1,5)) end
- term.setCursor(8,9) if lc[8]~=nil then io.write(unicode.sub(lc[8],1,5)) end
- term.setCursor(14,9) if lc[9]~=nil then io.write(unicode.sub(lc[9],1,5)) end
- end
- getxy()
- while true do menu() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement