diff --git a/Libraries/ARGraphics.lua b/Libraries/ARGraphics.lua index d3a7d54..2ee7b3a 100644 --- a/Libraries/ARGraphics.lua +++ b/Libraries/ARGraphics.lua @@ -1,42 +1,54 @@ -comp = require("component"); screen = require("term"); computer = require("computer"); event = require("event") +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 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) +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 + 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) + 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 + 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) + 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 + 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.setColor(hexToRGB(color)) + text.setAlpha(alpha) + text.setScale(scale) text.setText(name) return text end @@ -44,24 +56,33 @@ 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]) + 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]) + 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) + rect.setPosition(x, y) + rect.setSize(h, w) + rect.setColor(hexToRGB(color)) + rect.setAlpha(alpha) return rect end @@ -70,7 +91,7 @@ function AR.textSize(textObject, scale) oldX = oldX * textObject.getScale() oldY = oldY * textObject.getScale() textObject.setScale(scale) - textObject.setPosition(oldX/(scale+1), oldY/(scale+1)) + textObject.setPosition(oldX / (scale + 1), oldY / (scale + 1)) end function AR.hudText(glasses, displayText, x, y, color, scale) @@ -83,4 +104,4 @@ function AR.hudText(glasses, displayText, x, y, color, scale) return text end -return AR \ No newline at end of file +return AR diff --git a/Libraries/ARWidgets.lua b/Libraries/ARWidgets.lua index 67f2e9b..0b70fde 100644 --- a/Libraries/ARWidgets.lua +++ b/Libraries/ARWidgets.lua @@ -1,81 +1,110 @@ -comp=require("component");screen=require("term");computer=require("computer");event=require("event"); thread = require("thread") -get=require("easy"); ARG=require("ARGraphics") +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 euUpdateInterval = 120 local readings = {} local function updateEU(LSC) batteryBuffer = batteryBuffer or false - if counter == 1 then firstRead = computer.uptime() end + 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 + lastRead = computer.uptime() + ticks = math.ceil((lastRead - firstRead) * 20) + currentIO = math.floor((readings[euUpdateInterval - 1] - readings[1]) / ticks) + counter = 1 end - 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) + 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 + 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) + 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) + 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)) + fillTime = math.floor((maxEU - currentEU) / (currentIO * 20)) fillTimeString = "Full: " .. get.time(math.abs(fillTime)) - else - fillTime = math.floor((currentEU)/(currentIO*20)) + 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") + 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") + currentEnergyObj.setText(get.splitNumber(maxEU) .. " EU") percentageObj.setText(get.getPercent(1.0)) else - currentEnergyObj.setText(get.splitNumber(currentEU).." EU") + currentEnergyObj.setText(get.splitNumber(currentEU) .. " EU") percentageObj.setText(get.getPercent(percentage)) end if currentIO >= 0 then - currentFillrateObj.setText("+"..get.splitNumber(currentIO).." EU/t") + 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") + currentFillrateObj.setText(get.splitNumber(currentIO) .. " EU/t") end if percentage < 0.985 then timeObj.setText(fillTimeString) @@ -85,17 +114,17 @@ function ARWidgets.powerDisplay(glasses, data, x, y, w, h) 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); + 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); + 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, 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 @@ -108,28 +137,30 @@ function ARWidgets.minimapOverlay(glasses) 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) + 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) + 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 @@ -137,23 +168,40 @@ function popupText(glasses, text, x, y, color) 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 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(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) + 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 @@ -166,7 +214,7 @@ function popupText(glasses, text, x, y, color) end local function retract() direction = -1 - event.timer(0.03, advance, steps+2) + event.timer(0.03, advance, steps + 2) end event.timer(0.03, advance, steps) return retract @@ -181,25 +229,107 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap) 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 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) + 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) + 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) + 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) + 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 @@ -212,7 +342,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap) 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) + fillQuad.setVertex(2, x + w - fillPercentage * (w + 8), y + 8 + i * h) end lastRefresh = computer.uptime() end @@ -220,8 +350,12 @@ end local function refreshDatabase(itemList) local filteredList = {} for i = 1, #itemList, 1 do - if i % 200 == 0 then os.sleep() end - if itemList[i].size >= 100 then filteredList[itemList[i].label] = itemList[i].size end + if i % 200 == 0 then + os.sleep() + end + if itemList[i].size >= 100 then + filteredList[itemList[i].label] = itemList[i].size + end itemList[i] = nil end return filteredList @@ -230,14 +364,21 @@ 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 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 - local textLength = #text*5 + local textLength = #text * 5 local textRemaining = #text local textToRemove = #text local function truncate() @@ -266,10 +407,18 @@ local function rollingText(glasses, text, start, stop, y, color) 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 + 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 @@ -279,7 +428,7 @@ function difference(new) 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} + differenceArray[#differenceArray + 1] = {label, new[label] - amount} end end end @@ -293,49 +442,56 @@ 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" + return string.sub(millions, 1, 5) .. "M" else - return string.sub(millions, 1, 4).."M" + return string.sub(millions, 1, 4) .. "M" end end local function getTotalItemCount(items) local sum = 0 for i = 1, #items, 1 do - if i % 200 == 0 then os.sleep() end + if i % 200 == 0 then + os.sleep() + end 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) + 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) + 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) + 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) + rollingText(glasses, "+" .. amount, x + w, x, y + 4, positiveEUColour) else - rollingText(glasses, ""..amount, x+w, x, y+4, negativeEUColour) + rollingText(glasses, "" .. amount, x + w, x, y + 4, negativeEUColour) end end event.timer(#name * 0.12, showChange, 1) @@ -351,9 +507,9 @@ function ARWidgets.itemTicker(glasses, x, y, w) 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) + totalItems.setText("Total: " .. formatMillions(getTotalItemCount(allItems))) + patterns.setText("Patterns: " .. craftables) + uniqueItems.setText("Unique: " .. itemsInNetwork) changedItems = difference(refreshDatabase(allItems)) i = 1 clearTicker(glasses) @@ -361,43 +517,69 @@ function ARWidgets.itemTicker(glasses, x, y, w) 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) + 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 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) + 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) + 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) + 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) + 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() @@ -415,27 +597,30 @@ 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 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) + 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 = math.min(20.00, get.tps()) if tps > 15 then - TPSText.setText("TPS: "..string.sub(tps, 1, 5)) + 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.setText("TPS: " .. string.sub(tps, 1, 5)) TPSText.setColor(ARG.hexToRGB(workingColour)) else - TPSText.setText("TPS: "..string.sub(tps, 1, 4)) + TPSText.setText("TPS: " .. string.sub(tps, 1, 4)) TPSText.setColor(ARG.hexToRGB(negativeEUColour)) end end @@ -450,4 +635,4 @@ function ARWidgets.clear() lastUpdate = computer.uptime() - 60 end -return ARWidgets \ No newline at end of file +return ARWidgets diff --git a/Libraries/config.lua b/Libraries/config.lua index 674ccae..a4da859 100644 --- a/Libraries/config.lua +++ b/Libraries/config.lua @@ -1,7 +1,11 @@ -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 +machineBackground = 0x121010 +progressBackground = 0x272c2e +labelColour = 0xFF00FF +errorColour = 0xFF0000 +idleColour = 0xb300ff +workingColour = 0x00a6ff +positiveEUColour = 0x00CC00 +negativeEUColour = 0xCC0000 +timeColour = 0x5500FF +textColor = 0x000000 +hudColour = 0x1E1E28 diff --git a/Libraries/graphics.lua b/Libraries/graphics.lua index 733c0b7..238ae8d 100644 --- a/Libraries/graphics.lua +++ b/Libraries/graphics.lua @@ -1,28 +1,34 @@ -comp = require("component"); +comp = require("component") color = { - red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF, - purple = 0x5500FF, cyan = 0x00A6FF, lightGreen = 0x00CC00, - lightGray = 0x272c2e, darkGray = 0x121010, white = 0x000000 + 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) + 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, "▀"); + GPU.set(x, screenY, "▀") else --Lower half of pixel - GPU.set(x, screenY, "▄"); + 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 + local hLeft = h + if x > 0 and y > 0 then if y % 2 == 0 then - for i = x, x+w-1 do + for i = x, x + w - 1 do pixel(GPU, i, y, color) end hLeft = hLeft - 1 @@ -30,50 +36,56 @@ function graphics.rect(GPU, x, y, w, h, color) 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) + 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, "█") + 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) + 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)) + 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)) + if y % 2 == 0 then + error("Text position must be odd on y axis") end - GPU.setBackground(oldBackground); GPU.setForeground(oldForeground) + 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) + 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 currentWindows = {} function graphics.checkCollision(GPU, 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 + 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 @@ -81,8 +93,8 @@ function graphics.checkCollision(GPU, x, y) return nil end function graphics.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, GPU = GPU} + local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2)) + currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height, GPU = GPU} return pageNumber end local function copyWindow(GPU, x, y, page, destination) @@ -116,4 +128,4 @@ function graphics.clear() currentWindows = {} end -return graphics \ No newline at end of file +return graphics diff --git a/Libraries/gui.lua b/Libraries/gui.lua index 30db74c..b8f92bf 100644 --- a/Libraries/gui.lua +++ b/Libraries/gui.lua @@ -1,5 +1,9 @@ -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 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 = {} @@ -7,8 +11,8 @@ 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 + 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 @@ -18,38 +22,42 @@ end local contextMenus = 0 - function contextMenu(GPU, x, y, data) - function filterClicks(event) return event == "touch" end + 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 + if #data > longestData then + longestData = #data + end end - local contextWindow = createWindow(GPU, longestData, #data*2, "ContextMenu"..contextMenus) + local contextWindow = createWindow(GPU, longestData, #data * 2, "ContextMenu" .. contextMenus) GPU.setActiveBuffer(contextWindow) - draw.rect(GPU, 1, 1, longestData, #data*2, color.lightGray) + 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]) + draw.text(GPU, 1, 1 + i * 2 - 2, color.cyan, data[i]) end - currentWindows["ContextMenu"..contextMenus].x = x - currentWindows["ContextMenu"..contextMenus].y = y + 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 == "." then + quit = true + end if value == "e" then if editing then editing = false else - editing = true end + editing = true + end end - end return event.listen("key_up", processKey) end @@ -62,9 +70,15 @@ function processCommand(GPU, window, option) 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 + 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 @@ -72,26 +86,29 @@ 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) + 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"}) + 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) + 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 + currentWindows["ContextMenu" .. j] = nil end contextMenus = 0 end else - if activeWindow ~= "None " then end - xOffset = x - currentWindows[activeWindow].x - yOffset = y - currentWindows[activeWindow].y + if activeWindow ~= "None " then + end + xOffset = x - currentWindows[activeWindow].x + yOffset = y - currentWindows[activeWindow].y end end end @@ -111,29 +128,31 @@ 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} + 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 + 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 + if inContextMenu then local cont = currentWindows["ContextMenu1"] - copyWindow(GPU, cont.x, cont.y, cont.page) end + copyWindow(GPU, cont.x, cont.y, cont.page) + end GPU.setActiveBuffer(0) end @@ -144,7 +163,9 @@ end --return gui -GPU = comp.proxy(comp.get("de837fec")); screen = comp.get("48ce2988"); GPU.bind(screen); +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") @@ -162,7 +183,10 @@ GPU.setActiveBuffer(0) copyWindow(GPU, 1, 1, currentWindows["Black"].page) while true do - if quit then event.cancel(keyInput); break end + if quit then + event.cancel(keyInput) + break + end compose(GPU) os.sleep(0.1) -end \ No newline at end of file +end diff --git a/Libraries/utility.lua b/Libraries/utility.lua index 9559c04..0eb5c83 100644 --- a/Libraries/utility.lua +++ b/Libraries/utility.lua @@ -1,9 +1,12 @@ -local comp = require("component"); local event = require("event"); local thread = require("thread"); local uc = require("unicode") +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 + if (machineAddress ~= nil) then return comp.proxy(machineAddress) else return nil @@ -11,46 +14,56 @@ function utility.machine(address) end function utility.getPercent(number) - return (math.floor(number*1000)/10).."%" + 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 + 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) + 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 + 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 - 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] + 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 + if value == "e" then + run = false + end return false end event.listen("key_up", processKey) @@ -64,19 +77,19 @@ function utility.componentChange(broadcastPort) end function utility.progressText(current, max) - return current.."/"..max.."s" + 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")) + 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 +end -return utility \ No newline at end of file +return utility diff --git a/Libraries/widgets.lua b/Libraries/widgets.lua index 46cce6e..1ddd30a 100644 --- a/Libraries/widgets.lua +++ b/Libraries/widgets.lua @@ -1,5 +1,9 @@ -comp = require("component");screen = require("term"); computer = require("computer"); event = require("event") -draw = require("graphics"); util = require("utility") +comp = require("component") +screen = require("term") +computer = require("computer") +event = require("event") +draw = require("graphics") +util = require("utility") local widgets = {} @@ -10,20 +14,24 @@ function widgets.gtMachineInit(GPU, name, address) 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 + 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 + 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 + if parallel ~= nil then + draw.text(GPU, 11 + -(#parallel) .. "", 5, mainColor, parallel .. "x") + end end end else @@ -43,11 +51,11 @@ function widgets.gtMachine(GPU, name, address) local char, f, b if machine ~= nil then if machine.hasWork() then - local currentProgress = math.ceil(30*(machine.getWorkProgress()/machine.getWorkMaxProgress())) + local currentProgress = math.ceil(30 * (machine.getWorkProgress() / machine.getWorkMaxProgress())) local barAmount = currentProgress --First Straight _, f, _ = GPU.get(3, 1) - if f ~= mainColor then + 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) @@ -55,31 +63,32 @@ function widgets.gtMachine(GPU, name, address) 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, 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)) + 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) + draw.rect(GPU, 27, 9 - bars2, 1, bars2, mainColor) end - if barAmount > 10 then --Long Straight - local bars3 = math.max(0, barAmount-10) + 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) + 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) + 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) - + draw.text(GPU, 26 - #progressString, 5, accentA, progressString) else --No work _, f, _ = GPU.get(5, 1) if f ~= barColor then @@ -93,13 +102,16 @@ function widgets.gtMachine(GPU, name, address) 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 + ((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 + 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) @@ -110,19 +122,29 @@ function widgets.gtMachine(GPU, name, address) draw.rect(GPU, 23, 8, 1, 1, errorColor) end 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)) + 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} + 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 +return widgets diff --git a/Programs/Assembly Line/assemblyClient.lua b/Programs/Assembly Line/assemblyClient.lua index eaedadf..7322036 100644 --- a/Programs/Assembly Line/assemblyClient.lua +++ b/Programs/Assembly Line/assemblyClient.lua @@ -1,13 +1,18 @@ -comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread") +comp = require("component") +event = require("event") +screen = require("term") +computer = require("computer") +thread = require("thread") local AU = require("util") local AT = require("transport") -local S = require("serialization"); local uc = require("unicode") +local S = require("serialization") +local uc = require("unicode") local D = require("dictionary") local network = comp.modem local id, AD local function requestID() network.broadcast(100, "requestID") - local _, _, _, _, _, messageType, value = event.pull("modem_message"); + local _, _, _, _, _, messageType, value = event.pull("modem_message") while messageType ~= "sendID" do _, _, _, _, _, messageType, value = event.pull("modem_message") os.sleep(0.2) @@ -18,42 +23,75 @@ end function checkRepeat(recipe) local correctItems = 0 for i = 1, recipe.inputs, 1 do - if AT.isEmpty(AD["inputTransposer"..i], 16) then - if AT.check(AD["inputTransposer"..i], recipe["input"..i].name, recipe["input"..i].amount) then + if AT.isEmpty(AD["inputTransposer" .. i], 16) then + if AT.check(AD["inputTransposer" .. i], recipe["input" .. i].name, recipe["input" .. i].amount) then correctItems = correctItems + 1 - else return false end - else return false end + else + return false + end + else + return false + end end for i = 1, recipe.fluids, 1 do - if AT.isEmpty(AD["fluidTransposer"..i], 1) then - if AT.check(AD["fluidTransposer"..i], fluidMap[recipe["fluid"..i].name].name, recipe["fluid"..i].amount / fluidMap[recipe["fluid"..i].name].size) then + if AT.isEmpty(AD["fluidTransposer" .. i], 1) then + if + AT.check( + AD["fluidTransposer" .. i], + fluidMap[recipe["fluid" .. i].name].name, + recipe["fluid" .. i].amount / fluidMap[recipe["fluid" .. i].name].size + ) + then correctItems = correctItems + 1 - else return false end - else return false end + else + return false + end + else + return false + end + end + if correctItems == recipe.inputs + recipe.fluids then + return true + else + return false end - if correctItems == recipe.inputs + recipe.fluids then return true else return false end end local function processRecipe(recipe) local database, interface = AD.database, AD.input1 local function insert() - for i = 1, recipe.fluids, 1 do AT.move(AD["fluidTransposer"..i], recipe["fluid"..i].amount / fluidMap[recipe["fluid"..i].name].size, 1) end - for i = 1, recipe.inputs, 1 do AT.move(AD["inputTransposer"..i], recipe["input"..i].amount, 16) end - for i = 1, recipe.fluids, 1 do AT.empty(AD["fluidTransposer"..i]) end + for i = 1, recipe.fluids, 1 do + AT.move( + AD["fluidTransposer" .. i], + recipe["fluid" .. i].amount / fluidMap[recipe["fluid" .. i].name].size, + 1 + ) + end + for i = 1, recipe.inputs, 1 do + AT.move(AD["inputTransposer" .. i], recipe["input" .. i].amount, 16) + end + for i = 1, recipe.fluids, 1 do + AT.empty(AD["fluidTransposer" .. i]) + end end for i = 1, recipe.inputs, 1 do database.clear(i) - interface.store({label = recipe["input"..i].name}, database.address, i, 1) + interface.store({label = recipe["input" .. i].name}, database.address, i, 1) end for i = 1, recipe.fluids, 1 do - database.clear(20+i) - interface.store({label = fluidMap[recipe["fluid"..i].name].name}, database.address, 20+i, 1) + database.clear(20 + i) + interface.store({label = fluidMap[recipe["fluid" .. i].name].name}, database.address, 20 + i, 1) end for i = 1, recipe.inputs, 1 do - AT.set(AD["input"..i], database, i, recipe["input"..i].amount) + AT.set(AD["input" .. i], database, i, recipe["input" .. i].amount) end for i = 1, recipe.fluids, 1 do - AT.set(AD["fluid"..i], database, 20+i, recipe["fluid"..i].amount / fluidMap[recipe["fluid"..i].name].size) + AT.set( + AD["fluid" .. i], + database, + 20 + i, + recipe["fluid" .. i].amount / fluidMap[recipe["fluid" .. i].name].size + ) end ::insertRecipes:: insert() @@ -69,8 +107,12 @@ local function processRecipe(recipe) network.broadcast(id, "jammed") else screen.write(" ... Assembly Started") - while AD.controller.hasWork() do os.sleep(0.1) end - if checkRepeat(recipe) then goto insertRecipes end + while AD.controller.hasWork() do + os.sleep(0.1) + end + if checkRepeat(recipe) then + goto insertRecipes + end end AT.clearAll(AD) screen.write(" ... finished task!\n") @@ -80,7 +122,7 @@ end local function processMessage(localAddress, remoteAddress, port, distance, type, eventType, value2, value3) if eventType == "startAssembly" then local recipe = S.unserialize(value2) - screen.write("Starting assembly of "..recipe.label) + screen.write("Starting assembly of " .. recipe.label) processRecipe(recipe) elseif eventType == "clear" then AT.clearAll(AD) @@ -109,7 +151,9 @@ local function startAssembly() storedID = io.open("ID", "w") storedID:write(id) else - for line in io.lines("ID") do id = line + 0 end + for line in io.lines("ID") do + id = line + 0 + end end storedID:close() network.open(id) @@ -119,4 +163,4 @@ end startAssembly() event.listen("modem_message", processMessage) -event.listen("key_up", processKey) \ No newline at end of file +event.listen("key_up", processKey) diff --git a/Programs/Assembly Line/dictionary.lua b/Programs/Assembly Line/dictionary.lua index a0f8024..6897097 100644 --- a/Programs/Assembly Line/dictionary.lua +++ b/Programs/Assembly Line/dictionary.lua @@ -1,21 +1,20 @@ fluidMap = { - ["fluid.molten.solderingalloy"] = {name = "gt.metaitem.99.314.name", size = 144}, - ["fluid.lubricant"] = {name = "gt.Volumetric_Flask.name", size = 250}, - ["IC2 Coolant"] = {name = "Coolant Cell", size = 1000}, + ["fluid.molten.solderingalloy"] = {name = "gt.metaitem.99.314.name", size = 144}, + ["fluid.lubricant"] = {name = "gt.Volumetric_Flask.name", size = 250}, + ["IC2 Coolant"] = {name = "Coolant Cell", size = 1000}, ["fluid.molten.styrenebutadienerubber"] = {name = "gt.metaitem.99.635.name", size = 144}, - ["fluid.molten.niobiumtitanium"] = {name = "gt.metaitem.99.360.name", size = 144}, - ["fluid.molten.tritanium"] = {name = "gt.metaitem.99.329.name", size = 144}, - ["fluid.Neon"] = {name = "Neon Cell", size = 1000}, - ["fluid.molten.naquadria"] = {name = "gt.metaitem.99.327.name", size = 144} + ["fluid.molten.niobiumtitanium"] = {name = "gt.metaitem.99.360.name", size = 144}, + ["fluid.molten.tritanium"] = {name = "gt.metaitem.99.329.name", size = 144}, + ["fluid.Neon"] = {name = "Neon Cell", size = 1000}, + ["fluid.molten.naquadria"] = {name = "gt.metaitem.99.327.name", size = 144} } 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", + ["gt.metaitem.01.32704.name"] = "gt.metaitem.03.32083.name" } -- dictlist = { @@ -36,4 +35,4 @@ dictionary = { -- {"gt.metaitem.03.32091.name"}, -- UV -- {"gt.metaitem.03.32095.name","gt.metaitem.03.32099.name"}, -- UHV -- {"gt.metaitem.03.32120.name"} -- UEV --- } \ No newline at end of file +-- } diff --git a/Programs/Assembly Line/getClient.lua b/Programs/Assembly Line/getClient.lua index 461d43b..fdd4ead 100644 --- a/Programs/Assembly Line/getClient.lua +++ b/Programs/Assembly Line/getClient.lua @@ -1,17 +1,16 @@ local path = "/home" local shell = require("shell") -local download_list = -{ +local download_list = { "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Programs/Assembly%20Line/assemblyClient.lua", "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Programs/Assembly%20Line/dictionary.lua", "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Programs/Assembly%20Line/transport.lua", - "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Programs/Assembly%20Line/util.lua", + "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Programs/Assembly%20Line/util.lua" } shell.setWorkingDirectory(path) print("Updating Files") -for k,v in pairs(download_list) do - print("Fetching ",v) - local command = "wget "..v.." -f" +for k, v in pairs(download_list) do + print("Fetching ", v) + local command = "wget " .. v .. " -f" shell.execute(command) end -shell.setWorkingDirectory("/home") \ No newline at end of file +shell.setWorkingDirectory("/home") diff --git a/Programs/Assembly Line/recipeServer.lua b/Programs/Assembly Line/recipeServer.lua index fc02f4e..ae36693 100644 --- a/Programs/Assembly Line/recipeServer.lua +++ b/Programs/Assembly Line/recipeServer.lua @@ -1,4 +1,9 @@ -comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread"); uc = require("unicode") +comp = require("component") +event = require("event") +screen = require("term") +computer = require("computer") +thread = require("thread") +uc = require("unicode") AU = require("util") local S = require("serialization") local D = require("dictionary") @@ -16,20 +21,24 @@ local function getIDs() else for line in io.lines("IDs") do knownAssemblyLines = knownAssemblyLines + 1 - network.open(mainChannel+knownAssemblyLines) - assemblyStatus[mainChannel+knownAssemblyLines] = false + network.open(mainChannel + knownAssemblyLines) + assemblyStatus[mainChannel + knownAssemblyLines] = false end end end local function contains(t, value) for k, v in pairs(t) do - if v == value then return true end + if v == value then + return true + end end return false end local function getFree() for i = mainChannel, mainChannel + knownAssemblyLines, 1 do - if assemblyStatus[i] == false then return i end + if assemblyStatus[i] == false then + return i + end end return nil end @@ -41,7 +50,7 @@ local function processMessage(type, localAddress, remoteAddress, port, distance, assemblyStatus[newID] = false network.broadcast(mainChannel, "sendID", newID) local knownIDs = io.open("IDs", "a") - knownIDs:write(newID.."\n") + knownIDs:write(newID .. "\n") knownIDs:close() elseif eventType == "complete" then assemblyStatus[port] = false @@ -70,50 +79,80 @@ function startAssembly(assemblyport, recipe) end local function spairs(t, order) local keys = {} - for k in pairs(t) do keys[#keys+1] = k end - if order then table.sort(keys, function(a, b) return order(t, a, b) end) else table.sort(keys) end + for k in pairs(t) do + keys[#keys + 1] = k + end + if order then + table.sort( + keys, + function(a, b) + return order(t, a, b) + end + ) + else + table.sort(keys) + end local i = 0 return function() i = i + 1 - if keys[i] then return keys[i], t[keys[i] ] end + if keys[i] then + return keys[i], t[keys[i]] + end end end function matchRecipe(recipes) local items = comp.me_interface.getItemsInNetwork() local foundItems = {} - if #items > 0 then for i = 1, #items, 1 do foundItems[items[i].label] = items[i].size end end - for outputLabel, recipe in spairs(recipes, function(t,a,b) return t[b].inputs < t[a].inputs end) do + if #items > 0 then + for i = 1, #items, 1 do + foundItems[items[i].label] = items[i].size + end + end + for outputLabel, recipe in spairs( + recipes, + function(t, a, b) + return t[b].inputs < t[a].inputs + end + ) do local found = 0 local craftable = 1000 for i = 1, recipe.inputs, 1 do - local label, requiredAmount = recipe["input"..i].name, recipe["input"..i].amount - if dictionary[label] ~= nil then label = dictionary[label] end - if foundItems[label] == nil then break + local label, requiredAmount = recipe["input" .. i].name, recipe["input" .. i].amount + if dictionary[label] ~= nil then + label = dictionary[label] + end + if foundItems[label] == nil then + break else local existingAmount = foundItems[label] if existingAmount >= requiredAmount then found = found + 1 - craftable = math.min(math.floor(existingAmount/requiredAmount), craftable) + craftable = math.min(math.floor(existingAmount / requiredAmount), craftable) end end end for i = 1, recipe.fluids, 1 do local label, requiredAmount - if fluidMap[recipe["fluid"..i].name] ~= nil then - label, requiredAmount = fluidMap[recipe["fluid"..i].name].name, recipe["fluid"..i].amount / fluidMap[recipe["fluid"..i].name].size + if fluidMap[recipe["fluid" .. i].name] ~= nil then + label, requiredAmount = + fluidMap[recipe["fluid" .. i].name].name, + recipe["fluid" .. i].amount / fluidMap[recipe["fluid" .. i].name].size else break end - if foundItems[label] == nil then break + if foundItems[label] == nil then + break else local existingAmount = foundItems[label] if existingAmount >= requiredAmount then found = found + 1 - craftable = math.min(math.floor(existingAmount/requiredAmount), craftable) + craftable = math.min(math.floor(existingAmount / requiredAmount), craftable) end end end - if found == recipe.inputs + recipe.fluids then return recipe, craftable end + if found == recipe.inputs + recipe.fluids then + return recipe, craftable + end end return nil end @@ -125,7 +164,7 @@ local function scheduleTasks() if not contains(assemblyStatus, recipe.label) then local taskid = getFree() if taskid ~= nil then - screen.write("Started assembly of "..recipe.label.." with AL #"..taskid.."\n") + screen.write("Started assembly of " .. recipe.label .. " with AL #" .. taskid .. "\n") startAssembly(taskid, recipe) else screen.write("No free assembly lines.\n") @@ -137,7 +176,7 @@ local function scheduleTasks() local taskid = getFree() if taskid ~= nil then startAssembly(taskid, recipe) - screen.write("Started assembly of "..recipe.label.." with AL #"..taskid.."\n") + screen.write("Started assembly of " .. recipe.label .. " with AL #" .. taskid .. "\n") else screen.write("No free assembly lines.\n") end @@ -164,4 +203,4 @@ event.listen("key_up", processKey) while run do scheduleTasks() os.sleep(2) -end \ No newline at end of file +end diff --git a/Programs/Assembly Line/transport.lua b/Programs/Assembly Line/transport.lua index b46c60e..9b43472 100644 --- a/Programs/Assembly Line/transport.lua +++ b/Programs/Assembly Line/transport.lua @@ -1,4 +1,8 @@ -comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread") +comp = require("component") +event = require("event") +screen = require("term") +computer = require("computer") +thread = require("thread") local transport = {} @@ -16,23 +20,34 @@ function transport.clear(interface) end function transport.check(transposer, item, amount) local itemstack = transposer.getStackInSlot(0, 1) - if itemstack == nil then return false else - if itemstack.label == item and itemstack.size >= amount then return true else return false end end + if itemstack == nil then + return false + else + if itemstack.label == item and itemstack.size >= amount then + return true + else + return false + end + end end function transport.isEmpty(transposer, slot) - local itemstack = transposer.getStackInSlot(1, slot) - if itemstack == nil then return true else return false end + local itemstack = transposer.getStackInSlot(1, slot) + if itemstack == nil then + return true + else + return false + end end function transport.clearAll(assemblydata) for i = 1, 15, 1 do - if assemblydata["input"..i].getInterfaceConfiguration(1) ~= nil then - transport.clear(assemblydata["input"..i]) + if assemblydata["input" .. i].getInterfaceConfiguration(1) ~= nil then + transport.clear(assemblydata["input" .. i]) end end for i = 1, 4, 1 do - if assemblydata["fluid"..i].getInterfaceConfiguration(1) ~= nil then - transport.clear(assemblydata["fluid"..i]) + if assemblydata["fluid" .. i].getInterfaceConfiguration(1) ~= nil then + transport.clear(assemblydata["fluid" .. i]) end end end -return transport \ No newline at end of file +return transport diff --git a/Programs/Assembly Line/util.lua b/Programs/Assembly Line/util.lua index 2193dea..555de86 100644 --- a/Programs/Assembly Line/util.lua +++ b/Programs/Assembly Line/util.lua @@ -1,33 +1,52 @@ -comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread") +comp = require("component") +event = require("event") +screen = require("term") +computer = require("computer") +thread = require("thread") local assemblyUtil = {} local function addEntries(file, prompt, amount, type) local a, b, c for i = 1, amount, 1 do - screen.write(prompt.." "..i.." ") - a, b, c = event.pull() - while a ~= "component_added" do a, b, c = event.pull(); os.sleep() end - file:write(type..i..","..b.."\n") - screen.write(b.."\n") + screen.write(prompt .. " " .. i .. " ") + a, b, c = event.pull() + while a ~= "component_added" do + a, b, c = event.pull() + os.sleep() + end + file:write(type .. i .. "," .. b .. "\n") + screen.write(b .. "\n") end end local function addAuxilary(file, proxy, type) if proxy == nil then - screen.write("Cant find a valid "..type.."! Exiting...\n") + screen.write("Cant find a valid " .. type .. "! Exiting...\n") os.exit() else - file:write(type..","..proxy.address.."\n") + file:write(type .. "," .. proxy.address .. "\n") end end local 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) + 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 local function proxy(address) machineAddress = comp.get(address) - if(machineAddress ~= nil) then return comp.proxy(machineAddress) else return nil end + if (machineAddress ~= nil) then + return comp.proxy(machineAddress) + else + return nil + end end local function configureClient() local file = io.open("addresses", "w") @@ -71,15 +90,29 @@ local function voltageToTier(voltage) end function copyPattern(interface, slot, recipe, database) for i = 1, recipe.inputs, 1 do - local item = recipe["input"..i] + local item = recipe["input" .. i] local name = item.name - if dictionary[name] ~= nil then name = dictionary[name] end + if dictionary[name] ~= nil then + name = dictionary[name] + end interface.setInterfacePatternInput(slot, database, databaseMap[name], item.amount, i) end 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)) + return voltageToTier( + math.floor( + string.gsub( + string.sub( + controller.getSensorInformation()[4], + 1, + string.find(controller.getSensorInformation()[4], "/") - 1 + ), + "([^0-9]+)", + "" + ) + 0 + ) + ) end local function addRecipe(recipelist, slot, source, sourceSide) if source.getStackInSlot(sourceSide, slot) ~= nil then @@ -93,14 +126,14 @@ local function addRecipe(recipelist, slot, source, sourceSide) if pattern.inputItems ~= nil then local items = pattern.inputItems for i = 1, #items, 1 do - recipelist[pattern.output]["input"..i] = {name = items[i][1], amount = items[i][2]} + recipelist[pattern.output]["input" .. i] = {name = items[i][1], amount = items[i][2]} recipelist[pattern.output]["inputs"] = recipelist[pattern.output]["inputs"] + 1 end end if pattern.inputFluids ~= nil then local fluids = pattern.inputFluids for i = 1, #fluids do - recipelist[pattern.output]["fluid"..i] = {name = fluids[i][1], amount = fluids[i][2]} + recipelist[pattern.output]["fluid" .. i] = {name = fluids[i][1], amount = fluids[i][2]} recipelist[pattern.output]["fluids"] = recipelist[pattern.output]["fluids"] + 1 end end @@ -121,4 +154,4 @@ function assemblyUtil.getRecipes(recipelist) end end end -return assemblyUtil \ No newline at end of file +return assemblyUtil diff --git a/Programs/Autostocker/stocker.lua b/Programs/Autostocker/stocker.lua index e0674fd..034a33a 100644 --- a/Programs/Autostocker/stocker.lua +++ b/Programs/Autostocker/stocker.lua @@ -1,7 +1,15 @@ -comp=require("component");screen=require("term");computer=require("computer");event=require("event"); thread = require("thread"); sides = require("sides") -get=require("utility"); ARG=require("ARGraphics"); G = require("graphics") +comp = require("component") +screen = require("term") +computer = require("computer") +event = require("event") +thread = require("thread") +sides = require("sides") +get = require("utility") +ARG = require("ARGraphics") +G = require("graphics") S = require("stockerUtil") -local uc = require("unicode"); tx = require("transforms") +local uc = require("unicode") +tx = require("transforms") config = require("config") local GPU = comp.gpu interface = comp.me_interface @@ -18,13 +26,27 @@ function mouseListener() if activeWindow == "Button" then GPU.setActiveBuffer(0) if drawerItem == nil or number == "" then - G.rect(GPU, currentWindows["Button"].x+2, currentWindows["Button"].y*2+1, 6, 6, negativeEUColour) + G.rect( + GPU, + currentWindows["Button"].x + 2, + currentWindows["Button"].y * 2 + 1, + 6, + 6, + negativeEUColour + ) else - G.rect(GPU, currentWindows["Button"].x+2, currentWindows["Button"].y*2+1, 6, 6, positiveEUColour) + G.rect( + GPU, + currentWindows["Button"].x + 2, + currentWindows["Button"].y * 2 + 1, + 6, + 6, + positiveEUColour + ) if itemsToStock[drawerItem] ~= nil then S.update(drawerItem, itemsToStock[drawerItem], number) itemsToStock[drawerItem] = number - elseif number+0.0 > 0 then + elseif number + 0.0 > 0 then S.addPattern(drawerItem, number) itemsToStock[drawerItem] = number else @@ -37,11 +59,17 @@ function mouseListener() elseif activeWindow == "Number" then GPU.setActiveBuffer(0) if drawerItem == nil then - G.centeredText(GPU, currentWindows["Number"].x+25, currentWindows["Number"].y*2+3, 0xFFFFFF, "Pattern refresh requested...") + G.centeredText( + GPU, + currentWindows["Number"].x + 25, + currentWindows["Number"].y * 2 + 3, + 0xFFFFFF, + "Pattern refresh requested..." + ) S.refreshCraftables() end inNumberBox = true - G.rect(GPU, currentWindows["Number"].x+2, currentWindows["Number"].y*2+1, 46, 6, 0x333333) + G.rect(GPU, currentWindows["Number"].x + 2, currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333) else inNumberBox = false number = "" @@ -62,12 +90,14 @@ function keyboardListener() if key == 10 then inNumberBox = false G.refresh(GPU) - end - if key == 8 then number = string.sub(number, 1, #number-1) elseif (key >= 48 and key <= 57) then - number = number..value end - G.rect(GPU, currentWindows["Number"].x+2, currentWindows["Number"].y*2+1, 46, 6, 0x333333) - G.text(GPU, currentWindows["Number"].x+4, currentWindows["Number"].y*2+3, workingColour, number) + if key == 8 then + number = string.sub(number, 1, #number - 1) + elseif (key >= 48 and key <= 57) then + number = number .. value + end + G.rect(GPU, currentWindows["Number"].x + 2, currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333) + G.text(GPU, currentWindows["Number"].x + 4, currentWindows["Number"].y * 2 + 3, workingColour, number) end end return event.listen("key_down", processKey) @@ -100,8 +130,14 @@ function getNewItem(GPU, x, y) end GPU.setActiveBuffer(0) if itemsToStock[drawerItem] ~= nil then - G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y*2-3, 60, 2, 0x000000) - G.centeredText(GPU, currentWindows["Item"].x+30, currentWindows["Item"].y*2-3, 0xFFFFFF, "Configured: "..itemsToStock[drawerItem]) + G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000) + G.centeredText( + GPU, + currentWindows["Item"].x + 30, + currentWindows["Item"].y * 2 - 3, + 0xFFFFFF, + "Configured: " .. itemsToStock[drawerItem] + ) end G.refresh(GPU) else @@ -116,8 +152,14 @@ function getNewItem(GPU, x, y) end GPU.setActiveBuffer(0) if itemsToStock[drawerItem] ~= nil then - G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y*2-3, 60, 2, 0x000000) - G.centeredText(GPU, currentWindows["Item"].x+30, currentWindows["Item"].y*2-3, 0xFFFFFF, "Configured: "..itemsToStock[drawerItem]) + G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000) + G.centeredText( + GPU, + currentWindows["Item"].x + 30, + currentWindows["Item"].y * 2 - 3, + 0xFFFFFF, + "Configured: " .. itemsToStock[drawerItem] + ) end G.refresh(GPU) end @@ -129,7 +171,7 @@ function getNewItem(GPU, x, y) G.rect(GPU, 3, 3, 56, 2, 0x000000) G.centeredText(GPU, 30, 3, 0xFFFFFF, "") GPU.setActiveBuffer(0) - G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y*2-3, 60, 2, 0x000000) + G.rect(GPU, currentWindows["Item"].x, currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000) G.refresh(GPU) end end @@ -172,33 +214,33 @@ function craftableBox(GPU, x, y) S.updateCache() for label, amount in pairs(itemsToStock) do local stockedAmount = S.getAmount(label) - local stockedString = string.sub(stockedAmount.."", 1, #(stockedAmount.."")-2) - local toStock = amount+0.0 + 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); + G.text(GPU, 4, 3 + 2 * i, workingColour, label) elseif craftables[label] == nil then - G.text(GPU, 4, 3+2*i, negativeEUColour, label); + G.text(GPU, 4, 3 + 2 * i, negativeEUColour, label) else - G.text(GPU, 4, 3+2*i, 0xFFFFFF, label); + 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) + 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) + 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 + 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) + G.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, negativeEUColour, stockedString) end - G.text(GPU, 59, 3+2*i, 0xFFFFFF, "| "..amount) + G.text(GPU, 59, 3 + 2 * i, 0xFFFFFF, "| " .. amount) i = math.min(i + 1, 43) end end @@ -207,11 +249,17 @@ function craftableBox(GPU, x, y) G.refresh(GPU) end -mouseListener(); keyboardListener(); GPU.setResolution(160, 46); screen.clear() +mouseListener() +keyboardListener() +GPU.setResolution(160, 46) +screen.clear() G.clear() -numberBox(GPU, 100, 41); button(GPU, 150, 41); craftableBox(GPU, 0, 0) +numberBox(GPU, 100, 41) +button(GPU, 150, 41) +craftableBox(GPU, 0, 0) G.refresh(GPU) -S.refreshCraftables(); S.loadPatterns() +S.refreshCraftables() +S.loadPatterns() local timeSinceRefresh = computer.uptime() while true do getNewItem(GPU, 100, 38) diff --git a/Programs/Autostocker/stockerUtil.lua b/Programs/Autostocker/stockerUtil.lua index b008710..8a07a3b 100644 --- a/Programs/Autostocker/stockerUtil.lua +++ b/Programs/Autostocker/stockerUtil.lua @@ -1,6 +1,14 @@ -comp=require("component");screen=require("term");computer=require("computer");event=require("event"); thread = require("thread"); sides = require("sides") -get=require("utility"); ARG=require("ARGraphics"); G = require("graphics") -local uc = require("unicode"); tx = require("transforms") +comp = require("component") +screen = require("term") +computer = require("computer") +event = require("event") +thread = require("thread") +sides = require("sides") +get = require("utility") +ARG = require("ARGraphics") +G = require("graphics") +local uc = require("unicode") +tx = require("transforms") config = require("config") local GPU = comp.gpu local sUtil = {} @@ -12,61 +20,83 @@ function sUtil.refreshCraftables() end for i, craftable in pairs(c) do if i ~= "n" then - if i % 10 == 0 then - G.centeredText(GPU, currentWindows["Number"].x+25, currentWindows["Number"].y*2+3, 0xFFFFFF, "Discovering Patterns: "..i.." / "..#c) + if i % 10 == 0 then + G.centeredText( + GPU, + currentWindows["Number"].x + 25, + currentWindows["Number"].y * 2 + 3, + 0xFFFFFF, + "Discovering Patterns: " .. i .. " / " .. #c + ) end end if craftable ~= #c then craftables[craftable.getItemStack().label] = craftable.request end end - G.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: "..#c) + G.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: " .. #c) end local cachedAmounts = {} function sUtil.updateCache() local itemList = interface.getItemsInNetwork() for i = 1, #itemList, 1 do - if i % 200 == 0 then os.sleep() end + if i % 200 == 0 then + os.sleep() + end cachedAmounts[itemList[i].label] = itemList[i].size itemList[i] = nil end end function sUtil.getAmount(itemLabel) - if cachedAmounts[itemLabel] == nil then return 0 else return cachedAmounts[itemLabel] end + 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 file = io.open("configured", "r") local fileContent = {} local lineNumber = 0 local i = 1 for line in file:lines() do - if line == label..","..oldAmount then lineNumber = i end - table.insert (fileContent, line) + if line == label .. "," .. oldAmount then + lineNumber = i + end + table.insert(fileContent, line) i = i + 1 end io.close(file) - file = io.open("configured", 'w') + file = io.open("configured", "w") for index, value in ipairs(fileContent) do if index ~= lineNumber then - file:write(value..'\n') + file:write(value .. "\n") else - file:write(label..","..newAmount..'\n') + file:write(label .. "," .. newAmount .. "\n") end end io.close(file) end function sUtil.addPattern(label, amount) local file = io.open("configured", "a") - file:write(label..","..amount.."\n") + file:write(label .. "," .. amount .. "\n") file:close() itemsToStock[label] = amount end local 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) + 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 sUtil.loadPatterns() @@ -77,4 +107,4 @@ function sUtil.loadPatterns() end end -return sUtil \ No newline at end of file +return sUtil diff --git a/Programs/HUD/main.lua b/Programs/HUD/main.lua index 766ba4b..ca2a860 100644 --- a/Programs/HUD/main.lua +++ b/Programs/HUD/main.lua @@ -1,28 +1,35 @@ -comp = require("component"); event = require("event") +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 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.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} + 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() diff --git a/Programs/HUD/ticker.lua b/Programs/HUD/ticker.lua index 1e1fc79..40498f9 100644 --- a/Programs/HUD/ticker.lua +++ b/Programs/HUD/ticker.lua @@ -1,6 +1,7 @@ -comp = require("component"); event = require("event") +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 +end diff --git a/Programs/HUD/tps.lua b/Programs/HUD/tps.lua index b4fc938..683fa46 100644 --- a/Programs/HUD/tps.lua +++ b/Programs/HUD/tps.lua @@ -1,7 +1,8 @@ -comp = require("component"); event = require("event") +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 +end diff --git a/Programs/Nuclear Control/control.lua b/Programs/Nuclear Control/control.lua index 845a29b..3145f33 100644 --- a/Programs/Nuclear Control/control.lua +++ b/Programs/Nuclear Control/control.lua @@ -1,4 +1,8 @@ -comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread") +comp = require("component") +event = require("event") +screen = require("term") +computer = require("computer") +thread = require("thread") local GPU = comp.gpu GPU.setResolution(54, 26) @@ -14,8 +18,10 @@ function checkHeatLevels() 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 + screen.write("Reactor " .. i) + if i < 10 then + screen.write(" ") + end local reactor = comp.proxy(address) if reactor.getHeat() > 0 then GPU.setForeground(0xFF0000) @@ -51,4 +57,4 @@ screen.clear() while true do checkHeatLevels() os.sleep(1) -end \ No newline at end of file +end diff --git a/Programs/Spatial Teleporter/destination.lua b/Programs/Spatial Teleporter/destination.lua index 0ccb639..7b7d463 100644 --- a/Programs/Spatial Teleporter/destination.lua +++ b/Programs/Spatial Teleporter/destination.lua @@ -7,22 +7,25 @@ destinations = { [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 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 = { -} +local boundingBoxes = {} function createDestination(x, y, index) local width, height = 18, 6 - local page = GPU.allocateBuffer(width, math.ceil(height/2)) + 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} + 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) @@ -36,7 +39,7 @@ 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) + 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) @@ -62,11 +65,11 @@ 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 +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 +end diff --git a/Programs/Spatial Teleporter/spatial.lua b/Programs/Spatial Teleporter/spatial.lua index bc22d86..8540495 100644 --- a/Programs/Spatial Teleporter/spatial.lua +++ b/Programs/Spatial Teleporter/spatial.lua @@ -1,4 +1,7 @@ -local comp=require("component"); local event=require("event"); local screen=require("term"); local computer = require("computer") +local comp = require("component") +local event = require("event") +local screen = require("term") +local computer = require("computer") function cycle() comp.redstone.setOutput(2, 15) @@ -20,7 +23,6 @@ local ticket = 1 --end function setDestination(destination) - end function unload(index) @@ -56,8 +58,9 @@ function doStartupSequence() local gpu = comp.gpu gpu.freeAllBuffers() local colors = { - [0] = 0x00a6ff, - [1] = 0x000000} + [0] = 0x00a6ff, + [1] = 0x000000 + } local buffer = gpu.allocateBuffer() gpu.setActiveBuffer(buffer) for i = 2, 20, 1 do @@ -65,11 +68,7 @@ function doStartupSequence() 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, - "█") + comp.gpu.fill(2 + i * 2, 1 + i, 80 - i * 4, 40 - i * 2, "█") os.sleep(0.1) end gpu.setActiveBuffer(0) @@ -80,8 +79,8 @@ function doStartupSequence() end local starting = false function send() - local transposer = comp.transposer - if transposer.getStackInSlot(controller, 1) == nil then + local transposer = comp.transposer + if transposer.getStackInSlot(controller, 1) == nil then --screen.write("The operating cell is missing!\n") else doStartupSequence() diff --git a/Programs/armorCharger.lua b/Programs/armorCharger.lua index 20c9bfe..53f913c 100644 --- a/Programs/armorCharger.lua +++ b/Programs/armorCharger.lua @@ -1,4 +1,5 @@ -comp = require("component"); event = require("event") +comp = require("component") +event = require("event") local transposer = comp.transposer local dark = 2 @@ -7,4 +8,4 @@ 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 +end diff --git a/Programs/autofeeder.lua b/Programs/autofeeder.lua index 06107f0..683e805 100644 --- a/Programs/autofeeder.lua +++ b/Programs/autofeeder.lua @@ -1,17 +1,25 @@ -Comp=require("component") +Comp = require("component") local transposer = Comp.transposer -local players = {["Sampsa"] = 3, ["Dark"] = 2} +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 + 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], 28) - if itemStack ~= nil then return itemStack.size else return nil end + if itemStack ~= nil then + return itemStack.size + else + return nil + end end local function transferFood(player) @@ -19,14 +27,18 @@ local function transferFood(player) end local function transferEmpty(player) local slot = findEmptyCans(player) - if slot ~= nil then transposer.transferItem(players[player], 0, 64, slot, 2) end + if slot ~= nil then + transposer.transferItem(players[player], 0, 64, slot, 2) + end end local function check(player) if transposer.getInventorySize(players[player]) == 40 then local inInventory = checkLevel(player) if inInventory ~= nil then - if inInventory < 40 then transferFood(player) end + if inInventory < 40 then + transferFood(player) + end os.sleep(0.2) transferEmpty(player) end @@ -37,4 +49,4 @@ while true do check("Sampsa") check("Dark") os.sleep(2) -end \ No newline at end of file +end diff --git a/Programs/biovat.lua b/Programs/biovat.lua index a916718..2423cc0 100644 --- a/Programs/biovat.lua +++ b/Programs/biovat.lua @@ -1,4 +1,7 @@ -local comp=require("component"); local event=require("event"); local screen=require("term"); local computer = require("computer") +local comp = require("component") +local event = require("event") +local screen = require("term") +local computer = require("computer") local transposers = {} function configureTransposers() @@ -22,7 +25,7 @@ function configureTransposers() end end end - screen.write("Found "..countTransposers().." output hatches to keep at 50%\n") + screen.write("Found " .. countTransposers() .. " output hatches to keep at 50%\n") end function countTransposers() local count = 0 @@ -54,4 +57,4 @@ while true do count = tempCount tick() os.sleep() -end \ No newline at end of file +end diff --git a/Programs/energyControl.lua b/Programs/energyControl.lua index 35cd5cc..c722cf2 100644 --- a/Programs/energyControl.lua +++ b/Programs/energyControl.lua @@ -1,19 +1,24 @@ -comp=require("component"); event=require("event"); screen=require("term"); computer = require("computer"); thread = require("thread"); uc = require("unicode") +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 + 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 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 + return currentEU / maxEU end local turbineRedstone = { @@ -34,9 +39,13 @@ end local function checkLevels() local fill = getPercentage() if fill < 0.15 then - if not engaged then engage() end + if not engaged then + engage() + end elseif fill > 0.95 then - if engaged then disengage() end + if engaged then + disengage() + end end end @@ -44,4 +53,4 @@ disengage() while true do checkLevels() os.sleep(5) -end \ No newline at end of file +end diff --git a/Programs/update.lua b/Programs/update.lua index 017ae95..e23a1ee 100644 --- a/Programs/update.lua +++ b/Programs/update.lua @@ -1,19 +1,16 @@ -local path = "/lib" local shell = require("shell") -local download_list = -{ - "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/ARWidgets.lua", - "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/config.lua", - "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/graphics.lua", - "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/utility.lua", - "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/widgets.lua", - "https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/ARGraphics.lua" -} -shell.setWorkingDirectory(path) -print("Updating Files") -for k,v in pairs(download_list) do - print("Fetching ",v) - local command = "wget "..v.." -f" - shell.execute(command) -end -shell.setWorkingDirectory("/home") \ No newline at end of file + +local tarMan = "https://raw.githubusercontent.com/mpmxyz/ocprograms/master/usr/man/tar.man" +local tarBin = "https://raw.githubusercontent.com/mpmxyz/ocprograms/master/home/bin/tar.lua" +local InfOS = "https://github.com/gordominossi/InfOS/releases/download/v0/InfOS.tar" + +shell.setWorkingDirectory("/usr/man") +shell.execute("wget " .. tarMan .. " -f") + +shell.setWorkingDirectory("/bin") +shell.execute("wget " .. tarBin .. " -f") + +shell.setWorkingDirectory("/home") +print("Updating InfOS") +shell.execute("wget " .. InfOS .. " -f") +shell.execute("tar -xf InfOS.tar")