Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local moduleName = ...
- local moduleSettings
- if hudSettings[moduleName] then
- moduleSettings = hudSettings[moduleName]
- else
- local settingsFile = fs.open("/Hud/hudSettings","a")
- settingsFile.write(moduleName..[[
- = {
- coreComputerID = 0,
- coreComputerProtocol = "energyCore",
- rfSuffixes = {"K","M","G","T","P","E","Z","Y"},
- ioAdjustmentCycles = 200,
- ioAdjustmentRate = 0.0001,
- alpha = 1,
- barColor = 0xff0000,
- textColor = 0xffff00,
- y = 1,
- x = 1,
- height = 9,
- width = 350,
- }
- ]])
- settingsFile.close()
- os.loadAPI("/Hud/hudSettings")
- moduleSettings = hudSettings[moduleName]
- end
- function formatRF(rf,forceSign)
- local sign
- if rf < 0 then
- sign = "-"
- rf = 0-rf
- elseif rf > 0 then
- sign = forceSign and "+" or ""
- else
- return "0RF"
- end
- local log = math.floor(math.log(rf)/math.log(1000))
- return sign..string.format("%0.3f",rf/1000^log)..(log > 0 and moduleSettings.rfSuffixes[log] or "").."RF"
- end
- function formatTime(time)
- if time >= 315360000000 then
- return "A:Long:Time"
- elseif time < 1 then
- return "No:Time"
- end
- local seconds = string.format("%02d",time%60)
- local minutes = string.format("%02d",(time/60)%60)
- local hours = string.format("%02d",(time/3600)%24)
- local days = string.format("%03d",(time/86400)%365)
- local years = string.format("%04d",time/31536000)
- return years..":"..days..":"..hours..":"..minutes..":"..seconds
- end
- canvas.addRectangle(
- (moduleSettings.x + hudSettings.x-1) * hudSettings.scale,
- (moduleSettings.y + hudSettings.y-1) * hudSettings.scale,
- (moduleSettings.width + 2) * hudSettings.scale,
- (moduleSettings.height + 2) * hudSettings.scale,
- hudSettings.backgroundColor*256 + math.floor(moduleSettings.alpha * hudSettings.alpha * 255)
- )
- local bar = {
- size = {
- moduleSettings.width * hudSettings.scale,
- moduleSettings.height * hudSettings.scale
- },
- object = canvas.addRectangle(
- (moduleSettings.x + hudSettings.x) * hudSettings.scale,
- (moduleSettings.y + hudSettings.y) * hudSettings.scale,
- 0, 0,
- moduleSettings.barColor*256 + math.floor(moduleSettings.alpha * hudSettings.alpha * 255)
- ),
- }
- local text = {
- object = canvas.addText(
- {
- (1+moduleSettings.x+hudSettings.x) * hudSettings.scale,
- (1+moduleSettings.y+hudSettings.y) * hudSettings.scale
- },
- "",
- moduleSettings.textColor*256 + math.floor(moduleSettings.alpha * hudSettings.alpha * 255)
- )
- }
- text.object.setScale(moduleSettings.height * hudSettings.scale / 9)
- local trueIO, instantIO, cycles = 0, 0, 0
- while true do
- local data
- repeat
- rednet.send(
- moduleSettings.coreComputerID, "",
- moduleSettings.coreComputerProtocol
- )
- _, data = rednet.receive(moduleSettings.coreComputerProtocol, 1)
- until data
- instantIO = instantIO*(1-moduleSettings.ioAdjustmentRate) + data.IO*(moduleSettings.ioAdjustmentRate)
- if cycles%moduleSettings.ioAdjustmentCycles == 0 then
- instantIO = (instantIO - trueIO*(1-moduleSettings.ioAdjustmentRate)^moduleSettings.ioAdjustmentCycles)/
- (1-(1-moduleSettings.ioAdjustmentRate)^moduleSettings.ioAdjustmentCycles)
- trueIO = instantIO
- end
- local timeRemaining
- if trueIO < 0 then
- timeRemaining = -(data.RF/trueIO)/20
- elseif trueIO > 0 then
- timeRemaining = ((data.MaxRF-data.RF)/trueIO)/20
- else
- timeRemaining = 10^9
- end
- bar.object.setSize(bar.size[1]*data.RF/data.MaxRF, bar.size[2])
- text.object.setText(
- formatRF(data.RF).."/"..formatRF(data.MaxRF)..
- " ("..string.format("%0.2f",data.RF/data.MaxRF*100,true).."%) "..
- formatRF(trueIO,true).."/t "..formatTime(timeRemaining))
- cycles = cycles+1
- end
Add Comment
Please, Sign In to add comment