Advertisement
MeXaN1cK

ru

Mar 29th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.49 KB | None | 0 0
  1. local fs=require('filesystem')
  2. local shell=require('shell')
  3. local event = require('event')
  4. local term = require('term')
  5. local c = require('component')
  6. local gpu = c.gpu
  7. local serialization = require('serialization')
  8. local unicode=require('unicode')
  9. local name
  10. local h=4
  11. bun ={'Delete chest','Delete craft','    Exit    '} bun1={' Enter name ','Select chest','    Exit    '}
  12. men=1 men2=3 men3=10 men4=3 men5=3 men6=4
  13. plk='▌' plk2='▀' abl={} abl2={} lc={} lcp={}
  14. local b={'1','2','3','5','6','7','9','10','11','12','13'}
  15. local m= c.tunnel
  16. local bench={'╔═════╦═════╦═════╗','║     ║     ║     ║','╠═════╬═════╬═════╣','╚═════╩═════╩═════╝'} h=3
  17. function getxy() _,_,_,k2,_=event.pull('key_up') return k2 end
  18. local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
  19. 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
  20. 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
  21. local b1={"╔═══════════════════════════╗",' Add chest',' Add craft','Chest list','  Delete  ','   Exit   ','╚═══════════════════════════╝'}
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27.  
  28. function selectChest()
  29. item=nil item1=nil et2=true
  30. while et2 do
  31. 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()
  32. if p2==200 then men5=men5-1 if men5<1 then men5=1 end
  33. elseif p2==208 then men5=men5+1 if men5>3 then men5=3 end
  34. elseif p2==28 then
  35. if men5==1 then term.clear() term.setCursor(15,7) io.write('Chest name: ') item=tostring(io.read()) term.clear() getxy() et2=false
  36. elseif men5==2 then
  37. ab1=loadTbl('chests.txt') for i=1,#ab1 do abl[i]=ab1[i] end page1=1 k1=1 j1=14 et1=true oldPage1=0
  38. while et1 do
  39. 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)
  40. if oldPage1 ~= page1 then
  41. gpu.fill(1,1,50,14,' ')
  42. for i=k1,j1 do
  43. os.sleep(0.000001)
  44. if ab1[#ab1]~=nil then
  45. if ab1[i]~=nil then
  46. ab2='['..i..']'..'["'..abl[i]..'"]='
  47. os.sleep(0.000001)
  48. ab3=loadTbl('/chests/'..ab1[i]..'.txt')
  49. ab2=ab2..ab3['x']..','..ab3['y']..','..ab3['z']
  50. print(ab2)
  51. end oldPage1=page1 else term.setCursor(15,7) io.write('Пусто!') break
  52. end end end p2=getxy()
  53. if p2==203 then men6=men6-1 if men6<1 then men6=1 end
  54. elseif p2==205 then men6=men6+1 if men6>4 then men6=4 end elseif p2==28 then
  55. if men6==1 then if k1~=1 then k1=k1-14 j1=j1-14 page1=page1-1 end
  56. elseif men6==2 then k1=k1+14 j1=j1+14 page1=page1+1 elseif men6==3 then
  57. 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
  58. elseif men6==4 then term.clear() et1=false end end end
  59. elseif men5==3 then et2=false end end
  60. end return item end
  61.  
  62. function delFile()
  63. et4=true
  64. while et4 do
  65. term.clear() helps() pal4(men4) term.setCursor(1,4)
  66. for i=1,3 do print(b1[1]) print('║        '.. bun[i] ..'       ║')   print(b1[7]) end
  67. p2=getxy()
  68. if p2==200 then men4=men4-1 if men4<1 then men4=1 end
  69. elseif p2==208 then men4=men4+1 if men4>3 then men4=3 end
  70. elseif p2==28 then
  71. if men4==1 then
  72. term.clear()
  73. io.write("Enter chestname: ") chn=tostring(io.read())
  74. chn1=loadTbl("chests.txt")
  75. for i=1,#chn1 do
  76. if chn1[i]==chn then delo1=1 break else delo1=0 end
  77. end
  78. if delo1==0 then gpu.set(15,7,'Cannot find this name!') os.sleep(2)
  79. else
  80. for i=1,#chn1 do
  81. if chn1[i]==chn then chn1[i]=del end
  82. saveTbl(chn1,'chests.txt')
  83. end
  84. getxy()
  85. term.clear()
  86. fs.remove('/chests/'..chn..".txt")
  87. gpu.set(15,7,'Chest: '..chn..' deleted!')
  88. os.sleep(1.7)
  89. for i=1,#chn1 do
  90.  if chn1[i]==chn then chn1[i]=del end
  91. end
  92.  saveTbl(chn1,"chests.txt")
  93. end
  94. elseif men4==2 then
  95. term.clear()
  96. io.write("Enter name of craft: ") chn2=tostring(io.read())
  97. chn3=loadTbl("craftNames.txt")
  98. for i=1,#chn3 do
  99. if chn3[i]==chn2..'.txt' then delo=1 break else delo=0 end
  100. end
  101. if delo==0 then io.write("Cannot find this name!") os.sleep(2)
  102. else
  103. fs.remove('/crafts/'..chn2..".txt")
  104. for i=1,#chn3 do
  105.  if chn3[i]==chn2 then chn3[i]=del end
  106. end
  107.  term.clear()
  108.  gpu.set(15,7,'Craft: '..chn2..' deleted!')
  109.  os.sleep(1.7)
  110.  saveTbl(chn3,"craftNames.txt")
  111.  m.send('del'..chn2)
  112. end
  113. getxy()
  114. elseif men4==3 then term.clear() et4=false end end
  115. end end
  116.  
  117. function menu()
  118. term.clear()
  119. helps()
  120. for i=1,5 do print(b1[1]) print('║        ' .. b1[i+1] ..'         ║') print(b1[7]) end
  121. pal(men)
  122. p2=getxy()
  123. if p2==208 then men=men+1 if men>5 then men=5 end
  124. elseif p2==200 then men=men-1 if men<1 then men=1 end
  125. elseif p2==28 then
  126. if men==1 then term.clear() addChest()
  127. elseif men==2 then term.clear() addCraft()
  128. elseif men==3 then term.clear() chestList()
  129. elseif men==4 then term.clear() delFile()
  130. elseif men==5 then term.clear() os.exit() end
  131. end
  132. end
  133.  
  134. function chestList()
  135. ab1=loadTbl('chests.txt')
  136. for i=1,#ab1 do abl[i]=ab1[i] end
  137. page=1
  138. k=1 j=14
  139. et3=true
  140. oldPage=0
  141. while et3 do
  142. gpu.fill(1,15,50,2,' ')
  143. term.setCursor(2,16) io.write('Page: ',page)
  144. term.setCursor(19,16) io.write('<Back|Next>')
  145. term.setCursor(46,16) io.write('Exit') pal2(men2)
  146. term.setCursor(1,1)
  147. if oldPage ~= page then
  148. gpu.fill(1,1,50,14,' ')
  149. for i=k,j do
  150. os.sleep(0.000001)
  151. if ab1[#ab1]~=nil then
  152. if ab1[i]~=nil then
  153. ab2='["'..abl[i]..'"]='
  154. os.sleep(0.000001)
  155. ab3=loadTbl('/chests/'..ab1[i]..'.txt')
  156. ab2=ab2..ab3['x']..','..ab3['y']..','..ab3['z']
  157. print(ab2)
  158. end
  159. oldPage=page
  160. else
  161. term.setCursor(15,7) io.write('Пусто!') break
  162. end end end
  163. p2=getxy()
  164. if p2==203 then men2=men2-1 if men2<1 then men2=1 end
  165. elseif p2==205 then men2=men2+1 if men2>3 then men2=3 end
  166. elseif p2==28 then
  167. if men2==1 then if k~=1 then k=k-14 j=j-14 page=page-1 end
  168. elseif men2==2 then k=k+14 j=j+14 page=page+1
  169. elseif men2==3 then term.clear() et3=false end end
  170. end
  171. end
  172.  
  173. function addChest()
  174. term.setCursor(15,7) io.write('Enter name: ') chname=tostring(io.read())
  175. term.clear() term.setCursor(15,6) io.write("Enter X: ") x=tonumber(io.read())
  176. term.setCursor(15,7) io.write("Enter Y: ") y=tonumber(io.read())
  177. term.setCursor(15,8) io.write("Enter Z: ") z=tonumber(io.read())
  178. ch2=loadTbl('chests.txt')
  179. ch2[#ch2+1]=chname
  180. saveTbl(ch2,'chests.txt')
  181. ch1=io.open('/chests/'..chname..'.txt','w')
  182. ch1:write('{["x"]='..x..',["y"]='..y..',["z"]='..z..'}')
  183. ch1:close()
  184. getxy()
  185. end
  186.  
  187. function addCraft()
  188. lc={}
  189. et=true
  190. term.clear() term.setCursor(15,7) io.write('Enter craft: ') name=tostring(io.read())
  191. term.clear() term.setCursor(15,7) io.write('Enter min: ') ma=tostring(io.read())
  192. term.clear()
  193. newCraft=name..'.txt' newCraft=tostring(newCraft)
  194. 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
  195. getxy()
  196. while et do
  197. ben()
  198. pal3(men3)
  199. p2=getxy()
  200. if p2==205 then men3=men3+1 if men3>11 then men3=11 end
  201. elseif p2==203 then men3=men3-1 if men3<1 then men3=1 end
  202. elseif p2==200 then men3=men3-3 if men3<1 then men3=1 end
  203. elseif p2==208 then men3=men3+3 if men3>11 then men3=11 end
  204. elseif p2==28 then
  205. if men3==10 then os.sleep(1) term.clear() et=false
  206. elseif men3==11 then
  207. fil=io.open('/crafts/'..newCraft,'w') fil:write('{') fil:close()
  208. fil=io.open('/crafts/'..newCraft,'a')
  209. for j=1,9 do
  210. if lc[j] ~= nil then toi='["'.. b[j] ..'"]=' .. '"' .. lc[j] ..'"'
  211. else toi='["'..b[j]..'"]='..'"empty"' end
  212. lcp[j]=toi
  213. end
  214. for k=1,#lcp do
  215. if k==#lcp then fil:write(lcp[k]) fil:write(',["min"]='..ma..'}') elseif k~=#lcp then fil:write(lcp[k]) fil:write(',') end
  216. end
  217. fil:close()
  218. m.send('add'..name)
  219. et=false
  220. else
  221. item=selectChest()
  222. lc[men3]=item
  223. term.clear() ben() pal3(men3)
  224. end end end end
  225.  
  226. function ben()
  227. term.clear()
  228. 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])
  229. term.setCursor(1,11) io.write('┎╼╼╼╼╼╼┒┎╼╼╼╼╼╼╼╼╼┒')
  230. term.setCursor(1,12) io.write('┃ back ┃┃ success ┃')
  231. term.setCursor(1,13) io.write('┖╼╼╼╼╼╼┚┖╼╼╼╼╼╼╼╼╼┚')
  232. term.setCursor(2,3) if lc[1]~= nil then io.write(unicode.sub(lc[1],1,5)) end
  233. term.setCursor(8,3) if lc[2]~= nil then io.write(unicode.sub(lc[2],1,5)) end
  234. term.setCursor(14,3) if lc[3]~=nil then io.write(unicode.sub(lc[3],1,5)) end
  235. term.setCursor(2,6) if lc[4]~=nil then io.write(unicode.sub(lc[4],1,5)) end
  236. term.setCursor(8,6) if lc[5]~=nil then io.write(unicode.sub(lc[5],1,5)) end
  237. term.setCursor(14,6) if lc[6]~=nil then io.write(unicode.sub(lc[6],1,5)) end
  238. term.setCursor(2,9) if lc[7]~=nil then io.write(unicode.sub(lc[7],1,5)) end
  239. term.setCursor(8,9) if lc[8]~=nil then io.write(unicode.sub(lc[8],1,5)) end
  240. term.setCursor(14,9) if lc[9]~=nil then io.write(unicode.sub(lc[9],1,5)) end
  241. end
  242. getxy()
  243. while true do menu() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement