Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = require("component")
- local e = require("event")
- local color = require("colors")
- local term = require("term")
- local string = require("string")
- local filesystem = require("filesystem")
- local m = c.modem
- local gpu = c.gpu
- local CFon,CText, CFig, CRed, CGreen, CBut = 0xAAAAAA, 0x5F5F5F, 0x313131, 0xCC4C4C, 0x279C38, 0x9E9EFF
- local NanAd,NanPort = ' ', 1
- local Lpage,colEff,Ladr,LInp,LInp2 = 0,0,0,0,1
- local Act = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- local Act2 = {0,0,0,0,0,0,0,0,0,0,0,0}
- local RezIn= {} --сейв всех рабочих выводов (0,2:{moveSpeed,p.Hearts})
- local SaveBut = {"1","2","3","4","5","6","7","8","9","10","11","12"}
- local SaveBut2 = {0,0,0,0,0,0,0,0,0,0,0,0}
- local Macr = {}
- --m.open(37536)
- --m.broadcast(1,"nanomachines", "setResponsePort",37536)
- --m.send('0bb35ff9-f2ca-4c58-863a-db6d5af8a229',37536,"nanomachines","getHealth")
- --m.broadcast(37536,"nanomachines", "getHealth")
- function OpenAll()
- file = io.open('nano.conf','r')
- local Zaa = file:read("*l")
- colEff = tonumber(file:read("*l"))
- local da = 1
- for i = 1, colEff do
- local ad = string.find(Zaa,';',da+1)
- RezIn[i] = string.sub(Zaa,da+1,ad-1)
- da = ad
- end
- local Zab = file:read("*l")
- local da = 1
- for i = 1,18 do
- local dadd = string.byte(Zab,i*2)
- Act[i] = tonumber(string.char(dadd))
- end
- NanAd = file:read("*l")
- NanPort = tonumber(file:read("*l"))
- local Zac = file:read("*l")
- local Zad = file:read("*l")
- local da,dad = 1,1
- for i = 1,12 do
- local ad = string.find(Zac,';',da+1)
- SaveBut[i] = string.sub(Zac,da+1,ad-1)
- da = ad
- local dadd = string.find(Zad,';',dad+1)
- SaveBut2[i] = tonumber(string.sub(Zad,dad+1,dadd-1))
- dad = dadd
- end
- local Zav = file:read("*l")
- local da,ad = 1,1
- --local tal =
- for i = 1, 1 do
- local ad = string.find(Zav,';',da+1)
- Macr[i] = string.sub(Zav,da+1,ad-1)
- da = ad
- end
- file:close()
- m.open(NanPort)
- end
- function SaveAll()
- file = io.open('nano.conf','w')
- local Zaa,Zab,Zac,Zad,Zav = ";",";",";",";",";"
- for i=1, colEff do
- Zaa = Zaa..RezIn[i]..";"
- end
- for i=1, 18 do
- Zab = Zab..Act[i]..";"
- end
- for i=1,12 do
- Zac = Zac..SaveBut[i]..";"
- Zad = Zad..SaveBut2[i]..";"
- end
- for i = 1,1 do
- Zav = Zav..Macr[i]..";"
- end
- file:write(Zaa.."\n")
- file:write(colEff.."\n")
- file:write(Zab.."\n")
- file:write(NanAd.."\n")
- file:write(NanPort.."\n")
- file:write(Zac.."\n")
- file:write(Zad.."\n")
- file:write(Zav.."\n")
- file:close()
- end
- if not filesystem.exists("home/nano.conf") then
- SaveAll()
- else
- OpenAll()
- end
- function WaitMsg() -- основное ожидание событий
- while true do
- term.setCursor(1,25)
- local ev,s2,CliX,but,s5,s6,mes,mes1,mes2 = e.pull()
- if ev == "modem_message" then
- if type(mes1) == "number" then
- mes1 = tonumber(mes1)
- else
- mes1 = string.gsub(mes1,"particles","p")
- end
- if type(mes2) == "number" then
- mes2 = tonumber(mes2)
- else
- mes2 = " "
- end
- --mes1 = string.gsub(mes1,"particles","p")
- --print(mes1)
- gpu.set(4,25,"Показатель: "..mes.." "..mes1.." "..mes2)
- os.sleep(2)
- gpu.fill(4,25,80,1," ")
- if Ladr == 1 then
- NanAd = CliX
- Ladr = 0
- local sts = 0
- --check 171 input?
- if LInp == 0 and LInp2 == 1 then
- colEff = 0
- end
- for i = LInp,17 do
- --1 input
- if sts == 1 then
- sts = 0
- break
- end
- m.send(NanAd,NanPort,"nanomachines","setInput",i,true)
- os.sleep(1)
- for t = LInp2,18 do
- local r = t-i
- if r>0 then
- --2 input
- m.send(NanAd,NanPort,"nanomachines","setInput",t,true)
- os.sleep(1)
- m.send(NanAd,NanPort,"nanomachines","getActiveEffects")
- gpu.fill(4,25,80,1," ")
- gpu.set(4,25,"Проверка входов "..i.." "..t)
- --while true do
- local evs,_,_,bby,_,_,_,ss,_ = e.pull()
- --end
- --print(evs)
- if evs == "key_down" then
- if bby == 31 then --S
- gpu.fill(4,25,80,1," ")
- gpu.set(4,25,"Процесс остановлен на "..i.." "..t)
- SaveAll()
- os.sleep(2)
- gpu.fill(4,25,80,1," ")
- sts = 1
- break
- end
- end
- local hm = string.find(ss,'}')
- if hm ~= 2 then
- local skl = ""
- local nnc,nns = 1,1
- ss = string.gsub(ss,"particles","p")
- if colEff == 0 then
- local ncc = string.len(ss)
- ss = string.sub(ss,2,ncc-1)
- colEff = 1
- RezIn[1] = i..","..t..","..ss
- gpu.fill(4,25,80,1," ")
- --gpu.set(4,25,"Найденые эффекты "..RezIn[1])
- else
- for k in string.gmatch (ss, ",") do
- local nnd = ""
- local nnc2 = string.find(ss,',',nnc+1)
- nnd = string.sub(ss,nns+1,nnc2-1)
- --print(nnc2)
- nnc = nnc2
- nns = nnc2
- for i=1,colEff do--проверка 1 значения
- if type(string.match(RezIn[i],nnd))=='nil' then
- --print("Nd2"..RezIn[i].."<>"..nnd)--nnd не делит
- --os.sleep(1)
- if colEff == i then
- skl = skl..","..nnd
- end
- else
- --print("нашел совпадение")
- break--чего натворил?ужс
- --skl = skl..","..nnd
- end
- end
- --skl = skl..","..nnd
- end
- local nmc=string.len(ss)
- local nmd = string.sub(ss,nnc+1,nmc-1)
- --print(nmd.."@ "..nnc)--повтор от 3 вывода+1
- for i=1,colEff do
- local hs = string.match(RezIn[i],nmd)
- --print("Nd1"..RezIn[i].."<>"..nmd)
- --os.sleep(1)
- if type(hs) == 'nil' then
- --print("Naid1")--с типом проблема?
- if colEff == i then
- skl = skl..","..nmd
- end
- else
- break
- --skl = skl..","..nmd
- end
- end
- --skl = skl..","..nmd
- --print(skl)
- if skl ~= "" then
- colEff = colEff+1
- RezIn[colEff] = i..","..t..skl
- --print(RezIn[colEff])
- gpu.fill(4,25,80,1," ")
- --gpu.set(4,25,"Найденые эффекты "..RezIn[colEff])
- end
- end
- end
- os.sleep(0.25)
- m.send(NanAd,NanPort,"nanomachines","setInput",t,false)
- os.sleep(1)
- end
- end
- m.send(NanAd,NanPort,"nanomachines","setInput",i,false)
- os.sleep(1)
- end
- gpu.set(4,25,"Проверка входов завершена")
- os.sleep(0.5)
- gpu.fill(4,25,80,1," ")
- end
- elseif ev == "touch" then
- if CliX>38 and CliX<51 and but>1 and but<4 then
- Lpage = 0
- page()
- bugz()
- elseif CliX>50 and CliX<63 and but>1 and but<4 then
- Lpage = 1
- page()
- bugz()
- elseif CliX>62 and CliX<75 and but>1 and but<4 then
- Lpage = 2
- page()
- bugz()
- end
- if Lpage == 0 then
- if CliX>41 and CliX<58 then
- if but>4 and but<8 then
- m.send(NanAd,NanPort,"nanomachines","getName")
- elseif but>7 and but<11 then
- m.send(NanAd,NanPort,"nanomachines","getAge")
- elseif but>10 and but<14 then
- m.send(NanAd,NanPort,"nanomachines","getActiveEffects")
- elseif but>13 and but<17 then
- m.send(NanAd,NanPort,"nanomachines","getTotalInputCount")
- elseif but>16 and but<20 then
- m.send(NanAd,NanPort,"nanomachines", "getSafeActiveInput")
- elseif but>19 and but<23 then
- m.send(NanAd,NanPort,"nanomachines","getMaxActiveInput")
- end
- elseif CliX>59 and CliX<76 then
- if but>4 and but<8 then
- for i=1, 18 do
- local s = 0
- m.send(NanAd,NanPort,"nanomachines","getInput",i)
- while true do
- local e,_,_,_,_,_,_,_,s = e.pull("modem_message")
- if e == "modem_message" then
- if s == true then
- Act[i] = 1
- else
- Act[i] = 0
- end
- gpu.set(4,25,"Проверка входа "..i.." из 18")
- os.sleep(0.01)
- break
- end
- end
- end
- gpu.fill(4,25,80,1," ")
- bugz()
- elseif but>7 and but<11 then
- --check\scan+korektirovka adressa
- gpu.set(4,25,"С какого проверяем?(def 0) ")
- term.setCursor(31,25)
- LInp = tonumber(term.read(_,false))
- term.clearLine()
- gpu.set(4,25,"А второй?(def 1) ")
- term.setCursor(21,25)
- LInp2 = tonumber(term.read(_,false))
- term.clearLine()
- Ladr = 1
- m.broadcast(1,"nanomachines","getName")
- elseif but>10 and but<14 then
- gpu.set(4,25,"select port (1 to 65536):")
- term.setCursor(29,25)
- local LPort = tonumber(term.read(_,false))
- term.clearLine()
- m.send(NanAd,NanPort,"nanomachines","setResponsePort",LPort)
- m.open(LPort)
- m.close(NanPort)
- NanPort = LPort
- elseif but>13 and but<17 then
- for i=1,18 do
- Act[i]=0
- end
- bugz()
- elseif but>16 and but<20 then
- m.send(NanAd,NanPort,"nanomachines","saveConfiguration")
- elseif but>19 and but<23 then
- Lpage = 4
- gpu.set(4,25,"Select button")
- bugz()
- page()
- --configuration 2 page
- end
- elseif CliX>5 and CliX<12 then
- for i=1, 9 do
- if but==i*2+2 then
- if Act[i] == 0 then
- Act[i] = 1
- m.send(NanAd,NanPort,"nanomachines","setInput",i,true)
- gpu.setBackground(CGreen)
- gpu.set(13,i*2+2,tostring(i).." ")
- else
- Act[i] = 0
- m.send(NanAd,NanPort,"nanomachines","setInput",i,false)
- gpu.setBackground(CRed)
- gpu.set(13,i*2+2,tostring(i).." ")
- end
- end
- end
- elseif CliX>25 and CliX<32 then
- for i=1, 9 do
- if but==i*2+2 then
- if Act[i+9] == 0 then
- Act[i+9] = 1
- m.send(NanAd,NanPort,"nanomachines","setInput",i+9,true)
- gpu.setBackground(CGreen)
- gpu.set(23,i*2+2,tostring(i+9))
- else
- Act[i+9] = 0
- m.send(NanAd,NanPort,"nanomachines","setInput",i+9,false)
- gpu.setBackground(CRed)
- gpu.set(23,i*2+2,tostring(i+9))
- end
- end
- end
- end
- elseif Lpage == 1 then
- if CliX>41 and CliX<58 then
- for i = 1,6 do
- if but>(1+3*i) and but<(5+3*i) then
- if SaveBut2[i] ~= 0 then
- local ta = RezIn[SaveBut2[i]]
- local tad = string.find(ta,",")
- local taf = tonumber(string.sub(ta,1,tad-1))
- local tas = string.find(ta,",",tad+1)
- local tag = tonumber(string.sub(ta,tad+1,tas-1))
- if taf ~= 0 then
- if Act2[i] == 0 then
- m.send(NanAd,NanPort,"nanomachines","setInput",taf,true)
- Act[taf] = 1
- else
- m.send(NanAd,NanPort,"nanomachines","setInput",taf,false)
- Act[taf] = 0
- end
- os.sleep(1)
- end
- if Act2[i] == 0 then
- m.send(NanAd,NanPort,"nanomachines","setInput",tag,true)
- Act[tag] = 1
- Act2[i] = 1
- gpu.set(4,25,"Включено")
- else
- m.send(NanAd,NanPort,"nanomachines","setInput",tag,false)
- Act[tag] = 0
- Act2[i] = 0
- gpu.set(4,25,"Выключено")
- end
- os.sleep(1)
- gpu.fill(4,25,80,1," ")
- end
- end
- end
- elseif CliX>59 and CliX<76 then
- for i = 1,6 do
- if but>(1+3*i) and but<(5+3*i) then
- if SaveBut2[i+6] ~= 0 then
- local ta = RezIn[SaveBut2[i+6]]
- local tad = string.find(ta,",")
- local taf = tonumber(string.sub(ta,1,tad-1))
- local tas = string.find(ta,",",tad+1)
- local tag = tonumber(string.sub(ta,tad+1,tas-1))
- if taf ~= 0 then
- if Act2[i+6] == 0 then
- m.send(NanAd,NanPort,"nanomachines","setInput",taf,true)
- Act[taf] = 1
- else
- m.send(NanAd,NanPort,"nanomachines","setInput",taf,false)
- Act[taf] = 0
- end
- os.sleep(1)
- end
- if Act2[i+6] == 0 then
- m.send(NanAd,NanPort,"nanomachines","setInput",tag,true)
- Act[tag] = 1
- Act2[i+6] = 1
- gpu.set(4,25,"Включено")
- else
- m.send(NanAd,NanPort,"nanomachines","setInput",tag,false)
- Act[tag] = 0
- Act2[i+6] = 0
- gpu.set(4,25,"Выключено")
- end
- os.sleep(1)
- gpu.fill(4,25,80,1," ")
- end
- end
- end
- end
- elseif Lpage == 4 then
- local LSel = 0
- ---for i = 1,6 do
- ---but
- ---end
- if CliX>41 and CliX<58 then
- if but>4 and but<8 then
- --переменная? выбор эффекта из RezIn + название кнопки
- --наверно можно циклом
- LSel = 1
- elseif but>7 and but<11 then
- --m.send(NanAd,NanPort,"nanomachines","getAge")
- LSel = 2
- elseif but>10 and but<14 then
- --m.send(NanAd,NanPort,"nanomachines","getActiveEffects")
- LSel = 3
- elseif but>13 and but<17 then
- --m.send(NanAd,NanPort,"nanomachines","getTotalInputCount")
- LSel = 4
- elseif but>16 and but<20 then
- --m.send(NanAd,NanPort,"nanomachines", "getSafeActiveInput")
- LSel = 5
- elseif but>19 and but<23 then
- --m.send(NanAd,NanPort,"nanomachines","getMaxActiveInput")
- LSel = 6
- end
- elseif CliX>59 and CliX<76 then
- if but>4 and but<8 then
- LSel = 7
- elseif but>7 and but<11 then
- LSel = 8
- -- m.send(NanAd,NanPort,"nanomachines","getAge")
- elseif but>10 and but<14 then
- LSel = 9
- -- m.send(NanAd,NanPort,"nanomachines","getActiveEffects")
- elseif but>13 and but<17 then
- LSel = 10
- --m.send(NanAd,NanPort,"nanomachines","getTotalInputCount")
- elseif but>16 and but<20 then
- LSel = 11
- --m.send(NanAd,NanPort,"nanomachines", "getSafeActiveInput")
- elseif but>19 and but<23 then
- LSel = 12
- --m.send(NanAd,NanPort,"nanomachines","getMaxActiveInput")
- end
- end
- gpu.set(4,25,"Select input")
- while true do
- local evs,_,Sp,bby,_,_,_,ss,_ = e.pull()
- if evs == "touch" then
- if Sp>1 and Sp<35 then
- --RezIn[bby+1]
- SaveBut2[LSel] = bby-1
- --
- gpu.set(4,25,"Select name button ")
- term.setCursor(24,25)
- --SaveBut[LSel]
- local gas = term.read(_,false)--минус интер
- local ga = string.len(gas)
- SaveBut[LSel] = string.sub(gas,1,ga-1)
- term.clearLine()
- break
- end
- end
- end
- end
- gpu.setBackground(CFon)
- elseif ev == "key_down" then
- if but == 16 then --Q
- gpu.set(4,25,"бай-бай")
- m.close(NanPort)
- gpu.setBackground(CFig)
- gpu.setForeground(CFon)
- SaveAll()
- os.sleep(2)
- term.clear()
- os.exit()
- end
- end
- --print(s2)--пишем всякую фигню(данные) чтоб зналь
- --print(CliX)
- --print(but)
- --print(s5)
- --print(s6)
- end
- end
- function bugz()
- gpu.setForeground(CFig)
- gpu.fill(2,2,34,20," ")
- if Lpage == 4 or Lpage == 1 then
- for i = 1, colEff do
- if math.fmod(i,2) == 0 then
- gpu.setBackground(CBut)
- else
- gpu.setBackground(CFon)
- end
- gpu.fill(2,i+1,34,1," ")
- gpu.set(2,i+1,RezIn[i])
- end
- else
- gpu.set(12, 3,"╔════════════╗")
- for i = 1,17 do
- gpu.set(12,3+i,"║ ║")
- end
- gpu.set(12,21,"╚════════════╝")
- local xC = 4
- for i=1,9 do
- gpu.setBackground(CFon)
- gpu.fill(6,xC,6,1,"═")--6 29
- gpu.fill(26,xC,6,1,"═")
- if Act[i] == 0 then
- gpu.setBackground(CRed)
- gpu.set(13,xC,tostring(i).." ")
- else
- gpu.setBackground(CGreen)
- gpu.set(13,xC,tostring(i).." ")
- end
- if Act[i+9] == 0 then
- gpu.setBackground(CRed)
- gpu.set(23,xC,tostring(i+9))
- else
- gpu.setBackground(CGreen)
- gpu.set(23,xC,tostring(i+9))
- end
- xC = xC+2
- end
- end
- gpu.setForeground(CText)
- gpu.setBackground(CFon)
- end
- function graff()
- gpu.setBackground(CFon)
- gpu.setForeground(CText)
- term.clear()
- --term.setCursor(1,25)
- gpu.fill(1,24,80,1,"`")
- bugz()
- --gpu.fill(41,4,15,3," ")
- gpu.set(39,2,"╔══════════╗╔══════════╗╔══════════╗")
- gpu.set(39,3,"║ CONFIG ║║ EFFECT ║║ MACROS ║")
- for i = 1,18 do
- gpu.set(37,4+i,"║ ║")
- end
- gpu.set(37,23,"╚══════════════════════════════════════╝")
- page()
- end
- function page()
- local LLstr = " "
- for i = 1,18 do
- gpu.set(38,i+4," ")
- end
- if Lpage == 0 then
- LLstr = "╔═╝ ╚╩══════════╩╩══════════╩═╗"
- local xC = 4
- local sa = {" name"," age"," effects","totalInput","safeInput"," maxInput"," check"," scan","changePort"," clear","saveConfig","saveEffects"}
- for i = 1, 6 do
- gpu.set(40,xC+1,"╔══════════════╗ ╔══════════════╗")
- gpu.set(40,xC+2,"║ ║ ║ ║")
- gpu.set(40,xC+3,"╚══════════════╝ ╚══════════════╝")
- gpu.set(41,xC+2," "..sa[i])
- gpu.set(59,xC+2," "..sa[i+6])
- xC = xC+3
- end
- elseif Lpage == 1 or Lpage == 4 then
- LLstr = "╔═╩══════════╩╝ ╚╩══════════╩═╗"
- local xC = 4
- for i = 1,6 do
- gpu.set(40,xC+1,"╔══════════════╗ ╔══════════════╗")
- gpu.set(40,xC+2,"║ ║ ║ ║")
- gpu.set(40,xC+3,"╚══════════════╝ ╚══════════════╝")
- gpu.set(42,xC+2," "..SaveBut[i])
- gpu.set(61,xC+2," "..SaveBut[i+6])
- xC = xC+3
- end
- else
- LLstr = "╔═╩══════════╩╩══════════╩╝ ╚═╗"
- --page MACROS
- gpu.set(41,5,"Page 1")
- gpu.set(41,6,"Условие |P|H|U|A|N|E| ╳ ")
- gpu.set(41,7,"[Health] < [500]")
- gpu.set(41,8,"Действие ")-- твори странички)
- gpu.set(41,9,"[Вкл] вход [0]")
- gpu.set(38,10,"[-][Выкл] вход [4]")
- gpu.set(41,11,"[+]")
- end
- gpu.set(37, 4,LLstr)
- end
- graff()
- WaitMsg()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement