function sortByAmount(x, y)
return x.amount > y.amount
end
function generateList()
print("import started")
itemList={}
n=1
myList = lp.getAvailableItems()
print(#myList)
for key,value in pairs( myList ) do
z = myList[key]
id = z[1]
itemList[n] = {}
itemList[n].id = id
itemList[n].name = string.sub(lp.getUnlocalizedName(itemList[key].id),1,20)
itemList[n].amount = lp.getItemAmount(itemList[key].id)
if (key%10 == 0) then
sleep(0.00000000000000000000000000000001)
end
n= n+1
end
table.sort(itemList, sortByAmount)
updateDisplay()
return itemList
end
function checkAmount(itemList)
for i = 1, totalItemsToDisplay ,1 do
itemList[i].amount = lp.getItemAmount(itemList[i].id)
if (i%10 == 0) then
sleep(0.00000000000000000000000000000001)
end
end
table.sort(itemList, sortByAmount)
updateDisplay()
end
function updateDisplay()
monX = 1
monY = 2
mon.clear()
for i = 1, totalItemsToDisplay,1 do
name = itemList[i].name
amount = itemList[i].amount
mon.setCursorPos(monY, monX)
mon.write(name)
mon.setCursorPos(monY+21,monX)
mon.write(": ")
amountString = tostring(amount).." |"
mon.setCursorPos(monY+30-string.len(amountString),monX)
mon.write(amountString)
if monX == itemsToDisplayPerRow then
monX = 0
monY = monY+30
end
monX = monX+1
end
end
function boot()
iteration = 1
lp = peripheral.wrap(lpDirection)
mon=peripheral.wrap(monitorDirection)
mon.setTextScale(0.5)
mon.clear()
mon.setTextScale(0.5)
mon.setCursorPos(34,26)
mon.write("Platinawolf display system booting up, stand by...")
mon.setCursorPos(36,32)
sleep(1)
mon.write("Generating list")
itemList = generateList()
sleep(10)
end
function mainLoop()
while true do
if (iteration % 30==0) then
print("generating list")
itemList = generateList()
print("updateDisplay")
iteration = 1
else
print("Updating list")
checkAmount(itemList)
print("updateDisplay")
iteration = iteration +1
end
sleep(10)
end
end
--variables
totalItemsToDisplay = 208
itemsToDisplayPerRow = 52
lpDirection = "bottom"
monitorDirection = "top"
-- end variables
boot()
mainLoop()