Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Init program
- rednetSide = "top"
- m = peripheral.wrap("back")
- idSensorPC = 19
- mfsuList = {}
- mfsuOffset = 0
- td = true
- tick = 0
- titre = "MFSU VISUALIZER"
- lavaButton = false
- function horizontalLine(i, j)
- m.setCursorPos(i, j)
- if i > 1 and i < 36 then
- m.write("-")
- else
- m.write("+")
- end
- end
- function drawCadre()
- m.setBackgroundColor(colors.black)
- m.setTextColor(colors.white)
- m.clear()
- for i = 2, 35 do
- m.setCursorPos(1, i)
- m.write("|")
- m.setCursorPos(36, i)
- m.write("|")
- end
- for i = 1, 36 do
- horizontalLine(i, 1)
- horizontalLine(i, 3)
- horizontalLine(i, 16)
- horizontalLine(i, 20)
- end
- end
- function drawInterface()
- milieu = (36 / 2) - (string.len(titre) / 2) + 1
- m.setCursorPos(milieu, 2)
- m.setTextColor(colors.yellow)
- m.write(titre)
- m.setTextColor(colors.white)
- end
- function drawEnergy()
- if mfsuList ~= nil and type(mfsuList) == "table" then
- if mfsuOffset < (#mfsuList) and #mfsuList > 0 then
- for i = mfsuOffset, (mfsuOffset + 1) do
- lenght = (mfsuList[i]["p"] / 100) * 28
- cl = colors.red
- if lenght < 4 then
- cl = colors.red
- elseif lenght < 21 then
- cl = colors.orange
- elseif lenght > 20 then
- cl = colors.lime
- end
- y = (i - mfsuOffset) * 5
- percent = ""..mfsuList[i]["p"].."%"
- numId = i + 1
- num = " "..numId
- drawBar(2, lenght + 2, y + 5, y + 8, num, percent, cl)
- end
- end
- end
- end
- function drawBar(offset, limite, ymin, ymax, n, msg, couleur)
- for i = ymin, ymax do
- for j = offset, limite do
- m.setCursorPos(j, i)
- m.setBackgroundColor(couleur)
- m.write(" ")
- end
- end
- m.setBackgroundColor(colors.black)
- m.setCursorPos(36 - string.len(n) - 1, ymin)
- m.write(n)
- m.setCursorPos(36 - string.len(msg) - 1, ymin + 1)
- m.write(msg)
- end
- rednet.open(rednetSide)
- while true do
- event, id, msg, d = os.pullEvent()
- if tick >= 3 then
- tick = 0
- if td then
- if (mfsuOffset + 1) == #mfsuList then
- td = false
- else
- mfsuOffset = mfsuOffset + 1
- end
- else
- if mfsuOffset == 0 then
- td = true
- else
- mfsuOffset = mfsuOffset - 1
- end
- end
- else
- tick = tick + 1
- end
- if event == "monitor_touch" then
- print(msg)
- print(d)
- message = {}
- if msg > 1 and msg < 8 and d > 16 and d < 20 then
- if lavaButton then
- lavaButton = false
- message["button"] = "off_lava"
- else
- lavaButton = true
- message["button"] = "on_lava"
- end
- end
- r = ""
- while r ~= "ok" do
- rednet.send(idSensorPC, textutils.serialize(message))
- id, r, d = rednet.receive(0.5)
- end
- end
- if event == "rednet_message" then
- if id ~= nil and id == idSensorPC then
- if msg ~= nil then
- mfsuList = textutils.unserialize(msg)
- end
- end
- end
- m.setTextScale(2)
- drawCadre()
- drawInterface()
- drawEnergy()
- if lavaButton then
- m.setBackgroundColor(colors.lime)
- else
- m.setBackgroundColor(colors.red)
- end
- m.setTextColor(colors.white)
- for i = 2, 7 do
- for j = 17, 19 do
- m.setCursorPos(i, j)
- m.write(" ")
- end
- end
- m.setCursorPos(2, 18)
- m.write(" LAVE ")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement