Advertisement
MeXaN1cK

s.ru

Mar 31st, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.06 KB | None | 0 0
  1. local term=require('term')
  2. local event=require('event')
  3. local shell=require('shell')
  4. local com = require("component")
  5. local fs=require('filesystem')
  6. local serialization=require('serialization')
  7. local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
  8. 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
  9. local is=com.inventory_controller
  10. local s = require("sides")
  11. local gpu=com.gpu
  12. men=1 men2=3 abl={} abl2={} plk='▌' b={"╔═══════════════════════════╗",'Launch sort ','  Add chest ',' Chest list ','Delete chest','    Exit    ','╚═══════════════════════════╝'}
  13. 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
  14. 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
  15. function getxy() _,_,_,k2,_=event.pull('key_up') return k2 end
  16. 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
  17.  
  18. function delFile()
  19. term.clear()
  20. gpu.set(7,5,'═════════════╬Delete╬═════════════') gpu.set(7,9,'══════════════════════════════════')
  21. term.setCursor(27,7) gpu.set(7,7,"Enter chestname: ") chn2=tostring(io.read())
  22. chn3=loadTbl("chests.txt")
  23. for i=1,#chn3 do
  24. if chn3[i]==chn2..'.txt' then delo=1 break else delo=0 end
  25. end
  26. if delo==0 then gpu.set(5,5,'═════════════╬Delete╬═════════════') gpu.set(10,7,'Cannot find this name!') gpu.set(5,9,'══════════════════════════════════') os.sleep(2)
  27. else
  28. shell.execute("del /chests/"..chn2..".txt")
  29. for i=1,#chn3 do
  30.  if chn3[i]==chn2 then chn3[i]=del end
  31. end
  32.  term.clear()
  33.  gpu.set(5,5,'═════════════╬Delete╬═════════════')
  34.  gpu.set(15,7,'Craft: '..chn2..' deleted!')
  35.  gpu.set(5,9,'══════════════════════════════════')
  36.  os.sleep(1.7)
  37.  saveTbl(chn3,"chests.txt")
  38. end
  39. end
  40.  
  41. function addChest()
  42. term.clear() gpu.set(5,5,'═══════════╬Add chest╬════════════') gpu.set(5,6,' Положите предмет в 1 слот робота. ')  gpu.set(5,7,' После чего нажмите любую клавишу!') gpu.set(5,8,'══════════════════════════════════') getxy()  term.clear()
  43. 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())
  44. scans = is.getStackInInternalSlot(1)
  45.  a = scans["label"]
  46.  a=string.gsub(a,' ','_')
  47.  ch=loadTbl('chests.txt')
  48.  ch[#ch+1]=a
  49.  saveTbl(ch,'chests.txt')
  50.  fil=io.open('/chests/'..a..'.txt','w')
  51.  fil:write('{["x"]='..fx..',["y"]='..fy..',["z"]='..fz..'}')
  52.  fil:close() getxy()
  53. end
  54.  
  55. function chestList()
  56. ab1=loadTbl('chests.txt')
  57. for i=1,#ab1 do abl[i]=ab1[i] end
  58. page=1
  59. k=1 j=14
  60. et3=true
  61. oldPage=0
  62. while et3 do
  63. gpu.fill(1,15,50,2,' ')
  64. term.setCursor(2,16) io.write('Page: ',page)
  65. term.setCursor(19,16) io.write('<Back|Next>')
  66. term.setCursor(46,16) io.write('Exit') pal2(men2)
  67. term.setCursor(1,1)
  68. if oldPage ~= page then
  69. gpu.fill(1,1,50,14,' ')
  70. for i=k,j do
  71. os.sleep(0.000001)
  72. if ab1[#ab1]~=nil then
  73. if ab1[i]~=nil then
  74. ab2='["'..abl[i]..'"]='
  75. os.sleep(0.000001)
  76. ab3=loadTbl('/chests/'..ab1[i]..'.txt')
  77. ab2=ab2..ab3['x']..','..ab3['y']..','..ab3['z']
  78. print(ab2)
  79. end
  80. oldPage=page
  81. else
  82. term.setCursor(15,7) io.write('Пусто!') break
  83. end end end
  84. p2=getxy()
  85. if p2==203 then men2=men2-1 if men2<1 then men2=1 end
  86. elseif p2==205 then men2=men2+1 if men2>3 then men2=3 end
  87. elseif p2==28 then
  88. if men2==1 then if k~=1 then k=k-14 j=j-14 page=page-1 end
  89. elseif men2==2 then k=k+14 j=j+14 page=page+1
  90. elseif men2==3 then term.clear() et3=false end end
  91. end
  92. end
  93.  
  94. function menu()
  95. term.clear() helps() for i=1,5 do print(b[1]) print('║       ' .. b[i+1] ..'        ║') print(b[7]) end pal(men) p2=getxy()
  96. if p2==208 then men=men+1 if men>5 then men=5 end
  97. elseif p2==200 then men=men-1 if men<1 then men=1 end
  98. elseif p2==28 then
  99. if men==1 then term.clear() shell.execute('sorter')
  100. elseif men==2 then term.clear() addChest()
  101. elseif men==3 then term.clear() chestList()
  102. elseif men==4 then term.clear() delFile()
  103. elseif men==5 then term.clear() os.exit() end
  104. end
  105. end
  106. getxy() while true do menu() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement