Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load dependencies
- os.loadAPI( "ProgressBar" )
- -- Configurations
- local rednetLocation = "right"
- local monitorFontSize = 1.0
- local liquidPerScreen = 3
- -- Configurations End
- local monitor = {
- peripheral.find( "monitor" )
- }
- local liquidType = {}
- local monitorCount = {}
- -- Helper functions
- function stringSplit( str )
- local t = {}
- local function helper( word )
- table.insert( t, word )
- return ""
- end
- if not str:gsub( "%w+", helper ):find"%S" then
- return t
- end
- end
- function getAvailableMonitor()
- for monitorNum, monitorFunc in pairs( monitor ) do
- if table.getn( monitorCount[ monitorNum ] ) < liquidPerScreen then
- return monitorNum
- end
- end
- return nil
- end
- function getLatestMonitorLocation( monitor )
- end
- function writeToMonitor( liquid, msg )
- local liquid = liquidType[ liquid ]
- local m = monitor[ liquid["monitor"] ]
- end
- function printN( repetitions, msg )
- while repetitions >= 0 do
- print( msg )
- repetitions = repetitions - 1
- end
- end
- function parseMsg( id, msg )
- local incomingLine = stringSplit( msg )
- if "liquidData" == incomingLine[1] then
- local liquidID = incomingLine[2]
- local liquidCurrent = incomingLine[3]
- local liquidMax = incomingLine[4]
- local liquidLabel = incomingLine[5]
- local liquidPercent = ( liquidCurrent / liquidMax ) * 100
- if nil == liquidType[ liquidID ] then
- local newMonitor = getAvailableMonitor()
- if nil == newMonitor then
- printN( 20, "No more monitor space, expansion needed for " .. liquidLabel .. "!" )
- else
- local latestMonitorLocation = getLatestMonitorLocation( newMonitor )
- if nil == latestMonitorLocation then
- local progressBarStart = 1
- else
- local progressBarStart = latestMonitorLocation + 1
- end
- local newProgressBar = ProgressBar.SetPeripheral( monitor[ newMonitor ] )
- monitorCount[ newMonitor ][ liquidID ] = true
- liquidType[ liquidID ] = {}
- liquidType[ liquidID ]["label"] = liquidLabel
- liquidType[ liquidID ]["monitor"] = monitor[ newMonitor ]
- liquidType[ liquidID ]["writeLine"] = latestMonitorLocation
- liquidType[ liquidID ]["progress"] = newProgressBar
- newProgressBar.SetTable( liquidID, 100, 0, 5, barWidth, progressBarStart )
- end
- end
- if not nil == liquidType[ liquidID ] then
- local writeTo = liquidType[ liquidID ]["writeLine"]
- local m = liquidType[ liquidID ]["monitor"]
- local p = liquidType[ liquidID ]["progress"]
- m.setCursorPos( 5, writeTo )
- m.clearLine()
- m.write( liquidType[ liquidID ]["label"] .. " (" .. liquidCurrent .. " / " .. liquidMax .. "" )
- p.SetCurValue( liquidID, liquidPercent )
- end
- end
- end
- -- Start by resetting all active monitors
- for monitorNum, monitorFunc in pairs( monitor ) do
- monitorFunc.clear()
- monitorCount[monitorNum] = {}
- end
- rednet.open( rednetLocation )
- while true do
- id, msg, time = rednet.receive()
- print( msg )
- parseMsg( id, msg )
- end
- rednet.close( rednetLocation )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement