Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wired = peripheral.wrap("front") -- Wired modem
- wireless = peripheral.wrap("bottom") -- Wireless modem
- levelMon = peripheral.wrap("top")
- statusMon = peripheral.wrap("back")
- levelColors = { 2048, 512, 8, 16, 16384 }
- levelLimits = { 60, 45, 32, 15, 5 }
- aspects = {}
- filename = "MissingAspects"
- channel = 300 -- This is the channel all the messageing traffic goes on
- wireless.open(channel)
- function getCons()
- return wired.getNamesRemote()
- end
- function split(inputstr, sep) -- splits a string into a table
- if sep == nil then
- sep = "%s"
- end
- t={}
- i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function splitStr(pStr, pChar) -- splits string into two variables
- return string.match(pStr, "([^" .. pChar .. "]+)" .. pChar .. "([^" .. pChar .. "]+)")
- end
- function send(msg)
- print("sending: " .. msg)
- wireless.transmit(channel, 1, msg)
- end
- function receive()
- e = {os.pullEvent("modem_message")}
- print("received: " .. e[5])
- return e[5]
- end
- function getColor(count)
- for k,v in pairs(levelLimits) do
- if tonumber(count) <= tonumber(v) then
- levelMon.setTextColor(levelColors[k])
- end
- end
- end
- function updateJarLevelMonitor()
- levelMon.clear()
- local xmax, ymax = levelMon.getSize()
- levelMon.setCursorPos(2,1)
- for k,v in pairs(aspects) do
- local x, y = levelMon.getCursorPos()
- if tonumber(x+5) > tonumber(xmax) then
- levelMon.setCursorPos(2,y+1)
- x, y = levelMon.getCursorPos()
- end
- getColor(v.quantity)
- levelMon.write(string.sub(v.name, 1, 5))
- levelMon.setCursorPos(x+6,y)
- levelMon.write(tostring(v.quantity))
- levelMon.setCursorPos(x+10,y)
- end
- levelMon.setTextColor(colors.purple)
- levelMon.write(" Hit Screen to Refresh Jar Values")
- end
- function length(pTable)
- local count = 0
- for k,v in pairs(pTable) do count = count + 1 end
- return count
- end
- local btnColors = {colors.purple, colors.blue}
- function displayRefillButton(col)
- statusMon.setTextColor(btnColors[col])
- statusMon.setCursorPos(1,3) statusMon.write("+-------------+")
- statusMon.setCursorPos(1,4) statusMon.write("| HIT HERE |")
- statusMon.setCursorPos(1,5) statusMon.write("| TO |")
- statusMon.setCursorPos(1,6) statusMon.write("| REFILL JARS |")
- statusMon.setCursorPos(1,7) statusMon.write("+-------------+")
- end
- function updateStatusMonitor(msg)
- statusMon.clear()
- statusMon.setTextColor(colors.purple)
- statusMon.setTextScale(.5)
- local msgTable = split(msg, " ")
- local l = tonumber(length(msgTable))
- local y = 5 - math.ceil(l/2)
- for k,v in pairs(msgTable) do
- local x = 8 - math.ceil(string.len(v)/2)
- statusMon.setCursorPos(x,y) statusMon.write(v)
- y = y+1
- end
- end
- function updateAspects()
- cons = getCons()
- aspects = {}
- local i = 0
- for k,v in pairs(cons) do
- updateStatusMonitor("Checking Aspect Jars")
- local jar = peripheral.wrap(v)
- if jar then
- local aspectTbl = jar.getAspects()
- if aspectTbl then table.insert(aspects, aspectTbl[1]) end
- end
- i = (i+1)%5
- end
- updateStatusMonitor("Sorting Aspect Table")
- local sort_func = function( a,b ) return a.name < b.name end
- table.sort( aspects, sort_func )
- end
- function addToFile(str)
- local writeType = ""
- if fs.exists(filename) then
- writeType = "a"
- else
- writeType = "w"
- end
- local file = fs.open(filename, writeType)
- file.writeLine(str)
- file.close()
- end
- function refillAll()
- updateAspects()
- send(textutils.serialize(aspects))
- for i=1,3 do
- updateStatusMonitor("Waiting for Turtles " .. to string(4-tonumber(i)))
- local missingData = textutils.unserialize(receive())
- for k,v in pairs(missingData) do
- addToFile(v.name .. "," .. v.quantity)
- end
- end
- end
- while true do
- updateAspects()
- updateJarLevelMonitor()
- displayRefillButton(1)
- local e = {os.pullEvent("monitor_touch")}
- if e and e[1] == "monitor_touch" then
- if e[2] == "top" then
- updateJarLevelMonitor()
- elseif e[2] == "back" then
- displayRefillButton(2)
- sleep(.1)
- displayRefillButton(1)
- refillAll()
- send("check if done")
- updateStatusMonitor("Processing Essentia")
- local msg = receive()
- if msg and msg == "done" then
- updateStatusMonitor("Done!")
- end
- updateJarLevelMonitor()
- sleep(1)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement