Advertisement
Guest User

NanoControl.lua

a guest
Mar 8th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.30 KB | None | 0 0
  1. local c = require("component")
  2. local e = require("event")
  3. local color = require("colors")
  4. local term = require("term")
  5. local string = require("string")
  6.  
  7. local m = c.modem
  8. local gpu = c.gpu
  9. local CFon,CText, CFig, CRed, CGreen, CBut = 0xAAAAAA, 0x5F5F5F, 0x313131, 0xCC4C4C, 0x279C38, 0xAAAAAA
  10. local NanAd,NanPort = '0bb35ff9-f2ca-4c58-863a-db6d5af8a229', 37536
  11. local Act = {}
  12. m.open(37536)
  13. --m.broadcast(37536,"nanomachines", "setResponsePort",37536)
  14. --m.send('0bb35ff9-f2ca-4c58-863a-db6d5af8a229',37536,"nanomachines","getHealth")
  15. --m.broadcast(37536,"nanomachines", "getHealth")
  16.  
  17. local i = 0
  18.  
  19. while i < 18 do --что файл что фор, всеравно 18 секунд((
  20.   i = i+1
  21.   local s = 0
  22.   m.send(NanAd,NanPort,"nanomachines","getInput",i)
  23.   while true do
  24.   local e,_,_,_,_,_,_,_,s = e.pull("modem_message") --как прощелкать каждый вывод, возможно посмотри  в другие проги
  25.     if e == "modem_message" then
  26.  
  27.       if s == true then
  28.         Act[i] = 1
  29.       else
  30.         Act[i] = 0
  31.       end
  32.       os.sleep(0.01)
  33.       break
  34.     end
  35.   end
  36. end
  37.  
  38. function WaitMsg() -- основное ожидание событий
  39.   while true do
  40.     term.setCursor(1,25)
  41.  
  42.     local ev,s2,CliX,but,s5,s6,mes,mes1,mes2 = e.pull()
  43.     if ev == "modem_message" then
  44.       if type(mes1) == "number" then
  45.       mes1 = tonumber(mes1)
  46.       --else
  47.  
  48.       end
  49.       if type(mes2) == "number" then
  50.         mes2 = tonumber(mes2)
  51.       else
  52.         mes2 = " "
  53.       end
  54.       --print("вроде как норм?")
  55.       --mes1 = tonumber(mes1)
  56.       --mes2 = tonumber(mes2)
  57.       gpu.set(4,25,"Показатель: "..mes.." "..mes1.." "..mes2)
  58.       os.sleep(2)
  59.       gpu.fill(4,25,80,1," ")
  60.     elseif ev == "touch" then
  61.       if CliX>41 and CliX<58 then
  62.         if but>3 and but<7 then
  63.           m.send(NanAd,NanPort,"nanomachines","getHealth")
  64.         elseif but>6 and but<10 then
  65.           m.send(NanAd,NanPort,"nanomachines","getHunger")
  66.         elseif but>9 and but<13 then
  67.           m.send(NanAd,NanPort,"nanomachines","getPowerState")
  68.         elseif but>12 and but<16 then
  69.           m.send(NanAd,NanPort,"nanomachines","getAge")
  70.         elseif but>15 and but<19 then
  71.           m.send(NanAd,NanPort,"nanomachines", "getName")
  72.         end
  73.       elseif CliX>59 and CliX<76 then
  74.         if but>3 and but<7 then
  75.           m.send(NanAd,NanPort,"nanomachines","getActiveEffects")
  76.         end
  77.       elseif CliX>5 and CliX<12 then
  78.         for i=1, 9 do
  79.           if but==i*2+2 then
  80.             if Act[i] == 0 then
  81.               Act[i] = 1
  82.               m.send(NanAd,NanPort,"nanomachines","setInput",i,true)
  83.               gpu.setBackground(CGreen)
  84.               gpu.set(13,i*2+2,tostring(i).." ")
  85.             else
  86.               Act[i] = 0
  87.               m.send(NanAd,NanPort,"nanomachines","setInput",i,false)
  88.               gpu.setBackground(CRed)
  89.               gpu.set(13,i*2+2,tostring(i).." ")
  90.             end
  91.           end
  92.         end
  93.       elseif CliX>25 and CliX<32 then
  94.         for i=1, 9 do
  95.           if but==i*2+2 then
  96.             if Act[i+9] == 0 then
  97.               Act[i+9] = 1
  98.               m.send(NanAd,NanPort,"nanomachines","setInput",i+9,true)
  99.               gpu.setBackground(CGreen)
  100.               gpu.set(23,i*2+2,tostring(i+9))
  101.             else
  102.               Act[i+9] = 0
  103.               m.send(NanAd,NanPort,"nanomachines","setInput",i+9,false)
  104.               gpu.setBackground(CRed)
  105.               gpu.set(23,i*2+2,tostring(i+9))
  106.             end
  107.           end
  108.         end
  109.       end
  110.     gpu.setBackground(CFon)
  111.     elseif ev == "key_down" then
  112.       if but == 16 then --Q
  113.         gpu.set(4,25,"бай-бай")
  114.         m.close(37536)
  115.         gpu.setBackground(CFig)
  116.         gpu.setForeground(CFon)
  117.         os.sleep(2)
  118.         term.clear()
  119.         os.exit()
  120.       end
  121.     end
  122.    
  123.     --print(s2)--пишем всякую фигню(данные) чтоб зналь
  124.     --print(CliX)
  125.     --print(but)
  126.     --print(s5)
  127.     --print(s6)
  128.   end
  129. end
  130.  
  131. gpu.setBackground(CFon)
  132. gpu.setForeground(CText)
  133. term.clear()
  134. --term.setCursor(1,25)
  135. gpu.fill(1,24,80,1,"`")
  136. gpu.setForeground(CFig)
  137. gpu.set(12, 3,"╔════════════╗")
  138. for i = 1,17 do
  139. gpu.set(12,3+i,"║            ║")
  140. end
  141. gpu.set(12,21,"╚════════════╝")
  142. local xC = 4
  143.  
  144. for i=1,9 do
  145.   gpu.setBackground(CFon)
  146.   gpu.fill(6,xC,6,1,"═")--6 29
  147.   gpu.fill(26,xC,6,1,"═")
  148.   if Act[i] == 0 then
  149.     gpu.setBackground(CRed)
  150.     gpu.set(13,xC,tostring(i).." ")
  151.   else
  152.     gpu.setBackground(CGreen)
  153.     gpu.set(13,xC,tostring(i).." ")
  154.   end
  155.   if Act[i+9] == 0 then
  156.     gpu.setBackground(CRed)
  157.     gpu.set(23,xC,tostring(i+9))
  158.   else
  159.     gpu.setBackground(CGreen)
  160.     gpu.set(23,xC,tostring(i+9))
  161.   end
  162.   xC = xC+2
  163. end
  164.  
  165. gpu.setForeground(CText)
  166. gpu.setBackground(CBut)
  167.  
  168. --gpu.fill(41,4,15,3," ")
  169. local xC = 4
  170. local sa = {"health","hunger","energy"," age"," name","effects","2","3","4","5"}
  171. for i = 1, 5 do
  172.  
  173. gpu.set(42, xC, "╔══════════════╗")
  174. gpu.set(42,xC+1,"║              ║")--sa[i])
  175. gpu.set(42,xC+2,"╚══════════════╝")
  176. gpu.set(45,xC+1,"  "..sa[i])
  177. gpu.set(60, xC, "╔══════════════╗")
  178. gpu.set(60,xC+1,"║              ║")
  179. gpu.set(60,xC+2,"╚══════════════╝")
  180. gpu.set(63,xC+1,"  "..sa[i+5])
  181. xC = xC+3
  182. end
  183. function graff()
  184.  
  185.  
  186. end
  187. WaitMsg()
  188.  
  189. --graff()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement