Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- m = peripheral.wrap("monitor_0")
- os.loadAPI("button")
- prodID = 22
- outID = 51
- expID = 26
- jarType = "tilejar"
- voidType = "tilejarvoid"
- essentia = {}
- monCoord = {}
- add = {}
- jars = {}
- aspList = {
- "Aer", "Alienis", "Aqua", "Arbor", "Auram", "Bestia", "Cognitio", "Corpus",
- "Exanimis", "Fabrico", "Fames", "Gelum", "Granum", "Herba", "Humanus", "Ignis",
- "Instrumentum", "Iter", "Limus", "Lucrum", "Lux", "Machina", "Messis", "Metallum",
- "Meto", "Mortuus", "Motus", "Ordo", "Pannus", "Perditio", "Perfodio", "Permutatio",
- "Potentia", "Praecantatio", "Sano", "Saxum", "Sensus", "Spiritus", "Telum", "Tempestas",
- "Tempus", "Tenebrae", "Terra", "Tutamen", "Vacuos", "Venenum", "Victus", "Vinculum",
- "Vitium", "Vitreus", "Volatus"
- }
- color = {
- Aer = colors.yellow,
- Alienis = colors.purple,
- Aqua = colors.blue,
- Arbor = colors.brown,
- Auram = colors.pink,
- Bestia = colors.brown,
- Cognitio = colors.pink,
- Corpus = colors.magenta,
- Exanimis = colors.green,
- Fabrico = colors.gray,
- Fames = colors.red,
- Gelum = colors.lightGray,
- Granum = colors.brown,
- Herba = colors.green,
- Humanus = colors.lightGray,
- Ignis = colors.red,
- Instrumentum = colors.blue,
- Iter = colors.red,
- Limus = colors.lime,
- Lucrum = colors.yellow,
- Lux = colors.yellow,
- Machina = colors.gray,
- Messis = colors.brown,
- Metallum = colors.gray,
- Meto = colors.brown,
- Mortuus = colors.gray,
- Motus = colors.lightGray,
- Ordo = colors.lightGray,
- Pannus = colors.lightGray,
- Perditio = colors.gray,
- Perfodio = colors.lightGray,
- Permutatio = colors.green,
- Potentia = colors.lightGray,
- Praecantatio = colors.purple,
- Sano = colors.red,
- Saxum = colors.gray,
- Sensus = colors.lightBlue,
- Spiritus = colors.lightGray,
- Telum = colors.red,
- Tempestas = colors.lightGray,
- Tempus = colors.lightBlue,
- Tenebrae = colors.gray,
- Terra = colors.green,
- Tutamen = colors.lightBlue,
- Vacuos = colors.lightGray,
- Venenum = colors.lime,
- Victus = colors.red,
- Vinculum = colors.gray,
- Vitium = colors.purple,
- Vitreus = colors.lightBlue,
- Volatus = colors.lightGray
- }
- reqAmount = 0
- curEssentia = ""
- curAmount = 0
- rowsActive = true
- function initFunctions()
- for i = 0, 9 do
- add[i] = function()
- reqAmount = tonumber(reqAmount .. i);
- if (reqAmount > 64) then
- reqAmount = 64
- end
- if (reqAmount > (curAmount + essentia[curEssentia])) then
- reqAmount = curAmount + essentia[curEssentia]
- end
- drawJarGUI()
- end
- end
- end
- function remove()
- reqAmount = string.sub(reqAmount, 1, -2)
- if (reqAmount == "") then
- reqAmount = 0
- end
- reqAmount = tonumber(reqAmount)
- drawJarGUI()
- end
- function export()
- if (reqAmount <= curAmount) then
- reqAmount = curAmount
- drawJarGUI()
- else
- data = {}
- data.ess = curEssentia
- data.amount = reqAmount - curAmount
- rednet.send(expID, textutils.serialize(data))
- print("Pushing " .. data.amount .. " " .. data.ess)
- progress()
- end
- end
- function progress()
- m.clear()
- button.clearTable()
- drawJar()
- m.setCursorPos(30, 5)
- m.write("Filling jar: ")
- targetJar = peripheral.wrap(jarType .. "_" .. outID)
- if (targetJar == nil) then
- targetJar = peripheral.wrap(voidType .. "_" .. outID)
- end
- while (expID ~= rednet.receive(0.5)) do
- curAmount = getFill(targetJar)
- m.setCursorPos(43, 5)
- m.write(curAmount)
- drawEssentia()
- end
- m.clear()
- drawJar()
- curAmount = getFill(targetJar)
- drawEssentia()
- m.setCursorPos(35, 5)
- m.write("Done")
- m.setCursorPos(32, 6)
- m.write("Remove jar")
- end
- function sortEss(t)
- local keys = {}
- for k in pairs(t) do table.insert(keys, k) end
- table.sort(keys)
- local i = 0
- return function()
- i = i+1
- if keys[i] then
- return keys[i], t[keys[i]]
- end
- end
- end
- function mapJars()
- pers = peripheral.getNames()
- for i, v in pairs(pers) do
- if (peripheral.getType(v) == voidType) then
- if (string.sub(v, string.find(v, "_[^_]*$") + 1, -1) ~= outID) then
- table.insert(jars, peripheral.wrap(v))
- end
- end
- end
- end
- function scanEssentia()
- for i, v in pairs(aspList) do
- essentia[v] = 0
- end
- for i,j in pairs(jars) do
- aspects = j.getAspects()
- if (aspects[1] ~= nil) then
- essentia[aspects[1].name] = aspects[1].quantity
- end
- -- print(countasp)
- -- print(asp..":"..countasp)
- -- print(peripheral.getType(j))
- end
- end
- function printEssentia()
- m.setTextColor(colors.white)
- local x = 1
- local y = 1
- monCoord[x] = {}
- --for a = 1,17 do
- for i,j in sortEss(essentia) do
- if j<=20 then m.setTextColor(colors.red) end
- if j<40 and j>20 then m.setTextColor(colors.yellow) end
- if j>=40 then m.setTextColor(colors.green) end
- m.setCursorPos(x,y)
- m.write(i)
- m.setCursorPos(x+14,y)
- m.write(tostring(j))
- -- print(j)
- monCoord[x][y] = i
- if y < 17 then
- y = y+1
- else
- y = 1
- x = x+17
- monCoord[x] = {}
- end
- end
- m.setTextColor(colors.white)
- end
- function drawEssentia()
- m.setBackgroundColor(color[curEssentia])
- for i = (19 - math.floor(curAmount / 4)), 18 do
- for j = 2, 19 do
- m.setCursorPos(j, i)
- m.write(" ")
- end
- end
- m.setBackgroundColor(colors.black)
- end
- function getFill(per)
- aspInfo = per.getAspects()[1]
- if (aspInfo == nil) then
- return 0
- end
- return aspInfo.quantity
- end
- function outline(x1, x2, y1, y2)
- m.setBackgroundColor(colors.white)
- for i = x1, x2 do
- m.setCursorPos(i, y1)
- m.write(" ")
- m.setCursorPos(i, y2)
- m.write(" ")
- end
- for i = (y1 + 1), (y2 - 1) do
- m.setCursorPos(x1, i)
- m.write(" ")
- m.setCursorPos(x2, i)
- m.write(" ")
- end
- m.setBackgroundColor(colors.black)
- end
- function drawJar()
- outline(1, 20, 2, 19)
- m.setBackgroundColor(colors.brown)
- for i = 4, 17 do
- m.setCursorPos(i, 1)
- m.write(" ")
- end
- for i = 6, 15 do
- m.setCursorPos(i, 2)
- m.write(" ")
- end
- m.setBackgroundColor(colors.black)
- end
- function drawJarGUI()
- rowsActive = false
- button.clearTable()
- m.clear()
- for i = 0, 8 do
- button.setTable(tostring(i + 1),
- add[i + 1], false,
- 34 + ((i % 3) * 5),
- 38 + ((i % 3) * 5),
- 6 + math.floor(i / 3) * 3,
- 8 + math.floor(i / 3) * 3)
- end
- button.setTable("0", add[0], false, 39, 43, 15, 17)
- button.setTable("<", remove, false, 34, 38, 15, 17)
- button.setTable("Start", export, false, 44, 48, 15, 17)
- button.screen()
- drawJar()
- req_x = 47
- if (reqAmount > 9) then
- req_x = req_x - 1
- end
- m.setCursorPos(req_x, 4)
- m.write(reqAmount)
- outline(34, 48, 3, 5)
- m.setTextColor(colors.black)
- m.setCursorPos(49, 4)
- m.write(" ")
- m.setTextColor(colors.white)
- drawEssentia()
- m.setCursorPos(math.floor((54 - string.len(curEssentia)) / 2), 1)
- m.write(curEssentia)
- end
- function getClickOrJar()
- local event, side, x, y = os.pullEvent()
- print(event)
- if (event == "monitor_touch") then
- if (not button.checkxy(x,y)) then
- if (peripheral.isPresent(jarType .. "_" .. outID) or peripheral.isPresent(voidType .. "_" .. outID)) then
- curEssentia = monCoord[x-(x%17)+1][y]
- targetJar = peripheral.wrap(jarType .. "_" .. outID) or peripheral.wrap(voidType .. "_" .. outID)
- if (targetJar.getAspects()[1] ~= nil) then
- return
- end
- curAmount = getFill(targetJar)
- initFunctions()
- reqAmount = 0
- scanEssentia()
- drawJarGUI()
- end
- end
- elseif (event == "peripheral") then
- if ((side == (jarType .. "_" .. outID)) or (side == (voidType .. "_" .. outID))) then
- t = peripheral.call(side, "getAspects")[1]
- if (t ~= nil) then
- curEssentia = t.name
- curAmount = t.quantity
- initFunctions()
- reqAmount = 0
- scanEssentia()
- drawJarGUI()
- end
- end
- elseif ((event == "peripheral_detach") and not rowsActive) then
- fillTable()
- refresh()
- end
- end
- function refClick()
- return refresh(true)
- end
- function refresh(flash)
- if flash then
- button.flash("Refresh")
- end
- m.clear()
- scanEssentia()
- printEssentia()
- print("Refreshed")
- button.screen()
- button.label(24, 19, "Idle")
- end
- function refill()
- button.flash("Refill")
- scanEssentia()
- for asp, qty in sortEss(essentia) do
- if (qty < 64) then
- fillEss(asp, 64 - qty)
- end
- end
- refresh(false)
- end
- function fillTable()
- rowsActive = true
- button.clearTable()
- button.setTable("Refresh", refClick, false, 5, 20, 19, 19)
- button.setTable("Refill", refill, false, 30, 45, 19, 19)
- button.screen()
- end
- function fillEss(asp, amount)
- local essData = {}
- essData.asp = string.lower(asp)
- essData.amount = amount
- sendData = textutils.serialize(essData)
- rednet.send(prodID, sendData)
- button.label(24, 19, "Busy")
- print("Sent request for " .. amount .. " " .. asp .. " to #" .. prodID)
- rednet.receive()
- fillTable()
- refresh(false)
- end
- mapJars()
- print(table.getn(jars))
- fillTable()
- refresh(false)
- while true do getClickOrJar() end
Advertisement
Add Comment
Please, Sign In to add comment