Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local term=require('term')
- local event=require('event')
- local shell=require('shell')
- local com = require("component")
- local fs=require('filesystem')
- local serialization=require('serialization')
- 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
- local is=com.inventory_controller
- local s = require("sides")
- local gpu=com.gpu
- men=1 men2=3 abl={} abl2={} plk='▌' b={"╔═══════════════════════════╗",'Launch sort ',' Add chest ',' Chest list ','Delete chest',' Exit ','╚═══════════════════════════╝'}
- 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 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
- function getxy() _,_,_,k2,_=event.pull('key_up') return k2 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 delFile()
- term.clear()
- gpu.set(7,5,'═════════════╬Delete╬═════════════') gpu.set(7,9,'══════════════════════════════════')
- term.setCursor(27,7) gpu.set(7,7,"Enter chestname: ") chn2=tostring(io.read())
- chn3=loadTbl("chests.txt")
- for i=1,#chn3 do
- if chn3[i]==chn2..'.txt' then delo=1 break else delo=0 end
- end
- if delo==0 then gpu.set(5,5,'═════════════╬Delete╬═════════════') gpu.set(10,7,'Cannot find this name!') gpu.set(5,9,'══════════════════════════════════') os.sleep(2)
- else
- shell.execute("del /chests/"..chn2..".txt")
- for i=1,#chn3 do
- if chn3[i]==chn2 then chn3[i]=del end
- end
- term.clear()
- gpu.set(5,5,'═════════════╬Delete╬═════════════')
- gpu.set(15,7,'Craft: '..chn2..' deleted!')
- gpu.set(5,9,'══════════════════════════════════')
- os.sleep(1.7)
- saveTbl(chn3,"chests.txt")
- end
- end
- function addChest()
- term.clear() gpu.set(5,5,'═══════════╬Add chest╬════════════') gpu.set(5,6,' Положите предмет в 1 слот робота. ') gpu.set(5,7,' После чего нажмите любую клавишу!') gpu.set(5,8,'══════════════════════════════════') getxy() term.clear()
- gpu.set(5,5,'═══════════╬Add chest╬════════════') gpu.set(5,9,'══════════════════════════════════') term.setCursor(15,6) io.write("Enter X: ") fx=tonumber(io.read()) term.setCursor(15,7) io.write("Enter Y: ") fy=tonumber(io.read()) term.setCursor(15,8) io.write("Enter Z: ") fz=tonumber(io.read())
- scans = is.getStackInInternalSlot(1)
- a = scans["label"]
- a=string.gsub(a,' ','_')
- ch=loadTbl('chests.txt')
- ch[#ch+1]=a
- saveTbl(ch,'chests.txt')
- fil=io.open('/chests/'..a..'.txt','w')
- fil:write('{["x"]='..fx..',["y"]='..fy..',["z"]='..fz..'}')
- fil:close() getxy()
- 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 menu()
- term.clear() helps() for i=1,5 do print(b[1]) print('║ ' .. b[i+1] ..' ║') print(b[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() shell.execute('sorter')
- elseif men==2 then term.clear() addChest()
- 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
- getxy() while true do menu() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement