Xyzzy

CC/RailCraft Tank Gauge

May 31st, 2015
227
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Basic Railcraft Tank Gauge by wok86
  2. --Monitor size is 3 high x 2 wide
  3.  
  4. --Side of monitor
  5. local m = peripheral.wrap("top")
  6.  
  7. --Peripheral name of Right Tank
  8. local rT = peripheral.wrap("rcsteeltankvalvetile_0")
  9.  
  10. --Peripheral name of Left Tank
  11. local lT = peripheral.wrap("rcsteeltankvalvetile_1")
  12.  
  13.  
  14. --Leave this alone
  15. local t = term.native()
  16.  
  17.  
  18. while true do
  19.  
  20.   local rTT = rT.getTankInfo()
  21.   local lTT = lT.getTankInfo()
  22.   --local lTAmt = 0
  23.   --local rTAmt = 0
  24.  
  25.   --Right Tank variables
  26.  
  27.   if rTT[1]["contents"] == nil then
  28.     rTAmt = 0
  29.   else
  30.     rTAmt = rTT[1]["contents"]["amount"]
  31.   end
  32.   local rTCap = rTT[1]["capacity"]
  33.   local rTPer = (rTAmt/rTCap)*100
  34.  
  35.  
  36.   --Left Tank Variables
  37.  
  38.   if lTT[1]["contents"] == nil then
  39.     lTAmt = 0
  40.   else
  41.     lTAmt = lTT[1]["contents"]["amount"]
  42.   end
  43.   local lTCap = lTT[1]["capacity"]
  44.   local lTPer = (lTAmt/lTCap)*100
  45.  
  46.  
  47.  
  48.   --Monitor positions/sizes for the bars
  49.   local xMinl = 2
  50.   local xMaxl = 8
  51.   local xMinr = 11
  52.   local xMaxr = 17
  53.   local yMaxl = 18
  54.   local yMaxr = 18
  55.  
  56.   --Work out the height of the bar required
  57.   local yMinl = yMaxl - (math.floor((yMaxl/100) * math.ceil(lTPer)))
  58.   local yMinr = yMaxr - (math.floor((yMaxr/100) * math.ceil(rTPer)))
  59.  
  60.   --Make it so that the bar doesn't go too high
  61.   if yMinl == 0 or yMinl == 1 then
  62.     yMinl = 2
  63.   else
  64.     print(" ")
  65.   end
  66.  
  67.   if yMinr == 0 or yMinr == 1 then
  68.     yMinr = 2
  69.   else
  70.     print(" ")
  71.   end
  72.  
  73.  
  74.   --Reset the computer screen (not the monitor)
  75.   term.clear()
  76.   term.setCursorPos(1,1)
  77.  
  78.   --Print some raw info on computer screen (not the monitor)
  79.   print("Left Tank: "..math.ceil(lTPer).."%")
  80.   print("LTA: "..lTAmt)
  81.   print("LTC: "..lTCap)
  82.   print("Right Tank: "..math.ceil(rTPer).."%")
  83.   print("RTA: "..rTAmt)
  84.   print("RTC: "..rTCap)
  85.  
  86.   --Redirect output to the monitor
  87.   term.redirect(m)
  88.  
  89.   --Reset/clear the monitor
  90.   term.clear()
  91.   term.setCursorPos(1,1)
  92.   term.setBackgroundColor(colors.black)
  93.   term.setTextColor(colors.white)
  94.   m.clear()
  95.   m.setCursorPos(1,1)
  96.   m.setBackgroundColor(colors.black)
  97.   m.setTextColor(colors.white)
  98.  
  99.   --Print bar labels
  100.   term.setCursorPos(3, 1)
  101.   print("Tank1")
  102.   term.setCursorPos(12, 1)
  103.   print("Tank2")
  104.  
  105.   --Draw the Left bar
  106.   for i = xMinl, xMaxl do
  107.     for j = yMinl, yMaxl do
  108.       if math.ceil(lTPer) < 24 then
  109.         paintutils.drawPixel(i, j, colors.red)
  110.       elseif math.ceil(lTPer) >= 25 and math.ceil(lTPer) <= 60 then
  111.         paintutils.drawPixel(i, j, colors.orange)
  112.       else
  113.         paintutils.drawPixel(i, j, colors.lime)
  114.       end
  115.     end
  116.   end
  117.  
  118.   --Draw the Right bar
  119.   for k = xMinr, xMaxr do
  120.     for l = yMinr, yMaxr do
  121.       if math.ceil(rTPer) < 24 then
  122.         paintutils.drawPixel(k, l, colors.red)
  123.       elseif math.ceil(rTPer) >= 25 and math.ceil(rTPer) <= 60 then
  124.         paintutils.drawPixel(k, l, colors.orange)
  125.       else
  126.         paintutils.drawPixel(k, l, colors.lime)
  127.       end
  128.     end
  129.   end
  130.  
  131.  
  132.   --Print the percentage of the Left Tank
  133.   if math.ceil(lTPer) <= 9 then
  134.     term.setCursorPos(5, 18)
  135.   elseif math.ceil(lTPer) >= 10 and math.ceil(lTPer) <= 99 then
  136.     term.setCursorPos(4, 18)
  137.   else
  138.     term.setCursorPos(3, 18)
  139.   end
  140.  
  141.   if math.ceil(lTPer) < 24 then
  142.     term.setBackgroundColor(colors.red)
  143.   elseif math.ceil(lTPer) >= 25 and math.ceil(lTPer) <= 60 then
  144.     term.setBackgroundColor(colors.orange)
  145.   else
  146.     term.setBackgroundColor(colors.lime)
  147.   end
  148.  
  149.   term.setTextColor(colors.black)
  150.   print(math.ceil(lTPer).." %")
  151.  
  152.  
  153.   --Print the percentage of the Right Tank
  154.   if math.ceil(rTPer) <= 9 then
  155.     term.setCursorPos(14, 18)
  156.   elseif math.ceil(rTPer) >=10 and math.ceil(rTPer) <= 99 then
  157.     term.setCursorPos(13, 18)
  158.   else
  159.     term.setCursorPos(12, 18)
  160.   end
  161.  
  162.   if math.ceil(rTPer) < 24 then
  163.     term.setBackgroundColor(colors.red)
  164.   elseif math.ceil(rTPer) >= 25 and math.ceil(rTPer) <= 60 then
  165.     term.setBackgroundColor(colors.orange)
  166.   else
  167.     term.setBackgroundColor(colors.lime)
  168.   end
  169.  
  170.   term.setTextColor(colors.black)
  171.   print(math.ceil(rTPer).." %")
  172.  
  173.   --Redirect back to the computer screen
  174.   term.redirect(t)  
  175.  
  176.   --Wait
  177.   sleep(5)
  178.   print("sleep")
  179.  
  180. end
RAW Paste Data