gpochy

ae

Jul 19th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. function sortByAmount(x, y)
  2.   return x.amount > y.amount
  3. end
  4.  
  5. function generateList()
  6.     print("import started")
  7.     itemList={}
  8.     n=1
  9.     myList = lp.getAvailableItems()
  10.     print(#myList)
  11.     for key,value in pairs( myList ) do
  12.         z = myList[key]
  13.         id = z[1]
  14.         itemList[n] = {}
  15.         itemList[n].id = id
  16.         itemList[n].name = string.sub(lp.getUnlocalizedName(itemList[key].id),1,20)
  17.         itemList[n].amount = lp.getItemAmount(itemList[key].id)
  18.         if (key%10 == 0) then
  19.             sleep(0.00000000000000000000000000000001)
  20.         end
  21.         n= n+1
  22.     end  
  23.     table.sort(itemList, sortByAmount)
  24.     updateDisplay()
  25.     return itemList
  26. end
  27.  
  28. function checkAmount(itemList)
  29.     for i = 1, totalItemsToDisplay ,1 do
  30.         itemList[i].amount = lp.getItemAmount(itemList[i].id)
  31.         if (i%10 == 0) then
  32.             sleep(0.00000000000000000000000000000001)
  33.         end
  34.     end  
  35.     table.sort(itemList, sortByAmount)
  36.     updateDisplay()
  37. end  
  38.  
  39. function updateDisplay()
  40.     monX = 1
  41.     monY = 2
  42.     mon.clear()
  43.     for i = 1, totalItemsToDisplay,1 do
  44.         name = itemList[i].name
  45.         amount = itemList[i].amount
  46.         mon.setCursorPos(monY, monX)
  47.         mon.write(name)
  48.         mon.setCursorPos(monY+21,monX)
  49.         mon.write(":        ")
  50.         amountString = tostring(amount).." |"
  51.         mon.setCursorPos(monY+30-string.len(amountString),monX)
  52.         mon.write(amountString)
  53.         if monX == itemsToDisplayPerRow then
  54.             monX = 0
  55.             monY = monY+30
  56.         end  
  57.         monX = monX+1
  58.     end  
  59. end  
  60.  
  61. function boot()
  62.     iteration = 1
  63.     lp = peripheral.wrap(lpDirection)
  64.     mon=peripheral.wrap(monitorDirection)
  65.     mon.setTextScale(0.5)
  66.     mon.clear()
  67.     mon.setTextScale(0.5)
  68.     mon.setCursorPos(34,26)
  69.     mon.write("Platinawolf  display  system  booting  up,  stand by...")
  70.     mon.setCursorPos(36,32)
  71.     sleep(1)
  72.     mon.write("Generating  list")
  73.     itemList = generateList()
  74.    
  75.     sleep(10)
  76. end
  77.  
  78. function mainLoop()
  79.     while true do
  80.         if (iteration % 30==0) then
  81.             print("generating list")
  82.             itemList = generateList()
  83.             print("updateDisplay")  
  84.             iteration = 1
  85.         else  
  86.             print("Updating list")
  87.             checkAmount(itemList)
  88.             print("updateDisplay")  
  89.             iteration = iteration +1
  90.         end
  91.         sleep(10)
  92.     end
  93. end
  94.  
  95.  
  96. --variables
  97. totalItemsToDisplay = 208
  98. itemsToDisplayPerRow = 52
  99. lpDirection = "bottom"
  100. monitorDirection = "top"
  101. -- end variables
  102.  
  103.  
  104. boot()
  105. mainLoop()
Add Comment
Please, Sign In to add comment