Fixed item ticker not clearing tickers on restart

Added check to itemstocker to detect server restart
Fixed autofeeder breaking on server restart
Added simple script to control turbines depending on battery level
This commit is contained in:
Sampsa 2020-11-16 18:30:17 +02:00
parent 8336d49c95
commit 5d693800ca
5 changed files with 95 additions and 29 deletions

View File

@ -226,12 +226,14 @@ local function refreshDatabase(itemList)
end
return filteredList
end
local rollingTextObjects = {}
local function rollingText(glasses, text, start, stop, y, color)
local textObject = ARG.hudText(glasses, "", start, y, color)
textObject.setAlpha(0.8)
local backgroundEndWedge = ARG.hudTriangle(glasses, {stop, y-2},{stop, y+10},{stop+12, y+10}, hudColour)
local backgroundStartWedge = ARG.hudTriangle(glasses, {start-12, y-2},{start, y+10},{start+12, y-2}, hudColour)
local startWedge = ARG.hudQuad(glasses, {start, y-2},{start, y+8},{start+30, y+8}, {start+30, y-2}, hudColour)
rollingTextObjects[#rollingTextObjects+1] = {t = textObject, bew = backgroundEndWedge, bsw = backgroundStartWedge, sw = startWedge}
local stepSize = 1
local steps = start - stop / stepSize
local step = 0
@ -262,6 +264,15 @@ local function rollingText(glasses, text, start, stop, y, color)
event.timer(0.10, generate, #text + 1)
event.timer(0.02, roll, steps + 1)
end
local function clearTicker(glasses)
for i = 1, #rollingTextObjects do
if rollingTextObjects[i].t ~= nil then glasses.removeObject(rollingTextObjects[i].t.getID()) end
if rollingTextObjects[i].bew ~= nil then glasses.removeObject(rollingTextObjects[i].bew.getID()) end
if rollingTextObjects[i].bsw ~= nil then glasses.removeObject(rollingTextObjects[i].bsw.getID()) end
if rollingTextObjects[i].sw ~= nil then glasses.removeObject(rollingTextObjects[i].sw.getID()) end
end
rollingTextObjects = {}
end
local cachedAmounts = refreshDatabase(comp.me_interface.getItemsInNetwork())
function difference(new)
local differenceArray = {}
@ -310,9 +321,9 @@ function ARWidgets.itemTicker(glasses, x, y, w)
local divisor1 = ARG.hudRectangle(glasses, x+w - 118, y+20, 2, 12, hudColour)
local divisor2 = ARG.hudRectangle(glasses, x+w - 64, y+20, 2, 12, hudColour)
local bottomDataStripe = ARG.hudRectangle(glasses, x+w - 168, y+30, 168, 1, workingColour)
local uniqueItems = ARG.hudText(glasses, "", x, y, workingColour, 0.75)
local totalItems = ARG.hudText(glasses, "", x, y, workingColour, 0.75)
local patterns = ARG.hudText(glasses, "", x, y, workingColour, 0.75)
uniqueItems = ARG.hudText(glasses, "", x, y, workingColour, 0.75)
totalItems = ARG.hudText(glasses, "", x, y, workingColour, 0.75)
patterns = ARG.hudText(glasses, "", x, y, workingColour, 0.75)
uniqueItems.setPosition((x+w-114)*1.33333, (y+22)*1.33333)
totalItems.setPosition((x+w-168)*1.33333, (y+22)*1.33333)
patterns.setPosition((x+w-60)*1.33333, (y+22)*1.33333)
@ -345,6 +356,7 @@ function ARWidgets.itemTicker(glasses, x, y, w)
uniqueItems.setText("Unique: "..itemsInNetwork)
changedItems = difference(refreshDatabase(allItems))
i = 1
clearTicker(glasses)
event.timer(5, processQueue, #changedItems)
end
end

View File

@ -174,6 +174,7 @@ function craftableBox(GPU, x, y)
local stockedAmount = S.getAmount(label)
local stockedString = string.sub(stockedAmount.."", 1, #(stockedAmount.."")-2)
local toStock = amount+0.0
if S.uniques() > 2500 then --Check against rebooted system
if toStock > 0 then
if drawerItem == label then
G.text(GPU, 4, 3+2*i, workingColour, label);
@ -201,6 +202,7 @@ function craftableBox(GPU, x, y)
i = math.min(i + 1, 43)
end
end
end
GPU.setActiveBuffer(0)
G.refresh(GPU)
end

View File

@ -34,6 +34,9 @@ end
function sUtil.getAmount(itemLabel)
if cachedAmounts[itemLabel] == nil then return 0 else return cachedAmounts[itemLabel] end
end
function sUtil.uniques()
return #cachedAmounts
end
function sUtil.update(label, oldAmount, newAmount)
local file = io.open("configured", 'r')
local fileContent = {}

View File

@ -3,17 +3,19 @@ local transposer = Comp.transposer
local players = {["Sampsa"] = 3, ["Dark"] = 2}
local function findEmptyCans(player)
local allItems = transposer.getAllStacks(players[player]).getAll()
if #allItems > 30 then
for i = 0, 39, 1 do if allItems[i].label == "Tin Can" then return i + 1 end end
end
return nil
end
local function checkLevel(player)
local itemStack = transposer.getStackInSlot(players[player], 19)
local itemStack = transposer.getStackInSlot(players[player], 28)
if itemStack ~= nil then return itemStack.size else return nil end
end
local function transferFood(player)
transposer.transferItem(0, players[player], 64, 1, 19)
transposer.transferItem(0, players[player], 64, 1, 28)
end
local function transferEmpty(player)
local slot = findEmptyCans(player)

View File

@ -0,0 +1,47 @@
comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread"); uc = require("unicode")
local LSC = comp.gt_machine
local engaged = false
local function machine(address)
machineAddress = comp.get(address)
if(machineAddress ~= nil) then
return comp.proxy(machineAddress)
else
return nil
end
end
local function getPercentage()
local currentEU =math.floor(string.gsub(LSC.getSensorInformation()[2], "([^0-9]+)", "") + 0)
local maxEU = math.floor(string.gsub(LSC.getSensorInformation()[3], "([^0-9]+)", "") + 0)
return currentEU/maxEU
end
local turbineRedstone = {
[1] = machine("928880ed")
}
local function disengage()
for i = 1, #turbineRedstone do
turbineRedstone[i].setOutput(4, 0)
end
engaged = false
end
local function engage()
for i = 1, #turbineRedstone do
turbineRedstone[i].setOutput(4, 15)
end
engaged = true
end
local function checkLevels()
local fill = getPercentage()
if fill < 0.15 then
if not engaged then engage() end
elseif fill > 0.95 then
if engaged then disengage() end
end
end
disengage()
while true do
checkLevels()
os.sleep(5)
end