Advertisement
kwinto93

getMethods

Aug 19th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.71 KB | None | 0 0
  1.  --[[Stworzone przez kwinto93
  2.     Created by kwinto93
  3.     http://www.youtube.com/user/kwinto93
  4. --]]
  5.  
  6. os.loadAPI("ocs/apis/sensor") -- ładujemy API, bardzo istotna linijka
  7.  
  8. local ArgStartowe = {...}
  9. local strona = ArgStartowe[1]
  10.  
  11. sensor = nil
  12.  
  13. local linijka = 1
  14. local pokaz = 10 -- pokazuje 10 linii na raz
  15. local targets = false
  16.  
  17. local nameCurTarget = nil
  18.  
  19. local menuList = {} -- lista pozycji menu, zawierająca kolejne tabele
  20. local pozycja = 1
  21.  
  22. function main()
  23.     local wyjdz = false
  24.    
  25.     info()
  26.    
  27.     sleep(1)
  28.    
  29.     if strona == nil then
  30.         term.clear()
  31.         term.setCursorPos(1,1)
  32.         print("Uzycie: podlacz sensor i wloz do niego karte.")
  33.         print("Wpisz w konsoli: getMethods.lua <strona_komputera>\n")
  34.         sleep(2)
  35.         return
  36.     else
  37.         sensor = sensor.wrap(strona)
  38.     end
  39.    
  40.     while wyjdz == false do
  41.         local event, keyNum = os.pullEvent("key")
  42.        
  43.         if keyNum == 200 then
  44.             linijka = linijka - 1
  45.             if linijka < 1 then linijka = linijka + 1 end
  46.         elseif keyNum == 208 then
  47.             linijka = linijka + 1
  48.             if linijka > #menuList[pozycja] then linijka = linijka - 1 end
  49.         elseif keyNum == 18 then
  50.             wyjdz = true
  51.         elseif keyNum == 20 then
  52.             linijka = 1
  53.             loadTargets()
  54.             targets = true
  55.         elseif keyNum == 28 or keyNum == 205 then
  56.             loadDetails(menuList[pozycja])
  57.             linijka = 1
  58.         elseif keyNum == 203 or keyNum == 14 then
  59.             if pozycja > 1 then pozycja = pozycja - 1 end
  60.             linijka = 1
  61.         else
  62.             info()
  63.             targets = false
  64.         end
  65.        
  66.         -- wyswietlam
  67.         if targets == true and pozycja == 1 then
  68.             term.clear()
  69.             term.setCursorPos(1,1)
  70.            
  71.             print("\n#### getTargets() ####\n")
  72.             show(menuList[pozycja])
  73.             print("\n------------------------")
  74.         elseif targets == true then
  75.             term.clear()
  76.             term.setCursorPos(1,1)
  77.            
  78.             print("\n#### "..nameCurTarget.." ####\n")
  79.             show(menuList[pozycja])
  80.             print("\n------------------------")
  81.         end
  82.     end
  83.    
  84.     term.clear()
  85.     term.setCursorPos(1,1)
  86. end
  87.  
  88. function loadDetails(temp)
  89.     -- jeśli jest to tabela
  90.     if string.match(tostring(temp[linijka][2]), "table") then
  91.         local tableDetails = {}
  92.        
  93.         local x = linijka
  94.        
  95.         local tablica = temp[x][2]
  96.         nameCurTarget = temp[x][1]
  97.        
  98.         i = 1
  99.         for key, value in pairs(tablica) do
  100.             tableDetails[i] = {}
  101.             tableDetails[i][1] = key
  102.             tableDetails[i][2] = value
  103.            
  104.             i = i + 1
  105.         end
  106.        
  107.         menuList[pozycja+1] = tableDetails -- zapisuje nastepna pozycje menu
  108.         pozycja = pozycja + 1 -- przechodze do następnej pozycji menu
  109.     end
  110. end
  111.  
  112. function show(temp)
  113.     j = 3
  114.     for i = linijka, #temp do
  115.         term.setCursorPos(1, j)
  116.         if j == 3 then
  117.             term.write("## "..temp[i][1].." = "..tostring(temp[i][2]))
  118.         else
  119.             term.setCursorPos(4, j)
  120.             term.write(temp[i][1].." = "..tostring(temp[i][2]))
  121.         end
  122.         if i >= linijka + pokaz then break end
  123.         j = j+1
  124.     end
  125. end
  126.  
  127. function loadTargets()
  128.     local tableTargets = {}
  129.  
  130.     i = 1
  131.     if sensor.getTargets() ~= nil then
  132.         for key, value in pairs (sensor.getTargets()) do
  133.             tableTargets[i] = {}
  134.             tableTargets[i][1] = key
  135.             tableTargets[i][2] = value
  136.             i = i + 1
  137.         end
  138.     end
  139.  
  140.     menuList[1] = tableTargets -- zapisuje najbardziej zewnętrzną pozycję menu
  141. end
  142.  
  143. function info()
  144.     term.clear()
  145.     term.setCursorPos(1,1)
  146.     print("Manager metod OpenSource CCSensors by kwinto93")
  147.     print("http://www.youtube.com/user/kwinto93\n")
  148.     print("Uzycie: podlacz sensor i wloz do niego karte.")
  149.     print("Wpisz w konsoli: getMethods.lua <strona_komputera>\n")
  150.     print("Nacisnij e aby wyjsc.")
  151.     print("Nacisnij t aby zobaczyc aktualnie dostepne metody")
  152.     print("Do przewijania uzywaj strzalek.")
  153.     print("Klawiszem enter lub strzalka w prawo rozwin dodatkowe informacje.")
  154.     print("Aby sie cofnac uzyj klawisza Backspace lub strzalki w lewo.")
  155. end
  156.  
  157. main() -- włączam główną funkcję
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement