Advertisement
Guest User

startup

a guest
Dec 11th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.60 KB | None | 0 0
  1. local title = "SorteerToelie"
  2. local version = "v31.0.21_sikbeer1"
  3.  
  4. local update_rate = .3 -- 1 second update time
  5. local barrels = 0
  6. local aantal = 0
  7. local posX, posY = 0
  8.  
  9. local t1 = {
  10.   name = "",
  11.   item = "",
  12.   aantal = 0,
  13.   max = 0,
  14.   order = 0
  15. }
  16.  
  17. local t2 = {
  18.   name = "",
  19.   order = 0
  20. }
  21.  
  22. local monitor = term.redirect(peripheral.find("monitor"))
  23.  
  24. local function header()
  25.   term.setBackgroundColor(colors.black)
  26.   term.setTextColor(colors.green)
  27.   term.clear()
  28.   term.setCursorPos(1,1)
  29.   term.write(title .. " " .. version)
  30.   term.setCursorPos(1,4)
  31. end
  32.  
  33. local function getPeriphs()
  34.   periphs = peripheral.getNames()
  35.   table.sort(periphs)
  36. end
  37.  
  38. local function makePeriphs()
  39.   barrels = 0
  40.   for i, name in pairs(periphs) do
  41.     if peripheral.getType(name) == "mcp_mobius_betterbarrel" then
  42.       local wrap = peripheral.wrap(name)
  43.       if peripheral.isPresent(name) == true then
  44.         item = wrap.getStoredItems()["display_name"]
  45.         aantal = wrap.getStoredItems()["qty"]
  46.         max = wrap.getMaxStoredItems()
  47.       end
  48.       t1[barrels] = {}
  49.       t1[barrels].name = name
  50.       t1[barrels].item = item
  51.       t1[barrels].aantal = aantal
  52.       t1[barrels].max = max
  53.       barrels = barrels + 1
  54.     end
  55.   end
  56. end
  57.  
  58. local function showPeriphs()
  59.   header()
  60.   term.setTextColor(colors.white)
  61.   term.setCursorPos(4,5)
  62.   term.write("Item")
  63.   term.setCursorPos(44,5)
  64.   term.write("Amount")
  65.   term.setCursorPos(56,5)
  66.   term.write("Max amount")
  67.   term.setCursorPos(70,5)
  68.   term.write("Order amount")
  69.   x = 4
  70.   i = 0
  71.   r = 0
  72.   repeat
  73.     y = r + 6
  74.     term.setCursorPos(x,y)
  75.     term.setTextColor(colors.yellow)
  76.     if (t1[i] ~= nil) then
  77.       term.write(t1[i].item)
  78.     end
  79.     term.setCursorPos(x + 37,y)
  80.     term.setTextColor(colors.blue)
  81.     if (t1[i] ~= nil) then
  82.       term.write(string.format("% 9d",t1[i].aantal))
  83.     end
  84.     term.setCursorPos(x + 53,y)
  85.     term.setTextColor(colors.red)
  86.     if (t1[i] ~= nil) then
  87.       term.write(string.format("% 9d",t1[i].max))
  88.     end
  89.     term.setCursorPos(x + 67,y)
  90.     term.setTextColor(colors.white)
  91.     term.setBackgroundColor(colors.blue)
  92.     term.write(" + ")
  93.     term.setBackgroundColor(colors.black)
  94.     term.write(string.format("% 3d",t2[i].order))
  95.     term.write(" ")
  96.     term.setBackgroundColor(colors.blue)
  97.     term.write(" - ")
  98.     term.setBackgroundColor(colors.black)
  99.     i = i + 1
  100.     r = r + 1
  101.   until (i == 32)
  102. end
  103.  
  104. local function updatePeriphs()
  105.   getPeriphs()
  106.   makePeriphs()
  107.   showPeriphs()
  108. end
  109.  
  110. local function dumpItem(num,totaal)
  111.    naam = t1[num]
  112.    local wrap = peripheral.wrap(naam)
  113.    wrap.pushItemIntoSlot("down",2,totaal,1)
  114. end
  115.  
  116. local function checkClickPosition(mon)
  117.   if posY >= 6 and posY <= 38 then
  118.     if posX >= 71 and posX <= 73 then
  119.       t2[posY - 6].order = t2[posY - 6].order + 1
  120.     end
  121.     if posX >= 78 and posX <= 80 then
  122.       t2[posY - 6].order = t2[posY - 6].order - 1
  123.     end
  124.   end
  125. end
  126.  
  127. getPeriphs()
  128. makePeriphs()
  129.  
  130. for i = 0, 31 do
  131.   t2[i] = {}
  132.   t2[i].name = t1[i].name
  133.   t2[i].order = 0
  134. end
  135.  
  136. showPeriphs()
  137.  
  138. local timer = os.startTimer(update_rate)
  139.  
  140. while true do
  141.   sleep(0)
  142.   local event, p1, p2, p3 = os.pullEvent()
  143.   if event == "timer" then
  144.     updatePeriphs()
  145.     timer = os.startTimer(update_rate)
  146.   end
  147.   if event == "peripheral" then
  148.     updatePeriphs()
  149.   end
  150.   if event == "peripheral_detach" then
  151.     updatePeriphs()
  152.   end
  153.   if event == "monitor_touch" then
  154.     posX = p2
  155.     posY = p3
  156.     checkClickPosition(monitor)
  157.     updatePeriphs()
  158.   end
  159.   if event == "key" then
  160.     if p1 == keys.x then
  161.       break
  162.     end
  163.   end
  164. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement