Advertisement
cjburkey01

ComputerCraft & BigReactors

Sep 26th, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. reactorSide = "back";
  2. monitorSide = "right";
  3. updateMonitorSeconds = .1;
  4. minRun = 5000;
  5. maxRun = 9000000;
  6. maxTemp = 2000;
  7.  
  8. mon = peripheral.wrap(monitorSide);
  9. reactor = peripheral.wrap(reactorSide);
  10.  
  11. buttons = {
  12.     start = { x=1, y=1, text="Start", color=colors.orange, tcolor=colors.black, click=function() start(); end },
  13.     stop = { x=7, y=1, text="Stop", color=colors.orange, tcolor=colors.black, click=function() stop(); end },
  14. };
  15.  
  16. function monitor()
  17.     while(true) do
  18.         mon.clear();
  19.         mon.setTextScale(1.1);
  20.        
  21.         for k, v in pairs(buttons) do
  22.             mon.setBackgroundColor(v.color);
  23.             mon.setTextColor(v.tcolor);
  24.             mon.setCursorPos(v.x, v.y);
  25.             mon.write(v.text);
  26.         end
  27.        
  28.         mon.setTextColor(colors.white);
  29.         mon.setBackgroundColor(colors.black);
  30.         mon.setCursorPos(1, 2);
  31.        
  32.         energy = reactor.getEnergyStored();
  33.         temp1 = reactor.getFuelTemperature();
  34.         temp2 = reactor.getCasingTemperature();
  35.        
  36.         color();
  37.        
  38.         progress1 = energy / maxRun;
  39.         progress2 = temp1 / maxTemp;
  40.         progress3 = temp2 / maxTemp;
  41.         local w, h = mon.getSize();
  42.         local oldTerm = term.redirect(mon);
  43.         paintutils.drawFilledBox(1, 2, progress1 * w, 2, colors.yellow);
  44.         paintutils.drawFilledBox(1, 3, progress2 * w, 3, colors.orange);
  45.         paintutils.drawFilledBox(1, 4, progress3 * w, 4, colors.red);
  46.         term.redirect(oldTerm);
  47.        
  48.         color();
  49.        
  50.         if(energy <= minRun) then
  51.             start();
  52.         elseif(energy >= maxRun) then
  53.             stop();
  54.         end
  55.        
  56.         if(temp1 >= maxTemp or temp2 >= maxTemp) then
  57.             stop();
  58.         end
  59.        
  60.         sleep(updateMonitorSeconds);
  61.     end
  62. end
  63.  
  64. function color()
  65.     if(reactor.getActive()) then
  66.         mon.setBackgroundColor(colors.green);
  67.     else
  68.         mon.setBackgroundColor(colors.combine(colors.red, colors.black));
  69.     end
  70. end
  71.  
  72. function updateCheck()
  73.     while(true) do
  74.         local event, side, x, y = os.pullEvent("monitor_touch");
  75.        
  76.         for k, v in pairs(buttons) do
  77.             if(x >= v.x and x <= v.x + string.len(v.text)) then
  78.                 v.click();
  79.             end
  80.         end
  81.        
  82.         sleep(updateMonitorSeconds);
  83.     end
  84. end
  85.  
  86. function start()
  87.     reactor.setActive(true);
  88. end
  89.  
  90. function startP()
  91.     start();
  92.     print("Starting reactor.");
  93. end
  94.  
  95. function stop()
  96.     reactor.setActive(false);
  97. end
  98.  
  99. function stopP()
  100.     stop();
  101.     print("Stopping reactor.");
  102. end
  103.  
  104. function writeMon(mon, text)
  105.     local x, y = mon.getCursorPos();
  106.     mon.write(text);
  107.     mon.setCursorPos(x, y + 1);
  108. end
  109.  
  110. shell.run("clear");
  111. print("Running ComputerCraft & BigReactors System by CJ Burkey");
  112. parallel.waitForAll(monitor, updateCheck);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement