Created
March 12, 2015 10:03
-
-
Save evieluvsrainbows/cf0c05fe8b1064f0c459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--BR control by Graypup | |
--Legalese below | |
--[[ | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2004 Sam Hocevar <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. | |
]] | |
local term = require("term") | |
local component = require("component") | |
local unicode = require("unicode") | |
local event = require("event") | |
local br = component.br_reactor | |
local gpu = component.gpu | |
--Constants: | |
local cpromsg = "Currently producing: " | |
local fueltempmsg = "Current fuel temperature: " | |
local casetempmsg = "Current casing temperature: " | |
local estoragemsg = "Energy Stored: " | |
local ff = true | |
local lastOot | |
local lastActive | |
local resX, resY = gpu.getResolution() | |
local function round(num, idp) | |
local mult = 10^(idp or 0) | |
return math.floor(num * mult + 0.5) / mult | |
end | |
local function dotZero(num) | |
if num % 1 == 0 then | |
return num .. ".0" | |
else | |
return num | |
end | |
end | |
local function printCentered(thing) | |
local _,y = term.getCursor() | |
local w = gpu.getResolution() | |
term.setCursor((w-thing:len())/2, y) | |
end | |
local function printEnergyStorageBar() | |
local outOfTen = round(br.getEnergyStored() / 10000000 * 10) | |
local x,y = estoragemsg:len()+1, 5 | |
if outOfTen ~= lastOot then | |
local b, bp = gpu.getBackground() | |
gpu.setBackground(0x00FF00) | |
gpu.fill(x, y, outOfTen, 1, " ") | |
if 10-outOfTen > 0 then | |
gpu.setBackground(0xFF0000) | |
gpu.fill(x+outOfTen, y, 10-outOfTen, 1, " ") | |
end | |
gpu.setBackground(b,bp) | |
end | |
end | |
local function printActive() | |
isActive = br.getActive() | |
if isActive ~= lastActive then | |
local f, fb = gpu.getForeground() | |
if isActive then | |
gpu.fill(1, 1, resX, 1, " ") | |
gpu.setForeground(0x00FF00) | |
gpu.set(1, 1, "Online") | |
else | |
gpu.fill(1, 1, resX, 1, " ") | |
gpu.setForeground(0xFF0000) | |
gpu.set(1, 1, "Offline") | |
end | |
gpu.setForeground(f,fb) | |
end | |
lastActive = isActive | |
end | |
local function redraw() | |
printActive() | |
gpu.set(cpromsg:len()+1, 2, dotZero(tonumber(string.format("%.1f", br.getEnergyProducedLastTick()/1000))) .. " KiRF/t ") | |
gpu.set(fueltempmsg:len()+1, 3, dotZero(tonumber(string.format("%.1f", br.getFuelTemperature()))) .. unicode.char(0x00b0) .. "C ") | |
gpu.set(casetempmsg:len()+1, 4, dotZero(tonumber(string.format("%.1f", br.getCasingTemperature()))) .. unicode.char(0x00b0) .. "C ") | |
printEnergyStorageBar() | |
end | |
term.clear() | |
gpu.set(1, 2, cpromsg) | |
gpu.set(1, 3, fueltempmsg) | |
gpu.set(1, 4, casetempmsg) | |
gpu.set(1, 5, estoragemsg) | |
--Get the painting and control running | |
event.timer(0.4, reactorControl, math.huge) | |
event.timer(0.8, redraw, math.huge) | |
while true do | |
local _, _, char = event.pull("key_down") | |
if unicode.char(char) == " " then | |
stateToSet = not br.getActive() | |
br.setActive(stateToSet) | |
printActive() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment