Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitorSide = "top"
- needToOnOff = false
- p = peripheral.wrap("bottom")
- monitor = peripheral.wrap(monitorSide)
- monitor.clear()
- monW, monH = monitor.getSize()
- updateTimingWhenOffed = {0.5,4}
- updateTimingWhenOnned = {0,0.05}
- updateTiming = updateTimingWhenOnned --fast first screen update, then slowly until noone is running
- anyoneWasRunning = true
- defaultLayerOffset = 1
- layerOffset = defaultLayerOffset
- quarryMode=false
- if fs.exists("layerOffset.txt") then
- file = fs.open("layerOffset.txt","r")
- offset = file.readAll()
- if offset ~= nil then offset = tonumber(offset)
- if offset ~= nil and offset > 1 and offset < 1000 then layerOffset = offset end
- end
- file.close()
- end
- clients = {}
- clientsNames = { {"",colors.white}, {"",colors.orange}, {"",colors.magenta}, {"",colors.yellow}, {"",colors.lime}, {"",colors.pink}, {"",colors.lightGray}, {"",colors.cyan}, {"",colors.purple}, {"",colors.brown}, {"",colors.green}, {"",colors.red} }
- SData = {} --state,energy,layer,valuablesMined,valuablesInLayer
- defaultStyle = {
- id = colors.white,
- state = colors.yellow,
- energy = colors.cyan,
- layer = colors.white,
- progress = colors.red,
- background = colors.black,
- buttonGreenBack = colors.green,
- buttonRedBack = colors.red,
- buttonGreenText = colors.white,
- buttonRedText = colors.white,
- clientsNamesColors = {colors.white,colors.orange,colors.magenta,colors.yellow,colors.lime,colors.pink,colors.lightGray,colors.cyan,colors.purple,colors.brown,colors.green,colors.red}
- }
- tarelkaStyle = {
- id = colors.yellow,
- state = colors.lime,
- energy = colors.cyan,
- layer = colors.purple,
- progress = colors.orange,
- background = colors.black,
- buttonGreenBack = colors.cyan,
- buttonRedBack = colors.orange,
- buttonGreenText = colors.black,
- buttonRedText = colors.gray,
- clientsNamesColors = {colors.white,colors.orange,colors.magenta,colors.lightBlue,colors.yellow,colors.lime,colors.pink,colors.cyan,colors.purple,colors.brown,colors.green,colors.red}
- }
- --CHANGE THE SKIN
- Style = defaultStyle
- --clients initialization
- repeat
- sleep(3)
- potentialClients = p.getNamesRemote()
- until #potentialClients ~= 0
- j=1
- numberOfclientsNamesColors = #Style.clientsNamesColors
- for i=1,#potentialClients do
- if p.getTypeRemote(potentialClients[i]) == "mininglaser" then
- clients[j] = potentialClients[i]
- for v in string.gmatch(potentialClients[i],"%d+") do clientsNames[j] = v end
- if j>numberOfclientsNamesColors then
- Style.clientsNamesColors[j] = Style.clientsNamesColors[(j-1)% numberOfclientsNamesColors + 1]
- end
- j = j+1
- end
- end
- clientsPerPage=monH-3
- pagesNumber=math.ceil(#clients/clientsPerPage)
- currentPage=1
- clientStatus = {}
- for i=1,#clients do
- clientStatus[i] = {0,false}
- --0=Offed; 1=Onned; 2=unreachable
- --wasChanged
- end
- --methods initialization
- methods = p.getMethodsRemote(clients[1]) --[[startMining(1), stop(2), isMining(3), startQuarry(4), getMinerState(5), setStartLayerOffset(6) ]]--
- for i=1,#clients do
- SData[i] = {"",0,0,0,0}
- end
- function cR(clientNumber,method, p1) --wrap for p.callRemote(peripheral name, peripheral method)
- if p.isPresentRemote(clients[clientNumber]) == true then
- return p.callRemote(clients[clientNumber], method, p1)
- else
- clientStatus[clientNumber][1] = 2 --unreachable
- return nil
- end
- end
- function printText(x,y,text,clrLine,color,fromLeftSide,backColor)
- if backColor ~= nil then
- monitor.setBackgroundColor(backColor)
- end
- if fromLeftSide then
- monitor.setCursorPos(x,y)
- else
- monitor.setCursorPos(monW - string.len(text) - x,y)
- end
- if clrLine then
- monitor.clearLine()
- end
- --print(text)
- monitor.setTextColor(color)
- monitor.write(text)
- if backColor ~= nil then
- monitor.setBackgroundColor(Style.background)
- end
- end
- function printState(clientNumber)
- hisPos=clientNumber%clientsPerPage
- hisPage=(#clients-hisPos)/clientsPerPage+1
- hisPos=hisPos+1
- if hisPage == currentPage then
- --getInfo
- result = false
- isMining = cR(clientNumber,methods[3], nil)
- if isMining ~= nil then
- if isMining == false then
- clientStatus[clientNumber][1] = 0 --is offed
- else
- result = true
- clientStatus[clientNumber][1] = 1 --is oned
- end
- end
- --print lines
- printText(1,hisPos,SData[clientNumber][1],true,Style.state,true,nil)
- printText(18,hisPos,SData[clientNumber][2],false,Style.energy,true,nil)
- printText(27,hisPos,SData[clientNumber][3],false,Style.layer,true,nil)
- printText(36,hisPos,SData[clientNumber][4].. "/" .. SData[clientNumber][5], false, Style.progress,true,nil)
- printText(3,hisPos,clientsNames[clientNumber],false,Style.clientsNamesColors[clientNumber],false,nil)
- --print button
- if isMining ~= nil then
- if isMining == false then
- buttonText = "start"
- buttonColorBack = Style.buttonGreenBack
- buttonColorText = Style.buttonGreenText
- else
- buttonText = "stop "
- buttonColorBack = Style.buttonRedBack
- buttonColorText = Style.buttonRedText
- end
- printText(12,hisPos,buttonText,false,buttonColorText,true,buttonColorBack)
- end
- end
- return result
- end
- function crashedState(clientNumber,info)
- SData[clientNumber][1] = "#"..info
- SData[clientNumber][2] = 0
- SData[clientNumber][3] = 0
- SData[clientNumber][4] = 0
- SData[clientNumber][5] = 0
- end
- function updateState(clientNumber)
- SData[clientNumber][1], SData[clientNumber][2], SData[clientNumber][3], SData[clientNumber][4], SData[clientNumber][5] = cR(clientNumber,methods[5],nil)
- if SData[clientNumber][5] == nil then
- crashedState(clientNumber,"nil")
- end
- return printState(clientNumber)
- end
- function doOnOff(clientNumber)
- if clientStatus[clientNumber][1] == 0 then
- --print("VKLUCHAYU")
- cR(clientNumber,methods[6],layerOffset)
- if quarryMode == false then cR(clientNumber,methods[1],nil) else cR(clientNumber,methods[4],nil) end
- else
- --print("VIKLUCHAYOU")
- cR(clientNumber,methods[2],nil)
- end
- clientStatus[clientNumber][2] = false
- end
- function correctTiming(anyoneRunning)
- if anyoneWasRunning ~= anyoneRunning then
- if anyoneRunning then updateTiming = updateTimingWhenOnned else updateTiming = updateTimingWhenOffed end
- anyoneWasRunning = anyoneRunning
- end
- end
- function setQuarryMode()
- printText(10,monH,"start all",false,Style.buttonGreenText,true,Style.buttonGreenBack)
- printText(14,monH,"stop all",false,Style.buttonRedText,false,Style.buttonRedBack)
- if quarryMode then
- quarryMode = false printText(0,monH,"enableQuarry ",false,Style.buttonRedText,false,Style.buttonRedBack)
- else quarryMode = true printText(0,monH,"disableQuarry",false,Style.buttonGreenText,false,Style.buttonGreenBack)
- end
- end
- function serverCore()
- monitor.setBackgroundColor(Style.background)
- monitor.clear()
- printText(1,1,"State",true,Style.state,true,nil)
- printText(18,1,"Energy",false,Style.energy,true,nil)
- printText(27,1,"Layer",false,Style.layer,true,nil)
- printText(34,1,"Progress", false, Style.progress,true,nil)
- printText(3,1,"ID",false,Style.id,false,nil)
- printText(10,monH,"start all",false,Style.buttonGreenText,true,Style.buttonGreenBack)
- printText(14,monH,"stop all",false,Style.buttonRedText,false,Style.buttonRedBack)
- printText(0,monH,"enableQuarry ",false,Style.buttonRedText,false,Style.buttonRedBack)
- while true do
- anyoneRunning = false
- for i=1,#clients do
- if needToOnOff == true then
- for j=1,#clientStatus do
- if clientStatus[j][2] == true then
- doOnOff(j)
- anyoneRunning = updateState(j) or anyoneRunning
- end
- end
- needToOnOff = false
- end
- anyoneRunning = updateState(i) or anyoneRunning
- sleep(updateTiming[1])
- end
- correctTiming(anyoneRunning)
- sleep(updateTiming[2])
- end
- end
- function layerOffsetUpdate(offset)
- end
- function serverTouch()
- while true do
- local event, p1, p2, p3 = os.pullEvent("monitor_touch")
- if p1 == monitorSide then
- if p3 < monH-2 then
- if p2 > 11 and p2 < 16 then --singleToggleButton
- --if p3 % 2 == 0 then --u are not missed with your mouse
- clientNumber = (currentPage-1)*clientsPerPage+p3-1
- if clientStatus[clientNumber][1] ~= 2 then --not unreachable
- clientStatus[clientNumber][2] = true
- needToOnOff = true
- end
- --end
- end
- elseif p3 == monH-1 then
- --print("fucking buttons pressed")
- if p2 > 9 and p2 < 19 then --start all
- --print("start_all")
- for i=1,#clientStatus do
- if clientStatus[i][1] == 0 then --if anyone is offed
- clientStatus[i][2] = true
- end
- needToOnOff = true
- end
- elseif p2 > 27 and p2 < 36 then
- --print("stop_all")
- for i=1,#clientStatus do
- if clientStatus[i][1] == 1 then --if anyone is onned
- clientStatus[i][2] = true
- end
- needToOnOff = true
- end
- elseif p2 > 36 and p2 < 50 then
- setQuarryMode()
- end
- else --monH-2
- end
- end
- print(p2 .. " " .. p3)
- end
- end
- function setLayerOffset()
- printText(1,monH-1,"LayerOffset:",true,Style.layer,true,nil)
- printText(14,monH-1,layerOffset,false,Style.layer,true,nil)
- term.clear()
- term.setCursorPos(1,1)
- print("enter new layer offset or leave it empty to set the defaults (" .. defaultLayerOffset .. ")")
- while true do
- offset = read()
- layerOffset = defaultLayerOffset
- if offset ~= nil then offset = tonumber(offset)
- if offset ~= nil and offset > 1 and offset < 1000 then layerOffset = offset end
- end
- printText(1,monH-1,"LayerOffset:",true,Style.layer,true,nil)
- printText(14,monH-1,layerOffset,false,Style.layer,true,nil)
- file = fs.open("layerOffset.txt","w")
- file.write(offset)
- file.close()
- end
- end
- parallel.waitForAny(serverCore, serverTouch, setLayerOffset)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement