commit faff7bfa45f7fab7ec18f16fedf24341f657aab8 Author: Sampsa Date: Fri Oct 30 21:33:29 2020 +0200 Fix folder structure diff --git a/Libraries/ARGraphics.lua b/Libraries/ARGraphics.lua new file mode 100644 index 0000000..d3a7d54 --- /dev/null +++ b/Libraries/ARGraphics.lua @@ -0,0 +1,86 @@ +comp = require("component"); screen = require("term"); computer = require("computer"); event = require("event") + +local AR = {} + +local terminal = {x = 8257, y = 199, z = -2731} +local function hexToRGB(hexcode) + local r = ((hexcode >> 16) & 0xFF) / 255.0 + local g = ((hexcode >> 8) & 0xFF) / 255.0 + local b = ((hexcode) & 0xFF) / 255.0 + return r, g, b +end +function AR.hexToRGB(hexcode) + local r = ((hexcode >> 16) & 0xFF) / 255.0 + local g = ((hexcode >> 8) & 0xFF) / 255.0 + local b = ((hexcode) & 0xFF) / 255.0 + return r, g, b +end +function AR.cube(glasses, x, y, z, color, alpha, scale) + scale = scale or 1; alpha = alpha or 1 + local cube = glasses.addCube3D() + cube.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z) + cube.setColor(hexToRGB(color)); cube.setAlpha(alpha); cube.setScale(scale) + return cube +end + +function AR.line(glasses, source, dest, color, alpha, scale) + scale = scale or 1; alpha = alpha or 1 + local line = glasses.addLine3D() + line.setVertex(1, source.x - terminal.x+0.5, source.y - terminal.y+0.5, source.z - terminal.z+0.5) + line.setVertex(2, dest.x - terminal.x+0.5, dest.y - terminal.y+0.5, dest.z - terminal.z+0.5) + line.setColor(hexToRGB(color)); line.setAlpha(alpha); line.setScale(scale) + return line +end + +function AR.worldText(glasses, name, x, y, z, color, alpha, scale) + scale = scale or 0.04; alpha = alpha or 1 + local text = glasses.addFloatingText() + text.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z) + text.setColor(hexToRGB(color)); text.setAlpha(alpha); text.setScale(scale) + text.setText(name) + return text +end + +function AR.hudTriangle(glasses, a, b, c, color, alpha) + alpha = alpha or 1.0 + local triangle = glasses.addTriangle() + triangle.setColor(hexToRGB(color)); triangle.setAlpha(alpha); + triangle.setVertex(1, a[1], a[2]); triangle.setVertex(2, b[1], b[2]); triangle.setVertex(3, c[1], c[2]) + return triangle +end + +function AR.hudQuad(glasses, a, b, c, d, color, alpha) + alpha = alpha or 1.0 + local quad = glasses.addQuad() + quad.setColor(hexToRGB(color)); quad.setAlpha(alpha) + quad.setVertex(1, a[1], a[2]); quad.setVertex(2, b[1], b[2]); quad.setVertex(3, c[1], c[2]); quad.setVertex(4, d[1], d[2]) + return quad +end + +function AR.hudRectangle(glasses, x, y, w, h, color, alpha) + alpha = alpha or 1.0 + local rect = glasses.addRect() + rect.setPosition(x, y); rect.setSize(h, w) + rect.setColor(hexToRGB(color)); rect.setAlpha(alpha) + return rect +end + +function AR.textSize(textObject, scale) + local oldX, oldY = textObject.getPosition() + oldX = oldX * textObject.getScale() + oldY = oldY * textObject.getScale() + textObject.setScale(scale) + textObject.setPosition(oldX/(scale+1), oldY/(scale+1)) +end + +function AR.hudText(glasses, displayText, x, y, color, scale) + scale = scale or 1 + local text = glasses.addTextLabel() + text.setText(displayText) + text.setPosition(x, y) + text.setColor(hexToRGB(color)) + AR.textSize(text, scale) + return text +end + +return AR \ No newline at end of file diff --git a/Libraries/ARWidgets.lua b/Libraries/ARWidgets.lua new file mode 100644 index 0000000..9ca778a --- /dev/null +++ b/Libraries/ARWidgets.lua @@ -0,0 +1,439 @@ +comp=require("component");screen=require("term");computer=require("computer");event=require("event"); thread = require("thread") +get=require("easy"); ARG=require("ARGraphics") +config = require("config") +local ARWidgets = {} + +local firstRead, lastRead, counter, currentIO = 0, 0, 1, 1 +local euUpdateInterval = 120 +local readings = {} +local function updateEU(LSC) + batteryBuffer = batteryBuffer or false + if counter == 1 then firstRead = computer.uptime() end + if counter < euUpdateInterval then + readings[counter] = string.gsub(LSC.getSensorInformation()[2], "([^0-9]+)", "") + 0 + counter = counter + 1 + end + if counter == euUpdateInterval then + lastRead = computer.uptime() + ticks = math.ceil((lastRead-firstRead)*20) + currentIO = math.floor((readings[euUpdateInterval-1]-readings[1])/ticks) + counter = 1 + end + end +local currentEU, maxEU, percentage, fillTime, fillTimeString = 1, 1, 1, 1, 1 +local initializePowerDisplay = true +local maxEnergyObj, currentEnergyObj, currentFillrateObj, percentageObj, timeObj +function ARWidgets.powerDisplay(glasses, data, x, y, w, h) + updateEU(data) + currentEU =math.floor(string.gsub(data.getSensorInformation()[2], "([^0-9]+)", "") + 0) + maxEU = math.floor(string.gsub(data.getSensorInformation()[3], "([^0-9]+)", "") + 0) + percentage = currentEU/maxEU + if initializePowerDisplay then + ARG.hudRectangle(glasses, x, y, w, h, hudColour) + ARG.hudRectangle(glasses, x, y+h, w, 12, hudColour, 0.6) + ARG.hudTriangle(glasses, {x+2, y+3}, {x+2, y+3+h-6}, {x+2+h-6, y+3+h-6}, hudColour) + ARG.hudTriangle(glasses, {x+2+w-4, y+3}, {x+2+w-4-(h-6), y+3}, {x+2+w-4, y+3+h-6}, hudColour) + ARG.hudRectangle(glasses, x, y+h, 25, 12, hudColour) + ARG.hudTriangle(glasses, {x+25, y+h}, {x+25, y+h+12}, {x+37, y+h+12}, hudColour) + ARG.hudRectangle(glasses, x+w-25, y+h, 25, 12, hudColour) + ARG.hudTriangle(glasses, {x+w-37, y+h}, {x+w-25, y+h+12}, {x+w-25, y+h}, hudColour) + powerFill = ARG.hudQuad(glasses, {x+2, y+3}, {x+2+h-6, y+3+h-6}, {math.min(x+2+w-5, (w-4)*percentage), y+3+(h-6)}, {math.min(x+2+w-5-(h-6), (w-4)*percentage-(h-6)), y+3}, workingColour) + powerEmpty = ARG.hudQuad(glasses, {math.min(x+2+w-5-(h-6), (w-4)*percentage-(h-6)), y+3}, {math.min(x+2+w-5, (w-4)*percentage), y+3+(h-6)}, {x+2+w-5, y+3+h-6}, {x+2+w-5-(h-6), y+3}, machineBackground) + + maxEnergyObj = ARG.hudText(glasses, "", x+w-88, y-8, idleColour) + currentEnergyObj = ARG.hudText(glasses, "", x+2, y-8, workingColour) + currentFillrateObj = ARG.hudText(glasses, "", x+w/2-20, y+h+1, 0xFFFFFF) + percentageObj = ARG.hudText(glasses, "", x+w/2-5, y-8, labelColour) + timeObj = ARG.hudText(glasses, "", x+35, y+h+1, labelColour) + initializePowerDisplay = false + end + if currentIO >= 0 then + fillTime = math.floor((maxEU-currentEU)/(currentIO*20)) + fillTimeString = "Full: " .. get.time(math.abs(fillTime)) + else + fillTime = math.floor((currentEU)/(currentIO*20)) + fillTimeString = "Empty: " .. get.time(math.abs(fillTime)) + end + powerFill.setVertex(1, x+2, y+3) + powerFill.setVertex(2, x+2+h-6, y+3+h-6) + powerFill.setVertex(3, math.min(x+2+w-5, (w-4)*percentage), y+3+(h-6)) + powerFill.setVertex(4, math.min(x+2+w-5-(h-6), (w-4)*percentage-(h-6)), y+3) + powerEmpty.setVertex(1, math.min(x+2+w-5-(h-6), (w-4)*percentage-(h-6)), y+3) + powerEmpty.setVertex(2, math.min(x+2+w-5, (w-4)*percentage), y+3+(h-6)) + powerEmpty.setVertex(3, x+2+w-5, y+3+h-6) + powerEmpty.setVertex(4, x+2+w-5-(h-6), y+3) + maxEnergyObj.setText(get.splitNumber(maxEU).." EU") + if percentage > 0.995 then + currentEnergyObj.setText(get.splitNumber(maxEU).." EU") + percentageObj.setText(get.getPercent(1.0)) + else + currentEnergyObj.setText(get.splitNumber(currentEU).." EU") + percentageObj.setText(get.getPercent(percentage)) + end + if currentIO >= 0 then + currentFillrateObj.setText("+"..get.splitNumber(currentIO).." EU/t") + currentFillrateObj.setColor(0, 1, 0) + else + currentFillrateObj.setColor(1, 0, 0) + currentFillrateObj.setText(get.splitNumber(currentIO).." EU/t") + end + if percentage < 0.985 then + timeObj.setText(fillTimeString) + else + timeObj.setText("") + end +end +function ARWidgets.minimapOverlay(glasses) + --Minimap Borders + ARG.hudRectangle(glasses, 728, 10, 123, 3, hudColour); + ARG.hudRectangle(glasses, 728, 130, 123, 3,hudColour); + ARG.hudRectangle(glasses, 728, 10, 3, 123,hudColour); + ARG.hudRectangle(glasses, 848, 10, 3, 123, hudColour); + --Coordinate Borders + ARG.hudTriangle(glasses, {743, 133}, {728, 133}, {743, 143}, hudColour) + ARG.hudRectangle(glasses, 743, 133, 8, 10, hudColour); + ARG.hudRectangle(glasses, 751, 140, 170, 3, hudColour); + --Biome Borders + ARG.hudTriangle(glasses, {768, 143}, {753, 143}, {768, 153}, hudColour) + ARG.hudRectangle(glasses, 768, 150, 170, 3, hudColour); + ARG.hudRectangle(glasses, 829, 133, 50, 7, 0, 0.8) + ARG.hudRectangle(glasses, 811, 143, 50, 7, 0, 0.8) + --FPS Borders + ARG.hudRectangle(glasses, 728, 0, 150, 2, hudColour) + ARG.hudRectangle(glasses, 728, 0, 22, 12, hudColour) + ARG.hudRectangle(glasses, 750, 2, 28, 8, 0, 0.8) + ARG.hudTriangle(glasses, {758, 2}, {750, 2}, {750, 10}, hudColour) + ARG.hudRectangle(glasses, 801, 2, 70, 8, 0, 0.8) + ARG.hudRectangle(glasses, 851, 10, 5, 123, 0, 0.8) +end +function ARWidgets.hudOverlayBase(glasses, x, y) + local hotbarSplitter = ARG.hudRectangle(glasses, x, y, 183, 2, hudColour) + local expSplitter = ARG.hudRectangle(glasses, x, y-6, 183, 2, hudColour) + local expOverlay = ARG.hudRectangle(glasses, x, y-4, 183, 4, workingColour, 0.5) + local leftBorder = ARG.hudRectangle(glasses, x-1, y-13, 3, 38, hudColour) + local rightBorder = ARG.hudRectangle(glasses, x+182, y-5, 3, 30, hudColour) + local armorBox = ARG.hudRectangle(glasses, x, y-27, 90, 15, hudColour, 0.0) + local hpBox = ARG.hudRectangle(glasses, x+1, y-15, 94, 10, hudColour, 0.7) + local hpStopper = ARG.hudQuad(glasses, {x+88, y-16}, {x+77, y-5},{x+108, y-5}, {x+97, y-16}, hudColour) + local topBorder = ARG.hudRectangle(glasses, x+4, y-18, 178, 3, hudColour) + local topWedge = ARG.hudTriangle(glasses, {x+4, y-18}, {x-1, y-13}, {x+4, y-13}, hudColour) + local connector = ARG.hudTriangle(glasses, {x+182, y-18}, {x+182, y}, {x+200, y}, hudColour) + local topStrip = ARG.hudRectangle(glasses, x+4, y-17, 178, 1, workingColour) + local expWedge1 = ARG.hudTriangle(glasses, {x+179, y-4}, {x+183, y}, {x+183, y-4}, hudColour) + local expWedge2 = ARG.hudTriangle(glasses, {x+2, y-5}, {x+2, y}, {x+6, y}, hudColour) + --CPU Monitor + local base = ARG.hudRectangle(glasses, x+185, y, 28, 24, hudColour) + local cpuStrip = ARG.hudRectangle(glasses, x+185, y, 500, 3, hudColour) + local itemBorder1 = ARG.hudRectangle(glasses, x+28+185, y+3, 1, 21, workingColour, 0.8) + local itemBorder2 = ARG.hudRectangle(glasses, x+28+185, y+3, 61, 1, workingColour, 0.8) + local itemBorder3 = ARG.hudRectangle(glasses, x+88+185, y+3, 1, 21, workingColour, 0.8) + local itemBorder4 = ARG.hudRectangle(glasses, x+28+185, y+23, 61, 1, workingColour, 0.8) + local cpuBase1 = ARG.hudRectangle(glasses, x+89+185, y, 5, 24, hudColour) + local connectorStrip = ARG.hudQuad(glasses, {x+182, y-17}, {x+182, y-16},{x+213, y+15}, {x+213, y+14}, workingColour) +end +function popupText(glasses, text, x, y, color) + local substringLength = 1 + local width = #text * 5 + local steps = math.ceil(#text / substringLength) + local stepLength = substringLength * 5 + local i = 1 + local background = ARG.hudQuad(glasses, {x-5, y}, {x-5, y+9}, {x-5+1, y+9}, {x-5+1, y}, machineBackground, 0.5) + local top = ARG.hudQuad(glasses, {x-5, y-1}, {x-5, y}, {x-5+1, y}, {x-5+1, y-1}, machineBackground) + local bottom = ARG.hudQuad(glasses, {x-5, y+9}, {x-5, y+10}, {x-5+1, y+10}, {x-5+1, y+9}, machineBackground) + local hudText = ARG.hudText(glasses, "", x+1, y+1, color) + local wedge = ARG.hudQuad(glasses, {x-5-10, y-1}, {x-5, y-1}, {x-5, y+10}, {x-5+11, y+10}, machineBackground) + local direction = 1 + local function advance() + background.setVertex(3, math.min(width + 10, x + stepLength * i + 10), y+9) + background.setVertex(4, math.min(width, x + stepLength * i), y) + top.setVertex(3, math.min(width, x + stepLength * i), y) + top.setVertex(4, math.min(width, x + stepLength * i), y-1) + bottom.setVertex(3, math.min(width + 10, x + stepLength * i + 10), y+10) + bottom.setVertex(4, math.min(width + 10, x + stepLength * i + 10), y+9) + wedge.setVertex(1, math.min(width-1, x + stepLength * i-1), y-1) + wedge.setVertex(2, math.min(width + 10, x + stepLength * i + 10), y+10) + wedge.setVertex(3, math.min(width + 11, x + stepLength * i + 11), y+10) + wedge.setVertex(4, math.min(width + 1, x + stepLength * i + 1), y-1) + hudText.setText(string.sub(text, 1, substringLength * i)) + i = i + direction + if i < 0 then + glasses.removeObject(background.getID()) + glasses.removeObject(top.getID()) + glasses.removeObject(bottom.getID()) + glasses.removeObject(hudText.getID()) + glasses.removeObject(wedge.getID()) + end + end + local function retract() + direction = -1 + event.timer(0.03, advance, steps+2) + end + event.timer(0.03, advance, steps) + return retract +end +local initFluidMap = true +local fillLevels = {} +local lastRefresh = computer.uptime() - 30 +function ARWidgets.fluidMonitor(glasses, x, y, fluidMap) + local w = 60 + local h = 9 + local entries = 0 + local fluids = comp.me_interface.getFluidsInNetwork() + if initFluidMap then + for i = 0, #fluidMap, 1 do + local background = ARG.hudQuad(glasses, {x-8, y + i * h},{x-8, y+8 + i * h},{x+w, y+8 + i * h},{x+w, y + i * h}, hudColour, 0.5) + local top = ARG.hudQuad(glasses, {x-10, y-1 + i * h},{x-10, y + i * h},{x+w, y + i * h},{x+w, y-1 + i * h}, hudColour) + local bottom = ARG.hudQuad(glasses, {x-7, y+8 + i * h},{x-8, y+9 + i * h},{x+w, y+9 + i * h},{x+w, y+8 + i * h}, hudColour) + local fill = ARG.hudQuad(glasses, {x+w, y + i * h},{x+w, y+8 + i * h},{x+w, y+8 + i * h},{x+w, y + i * h}, fluidMap[i].color, 0.7) + local text = ARG.hudText(glasses, fluidMap[i].displayName, x, y + i * h, 0x777777, 0.75) + text.setPosition(x*1.33333 + 4, (y + i * h)*1.33333 + 2) + fillLevels[fluidMap[i].label] = fill + if i % 2 == 0 then + local wedge = ARG.hudQuad(glasses, {x-10, y + i * h},{x-10, y+9 + i * h},{x-6, y+9 + i * h},{x+3, y + i * h}, hudColour) + else + local wedge = ARG.hudQuad(glasses, {x-10, y + i * h},{x-10, y+9 + i * h},{x+3, y+9 + i * h},{x-6, y + i * h}, hudColour) + end + entries = i + end + entries = entries + 1 + local finish = ARG.hudQuad(glasses,{x-10, y + entries * h},{x-2, y+8 + entries * h},{x+w, y+8 + entries * h},{x+w, y + entries * h}, hudColour) + local verticalStrip = ARG.hudQuad(glasses,{x-8, y},{x-8, y - 2 + entries * h},{x-7, y - 2 + entries * h},{x-7, y}, workingColour) + local diagonalStrip = ARG.hudQuad(glasses,{x-8, y-2 + entries * h},{x, y+6 + entries * h},{x, y + 5 + entries * h},{x-7, y - 2 + entries * h}, workingColour) + local horizontalStrip = ARG.hudQuad(glasses,{x, y + 5 + entries * h},{x, y+6 + entries * h},{x+w, y+6 + entries * h},{x+w, y + 5 + entries * h}, workingColour) + initFluidMap = false + elseif computer.uptime() - lastRefresh > 30 then + for i = 0, #fluidMap, 1 do + local fillQuad = fillLevels[fluidMap[i].label] + local currentLevel = 0 + for f = 1, #fluids, 1 do + if fluids[f].label == fluidMap[i].label then + currentLevel = fluids[f].amount + end + end + local fillPercentage = math.min(currentLevel / (fluidMap[i].max * 1000000.0), 1) + fillQuad.setVertex(1, x + w - fillPercentage * (w + 8), y + i * h) + fillQuad.setVertex(2, x + w - fillPercentage * (w + 8), y+8 + i * h) + end + lastRefresh = computer.uptime() + end +end +local function refreshDatabase(itemList) + filteredList = {} + for i = 1, #itemList, 1 do + if itemList[i].size >= 100 then filteredList[itemList[i].label] = itemList[i].size end + itemList[i] = nil + end + return filteredList +end +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) + local stepSize = 1 + local steps = start - stop / stepSize + local step = 0 + local textLength = #text*5 + local textRemaining = #text + local textToRemove = #text + local function truncate() + textObject.setText(string.sub(text, #text - textToRemove, #text)) + textToRemove = textToRemove - 1 + if textToRemove == 0 then + glasses.removeObject(backgroundEndWedge.getID()) + glasses.removeObject(backgroundStartWedge.getID()) + glasses.removeObject(startWedge.getID()) + glasses.removeObject(textObject.getID()) + end + end + local function roll() + textObject.setPosition(start - (step * stepSize), y) + step = step + 1 + if step > steps then + event.timer(0.07, truncate, #text + 3) + end + end + local function generate() + textObject.setText(string.sub(text, 0, #text - textRemaining)) + textRemaining = textRemaining - 1 + end + event.timer(0.10, generate, #text + 1) + event.timer(0.02, roll, steps + 1) +end +local cachedAmounts = refreshDatabase(comp.me_interface.getItemsInNetwork()) +function difference(new) + local differenceArray = {} + for label, amount in pairs(cachedAmounts) do + if new[label] ~= nil then + if new[label] - amount > 64 or new[label] - amount < -64 then + differenceArray[#differenceArray+1] = {label, new[label] - amount} + end + end + end + cachedAmounts = new + return differenceArray +end +local initializeTicker = true +local allItems, itemsInNetwork, craftables +local lastUpdate = computer.uptime() - 60 +function ARWidgets.itemTicker(glasses, x, y, w) + local function formatMillions(number) + local millions = number / 1000000 + if millions >= 10 then + return string.sub(millions, 1, 5).."M" + else + return string.sub(millions, 1, 4).."M" + end + end + local function getTotalItemCount(items) + local sum = 0 + for i = 1, #items, 1 do + sum = sum + items[i].size + end + return sum + end + if initializeTicker then + local background = ARG.hudQuad(glasses, {x, y+2},{x, y+14},{x+w, y+14},{x+w, y+2}, machineBackground, 0.5) + local top = ARG.hudQuad(glasses, {x, y},{x, y+2},{x+w, y+2},{x+w, y}, hudColour) + local bottom = ARG.hudQuad(glasses, {x, y+14},{x, y+20},{x+w, y+20},{x+w, y+14}, hudColour) + local bottomStripe = ARG.hudQuad(glasses, {x, y+17},{x, y+18},{x+w, y+18},{x+w, y+17}, workingColour) + local wedge = ARG.hudTriangle(glasses, {x-20, y},{x, y+20},{x, y}, hudColour) + local backgroundEndWedge = ARG.hudTriangle(glasses, {x, y+2},{x, y+14},{x+12, y+14}, hudColour) + local backgroundStartWedge = ARG.hudTriangle(glasses, {x+w-12, y+2},{x+w, y+14},{x+w+12, y+2}, hudColour) + local diagonalStripe = ARG.hudQuad(glasses, {x-16, y+2},{x, y+18},{x, y+17},{x-15, y+2}, workingColour) + local bottomBorder = ARG.hudRectangle(glasses, x+w - 170, y + 28, 170, 4, hudColour) + local dataBorder = ARG.hudRectangle(glasses, x+w - 170, 20, 170, 12, hudColour, 0.5) + local endWedge = ARG.hudTriangle(glasses,{x+w-182, y+20},{x+w-170, y+32},{x+w-170, y+20}, hudColour) + 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) + 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) + initializeTicker = false + end + local function showTicker(name, amount) + rollingText(glasses, name, x+w, x, y+4, 0xAAAAAA) + local function showChange() + if amount > 0 then + rollingText(glasses, "+"..amount, x+w, x, y+4, positiveEUColour) + else + rollingText(glasses, ""..amount, x+w, x, y+4, negativeEUColour) + end + end + event.timer(#name * 0.12, showChange, 1) + end + local changedItems = {} + local i = 1 + local function processQueue() + showTicker(changedItems[i][1], changedItems[i][2]) + i = i + 1 + end + if computer.uptime() - lastUpdate > 60 then + lastUpdate = computer.uptime() + allItems = comp.me_interface.getItemsInNetwork() + itemsInNetwork = #allItems + craftables = #comp.me_interface.getCraftables() + totalItems.setText("Total: "..formatMillions(getTotalItemCount(allItems))) + patterns.setText("Patterns: "..craftables) + uniqueItems.setText("Unique: "..itemsInNetwork) + changedItems = difference(refreshDatabase(allItems)) + i = 1 + event.timer(5, processQueue, #changedItems) + end +end +function ARWidgets.crossHair(glasses, x, y) + local horizontal = ARG.hudRectangle(glasses, x, y+5, 4, 1, workingColour, 0.5) + local vertical = ARG.hudRectangle(glasses, x+5, y, 1, 4, workingColour, 0.5) + local horizontal2 = ARG.hudRectangle(glasses, x+7, y+5, 4, 1, workingColour, 0.5) + local vertical2 = ARG.hudRectangle(glasses, x+5, y+7, 1, 4, workingColour, 0.5) + local middle = ARG.hudRectangle(glasses, x+4, y+4, 3, 3, hudColour, 0.0) + local center = ARG.hudRectangle(glasses, x+5, y+5, 1, 1, hudColour, 0.7) +end +local initializeCpuMonitor = true +local cpuLights = {} +function ARWidgets.cpuMonitor(glasses, x, y) + if initializeCpuMonitor then + local cpuBase2 = ARG.hudRectangle(glasses, x+94, y+12, 8, 12, hudColour) + local cpuSplitter = ARG.hudRectangle(glasses, x+89, y+9, 400, 3, hudColour) + local cpuSplitter2 = ARG.hudRectangle(glasses, x+102, y+18, 380, 6, hudColour) + local function createCpuIndicator(cpuX, cpuY) + local status = ARG.hudQuad(glasses, {cpuX, cpuY}, {cpuX+6, cpuY+6}, {cpuX+16, cpuY+6}, {cpuX+10, cpuY}, hudColour, 1.0) + local leftTriangle = ARG.hudTriangle(glasses, {cpuX, cpuY}, {cpuX, cpuY+6}, {cpuX+6, cpuY+6}, hudColour) + local rightTriangle = ARG.hudQuad(glasses, {cpuX+10, cpuY}, {cpuX+16, cpuY+6}, {cpuX+18, cpuY+6}, {cpuX+18, cpuY}, hudColour) + return status + end + local i = 0 + local j = 0 + local cpuNumber = 1 + while i+j < 24 do + if (i+j) % 2 == 1 then + cpuLights[cpuNumber] = createCpuIndicator(x+102+j*17, y+12) + j = j + 1 + else + cpuLights[cpuNumber] = createCpuIndicator(x+94+i*17, y+3) + i = i + 1 + end + cpuNumber = cpuNumber + 1 + end + local rowStop1 = ARG.hudRectangle(glasses, x+94+i*17, y+3, 300, 6, hudColour) + local rowStop2 = ARG.hudRectangle(glasses, x+102+j*17, y+12, 300, 6, hudColour) + local horizontalStrip = ARG.hudRectangle(glasses, x+100, y+22, 210, 1, workingColour) + local diagonalStrip = ARG.hudQuad(glasses, {x+89, y+11}, {x+89, y+12}, {x+100, y+23}, {x+100, y+22}, workingColour) + initializeCpuMonitor = false + end + local cpus = comp.me_interface.getCpus() + for i = 1, #cpus, 1 do + if cpus[i].busy then + cpuLights[i].setColor(ARG.hexToRGB(positiveEUColour)) + else + cpuLights[i].setAlpha(0.7) + cpuLights[i].setColor(ARG.hexToRGB(workingColour)) + end + end +end +local TPSText +local initializeTPS = true +function ARWidgets.displayTPS(glasses, x, y) + if initializeTPS then + initializeTPS = false + local background = ARG.hudQuad(glasses, {x+40, y+4}, {x+40, y+15}, {x+93, y+15}, {x+105, y+4}, hudColour, 0.6) + local startBlock = ARG.hudRectangle(glasses, x, y, 40, 23, hudColour) + local top = ARG.hudRectangle(glasses, x+40, y, 65, 4, hudColour) + local bottom = ARG.hudRectangle(glasses, x+40, y+14, 50, 5, hudColour) + local wedge1 = ARG.hudQuad(glasses, {x+40, y+19}, {x+40, y+23}, {x+42, y+23}, {x+46, y+19}, hudColour) + local wedge2 = ARG.hudQuad(glasses, {x+105, y}, {x+86, y+19}, {x+93, y+19}, {x+112, y}, hudColour) + local stripe1 = ARG.hudRectangle(glasses, x+2, y+20, 39, 1, workingColour) + local stripe2 = ARG.hudRectangle(glasses, x+45, y+16, 48, 1, workingColour) + local stripe3 = ARG.hudQuad(glasses, {x+41, y+20}, {x+41, y+21}, {x+45, y+17}, {x+45, y+16}, workingColour) + local stripe4 = ARG.hudRectangle(glasses, x+1, y+2, 1, 19, workingColour) + TPSText = ARG.hudText(glasses, "", x+42, y+6, workingColour, 1) + end + local tps = get.tps() + if tps > 15 then + TPSText.setText("TPS: "..string.sub(tps, 1, 5)) + TPSText.setColor(ARG.hexToRGB(positiveEUColour)) + elseif tps >= 10 then + TPSText.setText("TPS: "..string.sub(tps, 1, 5)) + TPSText.setColor(ARG.hexToRGB(workingColour)) + else + TPSText.setText("TPS: "..string.sub(tps, 1, 4)) + TPSText.setColor(ARG.hexToRGB(negativeEUColour)) + end +end +function ARWidgets.clear() + initializePowerDisplay = true + initializeTicker = true + initFluidMap = true + initializeCpuMonitor = true + initializeTPS = true + fillLevels = {} + lastRefresh = computer.uptime() - 30 + lastUpdate = computer.uptime() - 60 +end + +return ARWidgets \ No newline at end of file diff --git a/Libraries/configuration.lua b/Libraries/configuration.lua new file mode 100644 index 0000000..674ccae --- /dev/null +++ b/Libraries/configuration.lua @@ -0,0 +1,7 @@ +machineBackground = 0x121010; progressBackground = 0x272c2e +labelColour = 0xFF00FF; +errorColour = 0xFF0000; +idleColour = 0xb300ff; workingColour = 0x00a6ff +positiveEUColour = 0x00CC00; negativeEUColour = 0xCC0000 +timeColour = 0x5500FF; textColor = 0x000000 +hudColour = 0x1E1E28; \ No newline at end of file diff --git a/Libraries/graphics.lua b/Libraries/graphics.lua new file mode 100644 index 0000000..8ab00f7 --- /dev/null +++ b/Libraries/graphics.lua @@ -0,0 +1,93 @@ +comp = require("component"); +color = { + red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF, + purple = 0x5500FF, cyan = 0x00A6FF, lightGreen = 0x00CC00, + lightGray = 0x272c2e, darkGray = 0x121010, white = 0x000000 +} +local graphics = {} + +function pixel(GPU, x, y, color) + local screenY = math.ceil(y/2); local baseChar, baseForeground, baseBackground = GPU.get(x, screenY) + GPU.setForeground(color) + GPU.setBackground(baseBackground) + if y % 2 == 1 then --Upper half of pixel + GPU.set(x, screenY, "▀"); + else --Lower half of pixel + GPU.set(x, screenY, "▄"); + end +end + + +function graphics.rect(GPU, x, y, w, h, color) + local hLeft = h + if x > 0 and y > 0 then + if y % 2 == 0 then + for i = x, x+w-1 do + pixel(GPU, i, y, color) + end + hLeft = hLeft - 1 + end + GPU.setBackground(color) + GPU.setForeground(color) + if hLeft % 2 == 1 then + GPU.fill(x, math.ceil(y/2)+(h-hLeft), w, (hLeft-1)/2, "█") + for j = x, x+w-1 do + pixel(GPU, j, y+h-1, color) + end + else + GPU.fill(x, math.ceil(y/2)+(h-hLeft), w, hLeft/2, "█") + end + end +end + +function graphics.text(GPU, x, y, color, string) + if y % 2 == 0 then error("Text position must be odd on y axis") end + local screenY = math.ceil(y/2) + GPU.setForeground(color); + for i = 0, #string-1 do + local baseChar, baseForeground, baseBackground = GPU.get(x+i, screenY) + GPU.setBackground(baseBackground) + GPU.fill(x+i, screenY, 1, 1, string:sub(i+1, i+1)) + end +end + +function graphics.centeredText(GPU, x, y, color, string) + if y % 2 == 0 then error("Text position must be odd on y axis") end + local screenY = math.ceil(y/2) + local oldForeground = GPU.setForeground(color); local oldBackground = GPU.getBackground() + for i = 0, #string-1 do + local baseChar, baseForeground, baseBackground = GPU.get(x+i-math.ceil(#string/2)+1, screenY) + GPU.setBackground(baseBackground) + GPU.fill(x+i-math.ceil(#string/2)+1, screenY, 1, 1, string:sub(i+1, i+1)) + end + GPU.setBackground(oldBackground); GPU.setForeground(oldForeground) +end + +function graphics.border(GPU, w, h, color) + draw.rect(GPU, 1, 1, w, 1, color) + draw.rect(GPU, 1, h*2, w, 1, color) + draw.rect(GPU, 1, 1, 1, h*2, color) + draw.rect(GPU, w, 1, 1, h*2, color) +end + +function copyWindow(GPU, x, y, page, destination) + destination = 0 or destination + GPU.bitblt(destination, x, math.ceil(y/2), 160, 46, page, 1, 1) +end +windows = {} +function graphics.update() + local function redraw() + for window, params in pairs(windows) do + copyWindow(params.GPU, params.x, params.y, params.page) + end + end + for name, params in pairs(windows) do + params.GPU.setActiveBuffer(params.page) + params.update(params.GPU, name, params.address) + params.GPU.setActiveBuffer(0) + end + redraw() + os.sleep() +end + +return graphics \ No newline at end of file diff --git a/Libraries/gui.lua b/Libraries/gui.lua new file mode 100644 index 0000000..9ad7c07 --- /dev/null +++ b/Libraries/gui.lua @@ -0,0 +1,168 @@ +local draw = require("graphics"); local event = require("event"); local thread = require("thread"); local uc = require("unicode") +local comp = require("component"); GPU = comp.proxy(comp.get("f26678f4")) + +local gui, quit, editing = {}, false, false +local currentWindows = {} +local activeWindow +local keyInput, mouseInput, drag, inContextMenu +function checkCollision(x, y) + for window, params in pairs(currentWindows) do + if x >= params.x and x <= params.x+params.w-1 then + if y >= params.y and y <= params.y+math.ceil(params.h/2)-1 then + return window + end + end + end + return "None " +end + +local contextMenus = 0 + + +function contextMenu(GPU, x, y, data) + function filterClicks(event) return event == "touch" end + inContextMenu = true + contextMenus = contextMenus + 1 + local longestData = 0 + for i, data in pairs(data) do + if #data > longestData then longestData = #data end + end + local contextWindow = createWindow(GPU, longestData, #data*2, "ContextMenu"..contextMenus) + GPU.setActiveBuffer(contextWindow) + draw.rect(GPU, 1, 1, longestData, #data*2, color.lightGray) + for i = 1, #data do + draw.text(GPU, 1, 1+i*2-2, color.cyan, data[i]) + end + currentWindows["ContextMenu"..contextMenus].x = x + currentWindows["ContextMenu"..contextMenus].y = y + GPU.setActiveBuffer(0) + +end + +function keyboardListener() + function processKey(event, address, key, code, player) + local value = uc.char(key) + if value == "." then quit = true end + if value == "e" then + if editing then + editing = false + else + editing = true end + end + + end + return event.listen("key_up", processKey) +end + +function processCommand(GPU, window, option) + local pageNumber = currentWindows[window].page + if currentWindows["ColorBox"] == nil then + createWindow(GPU, 10, 10, "ColorBox") + currentWindows["ColorBox"].x = 10 + currentWindows["ColorBox"].y = 10 + end + GPU.setActiveBuffer(currentWindows["ColorBox"].page) + if option == 1 then draw.rect(GPU, 1, 1, 10, 10, color.red) end + if option == 2 then draw.rect(GPU, 1, 1, 10, 10, color.blue) end + if option == 3 then draw.rect(GPU, 1, 1, 10, 10, color.green) end + GPU.setActiveBuffer(0) +end + +local i, xOffset, yOffset = 1, 0, 0 +function mouseListener() + function processClick(event, address, x, y, key, player) + activeWindow = checkCollision(x, y) + draw.text(GPU, 1, 1, color.cyan, "Active window: "..activeWindow) + if key == 1.0 and editing then + if inContextMenu then contextMenus = 0 end + contextMenu(GPU, x, y, {[1]="Red", [2]="Blue", [3]="Green"}) + else + if inContextMenu then + local cont = currentWindows["ContextMenu1"] + if x >= cont.x and x < cont.x+cont.w and y >= cont.y and y < cont.y+math.ceil(cont.h/2) then + processCommand(GPU, activeWindow, y-cont.y+1) + else + inContextMenu = false + for j = 1, contextMenus do + currentWindows["ContextMenu"..j] = nil + end + contextMenus = 0 + end + else + if activeWindow ~= "None " then end + xOffset = x - currentWindows[activeWindow].x + yOffset = y - currentWindows[activeWindow].y + end + end + end + return event.listen("touch", processClick) +end + +function dragListener() + function processDrag(event, address, x, y, key, player) + if editing and inContextMenu == false then + local window = currentWindows[activeWindow] + currentWindows[activeWindow].x = x - xOffset + currentWindows[activeWindow].y = y - yOffset + end + end + return event.listen("drag", processDrag) +end + +function dropListener() + function processDrop(event, address, x, y, key, player) + + end + return event.listen("drop", processDrop) +end + +function createWindow(GPU, width, height, name) + local pageNumber = GPU.allocateBuffer(width, math.ceil(height/2)) + currentWindows[name] = {page=pageNumber, x=1, y=1, w=width, h=height} + return pageNumber +end + +function compose(GPU) + local stateBuffer = currentWindows["State"].page + GPU.setActiveBuffer(stateBuffer) + if editing then copyWindow(GPU, 1, 1, currentWindows["Black"].page) end + for window, params in pairs(currentWindows) do + if params.w > 0 then + copyWindow(GPU, params.x, params.y, params.page, stateBuffer) + end + end + if inContextMenu then + local cont = currentWindows["ContextMenu1"] + copyWindow(GPU, cont.x, cont.y, cont.page) end + GPU.setActiveBuffer(0) +end + +function copyWindow(GPU, x, y, page, destination) + destination = 0 or destination + GPU.bitblt(destination, x, y, 160, 50, page, 1, 1) +end + +--return gui + +GPU = comp.proxy(comp.get("de837fec")); screen = comp.get("48ce2988"); GPU.bind(screen); +GPU.freeAllBuffers() +keyInput, mouseInput, drag = keyboardListener(), mouseListener(), dragListener() +createWindow(GPU, 160, 100, "Black") +GPU.setActiveBuffer(currentWindows["Black"].page) +draw.rect(GPU, 1, 1, 160, 100, 0x000000) +currentWindows["Black"].w = 0 +currentWindows["Black"].h = 0 +GPU.setActiveBuffer(0) +createWindow(GPU, 160, 100, "State") +GPU.setActiveBuffer(currentWindows["State"].page) +draw.rect(GPU, 1, 1, 160, 100, 0x000000) +currentWindows["State"].w = 0 +currentWindows["State"].h = 0 +GPU.setActiveBuffer(0) +copyWindow(GPU, 1, 1, currentWindows["Black"].page) + +while true do + if quit then event.cancel(keyInput); break end + compose(GPU) + os.sleep(0.1) +end \ No newline at end of file diff --git a/Libraries/network.lua b/Libraries/network.lua new file mode 100644 index 0000000..2fc69b4 --- /dev/null +++ b/Libraries/network.lua @@ -0,0 +1,16 @@ +local comp = require("component") +local event = require("event") +local modem = comp.modem +local screen = require("term") +local util = require("utility") +AR = require("AR") +glasses = util.machine("3770e3f9") + +local componentText = AR.hudText(glasses, " ", 0, 20) + +local function receive(localAddress, remoteAddress, port, distance, type, value1, value2, value3) + componentText.setText(value2) +end + +event.listen("modem_message", receive) +modem.open(1) diff --git a/Libraries/utility.lua b/Libraries/utility.lua new file mode 100644 index 0000000..9559c04 --- /dev/null +++ b/Libraries/utility.lua @@ -0,0 +1,82 @@ +local comp = require("component"); local event = require("event"); local thread = require("thread"); local uc = require("unicode") +local utility = {} + +function utility.machine(address) + machineAddress = comp.get(address) + if(machineAddress ~= nil) then + return comp.proxy(machineAddress) + else + return nil + end +end + +function utility.getPercent(number) + return (math.floor(number*1000)/10).."%" +end + +function utility.time(number) --Returns a given number formatted as Hours Minutes Seconds + if number == 0 then return 0 else return math.floor(number/3600).."h "..math.floor((number - math.floor(number/3600)*3600)/60).."min "..(number%60).."s" end +end + +function utility.splitNumber(number) --Returns given number formatted as XXX,XXX,XXX + local formattedNumber = {} + local string = tostring(math.abs(number)) + local sign = number/math.abs(number) + for i = 1, #string do + n = string:sub(i, i) + formattedNumber[i] = n + if ((#string-i) % 3 == 0) and (#string-i > 0) then + formattedNumber[i] = formattedNumber[i] .. "," + end + end + if(sign < 0) then table.insert(formattedNumber, 1, "-") end + return table.concat(formattedNumber, "") +end + +function utility.tier(number) + local values = {[1] = "LV", + [2] = "MV", + [3] = "HV", + [4] = "EV", + [5] = "IV", + [6] = "LuV", + [7] = "ZPM", + [8] = "UV", + [9] = "UHV", +} +return values[number] +end + +function utility.exit(key) + local function processKey(event, address, key, code, player) + local value = uc.char(key) + if value == "e" then run = false end + return false + end + event.listen("key_up", processKey) +end + +function utility.componentChange(broadcastPort) + local function sendAddress(event, address, type) + modem.broadcast(broadcastPort, event, address, type) + end + event.listen("component_added", sendAddress) +end + +function utility.progressText(current, max) + return current.."/"..max.."s" +end + +function utility.tps() + local function time() + local f = io.open("/tmp/TPS","w") + f:write("test") + f:close() + return(require("filesystem").lastModified("/tmp/TPS")) + end + local realTimeOld = time() + os.sleep(1) + return 20000 / (time() - realTimeOld) + end + +return utility \ No newline at end of file diff --git a/Libraries/widgets.lua b/Libraries/widgets.lua new file mode 100644 index 0000000..46cce6e --- /dev/null +++ b/Libraries/widgets.lua @@ -0,0 +1,128 @@ +comp = require("component");screen = require("term"); computer = require("computer"); event = require("event") +draw = require("graphics"); util = require("utility") + +local widgets = {} + +function widgets.gtMachineInit(GPU, name, address) + local maintenanceIndex = 0 + local machine = util.machine(address) + draw.rect(GPU, 1, 1, 28, 9, background) + draw.text(GPU, 4, 3, mainColor, name) + if machine ~= nil then + for i = 1, #machine.getSensorInformation() do --Get maintenance index + if string.match(machine.getSensorInformation()[i], "Problems") ~= nil then + maintenanceIndex = i + end + end + if maintenanceIndex ~= 0 and #machine.getSensorInformation() >= 7 then + --Check for tier on Processing Arrays + if string.match(machine.getSensorInformation()[6], "tier") ~= nil then + local tier = util.tier((string.gsub(machine.getSensorInformation()[6], "([^0-9]+)", "")-1)/10) + if tier ~= nil then draw.text(GPU, 4, 5, accentB, ""..tier) end + end + --Check for parallel on Processing Arrays + if string.match(machine.getSensorInformation()[7], "Parallel") ~= nil then + local parallel = string.gsub(machine.getSensorInformation()[7], "([^0-9]+)", "") + if parallel ~= nil then draw.text(GPU, 11+-#parallel.."", 5, mainColor, parallel.."x") end + end + end + else + draw.text(GPU, 4, 5, errorColor, "Unknown") + end + draw.rect(GPU, 3, 2, 3, 1, barColor) + draw.rect(GPU, 2, 2, 1, 7, barColor) + draw.rect(GPU, 3, 8, 20, 1, barColor) + draw.rect(GPU, 24, 8, 3, 1, barColor) + draw.rect(GPU, 27, 2, 1, 7, barColor) + draw.rect(GPU, 7, 2, 21, 1, barColor) + return maintenanceIndex +end + +function widgets.gtMachine(GPU, name, address) + local machine = util.machine(address) + local char, f, b + if machine ~= nil then + if machine.hasWork() then + local currentProgress = math.ceil(30*(machine.getWorkProgress()/machine.getWorkMaxProgress())) + local barAmount = currentProgress + --First Straight + _, f, _ = GPU.get(3, 1) + if f ~= mainColor then + local bars1 = math.max(0, math.min(3, barAmount)) + draw.rect(GPU, 3, 2, 3, 1, barColor) + draw.rect(GPU, 24, 8, 3, 1, barColor) + draw.rect(GPU, 2, 2, 1, 7, barColor) + draw.rect(GPU, 27, 2, 1, 7, barColor) + draw.rect(GPU, 3, 8, 20, 1, barColor) + draw.rect(GPU, 7, 2, 20, 1, barColor) + draw.rect(GPU, 6-bars1, 2, bars1, 1, mainColor) + draw.rect(GPU, 24, 8, bars1, 1, mainColor) + end + _, f, _ = GPU.get(2, 4) + if barAmount > 3 and f ~= mainColor then --Vertical + bars2 = math.max(0, math.min(7, barAmount-3)) + draw.rect(GPU, 2, 2, 1, 7, barColor) + draw.rect(GPU, 27, 2, 1, 7, barColor) + draw.rect(GPU, 3, 8, 20, 1, barColor) + draw.rect(GPU, 7, 2, 20, 1, barColor) + draw.rect(GPU, 2, 2, 1, bars2, mainColor) + draw.rect(GPU, 27, 9-bars2, 1, bars2, mainColor) + end + if barAmount > 10 then --Long Straight + local bars3 = math.max(0, barAmount-10) + draw.rect(GPU, 3, 8, 20, 1, barColor) + draw.rect(GPU, 7, 2, 20, 1, barColor) + draw.rect(GPU, 3, 8, bars3, 1, mainColor) + draw.rect(GPU, 27-bars3, 2, bars3, 1, mainColor) + end + progressString = tostring(math.floor(machine.getWorkProgress()/20)).."/"..tostring(math.floor(machine.getWorkMaxProgress()/20)).."s" + middlePoint = math.min(9, 12-#progressString/2) + draw.rect(GPU, 18, 5, 8, 2, background) + draw.text(GPU, 26-#progressString, 5, accentA, progressString) + + else --No work + _, f, _ = GPU.get(5, 1) + if f ~= barColor then + draw.rect(GPU, 18, 5, 8, 2, background) + draw.rect(GPU, 3, 2, 3, 1, barColor) + draw.rect(GPU, 2, 2, 1, 7, barColor) + draw.rect(GPU, 3, 8, 20, 1, barColor) + draw.rect(GPU, 24, 8, 3, 1, barColor) + draw.rect(GPU, 27, 2, 1, 7, barColor) + draw.rect(GPU, 7, 2, 20, 1, barColor) + end + end + _, f, _ = GPU.get(6, 1) + if ((windows[name].data == 0 or string.match(machine.getSensorInformation()[windows[name].data], ".*c0.*")) and machine.isWorkAllowed()) == true then + if f ~= background then + draw.rect(GPU, 6, 2, 1, 1, background) + draw.rect(GPU, 23, 8, 1, 1, background) + end + else + if(machine.isWorkAllowed()) then + if f ~= accentA then + draw.rect(GPU, 6, 2, 1, 1, accentA) + draw.rect(GPU, 23, 8, 1, 1, accentA) + end + else + if f ~= errorColor then + draw.rect(GPU, 6, 2, 1, 1, errorColor) + draw.rect(GPU, 23, 8, 1, 1, errorColor) + end + end + end + end +end + +function widgets.create(GPU, x, y, name, dataAddress, widget) + local width, height = widget.width, widget.height + local page = GPU.allocateBuffer(width, math.ceil(height/2)) + GPU.setActiveBuffer(page) + local widgetData = widget.initialize(GPU, name, dataAddress) + windows[name] = {GPU = GPU, page=page, address = dataAddress, x=x, y=y, w=width, h=height, update = widget.update, data = widgetData} + GPU.setActiveBuffer(0) +end + +GTMachine = {width = 28, height = 9, initialize = widgets.gtMachineInit, update = widgets.gtMachine} + +return widgets \ No newline at end of file diff --git a/Programs/Assembly Line/assemble.lua b/Programs/Assembly Line/assemble.lua new file mode 100644 index 0000000..883fbe3 --- /dev/null +++ b/Programs/Assembly Line/assemble.lua @@ -0,0 +1,280 @@ +comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread") +dict=require("dictionary"); line = require("transport"); config = require("configure") +function machine(address) + machineAddress = comp.get(address) + if(machineAddress ~= nil) then return comp.proxy(machineAddress) else return nil end +end +function findAddress(type) + for address, component in comp.list() do + if component == type then return address end + end +end +recipes = {} +fluidMap = {["fluid.molten.solderingalloy"] = {index = 81, size = 144}, + ["fluid.lubricant"] = {index = 80, size = 250}, + ["IC2 Coolant"] = {index = 79, size = 1000}, + ["fluid.molten.styrenebutadienerubber"] = {index = 78, size = 720}, + ["fluid.molten.niobiumtitanium"] = {index = 77, size = 144}, + ["fluid.molten.tritanium"] = {index = 76, size = 144} +} +local function addRecipe(slot, source, sourceSide) + if source.getStackInSlot(sourceSide, slot) ~= nil then + --screen.write("Adding a recipe\n") + local pattern = source.getStackInSlot(sourceSide, slot) + recipes[pattern.output] = {} + recipes[pattern.output]["label"] = pattern.output + recipes[pattern.output]["time"] = pattern.time + recipes[pattern.output]["inputs"] = 0 + recipes[pattern.output]["fluids"] = 0 + recipes[pattern.output]["tier"] = voltageToTier(pattern.eu) + if pattern.inputItems ~= nil then + local items = pattern.inputItems + for i = 1, #items, 1 do + --screen.write("Item "..i.." :"..items[i][1].." - "..items[i][2].."\n") + recipes[pattern.output]["input"..i] = {name = items[i][1], amount = items[i][2]} + recipes[pattern.output]["inputs"] = recipes[pattern.output]["inputs"] + 1 + end + end + if pattern.inputFluids ~= nil then + local fluids = pattern.inputFluids + for i = 1, #fluids do + --screen.write("Fluid "..i.." :"..fluids[i][1].." - "..fluids[i][2].."\n") + recipes[pattern.output]["fluid"..i] = {name = fluids[i][1], amount = fluids[i][2]} + recipes[pattern.output]["fluids"] = recipes[pattern.output]["fluids"] + 1 + end + end + end +end +function getRecipes(assemblyData) + if assemblyData["data"] ~= nil then + for i = 1, 16 do + addRecipe(i, assemblyData["data"], 0) + end + end +end +function copyPattern(interface, slot, recipe, database) + for i = 1, recipe.inputs, 1 do + local item = recipe["input"..i] + local name = item.name + if dictionary[name] ~= nil then name = dictionary[name] end + interface.setInterfacePatternInput(slot, database, databaseMap[name], item.amount, i) + end +end +local latestRecipe = {} +function processRecipe(assemblyData, recipe) + local inventory, database = assemblyData["inventory"], assemblyData["database"] + local needsConfiguring = false + if latestRecipe ~= nil then + if latestRecipe.label ~= recipe.label then + needsConfiguring = true + if latestRecipe.inputs ~= nil then + if latestRecipe.inputs > recipe.inputs then + line.clearInterfaces(assemblyData, recipe.inputs + 1, latestRecipe.inputs, latestRecipe.fluids - recipe.fluids, 4) + elseif latestRecipe.fluids > recipe.fluids then + line.clearInterfaces(assemblyData, 0, 0, recipe.fluids + 1, latestRecipe.fluids) + end + end + end + else + needsConfiguring = true + end + if needsConfiguring then + for i = 1, recipe["inputs"], 1 do + local item = recipe["input"..i] + local name = item.name + if dictionary[name] ~= nil then name = dictionary[name] end + if databaseMap[name] == nil then screen.write(" Updating database..."); updateDatabase(assemblyData, databaseMap); end + assemblyData["input"..i].setInterfaceConfiguration(1, database.address, databaseMap[name], item.amount) + screen.write(".") + end + for i = 1, recipe["fluids"], 1 do + local fluid = recipe["fluid"..i] + assemblyData["fluid"..i].setInterfaceConfiguration(1, database.address, fluidMap[fluid.name].index, fluid.amount/fluidMap[fluid.name].size) + screen.write(".") + end + if assemblyData["input15"].getInterfacePattern(1) ~= nil then + copyPattern(assemblyData["input15"], 1, recipe, database.address) + end + end + screen.write(" Inserting ...") + for i = 1, recipe["inputs"], 1 do + local item = recipe["input"..i] + assemblyData["inputTransposer"..i].transferItem(0, 1, item.amount, 1, 16) + screen.write(".") + end + for i = 1, recipe["fluids"], 1 do + local fluid = recipe["fluid"..i] + assemblyData["fluidTransposer"..i].transferItem(0, 1, fluid.amount/fluidMap[fluid.name].size, 1, 1) + screen.write(".") + end + os.sleep(1) + for i = 1, recipe["fluids"], 1 do + local fluid = recipe["fluid"..i] + assemblyData["fluidTransposer"..i].transferItem(1, 0, fluid.amount/fluidMap[fluid.name].size, 2, 9) + screen.write(".") + end + local recipeTicks = (recipe.time / math.pow(2, assemblyData.tier - recipe.tier)) + if needsConfiguring == false then + os.sleep(recipeTicks / 20 - 1.5) + end + latestRecipe = recipe + line.waitForAssemblyline(recipeTicks - 50 , assemblyData["controller"]) +end +function matchRecipe(recipeList, assemblyData, priority) + priority = priority or nil + local network = assemblyData["items"].getItemsInNetwork() + local size = #network * 2 + if size == 0 then size = 1 end + foundItems = {} + for i = 1, #network, 1 do + foundItems[network[i].label] = network[i].size end + for i = 1, 15, 1 do + if assemblyData["inputTransposer"..i].getStackInSlot(0, 1) ~= nil then + local interfaceItem = assemblyData["inputTransposer"..i].getStackInSlot(0, 1) + if interfaceItem.size ~= nil then + if foundItems[interfaceItem.label] == nil then + foundItems[interfaceItem.label] = interfaceItem.size + else + foundItems[interfaceItem.label] = foundItems[interfaceItem.label] + interfaceItem.size + end + end + end + end + for recipeLabel, v in pairs(recipeList) do + local recipe, found = recipeList[recipeLabel], 0 + local inputs = recipe.inputs + if debugMode then screen.write("Checking match for: "..recipeLabel.." with required N of "..recipe.inputs.."\n") end + for i = 1, inputs, 1 do + local label, requiredAmount = recipe["input"..i].name, recipe["input"..i].amount + if dictionary[label] ~= nil then label = dictionary[label] end + if debugMode then screen.write(" Searching for "..requiredAmount.." "..label) end + if foundItems[label] == nil then if debugMode then screen.write("\n") end break + else + local existingAmount = foundItems[label] + if existingAmount >= requiredAmount then + found = found + 1 + if debugMode then screen.write(" | Found!: "..label.." N: "..found.."\n") end + else if debugMode then screen.write(" | Didn't find enough: "..existingAmount.."\n") end + end + end + end + if found == inputs then + if priority == nil then + return recipe + else + if priority.label == recipe.label then return recipe end + end + end + end + return nil +end +function voltageToTier(voltage) + local maxTier = 15 + local tier = maxTier + voltage = voltage - 1 + local tierVoltage = 32 * math.pow(4, tier - 1) + while voltage % tierVoltage == voltage do + tier = tier - 1 + tierVoltage = 32 * math.pow(4, tier - 1) + end + return tier + 1 +end +function getControllerTier(assemblyData) + local controller = assemblyData["controller"] + return voltageToTier(math.floor(string.gsub(string.sub(controller.getSensorInformation()[4], 1, string.find(controller.getSensorInformation()[4], "/")-1), "([^0-9]+)", "") + 0)) +end +function refreshDatabase(assemblyData, databaseRef) + local database = assemblyData["database"] + local i = 2 + local entry = database.get(i) + while database.get(i) ~= nil do + screen.write(".") + databaseRef[entry.label] = i + i = i + 1 + entry = database.get(i) + end +end +function updateDatabase(assemblyData, databaseMap) + local chestSide = 5 + if assemblyData["inventory"] ~= nil and assemblyData["database"] ~= nil then + local inventory, database = assemblyData["inventory"], assemblyData["database"] + for i = 1, inventory.getInventorySize(chestSide), 1 do + if inventory.getStackInSlot(chestSide, i) ~= nil then + inventory.store(chestSide, i, database.address, 1) + local hash = database.computeHash(1) + database.clear(1) + local index = database.indexOf(hash) + if index < 0 then + local j = 2 + while database.get(j) ~= nil do + j = j + 1 + end + inventory.store(chestSide, i, database.address, j) + databaseMap[inventory.getStackInSlot(chestSide, i).label] = j + end + end + end + end +end +function split(s, sep) + local fields = {}; local sep = sep or " "; local pattern = string.format("([^%s]+)", sep) + string.gsub(s, pattern, function(c) fields[#fields + 1] = c end) + return fields +end +function buildAssembly() + screen.write("Starting Assembly Line initalization...") + local assemblyStructure = {} + local file = io.open("addresses", "r") + if file == nil then + screen.write(" no address configuration found, configuring:\n") + config.getAddresses() + file = io.lines("addresses") + else + file = io.lines("addresses") + end + for line in file do + screen.write(".") + local tokens = split(line, ",") + assemblyStructure[tokens[1]] = machine(tokens[2]) + end + screen.write("\n") + return assemblyStructure +end +function startAssembly(assemblyData) + assemblyData["tier"] = getControllerTier(assemblyData) + screen.write("Fetching recipes ... "); getRecipes(assemblyData); screen.write("Done") + databaseMap = {} + screen.write(" | Refreshing database ..."); refreshDatabase(assemblyData, databaseMap); screen.write(" Done") + screen.write(" | Clearing interfaces ... "); line.clearInterfaces(assemblyData); screen.write("Done") + debugMode = false + local cyclesSinceRefresh = 0 + local configured = false + screen.write(" | Beginning operation\n") + while true do + local foundRecipe = matchRecipe(recipes, assemblyData) + if foundRecipe ~= nil then + screen.write("Starting assembly of "..foundRecipe.label.." ...") + processRecipe(assemblyData, foundRecipe) + screen.write(" Done!\n") + configured = true + else + if cyclesSinceRefresh > 20 then + getRecipes(assemblyData) + cyclesSinceRefresh = 0 + end + cyclesSinceRefresh = cyclesSinceRefresh + 1 + if configured then + configured = false + line.clearInterfaces(assemblyData) + latestRecipe = nil + end + os.sleep(5) + end + end +end +local assemblyLine = buildAssembly() +startAssembly(assemblyLine) + +--Things to add: +--Make pattern match check for item sums instead of on a stack basis +--Add sanity check that everything was moved 100% \ No newline at end of file diff --git a/Programs/Assembly Line/configure.lua b/Programs/Assembly Line/configure.lua new file mode 100644 index 0000000..e851997 --- /dev/null +++ b/Programs/Assembly Line/configure.lua @@ -0,0 +1,93 @@ +comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread") + +function findAccess(type) + for address, component in comp.list() do + if component == type then + if type ~= "me_interface" then + return address + else + if comp.proxy(address).getItemsInNetwork ~= nil then + return address + end + end + end + end + return nil +end +local configure = {} + +function configure.getAddresses() + local file = io.open("addresses", "w") + local a, b, c + for item = 1, 15, 1 do + screen.write("Add item interface "..item.." ") + a, b, c = event.pull() + while a ~= "component_added" do + a, b, c = event.pull() + os.sleep() + end + screen.write(b.."\n") + file:write("input"..item..","..b.."\n") + end + for fluid = 1, 4, 1 do + screen.write("Add fluid interface "..fluid.." ") + a, b, c = event.pull() + while a ~= "component_added" do + a, b, c = event.pull() + end + screen.write(b.."\n") + file:write("fluid"..fluid..","..b.."\n") + end + for itemTransposer = 1, 15, 1 do + screen.write("Add item transposer "..itemTransposer.." ") + a, b, c = event.pull() + while a ~= "component_added" do + a, b, c = event.pull() + os.sleep() + end + screen.write(b.."\n") + file:write("inputTransposer"..itemTransposer..","..b.."\n") + end + for fluidTransposer = 1, 4, 1 do + screen.write("Add fluid transposer "..fluidTransposer.." ") + a, b, c = event.pull() + while a ~= "component_added" do + a, b, c = event.pull() + end + screen.write(b.."\n") + file:write("fluidTransposer"..fluidTransposer..","..b.."\n") + end + screen.write("Add data access hatch ") + a, b, c = event.pull() + while a ~= "component_added" do + a, b, c = event.pull() + end + screen.write(b.."\n") + file:write("data,"..b.."\n") + + local networkAccess = findAccess("me_interface") + if networkAccess == nil then + screen.write("Can't find a valid interface! Exiting...\n") + os.exit() + else file:write("items,"..networkAccess.."\n") end + os.sleep(0.5) + local databaseAccess = comp.database + if databaseAccess == nil then + screen.write("Can't find a valid database! Exiting...\n") + os.exit() + else file:write("database,"..databaseAccess.address.."\n") end + + local chestAccess = comp.inventory_controller + if chestAccess == nil then + screen.write("Can't find a valid inventory controller! Exiting...\n") + os.exit() + else file:write("inventory,"..chestAccess.address.."\n") end + + local controller = comp.gt_machine + if controller == nil then + screen.write("Can't find a valid Assembly Line! Exiting...\n") + os.exit() + else file:write("controller,"..controller.address.."\n") end + screen.write("All done!\n") + end +return configure \ No newline at end of file diff --git a/Programs/Assembly Line/oreDict.lua b/Programs/Assembly Line/oreDict.lua new file mode 100644 index 0000000..9f2df0d --- /dev/null +++ b/Programs/Assembly Line/oreDict.lua @@ -0,0 +1,28 @@ +-- dictlist = { +-- {"Nanoprocessor Assembly","Quantumprocessor","Workstation"}, --EV +-- {"Crystalprocessor","Elite Nanocomputer","Quantumprocessor Assembly","Mainframe"}, --IV +-- {"Master Quantumcomputer","Wetwareprocessor","Crystalprocessor Assembly","Nanoprocessor Mainframe"}, -- LuV +-- {"Bioprocessor","Wetwareprocessor Assembly","Ultimate Crystalcomputer","Quantumprocessor Mainframe"}, --ZPM +-- {"Wetware Supercomputer","Bioprocessor Assembly","Crystalprocessor Mainframe"}, -- UV +-- {"Wetware Mainframe","Bioware Supercomputer"}, -- UHV +-- {"Bio Mainframe"} -- UEV +-- } + +dictlist = { + {"gt.metaitem.03.32083.name","gt.metaitem.03.32085.name","gt.metaitem.01.32704.name"}, --EV + {"gt.metaitem.03.32089.name","gt.metaitem.03.32086.name","gt.metaitem.03.32084.name","gt.metaitem.01.32705.name"}, --IV + {"gt.metaitem.03.32087.name","gt.metaitem.03.32092.name","gt.metaitem.03.32096.name","gt.metaitem.01.32706.name"}, -- LuV + {"gt.metaitem.03.32097.name","gt.metaitem.03.32093.name","gt.metaitem.03.32090.name","gt.metaitem.03.32088.name"}, --ZPM + {"gt.metaitem.03.32091.name"}, -- UV + {"gt.metaitem.03.32095.name","gt.metaitem.03.32099.name"}, -- UHV + {"gt.metaitem.03.32120.name"} -- UEV +} + +dictionary = { + ["gt.metaitem.01.32705.name"] = "gt.metaitem.03.32084.name", --IV + ["gt.metaitem.03.32086.name"] = "gt.metaitem.03.32084.name", + ["gt.metaitem.03.32089.name"] = "gt.metaitem.03.32084.name", + + ["gt.metaitem.03.32085.name"] = "gt.metaitem.03.32083.name", --EV + ["gt.metaitem.01.32704.name"] = "gt.metaitem.03.32083.name", +} \ No newline at end of file diff --git a/Programs/Assembly Line/transport.lua b/Programs/Assembly Line/transport.lua new file mode 100644 index 0000000..c745b5a --- /dev/null +++ b/Programs/Assembly Line/transport.lua @@ -0,0 +1,41 @@ +local comp=require("component"); local event=require("event"); local screen=require("term"); local computer = require("computer") + +local transport = {} + +function transport.waitForAssemblyline(time, assemblyController) + local startTime = computer.uptime() + --Wait for assembling to start + while not assemblyController.hasWork() and computer.uptime() < startTime + 10 do + os.sleep(0.3) + end + if not assemblyController.hasWork() then + screen.write(" Error with starting assembly!") + else + screen.write(" Process started ...") + local progress = assemblyController.getWorkMaxProgress() - assemblyController.getWorkProgress() + while computer.uptime() < (startTime + (time / 20)) and progress > 100 and assemblyController.hasWork() do + os.sleep(0.1) + progress = assemblyController.getWorkMaxProgress() - assemblyController.getWorkProgress() + end + end +end + +function transport.clearInterfaces(assemblyData, itemFrom, itemTo, fluidFrom, fluidTo) + itemFrom = itemFrom or 1 + itemTo = itemTo or 15 + fluidFrom = fluidFrom or 1 + fluidTo = fluidTo or 4 + local database = assemblyData["database"] + if itemFrom > 0 then + for i = itemFrom, itemTo, 1 do + if assemblyData["input"..i].getInterfaceConfiguration(1) ~= nil then assemblyData["input"..i].setInterfaceConfiguration(1, database.address, 1, 0) end + end + end + if fluidFrom > 0 then + for i = fluidFrom, fluidTo, 1 do + if assemblyData["fluid"..i].getInterfaceConfiguration(1) ~= nil then assemblyData["fluid"..i].setInterfaceConfiguration(1, database.address, 1, 0) end + end + end +end + +return transport \ No newline at end of file diff --git a/Programs/HUD/main.lua b/Programs/HUD/main.lua new file mode 100644 index 0000000..766ba4b --- /dev/null +++ b/Programs/HUD/main.lua @@ -0,0 +1,34 @@ +comp = require("component"); event = require("event") +AR = require("ARWidgets") +ARG = require("ARGraphics") +local wSampsa, hSampsa = 853, 473 +local powerHudX, powerHudY, powerHudW, powerHudH = 0, hSampsa-24, wSampsa*0.39+3, 14 +local glasses = comp.glasses +glasses.removeAll() +AR.minimapOverlay(glasses); AR.hudOverlayBase(glasses, 335, 449); AR.clear(); +AR.crossHair(glasses, 422, 231) +screen.clear() +while true do + AR.powerDisplay(glasses, comp.gt_machine, powerHudX, powerHudY, powerHudW, powerHudH) + AR.fluidMonitor(glasses, 795, 153, { + [0] = {label = "Oxygen Gas", displayName = "Oxygen", color = 0x688690, max = 128}, + [1] = {label = "Nitrogen Gas", displayName = "Nitrogen", color = 0x976868, max = 128}, + [2] = {label = "Hydrogen Gas", displayName = "Hydrogen", color = 0xa78282, max = 128}, + [3] = {label = "fluid.chlorine", displayName = "Chlorine", color = 0x428282, max = 128}, + [4] = {label = "fluid.radon", displayName = "Radon", color = 0xff5bff, max = 2}, + [5] = {label = "UU-Matter", displayName = "UU Matter", color = 0x4a0946, max = 2}, + [6] = {label = "fluid.molten.plastic", displayName = "Rubber", color = 0x050505, max = 2}, + [7] = {label = "fluid.molten.polytetrafluoroethylene", displayName = "PTFE", color = 0x4d4d4d, max = 2}, + [8] = {label = "fluid.molten.styrenebutadienerubber", displayName = "SBR", color = 0x1d1817, max = 2}, + [9] = {label = "fluid.molten.epoxid", displayName = "Epoxid", color = 0x9d6f13, max = 2}, + [10] = {label = "fluid.molten.silicone", displayName = "Silicone Rubber", color = 0xa5a5a5, max = 2}, + [11] = {label = "fluid.molten.polybenzimidazole", displayName = "PBI", color = 0x262626, max = 2} + } + ) + os.sleep() +end + +--Widget ideas: +-- Charge level indicator for everything +-- Inventory fill level monitoring +-- Maintenance Monitoring diff --git a/Programs/HUD/ticker.lua b/Programs/HUD/ticker.lua new file mode 100644 index 0000000..1e1fc79 --- /dev/null +++ b/Programs/HUD/ticker.lua @@ -0,0 +1,6 @@ +comp = require("component"); event = require("event") +AR = require("ARWidgets") + +while true do + AR.itemTicker(comp.glasses, 348, 0, 380) +end \ No newline at end of file diff --git a/Programs/HUD/tps.lua b/Programs/HUD/tps.lua new file mode 100644 index 0000000..b4fc938 --- /dev/null +++ b/Programs/HUD/tps.lua @@ -0,0 +1,7 @@ +comp = require("component"); event = require("event") +AR = require("ARWidgets") + +while true do + AR.displayTPS(comp.glasses, 0, 0) + AR.cpuMonitor(comp.glasses, 520, 449) +end \ No newline at end of file diff --git a/Programs/Nuclear Control/control.lua b/Programs/Nuclear Control/control.lua new file mode 100644 index 0000000..845a29b --- /dev/null +++ b/Programs/Nuclear Control/control.lua @@ -0,0 +1,54 @@ +comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread") + +local GPU = comp.gpu +GPU.setResolution(54, 26) +function enableReactors() + comp.redstone.setOutput(1, 15) +end +function disableReactors() + comp.redstone.setOutput(1, 0) +end + +function checkHeatLevels() + screen.setCursor(1, 1) + local i = 1 + for address, type in pairs(comp.list()) do + if type == "reactor_chamber" then + screen.write("Reactor "..i) + if i < 10 then screen.write(" ") end + local reactor = comp.proxy(address) + if reactor.getHeat() > 0 then + GPU.setForeground(0xFF0000) + screen.write(" REACTOR HEATING! SHUTTING DOWN") + disableReactors() + GPU.setForeground(0xFFFFFF) + os.sleep(1) + os.exit() + else + if reactor.getReactorEUOutput() > 0 then + screen.write(" status: ") + GPU.setForeground(0x00FF00) + screen.write("NOMINAL") + GPU.setForeground(0xFFFFFF) + screen.write(" - Producing ") + GPU.setForeground(0xFF00FF) + screen.write(math.floor(reactor.getReactorEUOutput())) + GPU.setForeground(0xFFFFFF) + screen.write(" EU/t\n") + else + screen.write(" status: ") + GPU.setForeground(0xFFFF00) + screen.write("INACTIVE\n") + end + end + i = i + 1 + end + end +end + +enableReactors() +screen.clear() +while true do + checkHeatLevels() + os.sleep(1) +end \ No newline at end of file diff --git a/Programs/Spatial Teleporter/destination.lua b/Programs/Spatial Teleporter/destination.lua new file mode 100644 index 0000000..0ccb639 --- /dev/null +++ b/Programs/Spatial Teleporter/destination.lua @@ -0,0 +1,72 @@ +destinations = { + [1] = {name = "Earth", id = 3001, color = 0xFF0022}, + [2] = {name = "Pluto", id = 3002, color = 0x22FF00}, + [3] = {name = "Venus", id = 3003}, + [4] = {name = "Piky's Base", id = 2000, color = 0xFF7800}, + [5] = {name = "Test", id = 3004}, + [6] = {name = "Test", id = 3004} +} + +local comp=require("component"); local event=require("event"); local screen=require("term"); local computer = require("computer") +local util = require("utility"); local draw=require("graphics") +local GPU = comp.gpu +GPU.setResolution(80, 25) + +local boundingBoxes = { +} +function createDestination(x, y, index) + local width, height = 18, 6 + local page = GPU.allocateBuffer(width, math.ceil(height/2)) + GPU.setActiveBuffer(page) + draw.rect(GPU, 1, 1, 18, 6, 0x111111) + local destinationColor = destinations[index].color or 0x0055FF + draw.rect(GPU, 3, 3, 14, 2, 0x000000) + draw.centeredText(GPU, 10, 3, destinationColor ,destinations[index].name) + windows[index] = {GPU = GPU, page=page, address = "", x=x, y=y, w=width, h=height} + GPU.setActiveBuffer(0) +end +function setDestination(code) + for address, type in pairs(comp.list()) do + if type == "ender_chest" then + util.machine(address).setFrequency(code) + end + end +end +function checkClick(_, address, x, y, button, name) + for i = 1, #boundingBoxes, 1 do + local xb, yb = boundingBoxes[i].x, math.ceil(boundingBoxes[i].y / 2) + if x >= xb and x < xb + 21 and y >= yb and y < yb + 3 then + draw.rect(GPU, boundingBoxes[i].x+2, boundingBoxes[i].y+2, 14, 2, 0x00CC00) + local destinationColor = destinations[i].color or 0x0055FF + setDestination(destinations[i].id) + draw.rect(GPU, 30, 43, 22, 2, 0x000000) + draw.centeredText(GPU, 40, 43, destinationColor, destinations[i].name) + event.timer(0.2, draw.update) + return i + end + end +end +function addBoundingBox(index) + boundingBoxes[index] = {x = 2 + ((index - 1) % 5) * 20, y = 3 + math.floor((index - 1) / 4) * 8} +end +function getDestination() + for address, type in pairs(comp.list()) do + if type == "ender_chest" then + return util.machine(address).getFrequency() + end + end +end +event.listen("touch", checkClick) +GPU.freeAllBuffers() +GPU.fill(0, 0, 100, 100, " ") +draw.rect(GPU, 28, 41, 26, 6, 0x111111) +draw.rect(GPU, 30, 43, 22, 2, 0x000000) +draw.text(GPU, 31, 39, 0xFFFFFF, "Current Destination") +for i = 1 , #destinations, 1 do + addBoundingBox(i) + createDestination(boundingBoxes[i].x, boundingBoxes[i].y, i) + draw.update() +end +while true do + os.sleep() +end \ No newline at end of file diff --git a/Programs/Spatial Teleporter/spatial.lua b/Programs/Spatial Teleporter/spatial.lua new file mode 100644 index 0000000..bc22d86 --- /dev/null +++ b/Programs/Spatial Teleporter/spatial.lua @@ -0,0 +1,124 @@ +local comp=require("component"); local event=require("event"); local screen=require("term"); local computer = require("computer") + +function cycle() + comp.redstone.setOutput(2, 15) + os.sleep(1) + comp.redstone.setOutput(2, 0) +end + +comp.gpu.setResolution(80, 40) + +local incoming = 4 +local sending = 3 +local controller = 5 +local ticket = 1 +--while true do +-- a, b, c = event.pull() +-- if a == "walk" then +-- screen.write("Screen walked on") +-- end +--end + +function setDestination(destination) + +end + +function unload(index) + local transposer = comp.transposer + if transposer.getStackInSlot(controller, 1) ~= nil then + --Using a return ticket + cycle() + os.sleep(0.2) + --Move cell out of the way + transposer.transferItem(controller, incoming, 1, 2, 27) + os.sleep(0.2) + --Insert incoming arrival + transposer.transferItem(incoming, controller, 1, index, 1) + os.sleep(0.2) + --Unload arrival + cycle() + os.sleep(0.2) + --Return ticket + transposer.transferItem(controller, ticket, 1, 2, 1) + --Return operating cell + transposer.transferItem(incoming, controller, 1, 27, 1) + else + --Normal operation + transposer.transferItem(incoming, controller, 1, index, 1) + end +end +function copyWindow(GPU, x, y, page, destination) + destination = 0 or destination + GPU.bitblt(destination, x, y, 160, 46, page, 1, 1) +end +windows = {} +function doStartupSequence() + local gpu = comp.gpu + gpu.freeAllBuffers() + local colors = { + [0] = 0x00a6ff, + [1] = 0x000000} + local buffer = gpu.allocateBuffer() + gpu.setActiveBuffer(buffer) + for i = 2, 20, 1 do + if i % 2 == 0 then + copyWindow(gpu, 0, 0, buffer, 0) + end + gpu.setForeground(colors[i % 2]) + comp.gpu.fill(2 + i * 2, + 1 + i, + 80 - i * 4, + 40 - i * 2, + "█") + os.sleep(0.1) + end + gpu.setActiveBuffer(0) + os.sleep(0.5) + gpu.setForeground(0x000000) + gpu.fill(0, 0, 100, 50, "█") + gpu.setForeground(0xFFFFFF) +end +local starting = false +function send() + local transposer = comp.transposer + if transposer.getStackInSlot(controller, 1) == nil then + --screen.write("The operating cell is missing!\n") + else + doStartupSequence() + cycle() + os.sleep(0.2) + transposer.transferItem(controller, sending, 1, 2, 1) + end +end +function checkArrivals() + local transposer = comp.transposer + for i = 1, 26 do + if transposer.getStackInSlot(incoming, i) ~= nil then + return i + end + end + return 0 +end +local lastActivation = 0 +function setStarting() + starting = false +end +function activateTeleporter() + if starting == false then + starting = true + send() + event.timer(10, setStarting) + end + lastActivation = computer.uptime() +end +event.listen("walk", activateTeleporter) +comp.gpu.fill(0, 0, 100, 50, " ") +while true do + local arrival = checkArrivals() + if arrival ~= 0 then + starting = true + event.timer(10, setStarting) + unload(arrival) + end + os.sleep(0.5) +end diff --git a/Programs/armorCharger.lua b/Programs/armorCharger.lua new file mode 100644 index 0000000..20c9bfe --- /dev/null +++ b/Programs/armorCharger.lua @@ -0,0 +1,10 @@ +comp = require("component"); event = require("event") + +local transposer = comp.transposer +local dark = 2 +local charger = 3 +function swap() + transposer.transferItem(dark, charger, 1, 39, 5) + transposer.transferItem(charger, dark, 1, 1, 39) + transposer.transferItem(charger, charger, 1, 5, 1) +end \ No newline at end of file diff --git a/Programs/biovat.lua b/Programs/biovat.lua new file mode 100644 index 0000000..a916718 --- /dev/null +++ b/Programs/biovat.lua @@ -0,0 +1,57 @@ +local comp=require("component"); local event=require("event"); local screen=require("term"); local computer = require("computer") + +local transposers = {} +function configureTransposers() + for address, type in pairs(comp.list()) do + if type == "transposer" then + local transposer = comp.proxy(comp.get(address)) + local foundTanks = {} + for side = 0, 5, 1 do + if transposer.getTankCapacity(side) > 0 then + foundTanks[#foundTanks + 1] = {side = side, capacity = transposer.getTankCapacity(side)} + end + end + if #foundTanks == 2 then + if foundTanks[1].capacity > foundTanks[2].capacity then + transposers[address] = {source = foundTanks[2].side, sink = foundTanks[1].side} + else + transposers[address] = {source = foundTanks[1].side, sink = foundTanks[2].side} + end + else + screen.write("Some transposers have more than two tanks! FIX IT!\n") + end + end + end + screen.write("Found "..countTransposers().." output hatches to keep at 50%\n") +end +function countTransposers() + local count = 0 + for address, type in pairs(comp.list()) do + if type == "transposer" then + count = count + 1 + end + end + return count +end +function tick() + for address, sides in pairs(transposers) do + local transposer = comp.proxy(comp.get(address)) + local sourceCurrent, sourceMax = transposer.getTankLevel(sides.source), transposer.getTankCapacity(sides.source) + if sourceCurrent / sourceMax > 0.5 then + local fluidToRemove = sourceCurrent - sourceMax / 2 + transposer.transferFluid(sides.source, sides.sink, fluidToRemove) + end + end +end +configureTransposers() +local count = countTransposers() +local tempCount = 0 +while true do + tempCount = countTransposers() + if count ~= tempCount then + configureTransposers() + end + count = tempCount + tick() + os.sleep() +end \ No newline at end of file diff --git a/codesilo.lua b/codesilo.lua new file mode 100644 index 0000000..78ed3ec --- /dev/null +++ b/codesilo.lua @@ -0,0 +1,55 @@ +comp = require("component"); event = require("event") +ARG = require("ARGraphics"); get = require("easy"); config = require("config") +comp.glasses.removeAll() +local initializeCpuMonitor = true +local cpuLights = {} +local function cpuMonitor(glasses, x, y) + if initializeCpuMonitor then + local base = ARG.hudRectangle(glasses, x, y, 28, 24, hudColour) + local topStrip = ARG.hudRectangle(glasses, x, y, 500, 3, hudColour) + local itemBorder1 = ARG.hudRectangle(glasses, x+28, y+3, 1, 21, workingColour, 0.8) + local itemBorder2 = ARG.hudRectangle(glasses, x+28, y+3, 61, 1, workingColour, 0.8) + local itemBorder3 = ARG.hudRectangle(glasses, x+88, y+3, 1, 21, workingColour, 0.8) + local itemBorder4 = ARG.hudRectangle(glasses, x+28, y+23, 61, 1, workingColour, 0.8) + local cpuBase1 = ARG.hudRectangle(glasses, x+89, y, 5, 24, hudColour) + local cpuBase2 = ARG.hudRectangle(glasses, x+94, y+12, 8, 12, hudColour) + local cpuSplitter = ARG.hudRectangle(glasses, x+89, y+9, 400, 3, hudColour) + local cpuSplitter2 = ARG.hudRectangle(glasses, x+102, y+18, 380, 6, hudColour) + local function createCpuIndicator(cpuX, cpuY) + local status = ARG.hudQuad(glasses, {cpuX, cpuY}, {cpuX+6, cpuY+6}, {cpuX+16, cpuY+6}, {cpuX+10, cpuY}, hudColour, 1.0) + local leftTriangle = ARG.hudTriangle(glasses, {cpuX, cpuY}, {cpuX, cpuY+6}, {cpuX+6, cpuY+6}, hudColour) + local rightTriangle = ARG.hudQuad(glasses, {cpuX+10, cpuY}, {cpuX+16, cpuY+6}, {cpuX+18, cpuY+6}, {cpuX+18, cpuY}, hudColour) + return status + end + local i = 0 + local j = 0 + local cpuNumber = 1 + while i+j < 24 do + if (i+j) % 2 == 1 then + cpuLights[cpuNumber] = createCpuIndicator(x+102+j*17, y+12) + j = j + 1 + else + cpuLights[cpuNumber] = createCpuIndicator(x+94+i*17, y+3) + i = i + 1 + end + cpuNumber = cpuNumber + 1 + end + local rowStop1 = ARG.hudRectangle(glasses, x+94+i*17, y+3, 300, 6, hudColour) + local rowStop2 = ARG.hudRectangle(glasses, x+102+j*17, y+12, 300, 6, hudColour) + local horizontalStrip = ARG.hudRectangle(glasses, x+100, y+22, 210, 1, workingColour) + local diagonalStrip = ARG.hudQuad(glasses, {x+89, y+11}, {x+89, y+12}, {x+100, y+23}, {x+100, y+22}, workingColour) + initializeCpuMonitor = false + end + local cpus = comp.me_interface.getCpus() + for i = 1, #cpus, 1 do + if cpus[i].busy then + cpuLights[i].setColor(ARG.hexToRGB(positiveEUColour)) + else + cpuLights[i].setAlpha(0.7) + cpuLights[i].setColor(ARG.hexToRGB(workingColour)) + end + end +end +while true do + cpuMonitor(comp.glasses, 520, 449) +end \ No newline at end of file diff --git a/codesilo2.lua b/codesilo2.lua new file mode 100644 index 0000000..5920623 --- /dev/null +++ b/codesilo2.lua @@ -0,0 +1,48 @@ +comp = require("component"); event = require("event") +ARG = require("ARGraphics"); get = require("easy"); config = require("config") +ARW = require("ARWidgets") + +function popupText(glasses, text, x, y, color) + local substringLength = 1 + local width = #text * 5 + local steps = math.ceil(#text / substringLength) + local stepLength = substringLength * 5 + local i = 1 + local background = ARG.hudQuad(glasses, {x-5, y}, {x-5, y+9}, {x-5+1, y+9}, {x-5+1, y}, machineBackground, 0.5) + local top = ARG.hudQuad(glasses, {x-5, y-1}, {x-5, y}, {x-5+1, y}, {x-5+1, y-1}, machineBackground) + local bottom = ARG.hudQuad(glasses, {x-5, y+9}, {x-5, y+10}, {x-5+1, y+10}, {x-5+1, y+9}, machineBackground) + local hudText = ARG.hudText(glasses, "", x+1, y+1, color) + local wedge = ARG.hudQuad(glasses, {x-5-10, y-1}, {x-5, y-1}, {x-5, y+10}, {x-5+11, y+10}, machineBackground) + local direction = 1 + local function advance() + background.setVertex(3, math.min(width + 10, x + stepLength * i + 10), y+9) + background.setVertex(4, math.min(width, x + stepLength * i), y) + top.setVertex(3, math.min(width, x + stepLength * i), y) + top.setVertex(4, math.min(width, x + stepLength * i), y-1) + bottom.setVertex(3, math.min(width + 10, x + stepLength * i + 10), y+10) + bottom.setVertex(4, math.min(width + 10, x + stepLength * i + 10), y+9) + wedge.setVertex(1, math.min(width-1, x + stepLength * i-1), y-1) + wedge.setVertex(2, math.min(width + 10, x + stepLength * i + 10), y+10) + wedge.setVertex(3, math.min(width + 11, x + stepLength * i + 11), y+10) + wedge.setVertex(4, math.min(width + 1, x + stepLength * i + 1), y-1) + hudText.setText(string.sub(text, 1, substringLength * i)) + i = i + direction + if i < 0 then + glasses.removeObject(background.getID()) + glasses.removeObject(top.getID()) + glasses.removeObject(bottom.getID()) + glasses.removeObject(hudText.getID()) + glasses.removeObject(wedge.getID()) + end + end + local function retract() + direction = -1 + event.timer(0.03, advance, steps+2) + end + event.timer(0.03, advance, steps) + return retract +end + +a = popupText(comp.glasses, "Made by Sampsa ", 0, 50, workingColour) +b = popupText(comp.glasses, "Widget breakdown in comments!", 0, 65, workingColour) +c = popupText(comp.glasses, "+ github!", 0, 80, workingColour) \ No newline at end of file diff --git a/test.lua b/test.lua new file mode 100644 index 0000000..aa46f2b --- /dev/null +++ b/test.lua @@ -0,0 +1,41 @@ +comp = require("component"); event = require("event") +AR = require("ARWidgets") +ARG = require("ARGraphics") +local wSampsa, hSampsa = 853, 473 +local powerHudX, powerHudY, powerHudW, powerHudH = 0, hSampsa-24, wSampsa*0.39+3, 14 +comp.glasses.removeAll() +AR.minimapOverlay(comp.glasses); AR.hudOverlayBase(comp.glasses, wSampsa, hSampsa); AR.clear(); +screen.clear() +while true do + AR.powerDisplay(comp.glasses, comp.gt_machine, powerHudX, powerHudY, powerHudW, powerHudH) + AR.fluidMonitor(comp.glasses, 795, 153, { + [0] = {label = "Oxygen Gas", displayName = "Oxygen", color = 0x688690, max = 128}, + [1] = {label = "Nitrogen Gas", displayName = "Nitrogen", color = 0x976868, max = 128}, + [2] = {label = "Hydrogen Gas", displayName = "Hydrogen", color = 0xa78282, max = 128}, + [3] = {label = "fluid.chlorine", displayName = "Chlorine", color = 0x428282, max = 128}, + [4] = {label = "fluid.radon", displayName = "Radon", color = 0xff5bff, max = 2}, + [5] = {label = "UU-Matter", displayName = "UU Matter", color = 0x4a0946, max = 2}, + [6] = {label = "fluid.molten.plastic", displayName = "Rubber", color = 0x050505, max = 2}, + [7] = {label = "fluid.molten.polytetrafluoroethylene", displayName = "PTFE", color = 0x4d4d4d, max = 2}, + [8] = {label = "fluid.molten.styrenebutadienerubber", displayName = "SBR", color = 0x1d1817, max = 2}, + [9] = {label = "fluid.molten.epoxid", displayName = "Epoxid", color = 0x9d6f13, max = 2}, + [10] = {label = "fluid.molten.silicone", displayName = "Silicone Rubber", color = 0xa5a5a5, max = 2}, + [11] = {label = "fluid.molten.polybenzimidazole", displayName = "PBI", color = 0x262626, max = 2} + } + ) + os.sleep() +end + +while true do + itemTicker(comp.glasses, 348, 0, 380) +end + +--Widget ideas: +-- Charge level indicator for everything +-- Inventory fill level monitoring +-- Autocrafting CPU usage +-- Item stocker script +-- Maintenance Monitoring +-- Total amount of items in AE +-- Total amount of craftables +-- Total amount of unique items \ No newline at end of file