Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.81 KB | None | 0 0
  1.     table.insert(lines, {numbersSize['startX'] + margin , numbersSize['startY'], numbersSize['startX'] + (margin*2) + #name+1, numbersSize['startY'], colors.black})
  2.     table.insert(texts, {numbersSize['startX'] + (margin*2), numbersSize['startY'], name, colors.white, colors.black})
  3.  
  4.     refresh = true
  5.     while refresh do
  6.         parallel.waitForAny(refreshSingleReactor,clickEvent)
  7.     end
  8. end
  9.  
  10. -- Makes and Handles the draw function for less lag in the visual
  11.  
  12. function refreshSingleReactor()
  13.     local rfPerTick = 0
  14.     local rfTotal = 0
  15.     local rfTotalMax = 10000000
  16.     local reactor = reactors[1]
  17.  
  18.     rfTotal = reactor.getEnergyStored()
  19.     rfPerTick = math.floor(reactor.getEnergyProducedLastTick())
  20.     rodLevel = math.floor(reactor.getControlRodLevel(0))
  21.     fuelPerTick = reactor.getFuelConsumedLastTick();
  22.  
  23.     local i = 0
  24.     local infotoAdd = 'RF PER TICK : '
  25.  
  26.     if currentRfTick ~= rfPerTick then
  27.         currentRfTick = rfPerTick
  28.         if rfPerTick > rfPerTickMax then
  29.             rfPerTickMax = rfPerTick
  30.         end
  31.  
  32.         table.insert(lines, {numbersSize['inX'] , numbersSize['inY'],numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'], colors.black})
  33.         table.insert(texts, {numbersSize['inX'], numbersSize['inY'], infotoAdd .. rfPerTick .. " RF", colors.white, colors.black})
  34.         table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
  35.  
  36.         width = math.floor((infosSize['width'] / rfPerTickMax)*rfPerTick)
  37.         table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
  38.  
  39.     end
  40.  
  41.     i = 1
  42.     infotoAdd = 'ENERGY STORED : '
  43.     if currentRfTotal ~= rfTotal then
  44.         currentRfTotal = rfTotal
  45.  
  46.         table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
  47.  
  48.         width = math.floor((infosSize['width'] / rfTotalMax)*rfTotal)
  49.         table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
  50.         table.insert(lines, {numbersSize['inX'] , numbersSize['inY'] +2 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +2, colors.black})
  51.         table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 2 , infotoAdd .. rfTotal .. " RF", colors.white, colors.black})
  52.     end
  53.  
  54.     i = 2
  55.     infotoAdd = 'CONTROL ROD LEVEL : '
  56.     if currentRodLevel ~= rodLevel then
  57.         currentRodLevel = rodLevel
  58.  
  59.         table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
  60.  
  61.         width = math.floor((infosSize['width'] / 100)*rodLevel)
  62.         table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green})
  63.         table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+4 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +4, colors.black})
  64.         table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 4 , infotoAdd .. rodLevel .. "%", colors.white, colors.black})
  65.     end
  66.  
  67.     i = 3
  68.     infotoAdd = 'FUEL USAGE : '
  69.     if currentFuelConsumedLastTick ~= fuelPerTick then
  70.         currentFuelConsumedLastTick = fuelPerTick
  71.  
  72.         table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+6 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +6, colors.black})
  73.         table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 6 , infotoAdd .. format_num(tonumber(fuelPerTick),3) .. "mb/t", colors.white, colors.black})
  74.     end
  75.  
  76.     mon.setTextColor(colors.white)
  77.     adjustRodsLevel()
  78.  
  79.     draw()
  80.  
  81.     sleep(2)
  82. end
  83.  
  84. --
  85. -- ** Get the informations from the index file
  86. -- line 1 = min ROD
  87. -- line 2 = max ROD
  88. --
  89.  
  90. function getInfoFromFile()
  91.  
  92.      if (fs.exists(index..".txt") == false) then
  93.         file = io.open(index..".txt","w")
  94.         file:write("0")
  95.         file:write("\n")
  96.         file:write("100")
  97.         file:close()
  98.     else
  99.         file = fs.open(index..".txt","r")
  100.         minPowerRod = tonumber(file.readLine())
  101.         maxPowerRod = tonumber(file.readLine())
  102.         file.close()
  103.     end
  104. end
  105.  
  106. -- Save informations to the index file
  107.  
  108. function setInfoToFile()
  109.     file = io.open(index..".txt","w")
  110.     file:write(minPowerRod .. "\n" .. maxPowerRod)
  111.     file:flush()
  112.     file:close()
  113. end
  114.  
  115. ---============================================================
  116. -- add comma to separate thousands
  117. -- From Lua-users.org/wiki/FormattingNumbers
  118. --
  119. --
  120. function comma_value(amount)
  121.   local formatted = amount
  122.   while true do
  123.     formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  124.     if (k==0) then
  125.       break
  126.     end
  127.   end
  128.   return formatted
  129. end
  130.  
  131. ---============================================================
  132. -- rounds a number to the nearest decimal places
  133. -- From Lua-users.org/wiki/FormattingNumbers
  134. --
  135. --
  136. function round(val, decimal)
  137.   if (decimal) then
  138.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  139.   else
  140.     return math.floor(val+0.5)
  141.   end
  142. end
  143.  
  144. --===================================================================
  145. -- given a numeric value formats output with comma to separate thousands
  146. -- and rounded to given decimal places
  147. -- From Lua-users.org/wiki/FormattingNumbers
  148. --
  149. function format_num(amount, decimal, prefix, neg_prefix)
  150.   local str_amount,  formatted, famount, remain
  151.  
  152.   decimal = decimal or 2  -- default 2 decimal places
  153.   neg_prefix = neg_prefix or "-" -- default negative sign
  154.  
  155.   famount = math.abs(round(amount,decimal))
  156.   famount = math.floor(famount)
  157.  
  158.   remain = round(math.abs(amount) - famount, decimal)
  159.  
  160.         -- comma to separate the thousands
  161.   formatted = comma_value(famount)
  162.  
  163.         -- attach the decimal portion
  164.   if (decimal > 0) then
  165.     remain = string.sub(tostring(remain),3)
  166.     formatted = formatted .. "." .. remain ..
  167.                 string.rep("0", decimal - string.len(remain))
  168.   end
  169.  
  170.         -- attach prefix string e.g '$'
  171.   formatted = (prefix or "") .. formatted
  172.  
  173.         -- if value is negative then format accordingly
  174.   if (amount<0) then
  175.     if (neg_prefix=="()") then
  176.       formatted = "("..formatted ..")"
  177.     else
  178.       formatted = neg_prefix .. formatted
  179.     end
  180.   end
  181.  
  182.   return formatted
  183. end
  184.  
  185. -- Clear and make the pixel smaller because we are not blind
  186.  
  187. mon.setBackgroundColor(colors.black)
  188. mon.clear()
  189. mon.setTextScale(0.5)
  190.  
  191. -- Get the information from the index file
  192. getInfoFromFile()
  193.  
  194.  
  195. -- Add's the visual and starts the Loop
  196. addDrawBoxesSingleReactor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement