Nike622000

Reaktor Graph overlay

Oct 29th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.18 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. local monSide   = "top"
  4. local Rside     = "back"
  5. local OPD       = "front"
  6. local Ic2sensor = "left"
  7. local xPosIc2   =  1
  8. local yPosIc2   = -3
  9. local zPosIc2   =  1
  10. local Invsensor = "right"
  11. local xPosInv   =  1
  12. local yPosInv   = -3
  13. local zPosInv   = -1
  14.  
  15. -- Stat true = Reactor laeuft beim starten, Stat false, Reaktor aus beim starten
  16. local Stat      = false
  17.  
  18. mon = peripheral.wrap(monSide)
  19.  
  20. local xMax,yMax = mon.getSize()
  21.  
  22. function Background(col)
  23.   mon.setBackgroundColor(col)
  24.   for xPos = 1,xMax do
  25.     for yPos = 1,yMax do
  26.       mon.setCursorPos(xPos,yPos)
  27.       mon.write(" ")
  28.     end
  29.   end
  30. end
  31.  
  32. function JoJa(xPos,yPos)
  33.   mon.setCursorPos(xPos,yPos)
  34.   mon.setBackgroundColor(colors.gray)
  35.   mon.setTextColor(colors.cyan)
  36.   mon.write("Jo")
  37.   mon.setTextColor(colors.orange)
  38.   mon.write("Ja ")
  39.   mon.setTextColor(colors.lightGray)
  40.   mon.write("Productions")
  41.   mon.setBackgroundColor(colors.black)
  42.   mon.setTextColor(colors.white)
  43. end
  44.  
  45. function edge(startPosX,startPosY,endPosX,endPosY)
  46.   mon.setBackgroundColor(colors.gray)
  47.   for xPos = startPosX,endPosX do
  48.     mon.setCursorPos(xPos,startPosY)
  49.     mon.write(" ")
  50.     mon.setCursorPos(xPos,endPosY)
  51.     mon.write(" ")
  52.   end
  53.   for yPos = startPosY,endPosY do
  54.     mon.setCursorPos(startPosX,yPos)
  55.     mon.write(" ")
  56.     mon.setCursorPos(endPosX,yPos)
  57.     mon.write(" ")
  58.   end
  59. end
  60.  
  61. function overlay(xPos,yPos,text)
  62.   mon.setBackgroundColor(colors.black)
  63.   mon.setCursorPos(xPos,yPos)
  64.   mon.write(text)
  65. end
  66.  
  67. function checkIC2()
  68.   sen = sensor.wrap(Ic2sensor)
  69.   for a,b in pairs(sen.getTargets()) do
  70.     if b.Name == "Nuclear Reactor"
  71.     and b.Position.X == xPosIc2
  72.     and b.Position.Y == yPosIc2
  73.     and b.Position.Z == zPosIc2
  74.     then
  75.       print("Reaktor detection complete. X: "..b.Position.X.." Y: "..b.Position.Y.." Z: "..b.Position.Z)
  76.       for k,v in pairs(sen.getTargetDetails(a)) do
  77.         if type(v) == "table" then
  78.         else
  79.        
  80.           if k == "Active" then
  81.           term.write("Reaktor: ")
  82.             if v == true then
  83.               Status = true
  84.               print("AN")
  85.             else
  86.               Status = false
  87.               print("AUS")
  88.             end
  89.           end
  90.          
  91.           if k == "Output" then
  92.             print("Output: "..v.." eu/t")
  93.             Output = v
  94.           end
  95.          
  96.           if k == "Heat" then
  97.             print("Heat: "..v)
  98.             Heat = v
  99.           end
  100.          
  101.           if k == "MaxHeat" then
  102.             print("maxHeat: "..v)
  103.             maxHeat = v
  104.           end
  105.         end
  106.       end
  107.     end
  108.   end  
  109. end
  110.  
  111. function checkInv()
  112.   Name     = {}
  113.   Schaden  = {}
  114.   sUranC   = 0
  115.   dUranC   = 0
  116.   qUranC   = 0
  117.   Schaden  = 0
  118.   Anzahl   = 0
  119.   SchadenR = 0
  120.   AnzahlR  = 0
  121.   sen = sensor.wrap(Invsensor)
  122.   for k,v in pairs(sen.getTargets()) do
  123.     if  v.Name == "Nuclear Reactor"
  124.     and v.Position.X == xPosInv
  125.     and v.Position.Y == yPosInv
  126.     and v.Position.Z == zPosInv
  127.     then
  128.       details = sen.getTargetDetails(k)
  129.       Slots = #details.Slots
  130.       for Slot = 1,Slots do
  131.         Name[Slot] = details.Slots[Slot].Name
  132.         if     Name[Slot] == "Uranium Cell"      then
  133.           sUranC = sUranC+1
  134.         elseif Name[Slot] == "Dual Uranium Cell" then
  135.           dUranC = dUranC+1
  136.         elseif Name[Slot] == "Quad Uranium Cell" then
  137.           qUranC = qUranC+1
  138.         end
  139.        
  140.        
  141.         if Name[Slot] == "Uranium Cell"
  142.         or Name[Slot] == "Dual Uranium Cell"
  143.         or Name[Slot] == "Quad Uranium Cell"
  144.         then
  145.           Schaden = Schaden + details.Slots[Slot].DamageValue
  146.           Anzahl = Anzahl + 1
  147.         else
  148.           if Name[Slot] ~= "empty" then
  149.             SchadenR = 0
  150.             AnzahlR = 0
  151.             SchadenR = SchadenR + details.Slots[Slot].DamageValue
  152.             AnzahlR = AnzahlR + 1
  153.           end
  154.         end
  155.       end
  156.     end
  157.   end
  158. end
  159.  
  160. function graph(Wert1,Wert2,xPos,xMax,yPos,col1,col2)
  161.   mon.setBackgroundColor(col2)
  162.   for xP = xPos,xMax do
  163.     mon.setCursorPos(xP,yPos)
  164.     mon.write(" ")
  165.     mon.setCursorPos(xP,yPos+1)
  166.     mon.write(" ")
  167.   end
  168.   percentageWert = (Wert1/Wert2)*100
  169.   space = xMax-xPos
  170.   mon.setBackgroundColor(col1)
  171.   for xP = xPos,xPos+math.floor(space*(percentageWert/100)) do
  172.     mon.setCursorPos(xP,yPos)
  173.     mon.write(" ")
  174.     mon.setCursorPos(xP,yPos+1)
  175.     mon.write(" ")
  176.   end
  177. end
  178.  
  179. function graph2(Wert1,Wert2,xPos,xMax,yPos,col1,col2)
  180.   mon.setBackgroundColor(col2)
  181.   for xP = xPos,xMax do
  182.     mon.setCursorPos(xP,yPos)
  183.     mon.write(" ")
  184.     mon.setCursorPos(xP,yPos+1)
  185.     mon.write(" ")
  186.   end
  187.   percentageWert = 100-((Wert1/Wert2)*100)
  188.   space = xMax-xPos
  189.   mon.setBackgroundColor(col1)
  190.   for xP = xPos,xPos+math.floor(space*(percentageWert/100)) do
  191.     mon.setCursorPos(xP,yPos)
  192.     mon.write(" ")
  193.     mon.setCursorPos(xP,yPos+1)
  194.     mon.write(" ")
  195.   end
  196. end
  197.  
  198. function Button(xP1,xP2,yP1,yP2,col)
  199.   mon.setBackgroundColor(col)
  200.   for xPos = xP1,xP2 do
  201.     for yPos = yP1,yP2 do
  202.       mon.setCursorPos(xPos,yPos)
  203.       mon.write(" ")
  204.     end  
  205.   end
  206.   mon.setBackgroundColor(colors.black)
  207. end
  208.  
  209. function checkButton()
  210.   os.startTimer(10)
  211.   event,_,xPos,yPos = os.pullEvent()
  212.   if event == "monitor_touch"
  213.   and xPos >= 33 and xPos <= xMax-10
  214.   and yPos >= 14 and yPos <= yMax-2
  215.   then
  216.     Stat = true
  217.   elseif event == "monitor_touch"
  218.   and xPos >= xMax-9 and xPos <= xMax-2
  219.   and yPos >= 14 and yPos <= yMax-2
  220.   then
  221.     Stat = false
  222.   end
  223.   if event == "timer" then
  224.     print("time out")
  225.   end
  226. end
  227.  
  228. while true do
  229. if rs.getInput(OPD) then
  230.   checkIC2()
  231.   checkInv()
  232.   Background(colors.black)
  233.   JoJa(xMax/2-7,1)
  234.   edge(2,3,30,yMax-1)
  235.   mon.setTextColor(colors.white)
  236.   overlay(4,3," Info ")
  237.   overlay(3,5," Heat ")
  238.   graph(Heat,maxHeat,4,28,6,colors.red,colors.lightGray)
  239.   overlay(3,9," Durability Uran ")
  240.   graph2(Schaden/Anzahl,10000,4,28,10,colors.lime,colors.lightGray)
  241.   overlay(3,13," Durability Components ")
  242.   graph2(SchadenR/AnzahlR,10000,4,28,14,colors.cyan,colors.lightGray)
  243.   edge(32,3,xMax-1,11)
  244.   overlay(34,3," Data ")
  245.   overlay(33,5," Status: ")
  246.   if Status then
  247.     mon.setTextColor(colors.lime)
  248.     mon.write("ON ")
  249.     mon.setTextColor(colors.white)
  250.   else
  251.     mon.setTextColor(colors.red)
  252.     mon.write("OFF")
  253.     mon.setTextColor(colors.white)
  254.   end
  255.   overlay(33,6," Output: "..Output.."eu/t")
  256.   overlay(33,7," s.UranC:"..sUranC)
  257.   overlay(33,8," d.UranC:"..dUranC)
  258.   overlay(33,9," q.UranC:"..qUranC)
  259.  
  260.   edge(32,13,xMax-1,yMax-1)
  261.   overlay(34,13," Menu ")
  262.   Button(33,xMax-10,14,yMax-2,colors.lime)
  263.   Button(xMax-9,xMax-2,14,yMax-2,colors.red)
  264.   mon.setBackgroundColor(colors.lime)
  265.   mon.setCursorPos(34,15)
  266.   mon.write("Reactor")
  267.   mon.setCursorPos(36,16)
  268.   mon.write("ON")
  269.   mon.setBackgroundColor(colors.black)
  270.   mon.setBackgroundColor(colors.red)
  271.   mon.setCursorPos(xMax-8,15)
  272.   mon.write("Reactor")
  273.   mon.setCursorPos(xMax-6,16)
  274.   mon.write("OFF")
  275.   mon.setBackgroundColor(colors.black)
  276.   checkButton()
  277.  
  278.   rs.setOutput(Rside, Stat)
  279. else
  280. Background(colors.black)
  281. JoJa(xMax/2-7,1)
  282. mon.setCursorPos(xMax/2-4,yMax/2)
  283. mon.setTextColor(colors.gray)
  284. mon.write("offline")
  285. sleep(2)
  286. end
  287. end
Advertisement
Add Comment
Please, Sign In to add comment