Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactors = {};
- local energyCell = 1;
- local mon = 1;
- local reactorSel = 1;
- local monSel = 1;
- local w = 1;
- local h = 1;
- local clicked = "none";
- local run = false;
- local cell;
- function getReactors()
- i = {};
- j = 1;
- for k=1, #peripheral.getNames() do
- if (string.find(peripheral.getNames()[k], "Reactor") ~= nil) then
- table.insert(i, j, peripheral.wrap(peripheral.getNames()[k]));
- j = j+1;
- end
- end
- return i;
- end
- function numberOf(item)
- i = 0;
- for j=1, #peripheral.getNames() do
- if (string.find(peripheral.getNames()[j], item) ~= nil) then
- i = i+1;
- end
- end
- return i;
- end
- function getMonitors()
- i = {};
- j = 1;
- for k=1, #peripheral.getNames() do
- if (string.find(peripheral.getNames()[k], "monitor") ~= nil) then
- table.insert(i, j, peripheral.wrap(peripheral.getNames()[k]));
- j = j+1;
- end
- end
- return i;
- end
- function getCell()
- for j=1, #peripheral.getNames() do
- if (string.find(peripheral.getNames()[j], "thermalexpansion_cell") ~= nil) then
- return peripheral.wrap(peripheral.getNames()[j]);
- end
- end
- end
- function setup()
- term.clear();
- term.setCursorPos(1,1);
- reactors = getReactors();
- if (#reactors > 0) then
- write(numberOf("monitor") .. " monitors detected.\nSelect 1-" .. numberOf("monitor") .. "\n>");
- monSel = tonumber(read());
- if (monSel < numberOf("monitor")) or (monSel > numberOf("monitor")) then
- write("Invalid monitor!\n");
- else
- mon = getMonitors()[monSel];
- term.redirect(mon);
- w, h = term.getSize();
- button.newButton("last", 3,2,3,2);
- button.newButton("next", 7,2,7,2);
- button.newButton("exit", w,h,w,h);
- button.newButton("power", 9,2,13,2);
- cell = getCell();
- run = true;
- end
- else
- write("No reactors detected!\n");
- end
- end
- function main()
- if (clicked == "last") then
- if (reactorSel > 0) then
- reactorSel = reactorSel-1;
- end
- elseif (clicked == "next") then
- if(reactorSel < numberOf("Reactor")) then
- reactorSel = reactorSel+1;
- end
- elseif (clicked == "exit") then
- term.setBackgroundColor(colors.black);
- term.clear();
- run = false;
- return;
- elseif (clicked == "power") then
- if(reactors[reactorSel].getActive()) then
- reactors[reactorSel].setActive(false);
- else
- reactors[reactorSel].setActive(true);
- end
- end
- paintutils.drawFilledBox(1, 1, w, h, colors.black);
- current = reactors[reactorSel];
- term.setCursorPos(3,2);
- term.setBackgroundColor(colors.blue);
- term.setTextColor(colors.black);
- term.write("<");
- term.setBackgroundColor(colors.black);
- term.setTextColor(colors.white);
- term.write(" " .. reactorSel .. " ");
- term.setBackgroundColor(colors.blue);
- term.setTextColor(colors.black);
- term.write(">");
- term.setCursorPos(9,2);
- if(current.getActive()) then
- term.setBackgroundColor(colors.red);
- term.setTextColor(colors.black);
- term.write("STOP ");
- else
- term.setBackgroundColor(colors.green);
- term.setTextColor(colors.black);
- term.write("START");
- end
- term.setCursorPos(1, h-2);
- term.setTextColor(colors.white);
- term.setBackgroundColor(colors.black);
- term.write("Energy Cell Storage");
- paintutils.drawFilledBox(1, h-1, w*(cell.getEnergyStored()/cell.getMaxEnergyStored()), h, colors.red);
- paintutils.drawFilledBox(2, (h*(1/4))*(current.getFuelAmount()/current.getFuelAmountMax()), 4, h-4, colors.yellow);
- term.setCursorPos(w,h);
- term.setBackgroundColor(colors.red);
- term.setTextColor(colors.black);
- term.write("X");
- os.startTimer(5);
- os.pullEventRaw("timer");
- end
- setup();
- while run do
- parallel.waitForAny(button.monDetect, main);
- clicked = button.getLastClicked();
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement