Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Stworzone przez kwinto93
- Created by kwinto93
- http://www.youtube.com/user/kwinto93
- --]]
- os.loadAPI("ocs/apis/sensor") -- ładujemy API, bardzo istotna linijka
- local ArgStartowe = {...}
- local strona = ArgStartowe[1]
- sensor = nil
- local linijka = 1
- local pokaz = 10 -- pokazuje 10 linii na raz
- local targets = false
- local nameCurTarget = nil
- local menuList = {} -- lista pozycji menu, zawierająca kolejne tabele
- local pozycja = 1
- function main()
- local wyjdz = false
- info()
- sleep(1)
- if strona == nil then
- term.clear()
- term.setCursorPos(1,1)
- print("Uzycie: podlacz sensor i wloz do niego karte.")
- print("Wpisz w konsoli: getMethods.lua <strona_komputera>\n")
- sleep(2)
- return
- else
- sensor = sensor.wrap(strona)
- end
- while wyjdz == false do
- local event, keyNum = os.pullEvent("key")
- if keyNum == 200 then
- linijka = linijka - 1
- if linijka < 1 then linijka = linijka + 1 end
- elseif keyNum == 208 then
- linijka = linijka + 1
- if linijka > #menuList[pozycja] then linijka = linijka - 1 end
- elseif keyNum == 18 then
- wyjdz = true
- elseif keyNum == 20 then
- linijka = 1
- loadTargets()
- targets = true
- elseif keyNum == 28 or keyNum == 205 then
- loadDetails(menuList[pozycja])
- linijka = 1
- elseif keyNum == 203 or keyNum == 14 then
- if pozycja > 1 then pozycja = pozycja - 1 end
- linijka = 1
- else
- info()
- targets = false
- end
- -- wyswietlam
- if targets == true and pozycja == 1 then
- term.clear()
- term.setCursorPos(1,1)
- print("\n#### getTargets() ####\n")
- show(menuList[pozycja])
- print("\n------------------------")
- elseif targets == true then
- term.clear()
- term.setCursorPos(1,1)
- print("\n#### "..nameCurTarget.." ####\n")
- show(menuList[pozycja])
- print("\n------------------------")
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- end
- function loadDetails(temp)
- -- jeśli jest to tabela
- if string.match(tostring(temp[linijka][2]), "table") then
- local tableDetails = {}
- local x = linijka
- local tablica = temp[x][2]
- nameCurTarget = temp[x][1]
- i = 1
- for key, value in pairs(tablica) do
- tableDetails[i] = {}
- tableDetails[i][1] = key
- tableDetails[i][2] = value
- i = i + 1
- end
- menuList[pozycja+1] = tableDetails -- zapisuje nastepna pozycje menu
- pozycja = pozycja + 1 -- przechodze do następnej pozycji menu
- end
- end
- function show(temp)
- j = 3
- for i = linijka, #temp do
- term.setCursorPos(1, j)
- if j == 3 then
- term.write("## "..temp[i][1].." = "..tostring(temp[i][2]))
- else
- term.setCursorPos(4, j)
- term.write(temp[i][1].." = "..tostring(temp[i][2]))
- end
- if i >= linijka + pokaz then break end
- j = j+1
- end
- end
- function loadTargets()
- local tableTargets = {}
- i = 1
- if sensor.getTargets() ~= nil then
- for key, value in pairs (sensor.getTargets()) do
- tableTargets[i] = {}
- tableTargets[i][1] = key
- tableTargets[i][2] = value
- i = i + 1
- end
- end
- menuList[1] = tableTargets -- zapisuje najbardziej zewnętrzną pozycję menu
- end
- function info()
- term.clear()
- term.setCursorPos(1,1)
- print("Manager metod OpenSource CCSensors by kwinto93")
- print("http://www.youtube.com/user/kwinto93\n")
- print("Uzycie: podlacz sensor i wloz do niego karte.")
- print("Wpisz w konsoli: getMethods.lua <strona_komputera>\n")
- print("Nacisnij e aby wyjsc.")
- print("Nacisnij t aby zobaczyc aktualnie dostepne metody")
- print("Do przewijania uzywaj strzalek.")
- print("Klawiszem enter lub strzalka w prawo rozwin dodatkowe informacje.")
- print("Aby sie cofnac uzyj klawisza Backspace lub strzalki w lewo.")
- end
- main() -- włączam główną funkcję
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement