Advertisement
Guest User

startup

a guest
May 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.87 KB | None | 0 0
  1. local monitors = {peripheral.find("monitor")}
  2. local mon = monitors[1]
  3. local reactors = {peripheral.find("BigReactors-Reactor")}
  4.  
  5. local button={}
  6. local filleds = {}
  7. local boxes = {}
  8. local lines = {}
  9. local texts = {}
  10.  
  11. local refresh = true
  12.  
  13. local infosSize = {}
  14. local contorlsSize = {}
  15. local numbersSize = {}
  16. local currentRfTotal = 1
  17. local currentRfTick = 1
  18. local currentFuelConsumedLastTick = 0.00001
  19.  
  20.  
  21. local rfPerTickMax = 1
  22. local minPowerRod = 0
  23. local maxPowerRod = 100
  24. local currentRodLevel = 1
  25.  
  26. -- you need to give the index to be able to use the program  
  27. -- ex : NameOfProgram Index   (reactor Krakaen)
  28.  
  29. local args = { "startup" }
  30. local index = ""
  31.  
  32. if (#args == 0) then
  33.     error("No index Given")
  34. end
  35.  
  36. if (#args == 1) then
  37.     index = args[1]
  38. end
  39.  
  40. -- use the black thingy sponge to clear the chalkboard
  41.  
  42. term.redirect(mon)
  43. mon.clear()
  44. mon.setTextColor(colors.white)
  45. mon.setBackgroundColor(colors.black)
  46.  
  47. function clearTable()
  48.     button = {}
  49. end
  50.  
  51. -- All the things that make my buttons work
  52.  
  53. function setButton(name, title, func, xmin, ymin, xmax, ymax, elem, elem2, color)
  54.     button[name] = {}
  55.     button[name]["title"] = title
  56.     button[name]["func"] = func
  57.     button[name]["active"] = false
  58.     button[name]["xmin"] = xmin
  59.     button[name]["ymin"] = ymin
  60.     button[name]["xmax"] = xmax
  61.     button[name]["ymax"] = ymax
  62.     button[name]["color"] = color
  63.     button[name]["elem"] = elem
  64.     button[name]["elem2"] = elem2
  65. end
  66.  
  67. -- stuff and things for buttons
  68.  
  69. function fill(text, color, bData)
  70.    mon.setBackgroundColor(color)
  71.    mon.setTextColor(colors.white)
  72.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  73.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["title"])) /2) +1
  74.    for j = bData["ymin"], bData["ymax"] do
  75.       mon.setCursorPos(bData["xmin"], j)
  76.       if j == yspot then
  77.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["title"]) +1 do
  78.             if k == xspot then
  79.                mon.write(bData["title"])
  80.             else
  81.                mon.write(" ")
  82.             end
  83.          end
  84.       else
  85.          for i = bData["xmin"], bData["xmax"] do
  86.             mon.write(" ")
  87.          end
  88.       end
  89.    end
  90.    mon.setBackgroundColor(colors.black)
  91. end
  92.  
  93. -- stuff and things for buttons
  94.  
  95. function screen()
  96.    local currColor
  97.    for name,data in pairs(button) do
  98.       local on = data["active"]
  99.       currColor = data["color"]
  100.       fill(name, currColor, data)
  101.    end
  102. end
  103.  
  104. -- stuff and things for buttons
  105.  
  106. function flash(name)
  107.  
  108.     screen()
  109. end
  110.  
  111. -- magical handler for clicky clicks
  112.  
  113. function checkxy(x, y)
  114.    for name, data in pairs(button) do
  115.       if y>=data["ymin"] and  y <= data["ymax"] then
  116.          if x>=data["xmin"] and x<= data["xmax"] then
  117.             data["func"](data["elem"], data["elem2"])
  118.             flash(data['name'])
  119.             return true
  120.             --data["active"] = not data["active"]
  121.             --print(name)
  122.          end
  123.       end
  124.    end
  125.    return false
  126. end
  127.  
  128. -- Don't question my code, it works on my machine...
  129.  
  130. function label(w, h, text)
  131.    mon.setCursorPos(w, h)
  132.    mon.write(text)
  133. end
  134.  
  135. -- Draw function : put's all the beautiful magic in the screen
  136.  
  137. function draw()
  138.    
  139.     for key,value in pairs(filleds) do
  140.         paintutils.drawFilledBox(value[1] , value[2], value[3], value[4], value[5])
  141.     end
  142.  
  143.     for key,value in pairs(boxes) do
  144.         paintutils.drawBox(value[1] , value[2], value[3], value[4], value[5])
  145.     end
  146.  
  147.     for key,value in pairs(lines) do
  148.         paintutils.drawLine(value[1] , value[2], value[3], value[4], value[5])
  149.     end
  150.  
  151.     for key,value in pairs(texts) do
  152.         mon.setCursorPos(value[1], value[2])
  153.         mon.setTextColor(value[4])
  154.         mon.setBackgroundColor(value[5])
  155.         mon.write(value[3])
  156.     end
  157.     screen()
  158.     resetDraw()
  159. end
  160.  
  161. -- Resets the elements to draw to only draw the neccessity
  162.  
  163. function resetDraw()
  164.     filleds = {}
  165.     boxes = {}
  166.     lines = {}
  167.     texts = {}
  168. end
  169.  
  170. -- Handles all the clicks for the buttons
  171.  
  172. function clickEvent()
  173.     local myEvent={os.pullEvent("monitor_touch")}
  174.     checkxy(myEvent[3], myEvent[4])
  175. end
  176.  
  177. -- Power up the reactor (M&N are a good source of food right?)
  178.  
  179. function powerUp(m,n)
  180.     local reactor = reactors[1]
  181.     reactor.setActive(true)
  182. end
  183.  
  184. -- Power down the reactor (M&N are a good source of food right?)
  185.  
  186. function powerDown(m,n)
  187.     local reactor = reactors[1]
  188.     reactor.setActive(false)
  189. end
  190.  
  191. -- Handles and calculate the Min and Max of the power limitation
  192.  
  193. function modifyRods(limit, number)
  194.     local tempLevel = 0
  195.  
  196.     if limit == "min" then
  197.         tempLevel = minPowerRod + number
  198.         if tempLevel <= 0 then
  199.             minPowerRod = 0
  200.         end
  201.  
  202.         if tempLevel >= maxPowerRod then
  203.             minPowerRod = maxPowerRod -10
  204.         end
  205.  
  206.         if tempLevel < maxPowerRod and tempLevel > 0 then
  207.             minPowerRod = tempLevel
  208.         end
  209.     else
  210.         tempLevel = maxPowerRod + number
  211.         if tempLevel <= minPowerRod then
  212.             maxPowerRod = minPowerRod +10
  213.         end
  214.  
  215.         if tempLevel >= 100 then
  216.             maxPowerRod = 100
  217.         end
  218.  
  219.         if tempLevel > minPowerRod and tempLevel < 100 then
  220.             maxPowerRod = tempLevel
  221.         end
  222.     end
  223.  
  224.     table.insert(lines, {contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY']+(contorlsSize['sectionHeight']*1)+4, colors.black})
  225.    
  226.     table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, minPowerRod .. '%', colors.lightBlue, colors.black})
  227.     table.insert(texts, {contorlsSize['inX']+13, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
  228.     table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, maxPowerRod .. '%', colors.purple, colors.black})
  229.  
  230.     setInfoToFile()
  231.     adjustRodsLevel()
  232. end
  233.  
  234. -- Calculate and adjusts the level of the rods
  235.  
  236. function adjustRodsLevel()
  237.     local reactor = reactors[1]
  238.     local rfTotalMax = 10000000
  239.     local currentRfTotal = reactor.getEnergyStored()
  240.  
  241.     differenceMinMax = maxPowerRod - minPowerRod
  242.  
  243.     maxPower = (rfTotalMax/100) * maxPowerRod
  244.     minPower = (rfTotalMax/100) * minPowerRod
  245.  
  246.     if currentRfTotal >= maxPower then
  247.         currentRfTotal = maxPower
  248.     end
  249.  
  250.     if currentRfTotal <= minPower then
  251.         currentRfTotal = minPower
  252.     end
  253.        
  254.     currentRfTotal = currentRfTotal - (rfTotalMax/100) * minPowerRod
  255.    
  256.     local rfInBetween = (rfTotalMax/100) * differenceMinMax
  257.     local rodLevel = math.floor((currentRfTotal/rfInBetween)*100)
  258.  
  259.     reactor.setAllControlRodLevels(rodLevel)
  260. end
  261.  
  262. -- Creates the frame and the basic of the visual
  263. -- Also adds the variables informations for placement of stuff and things
  264.  
  265. function addDrawBoxesSingleReactor()
  266.     local w, h = mon.getSize()
  267.     local margin = math.floor((w/100)*2)
  268.  
  269.     infosSize['startX'] = margin + 1
  270.     infosSize['startY'] =  margin + 1
  271.     infosSize['endX'] = (((w-(margin*2))/3)*2)-margin
  272.     infosSize['endY'] = h - margin
  273.     infosSize['height'] = infosSize['endY']-infosSize['startY']-(margin*2)-2
  274.     infosSize['width'] = infosSize['endX']-infosSize['startX']-(margin*2)-2
  275.     infosSize['inX'] = infosSize['startX'] + margin +1
  276.     infosSize['inY'] = infosSize['startY'] + margin +1
  277.     infosSize['sectionHeight'] = math.floor(infosSize['height']/3)
  278.  
  279.     table.insert(boxes, {infosSize['startX'] , infosSize['startY'], infosSize['endX'], infosSize['endY'], colors.gray})
  280.     local name = "INFOS"
  281.     table.insert(lines, {infosSize['startX'] + margin , infosSize['startY'], infosSize['startX'] + (margin*2) + #name+1, infosSize['startY'], colors.black})
  282.     table.insert(texts, {infosSize['startX'] + (margin*2), infosSize['startY'], name, colors.white, colors.black})
  283.  
  284.     local names = {}
  285.     names[1] = 'ENERGY LAST TICK'
  286.     names[2] = 'ENERGY STORED'
  287.     names[3] = 'CONTROL ROD LEVEL'
  288.  
  289.     for i=0,2,1 do
  290.         table.insert(texts, {infosSize['inX'] + margin, infosSize['inY'] + (infosSize['sectionHeight']*i) +i, names[i+1], colors.white, colors.black})
  291.         table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 2 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray})
  292.     end
  293.  
  294.  
  295.     -- Controls
  296.  
  297.     contorlsSize['startX'] = infosSize['endX'] + margin + 1
  298.     contorlsSize['startY'] =  margin + 1
  299.     contorlsSize['endX'] = w-margin
  300.     contorlsSize['endY'] = (((h - (margin*2))/3)*2) +1
  301.     contorlsSize['height'] = contorlsSize['endY']-contorlsSize['startY']-(margin)-1
  302.     contorlsSize['width'] = contorlsSize['endX']-contorlsSize['startX']-(margin*2)-2
  303.     contorlsSize['inX'] = contorlsSize['startX'] + margin +1
  304.     contorlsSize['inY'] = contorlsSize['startY'] + margin
  305.  
  306.     table.insert(boxes, {contorlsSize['startX'] , contorlsSize['startY'], contorlsSize['endX'], contorlsSize['endY'], colors.gray})
  307.     name = "CONTROLS"
  308.     table.insert(lines, {contorlsSize['startX'] + margin , contorlsSize['startY'], contorlsSize['startX'] + (margin*2) + #name+1, contorlsSize['startY'], colors.black})
  309.     table.insert(texts, {contorlsSize['startX'] + (margin*2), contorlsSize['startY'], name, colors.white, colors.black})
  310.    
  311.     contorlsSize['sectionHeight'] = math.floor(contorlsSize['height']/4)
  312.  
  313.     reactor = reactors[1]
  314.  
  315.     mon.setTextColor(colors.white)
  316.     setButton("ON","ON", powerUp, contorlsSize['inX'], contorlsSize['inY'], contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +2, 0, 0, colors.green)
  317.     setButton("OFF","OFF", powerDown, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'], contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +2,0, 0, colors.red)
  318.  
  319.     table.insert(texts, {contorlsSize['inX']+8, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+1, 'AUTO-CONTROL', colors.white, colors.black})
  320.  
  321.     table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+3, 'MIN', colors.lightBlue, colors.black})
  322.     table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, minPowerRod..'%', colors.lightBlue, colors.black})
  323.  
  324.     table.insert(texts, {contorlsSize['inX']+13, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black})
  325.     table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+3, 'MAX', colors.purple, colors.black})
  326.     table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, maxPowerRod..'%', colors.purple, colors.black})
  327.     mon.setTextColor(colors.white)
  328.  
  329.     setButton("low-10","-10", modifyRods, contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+2, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+4, "min", -10, colors.lightBlue)
  330.     setButton("high-10","-10", modifyRods, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+2, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+4, "max", -10, colors.purple)   
  331.  
  332.     setButton("low+10","+10", modifyRods, contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+2, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+4, "min", 10, colors.lightBlue)
  333.     setButton("high+10","+10", modifyRods, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+2, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+4, "max", 10, colors.purple)
  334.  
  335.     -- Numbers
  336.  
  337.     numbersSize['startX'] = infosSize['endX'] + margin + 1
  338.     numbersSize['startY'] = contorlsSize['endY'] + margin + 1
  339.     numbersSize['endX'] = w-margin
  340.     numbersSize['endY'] = h-margin
  341.     numbersSize['height'] = numbersSize['endY']-numbersSize['startY']-(margin)-1
  342.     numbersSize['width'] = numbersSize['endX']-numbersSize['startX']-(margin*2)-2
  343.     numbersSize['inX'] = numbersSize['startX'] + margin +1
  344.     numbersSize['inY'] = numbersSize['startY'] + margin
  345.  
  346.     table.insert(boxes, {numbersSize['startX'] , numbersSize['startY'], numbersSize['endX'], numbersSize['endY'], colors.gray})
  347.     name = "NUMBERS"
  348.     table.insert(lines, {numbersSize['startX'] + margin , numbersSize['startY'], numbersSize['startX'] + (margin*2) + #name+1, numbersSize['startY'], colors.black})
  349.     table.insert(texts, {numbersSize['startX'] + (margin*2), numbersSize['startY'], name, colors.white, colors.black})
  350.  
  351.     refresh = true
  352.     while refresh do
  353.         parallel.waitForAny(refreshSingleReactor,clickEvent)
  354.     end
  355. end
  356.  
  357. -- Makes and Handles the draw function for less lag in the visual
  358.  
  359. function refreshSingleReactor()
  360.     local rfPerTick = 0
  361.     local rfTotal = 0
  362.     local rfTotalMax = 10000000
  363.     local reactor = reactors[1]
  364.  
  365.     rfTotal = reactor.getEnergyStored()
  366.     rfPerTick = math.floor(reactor.getEnergyProducedLastTick())
  367.     rodLevel = math.floor(reactor.getControlRodLevel(0))
  368.     fuelPerTick = reactor.getFuelConsumedLastTick();
  369.  
  370.     local i = 0
  371.     local infotoAdd = 'RF PER TICK : '
  372.  
  373.     if currentRfTick ~= rfPerTick then
  374.         currentRfTick = rfPerTick
  375.         if rfPerTick > rfPerTickMax then
  376.             rfPerTickMax = rfPerTick
  377.         end
  378.  
  379.         table.insert(lines, {numbersSize['inX'] , numbersSize['inY'],numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'], colors.black})
  380.         table.insert(texts, {numbersSize['inX'], numbersSize['inY'], infotoAdd .. rfPerTick .. " RF", colors.white, colors.black})
  381.         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})
  382.    
  383.         width = math.floor((infosSize['width'] / rfPerTickMax)*rfPerTick)
  384.         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})
  385.  
  386.     end
  387.  
  388.     i = 1
  389.     infotoAdd = 'ENERGY STORED : '
  390.     if currentRfTotal ~= rfTotal then
  391.         currentRfTotal = rfTotal
  392.  
  393.         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})
  394.    
  395.         width = math.floor((infosSize['width'] / rfTotalMax)*rfTotal)
  396.         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})
  397.         table.insert(lines, {numbersSize['inX'] , numbersSize['inY'] +2 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +2, colors.black})
  398.         table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 2 , infotoAdd .. rfTotal .. " RF", colors.white, colors.black})
  399.     end
  400.  
  401.     i = 2
  402.     infotoAdd = 'CONTROL ROD LEVEL : '
  403.     if currentRodLevel ~= rodLevel then
  404.         currentRodLevel = rodLevel
  405.  
  406.         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})
  407.    
  408.         width = math.floor((infosSize['width'] / 100)*rodLevel)
  409.         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})
  410.         table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+4 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +4, colors.black})
  411.         table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 4 , infotoAdd .. rodLevel .. "%", colors.white, colors.black})
  412.     end
  413.  
  414.     i = 3
  415.     infotoAdd = 'FUEL USAGE : '
  416.     if currentFuelConsumedLastTick ~= fuelPerTick then
  417.         currentFuelConsumedLastTick = fuelPerTick
  418.  
  419.         table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+6 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +6, colors.black})
  420.         table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 6 , infotoAdd .. format_num(tonumber(fuelPerTick),3) .. "mb/t", colors.white, colors.black})  
  421.     end
  422.    
  423.     mon.setTextColor(colors.white)
  424.     adjustRodsLevel()
  425.    
  426.     draw()
  427.  
  428.     sleep(2)
  429. end
  430.  
  431. --
  432. -- ** Get the informations from the index file
  433. -- line 1 = min ROD
  434. -- line 2 = max ROD
  435. --
  436.  
  437. function getInfoFromFile()
  438.  
  439.      if (fs.exists(index..".txt") == false) then
  440.         file = io.open(index..".txt","w")
  441.         file:write("0")
  442.         file:write("\n")
  443.         file:write("100")
  444.         file:close()
  445.     else
  446.         file = fs.open(index..".txt","r")
  447.         minPowerRod = tonumber(file.readLine())
  448.         maxPowerRod = tonumber(file.readLine())
  449.         file.close()
  450.     end
  451. end
  452.  
  453. -- Save informations to the index file
  454.  
  455. function setInfoToFile()
  456.     file = io.open(index..".txt","w")
  457.     file:write(minPowerRod .. "\n" .. maxPowerRod)
  458.     file:flush()
  459.     file:close()
  460. end
  461.  
  462. ---============================================================
  463. -- add comma to separate thousands
  464. -- From Lua-users.org/wiki/FormattingNumbers
  465. --
  466. --
  467. function comma_value(amount)
  468.   local formatted = amount
  469.   while true do  
  470.     formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  471.     if (k==0) then
  472.       break
  473.     end
  474.   end
  475.   return formatted
  476. end
  477.  
  478. ---============================================================
  479. -- rounds a number to the nearest decimal places
  480. -- From Lua-users.org/wiki/FormattingNumbers
  481. --
  482. --
  483. function round(val, decimal)
  484.   if (decimal) then
  485.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  486.   else
  487.     return math.floor(val+0.5)
  488.   end
  489. end
  490.  
  491. --===================================================================
  492. -- given a numeric value formats output with comma to separate thousands
  493. -- and rounded to given decimal places
  494. -- From Lua-users.org/wiki/FormattingNumbers
  495. --
  496. function format_num(amount, decimal, prefix, neg_prefix)
  497.   local str_amount,  formatted, famount, remain
  498.  
  499.   decimal = decimal or 2  -- default 2 decimal places
  500.   neg_prefix = neg_prefix or "-" -- default negative sign
  501.  
  502.   famount = math.abs(round(amount,decimal))
  503.   famount = math.floor(famount)
  504.  
  505.   remain = round(math.abs(amount) - famount, decimal)
  506.  
  507.         -- comma to separate the thousands
  508.   formatted = comma_value(famount)
  509.  
  510.         -- attach the decimal portion
  511.   if (decimal > 0) then
  512.     remain = string.sub(tostring(remain),3)
  513.     formatted = formatted .. "." .. remain ..
  514.                 string.rep("0", decimal - string.len(remain))
  515.   end
  516.  
  517.         -- attach prefix string e.g '$'
  518.   formatted = (prefix or "") .. formatted
  519.  
  520.         -- if value is negative then format accordingly
  521.   if (amount<0) then
  522.     if (neg_prefix=="()") then
  523.       formatted = "("..formatted ..")"
  524.     else
  525.       formatted = neg_prefix .. formatted
  526.     end
  527.   end
  528.  
  529.   return formatted
  530. end
  531.  
  532. -- Clear and make the pixel smaller because we are not blind
  533.  
  534. mon.setBackgroundColor(colors.black)
  535. mon.clear()
  536. mon.setTextScale(0.5)
  537.  
  538. -- Get the information from the index file
  539. getInfoFromFile()
  540.  
  541.  
  542. -- Add's the visual and starts the Loop
  543. addDrawBoxesSingleReactor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement