GamerNebulae

Nebulae API

Aug 8th, 2013
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.06 KB | None | 0 0
  1. -- Thanks for downloading the Nebulae API!
  2. -- You can change this API any way you want as long as you leave this in
  3. -- Made by GamerNebulae
  4.  
  5. data = peripheral.getNames(side)
  6.  
  7. for i,j in pairs(data) do
  8.     type_peripheral = peripheral.getType(j)
  9.     if type_peripheral == "monitor" then
  10.         mon = peripheral.wrap(data[i])
  11.     elseif type_peripheral == "nuclearReader" then
  12.         information_reader = peripheral.wrap(data[i])
  13.     end
  14. end
  15.  
  16. mon.clear()
  17. mon.setBackgroundColor(colors.black)
  18. mon.setTextColor(colors.white)
  19.  
  20. function clear()
  21.     mon.clear()
  22.     mon.setTextColor(colors.white)
  23.     mon.setBackgroundColor(colors.black)
  24. end
  25.  
  26. function dataTable(name, slot, heading, liquid)
  27.     dataTable = {}
  28.     dataTable[name] = {}
  29.     dataTable[name]["side"] = side
  30.     dataTable[name]["slot"] = slot
  31.     dataTable[name]["heading"] = heading
  32.     dataTable[name]["liquid"] = liquid
  33.     drawBar(dataTable)
  34. end
  35.  
  36. function drawBar(info)
  37.     for name, progress_bar in pairs(info) do
  38.         Math(progress_bar)
  39.         if (length_bar >= begin_text) then
  40.             before_text = begin_text - 1
  41.             after_text = begin_text + #text
  42.             for i = 1, before_text do
  43.                 mon.setBackgroundColor(colors.blue)
  44.                 mon.setCursorPos(i, y_bar)
  45.                 mon.write(" ")
  46.             end
  47.             if (length_bar >= begin_text and length_bar <= end_text) then
  48.                 splitText(text)
  49.             else
  50.                 mon.write(text)
  51.             end
  52.             for j = after_text, length_bar do
  53.                 mon.setBackgroundColor(colors.blue)
  54.                 mon.setCursorPos(j, y_bar)
  55.                 mon.write(" ")
  56.             end
  57.         else
  58.             for i = 1, length_bar do
  59.                 mon.setBackgroundColor(colors.blue)
  60.                 mon.setCursorPos(i, y_bar)
  61.                 mon.write(" ")
  62.             end
  63.             mon.setBackgroundColor(colors.black)
  64.             mon.setCursorPos(begin_text, y_text)
  65.             mon.write(text)
  66.             end
  67.         end
  68.     mon.setBackgroundColor(colors.black)
  69. end
  70.  
  71. function Math(progress_bar)
  72.     mon_size_x, mon_size_y = mon.getSize()
  73.     y_bar = 2 * progress_bar["slot"]
  74.     x_heading = math.floor(((mon_size_x - #progress_bar["heading"]) / 2) + 1)
  75.     y_heading = 2 * progress_bar["slot"] - 1
  76.     mon.setCursorPos(x_heading, y_heading)
  77.     mon.write(progress_bar["heading"])
  78.     if progress_bar["liquid"] then
  79.         a, b, c, data = information_reader.get(progress_bar["slot"])
  80.         value = math.floor((data.amount / data.capacity) * 100)
  81.     else
  82.         a, b, c, data = information_reader.get(progress_bar["slot"])
  83.         value = math.floor((data.energyL / data.maxStorageL) * 100)
  84.     end
  85.     begin_text = math.floor(((mon_size_x - #(value.."%")) / 2) + 1)
  86.     end_text = math.floor((begin_text + #(value.."%")) - 1)
  87.     y_text = y_bar
  88.     text = tostring(value).."%"
  89.     length_bar = math.floor(mon_size_x * (value / 100))
  90. end
  91.  
  92. function splitText(text)
  93.     colored_text = length_bar - begin_text + 1
  94.     dataText = {}
  95.     for k,v in text:gmatch"." do
  96.         dataText[#dataText + 1] = tostring(k)
  97.     end
  98.     if colored_text <= #dataText then
  99.         mon.setCursorPos(begin_text, y_text)
  100.         for i = 1, colored_text do
  101.             mon.setBackgroundColor(colors.blue)
  102.             mon.write(dataText[i])
  103.         end
  104.         if colored_text < #dataText then
  105.             for j = colored_text + 1, #dataText do
  106.                 mon.setBackgroundColor(colors.black)
  107.                 mon.write(dataText[j])
  108.             end
  109.         end
  110.     end
  111.  end
Advertisement
Add Comment
Please, Sign In to add comment