diff --git a/Libraries/ARWidgets.lua b/Libraries/ARWidgets.lua index 550a5d1..67f2e9b 100644 --- a/Libraries/ARWidgets.lua +++ b/Libraries/ARWidgets.lua @@ -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 diff --git a/Programs/Autostocker/stocker.lua b/Programs/Autostocker/stocker.lua index 9c09787..e0674fd 100644 --- a/Programs/Autostocker/stocker.lua +++ b/Programs/Autostocker/stocker.lua @@ -174,31 +174,33 @@ function craftableBox(GPU, x, y) local stockedAmount = S.getAmount(label) local stockedString = string.sub(stockedAmount.."", 1, #(stockedAmount.."")-2) local toStock = amount+0.0 - if toStock > 0 then - if drawerItem == label then - G.text(GPU, 4, 3+2*i, workingColour, label); - elseif craftables[label] == nil then - G.text(GPU, 4, 3+2*i, negativeEUColour, label); - else - G.text(GPU, 4, 3+2*i, 0xFFFFFF, label); - end - if stockedAmount >= toStock then --In stock - G.text(GPU, 59 - (#stockedString + 1), 3+2*i, 0xFFFFFF, stockedString) - elseif stockedAmount >= toStock * 0.85 then --Edit hysteresis here, slightly below stock - G.text(GPU, 59 - (#stockedString + 1), 3+2*i, workingColour, stockedString) - else --Needs to be ordered - --Add crafting request loop here - if craftables[label] ~= nil then - if currentlyCrafting[label] == nil then - currentlyCrafting[label] = craftables[label](toStock - stockedAmount) - elseif currentlyCrafting[label].isDone() or currentlyCrafting[label].isCanceled() then - currentlyCrafting[label] = nil - end + 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); + elseif craftables[label] == nil then + G.text(GPU, 4, 3+2*i, negativeEUColour, label); + else + G.text(GPU, 4, 3+2*i, 0xFFFFFF, label); end - G.text(GPU, 59 - (#stockedString + 1), 3+2*i, negativeEUColour, stockedString) + if stockedAmount >= toStock then --In stock + G.text(GPU, 59 - (#stockedString + 1), 3+2*i, 0xFFFFFF, stockedString) + elseif stockedAmount >= toStock * 0.85 then --Edit hysteresis here, slightly below stock + G.text(GPU, 59 - (#stockedString + 1), 3+2*i, workingColour, stockedString) + else --Needs to be ordered + --Add crafting request loop here + if craftables[label] ~= nil then + if currentlyCrafting[label] == nil then + currentlyCrafting[label] = craftables[label](toStock - stockedAmount) + elseif currentlyCrafting[label].isDone() or currentlyCrafting[label].isCanceled() then + currentlyCrafting[label] = nil + end + end + G.text(GPU, 59 - (#stockedString + 1), 3+2*i, negativeEUColour, stockedString) + end + G.text(GPU, 59, 3+2*i, 0xFFFFFF, "| "..amount) + i = math.min(i + 1, 43) end - G.text(GPU, 59, 3+2*i, 0xFFFFFF, "| "..amount) - i = math.min(i + 1, 43) end end GPU.setActiveBuffer(0) diff --git a/Programs/Autostocker/stockerUtil.lua b/Programs/Autostocker/stockerUtil.lua index 3ec0983..b008710 100644 --- a/Programs/Autostocker/stockerUtil.lua +++ b/Programs/Autostocker/stockerUtil.lua @@ -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 = {} diff --git a/Programs/autofeeder.lua b/Programs/autofeeder.lua index 7d5161c..06107f0 100644 --- a/Programs/autofeeder.lua +++ b/Programs/autofeeder.lua @@ -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() - for i = 0, 39, 1 do if allItems[i].label == "Tin Can" then return i + 1 end end + 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) diff --git a/Programs/energyControl.lua b/Programs/energyControl.lua new file mode 100644 index 0000000..35cd5cc --- /dev/null +++ b/Programs/energyControl.lua @@ -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 \ No newline at end of file