Formatting files

This commit is contained in:
Gabriel Moreira Minossi 2020-12-19 16:24:16 -03:00
parent 5d693800ca
commit a3dd881119
26 changed files with 1077 additions and 550 deletions

View File

@ -1,4 +1,7 @@
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 AR = {}
@ -16,27 +19,36 @@ function AR.hexToRGB(hexcode)
return r, g, b return r, g, b
end end
function AR.cube(glasses, x, y, z, color, alpha, scale) 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() local cube = glasses.addCube3D()
cube.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z) 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 return cube
end end
function AR.line(glasses, source, dest, color, alpha, scale) 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() 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(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.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.setColor(hexToRGB(color))
line.setAlpha(alpha)
line.setScale(scale)
return line return line
end end
function AR.worldText(glasses, name, x, y, z, color, alpha, scale) 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() local text = glasses.addFloatingText()
text.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z) 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) text.setText(name)
return text return text
end end
@ -44,24 +56,33 @@ end
function AR.hudTriangle(glasses, a, b, c, color, alpha) function AR.hudTriangle(glasses, a, b, c, color, alpha)
alpha = alpha or 1.0 alpha = alpha or 1.0
local triangle = glasses.addTriangle() local triangle = glasses.addTriangle()
triangle.setColor(hexToRGB(color)); triangle.setAlpha(alpha); triangle.setColor(hexToRGB(color))
triangle.setVertex(1, a[1], a[2]); triangle.setVertex(2, b[1], b[2]); triangle.setVertex(3, c[1], c[2]) 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 return triangle
end end
function AR.hudQuad(glasses, a, b, c, d, color, alpha) function AR.hudQuad(glasses, a, b, c, d, color, alpha)
alpha = alpha or 1.0 alpha = alpha or 1.0
local quad = glasses.addQuad() local quad = glasses.addQuad()
quad.setColor(hexToRGB(color)); quad.setAlpha(alpha) quad.setColor(hexToRGB(color))
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.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 return quad
end end
function AR.hudRectangle(glasses, x, y, w, h, color, alpha) function AR.hudRectangle(glasses, x, y, w, h, color, alpha)
alpha = alpha or 1.0 alpha = alpha or 1.0
local rect = glasses.addRect() local rect = glasses.addRect()
rect.setPosition(x, y); rect.setSize(h, w) rect.setPosition(x, y)
rect.setColor(hexToRGB(color)); rect.setAlpha(alpha) rect.setSize(h, w)
rect.setColor(hexToRGB(color))
rect.setAlpha(alpha)
return rect return rect
end end
@ -70,7 +91,7 @@ function AR.textSize(textObject, scale)
oldX = oldX * textObject.getScale() oldX = oldX * textObject.getScale()
oldY = oldY * textObject.getScale() oldY = oldY * textObject.getScale()
textObject.setScale(scale) textObject.setScale(scale)
textObject.setPosition(oldX/(scale+1), oldY/(scale+1)) textObject.setPosition(oldX / (scale + 1), oldY / (scale + 1))
end end
function AR.hudText(glasses, displayText, x, y, color, scale) function AR.hudText(glasses, displayText, x, y, color, scale)

View File

@ -1,81 +1,110 @@
comp=require("component");screen=require("term");computer=require("computer");event=require("event"); thread = require("thread") comp = require("component")
get=require("easy"); ARG=require("ARGraphics") screen = require("term")
computer = require("computer")
event = require("event")
thread = require("thread")
get = require("easy")
ARG = require("ARGraphics")
config = require("config") config = require("config")
local ARWidgets = {} local ARWidgets = {}
local firstRead, lastRead, counter, currentIO = 0, 0, 1, 1 local firstRead, lastRead, counter, currentIO = 0, 0, 1, 1
local euUpdateInterval = 120 local euUpdateInterval = 120
local readings = {} local readings = {}
local function updateEU(LSC) local function updateEU(LSC)
batteryBuffer = batteryBuffer or false batteryBuffer = batteryBuffer or false
if counter == 1 then firstRead = computer.uptime() end if counter == 1 then
firstRead = computer.uptime()
end
if counter < euUpdateInterval then if counter < euUpdateInterval then
readings[counter] = string.gsub(LSC.getSensorInformation()[2], "([^0-9]+)", "") + 0 readings[counter] = string.gsub(LSC.getSensorInformation()[2], "([^0-9]+)", "") + 0
counter = counter + 1 counter = counter + 1
end end
if counter == euUpdateInterval then if counter == euUpdateInterval then
lastRead = computer.uptime() lastRead = computer.uptime()
ticks = math.ceil((lastRead-firstRead)*20) ticks = math.ceil((lastRead - firstRead) * 20)
currentIO = math.floor((readings[euUpdateInterval-1]-readings[1])/ticks) currentIO = math.floor((readings[euUpdateInterval - 1] - readings[1]) / ticks)
counter = 1 counter = 1
end end
end end
local currentEU, maxEU, percentage, fillTime, fillTimeString = 1, 1, 1, 1, 1 local currentEU, maxEU, percentage, fillTime, fillTimeString = 1, 1, 1, 1, 1
local initializePowerDisplay = true local initializePowerDisplay = true
local maxEnergyObj, currentEnergyObj, currentFillrateObj, percentageObj, timeObj local maxEnergyObj, currentEnergyObj, currentFillrateObj, percentageObj, timeObj
function ARWidgets.powerDisplay(glasses, data, x, y, w, h) function ARWidgets.powerDisplay(glasses, data, x, y, w, h)
updateEU(data) 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) maxEU = math.floor(string.gsub(data.getSensorInformation()[3], "([^0-9]+)", "") + 0)
percentage = currentEU/maxEU percentage = currentEU / maxEU
if initializePowerDisplay then if initializePowerDisplay then
ARG.hudRectangle(glasses, x, y, w, h, hudColour) ARG.hudRectangle(glasses, x, y, w, h, hudColour)
ARG.hudRectangle(glasses, x, y+h, w, 12, hudColour, 0.6) 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, 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.hudTriangle(
ARG.hudRectangle(glasses, x, y+h, 25, 12, hudColour) glasses,
ARG.hudTriangle(glasses, {x+25, y+h}, {x+25, y+h+12}, {x+37, y+h+12}, hudColour) {x + 2 + w - 4, y + 3},
ARG.hudRectangle(glasses, x+w-25, y+h, 25, 12, hudColour) {x + 2 + w - 4 - (h - 6), y + 3},
ARG.hudTriangle(glasses, {x+w-37, y+h}, {x+w-25, y+h+12}, {x+w-25, y+h}, hudColour) {x + 2 + w - 4, y + 3 + h - 6},
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) hudColour
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, 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) maxEnergyObj = ARG.hudText(glasses, "", x + w - 88, y - 8, idleColour)
currentEnergyObj = ARG.hudText(glasses, "", x+2, y-8, workingColour) currentEnergyObj = ARG.hudText(glasses, "", x + 2, y - 8, workingColour)
currentFillrateObj = ARG.hudText(glasses, "", x+w/2-20, y+h+1, 0xFFFFFF) currentFillrateObj = ARG.hudText(glasses, "", x + w / 2 - 20, y + h + 1, 0xFFFFFF)
percentageObj = ARG.hudText(glasses, "", x+w/2-5, y-8, labelColour) percentageObj = ARG.hudText(glasses, "", x + w / 2 - 5, y - 8, labelColour)
timeObj = ARG.hudText(glasses, "", x+35, y+h+1, labelColour) timeObj = ARG.hudText(glasses, "", x + 35, y + h + 1, labelColour)
initializePowerDisplay = false initializePowerDisplay = false
end end
if currentIO >= 0 then 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)) fillTimeString = "Full: " .. get.time(math.abs(fillTime))
else else
fillTime = math.floor((currentEU)/(currentIO*20)) fillTime = math.floor((currentEU) / (currentIO * 20))
fillTimeString = "Empty: " .. get.time(math.abs(fillTime)) fillTimeString = "Empty: " .. get.time(math.abs(fillTime))
end end
powerFill.setVertex(1, x+2, y+3) powerFill.setVertex(1, x + 2, y + 3)
powerFill.setVertex(2, x+2+h-6, y+3+h-6) 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(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) 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(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(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(3, x + 2 + w - 5, y + 3 + h - 6)
powerEmpty.setVertex(4, x+2+w-5-(h-6), y+3) powerEmpty.setVertex(4, x + 2 + w - 5 - (h - 6), y + 3)
maxEnergyObj.setText(get.splitNumber(maxEU).." EU") maxEnergyObj.setText(get.splitNumber(maxEU) .. " EU")
if percentage > 0.995 then if percentage > 0.995 then
currentEnergyObj.setText(get.splitNumber(maxEU).." EU") currentEnergyObj.setText(get.splitNumber(maxEU) .. " EU")
percentageObj.setText(get.getPercent(1.0)) percentageObj.setText(get.getPercent(1.0))
else else
currentEnergyObj.setText(get.splitNumber(currentEU).." EU") currentEnergyObj.setText(get.splitNumber(currentEU) .. " EU")
percentageObj.setText(get.getPercent(percentage)) percentageObj.setText(get.getPercent(percentage))
end end
if currentIO >= 0 then if currentIO >= 0 then
currentFillrateObj.setText("+"..get.splitNumber(currentIO).." EU/t") currentFillrateObj.setText("+" .. get.splitNumber(currentIO) .. " EU/t")
currentFillrateObj.setColor(0, 1, 0) currentFillrateObj.setColor(0, 1, 0)
else else
currentFillrateObj.setColor(1, 0, 0) currentFillrateObj.setColor(1, 0, 0)
currentFillrateObj.setText(get.splitNumber(currentIO).." EU/t") currentFillrateObj.setText(get.splitNumber(currentIO) .. " EU/t")
end end
if percentage < 0.985 then if percentage < 0.985 then
timeObj.setText(fillTimeString) timeObj.setText(fillTimeString)
@ -85,17 +114,17 @@ function ARWidgets.powerDisplay(glasses, data, x, y, w, h)
end end
function ARWidgets.minimapOverlay(glasses) function ARWidgets.minimapOverlay(glasses)
--Minimap Borders --Minimap Borders
ARG.hudRectangle(glasses, 728, 10, 123, 3, hudColour); ARG.hudRectangle(glasses, 728, 10, 123, 3, hudColour)
ARG.hudRectangle(glasses, 728, 130, 123, 3,hudColour); ARG.hudRectangle(glasses, 728, 130, 123, 3, hudColour)
ARG.hudRectangle(glasses, 728, 10, 3, 123,hudColour); ARG.hudRectangle(glasses, 728, 10, 3, 123, hudColour)
ARG.hudRectangle(glasses, 848, 10, 3, 123, hudColour); ARG.hudRectangle(glasses, 848, 10, 3, 123, hudColour)
--Coordinate Borders --Coordinate Borders
ARG.hudTriangle(glasses, {743, 133}, {728, 133}, {743, 143}, hudColour) ARG.hudTriangle(glasses, {743, 133}, {728, 133}, {743, 143}, hudColour)
ARG.hudRectangle(glasses, 743, 133, 8, 10, hudColour); ARG.hudRectangle(glasses, 743, 133, 8, 10, hudColour)
ARG.hudRectangle(glasses, 751, 140, 170, 3, hudColour); ARG.hudRectangle(glasses, 751, 140, 170, 3, hudColour)
--Biome Borders --Biome Borders
ARG.hudTriangle(glasses, {768, 143}, {753, 143}, {768, 153}, hudColour) 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, 829, 133, 50, 7, 0, 0.8)
ARG.hudRectangle(glasses, 811, 143, 50, 7, 0, 0.8) ARG.hudRectangle(glasses, 811, 143, 50, 7, 0, 0.8)
--FPS Borders --FPS Borders
@ -108,28 +137,30 @@ function ARWidgets.minimapOverlay(glasses)
end end
function ARWidgets.hudOverlayBase(glasses, x, y) function ARWidgets.hudOverlayBase(glasses, x, y)
local hotbarSplitter = ARG.hudRectangle(glasses, x, y, 183, 2, hudColour) local hotbarSplitter = ARG.hudRectangle(glasses, x, y, 183, 2, hudColour)
local expSplitter = ARG.hudRectangle(glasses, x, y-6, 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 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 leftBorder = ARG.hudRectangle(glasses, x - 1, y - 13, 3, 38, hudColour)
local rightBorder = ARG.hudRectangle(glasses, x+182, y-5, 3, 30, 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 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 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 hpStopper =
local topBorder = ARG.hudRectangle(glasses, x+4, y-18, 178, 3, hudColour) ARG.hudQuad(glasses, {x + 88, y - 16}, {x + 77, y - 5}, {x + 108, y - 5}, {x + 97, y - 16}, hudColour)
local topWedge = ARG.hudTriangle(glasses, {x+4, y-18}, {x-1, y-13}, {x+4, y-13}, hudColour) local topBorder = ARG.hudRectangle(glasses, x + 4, y - 18, 178, 3, hudColour)
local connector = ARG.hudTriangle(glasses, {x+182, y-18}, {x+182, y}, {x+200, y}, hudColour) local topWedge = ARG.hudTriangle(glasses, {x + 4, y - 18}, {x - 1, y - 13}, {x + 4, y - 13}, hudColour)
local topStrip = ARG.hudRectangle(glasses, x+4, y-17, 178, 1, workingColour) local connector = ARG.hudTriangle(glasses, {x + 182, y - 18}, {x + 182, y}, {x + 200, y}, hudColour)
local expWedge1 = ARG.hudTriangle(glasses, {x+179, y-4}, {x+183, y}, {x+183, y-4}, hudColour) local topStrip = ARG.hudRectangle(glasses, x + 4, y - 17, 178, 1, workingColour)
local expWedge2 = ARG.hudTriangle(glasses, {x+2, y-5}, {x+2, y}, {x+6, y}, hudColour) 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 --CPU Monitor
local base = ARG.hudRectangle(glasses, x+185, y, 28, 24, hudColour) local base = ARG.hudRectangle(glasses, x + 185, y, 28, 24, hudColour)
local cpuStrip = ARG.hudRectangle(glasses, x+185, y, 500, 3, 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 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 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 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 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 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 connectorStrip =
ARG.hudQuad(glasses, {x + 182, y - 17}, {x + 182, y - 16}, {x + 213, y + 15}, {x + 213, y + 14}, workingColour)
end end
function popupText(glasses, text, x, y, color) function popupText(glasses, text, x, y, color)
local substringLength = 1 local substringLength = 1
@ -137,23 +168,40 @@ function popupText(glasses, text, x, y, color)
local steps = math.ceil(#text / substringLength) local steps = math.ceil(#text / substringLength)
local stepLength = substringLength * 5 local stepLength = substringLength * 5
local i = 1 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 background =
local top = ARG.hudQuad(glasses, {x-5, y-1}, {x-5, y}, {x-5+1, y}, {x-5+1, y-1}, machineBackground) ARG.hudQuad(glasses, {x - 5, y}, {x - 5, y + 9}, {x - 5 + 1, y + 9}, {x - 5 + 1, y}, machineBackground, 0.5)
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 top = ARG.hudQuad(glasses, {x - 5, y - 1}, {x - 5, y}, {x - 5 + 1, y}, {x - 5 + 1, y - 1}, machineBackground)
local hudText = ARG.hudText(glasses, "", x+1, y+1, color) local bottom =
local wedge = ARG.hudQuad(glasses, {x-5-10, y-1}, {x-5, y-1}, {x-5, y+10}, {x-5+11, y+10}, machineBackground) 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 direction = 1
local function advance() 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) background.setVertex(4, math.min(width, x + stepLength * i), y)
top.setVertex(3, 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) 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(3, math.min(width + 10, x + stepLength * i + 10), y + 10)
bottom.setVertex(4, math.min(width + 10, x + stepLength * i + 10), y+9) 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(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(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(3, math.min(width + 11, x + stepLength * i + 11), y + 10)
wedge.setVertex(4, math.min(width + 1, x + stepLength * i + 1), y-1) wedge.setVertex(4, math.min(width + 1, x + stepLength * i + 1), y - 1)
hudText.setText(string.sub(text, 1, substringLength * i)) hudText.setText(string.sub(text, 1, substringLength * i))
i = i + direction i = i + direction
if i < 0 then if i < 0 then
@ -166,7 +214,7 @@ function popupText(glasses, text, x, y, color)
end end
local function retract() local function retract()
direction = -1 direction = -1
event.timer(0.03, advance, steps+2) event.timer(0.03, advance, steps + 2)
end end
event.timer(0.03, advance, steps) event.timer(0.03, advance, steps)
return retract return retract
@ -181,25 +229,107 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
local fluids = comp.me_interface.getFluidsInNetwork() local fluids = comp.me_interface.getFluidsInNetwork()
if initFluidMap then if initFluidMap then
for i = 0, #fluidMap, 1 do 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 background =
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) ARG.hudQuad(
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) glasses,
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) {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) 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 fillLevels[fluidMap[i].label] = fill
if i % 2 == 0 then 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 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 end
entries = i entries = i
end end
entries = entries + 1 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 finish =
local verticalStrip = ARG.hudQuad(glasses,{x-8, y},{x-8, y - 2 + entries * h},{x-7, y - 2 + entries * h},{x-7, y}, workingColour) ARG.hudQuad(
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) glasses,
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) {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 initFluidMap = false
elseif computer.uptime() - lastRefresh > 30 then elseif computer.uptime() - lastRefresh > 30 then
for i = 0, #fluidMap, 1 do for i = 0, #fluidMap, 1 do
@ -212,7 +342,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
end end
local fillPercentage = math.min(currentLevel / (fluidMap[i].max * 1000000.0), 1) local fillPercentage = math.min(currentLevel / (fluidMap[i].max * 1000000.0), 1)
fillQuad.setVertex(1, x + w - fillPercentage * (w + 8), y + i * h) 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 end
lastRefresh = computer.uptime() lastRefresh = computer.uptime()
end end
@ -220,8 +350,12 @@ end
local function refreshDatabase(itemList) local function refreshDatabase(itemList)
local filteredList = {} local filteredList = {}
for i = 1, #itemList, 1 do for i = 1, #itemList, 1 do
if i % 200 == 0 then os.sleep() end if i % 200 == 0 then
if itemList[i].size >= 100 then filteredList[itemList[i].label] = itemList[i].size end os.sleep()
end
if itemList[i].size >= 100 then
filteredList[itemList[i].label] = itemList[i].size
end
itemList[i] = nil itemList[i] = nil
end end
return filteredList return filteredList
@ -230,14 +364,21 @@ local rollingTextObjects = {}
local function rollingText(glasses, text, start, stop, y, color) local function rollingText(glasses, text, start, stop, y, color)
local textObject = ARG.hudText(glasses, "", start, y, color) local textObject = ARG.hudText(glasses, "", start, y, color)
textObject.setAlpha(0.8) textObject.setAlpha(0.8)
local backgroundEndWedge = ARG.hudTriangle(glasses, {stop, y-2},{stop, y+10},{stop+12, y+10}, hudColour) 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 backgroundStartWedge =
local startWedge = ARG.hudQuad(glasses, {start, y-2},{start, y+8},{start+30, y+8}, {start+30, y-2}, hudColour) ARG.hudTriangle(glasses, {start - 12, y - 2}, {start, y + 10}, {start + 12, y - 2}, hudColour)
rollingTextObjects[#rollingTextObjects+1] = {t = textObject, bew = backgroundEndWedge, bsw = backgroundStartWedge, sw = startWedge} 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 stepSize = 1
local steps = start - stop / stepSize local steps = start - stop / stepSize
local step = 0 local step = 0
local textLength = #text*5 local textLength = #text * 5
local textRemaining = #text local textRemaining = #text
local textToRemove = #text local textToRemove = #text
local function truncate() local function truncate()
@ -266,10 +407,18 @@ local function rollingText(glasses, text, start, stop, y, color)
end end
local function clearTicker(glasses) local function clearTicker(glasses)
for i = 1, #rollingTextObjects do for i = 1, #rollingTextObjects do
if rollingTextObjects[i].t ~= nil then glasses.removeObject(rollingTextObjects[i].t.getID()) end if rollingTextObjects[i].t ~= nil then
if rollingTextObjects[i].bew ~= nil then glasses.removeObject(rollingTextObjects[i].bew.getID()) end glasses.removeObject(rollingTextObjects[i].t.getID())
if rollingTextObjects[i].bsw ~= nil then glasses.removeObject(rollingTextObjects[i].bsw.getID()) end end
if rollingTextObjects[i].sw ~= nil then glasses.removeObject(rollingTextObjects[i].sw.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 end
rollingTextObjects = {} rollingTextObjects = {}
end end
@ -279,7 +428,7 @@ function difference(new)
for label, amount in pairs(cachedAmounts) do for label, amount in pairs(cachedAmounts) do
if new[label] ~= nil then if new[label] ~= nil then
if new[label] - amount > 64 or new[label] - amount < -64 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 end
end end
@ -293,49 +442,56 @@ function ARWidgets.itemTicker(glasses, x, y, w)
local function formatMillions(number) local function formatMillions(number)
local millions = number / 1000000 local millions = number / 1000000
if millions >= 10 then if millions >= 10 then
return string.sub(millions, 1, 5).."M" return string.sub(millions, 1, 5) .. "M"
else else
return string.sub(millions, 1, 4).."M" return string.sub(millions, 1, 4) .. "M"
end end
end end
local function getTotalItemCount(items) local function getTotalItemCount(items)
local sum = 0 local sum = 0
for i = 1, #items, 1 do 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 sum = sum + items[i].size
end end
return sum return sum
end end
if initializeTicker then 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 background =
local top = ARG.hudQuad(glasses, {x, y},{x, y+2},{x+w, y+2},{x+w, y}, hudColour) ARG.hudQuad(glasses, {x, y + 2}, {x, y + 14}, {x + w, y + 14}, {x + w, y + 2}, machineBackground, 0.5)
local bottom = ARG.hudQuad(glasses, {x, y+14},{x, y+20},{x+w, y+20},{x+w, y+14}, hudColour) local top = ARG.hudQuad(glasses, {x, y}, {x, y + 2}, {x + w, y + 2}, {x + w, y}, hudColour)
local bottomStripe = ARG.hudQuad(glasses, {x, y+17},{x, y+18},{x+w, y+18},{x+w, y+17}, workingColour) local bottom = ARG.hudQuad(glasses, {x, y + 14}, {x, y + 20}, {x + w, y + 20}, {x + w, y + 14}, hudColour)
local wedge = ARG.hudTriangle(glasses, {x-20, y},{x, y+20},{x, y}, hudColour) local bottomStripe =
local backgroundEndWedge = ARG.hudTriangle(glasses, {x, y+2},{x, y+14},{x+12, y+14}, hudColour) ARG.hudQuad(glasses, {x, y + 17}, {x, y + 18}, {x + w, y + 18}, {x + w, y + 17}, workingColour)
local backgroundStartWedge = ARG.hudTriangle(glasses, {x+w-12, y+2},{x+w, y+14},{x+w+12, y+2}, hudColour) local wedge = ARG.hudTriangle(glasses, {x - 20, y}, {x, y + 20}, {x, y}, hudColour)
local diagonalStripe = ARG.hudQuad(glasses, {x-16, y+2},{x, y+18},{x, y+17},{x-15, y+2}, workingColour) local backgroundEndWedge = ARG.hudTriangle(glasses, {x, y + 2}, {x, y + 14}, {x + 12, y + 14}, hudColour)
local bottomBorder = ARG.hudRectangle(glasses, x+w - 170, y + 28, 170, 4, hudColour) local backgroundStartWedge =
local dataBorder = ARG.hudRectangle(glasses, x+w - 170, 20, 170, 12, hudColour, 0.5) ARG.hudTriangle(glasses, {x + w - 12, y + 2}, {x + w, y + 14}, {x + w + 12, y + 2}, hudColour)
local endWedge = ARG.hudTriangle(glasses,{x+w-182, y+20},{x+w-170, y+32},{x+w-170, y+20}, hudColour) local diagonalStripe =
local divisor1 = ARG.hudRectangle(glasses, x+w - 118, y+20, 2, 12, hudColour) ARG.hudQuad(glasses, {x - 16, y + 2}, {x, y + 18}, {x, y + 17}, {x - 15, y + 2}, workingColour)
local divisor2 = ARG.hudRectangle(glasses, x+w - 64, y+20, 2, 12, hudColour) local bottomBorder = ARG.hudRectangle(glasses, x + w - 170, y + 28, 170, 4, hudColour)
local bottomDataStripe = ARG.hudRectangle(glasses, x+w - 168, y+30, 168, 1, workingColour) 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) uniqueItems = ARG.hudText(glasses, "", x, y, workingColour, 0.75)
totalItems = 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) patterns = ARG.hudText(glasses, "", x, y, workingColour, 0.75)
uniqueItems.setPosition((x+w-114)*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) totalItems.setPosition((x + w - 168) * 1.33333, (y + 22) * 1.33333)
patterns.setPosition((x+w-60)*1.33333, (y+22)*1.33333) patterns.setPosition((x + w - 60) * 1.33333, (y + 22) * 1.33333)
initializeTicker = false initializeTicker = false
end end
local function showTicker(name, amount) 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() local function showChange()
if amount > 0 then if amount > 0 then
rollingText(glasses, "+"..amount, x+w, x, y+4, positiveEUColour) rollingText(glasses, "+" .. amount, x + w, x, y + 4, positiveEUColour)
else else
rollingText(glasses, ""..amount, x+w, x, y+4, negativeEUColour) rollingText(glasses, "" .. amount, x + w, x, y + 4, negativeEUColour)
end end
end end
event.timer(#name * 0.12, showChange, 1) event.timer(#name * 0.12, showChange, 1)
@ -351,9 +507,9 @@ function ARWidgets.itemTicker(glasses, x, y, w)
allItems = comp.me_interface.getItemsInNetwork() allItems = comp.me_interface.getItemsInNetwork()
itemsInNetwork = #allItems itemsInNetwork = #allItems
craftables = #comp.me_interface.getCraftables() craftables = #comp.me_interface.getCraftables()
totalItems.setText("Total: "..formatMillions(getTotalItemCount(allItems))) totalItems.setText("Total: " .. formatMillions(getTotalItemCount(allItems)))
patterns.setText("Patterns: "..craftables) patterns.setText("Patterns: " .. craftables)
uniqueItems.setText("Unique: "..itemsInNetwork) uniqueItems.setText("Unique: " .. itemsInNetwork)
changedItems = difference(refreshDatabase(allItems)) changedItems = difference(refreshDatabase(allItems))
i = 1 i = 1
clearTicker(glasses) clearTicker(glasses)
@ -361,43 +517,69 @@ function ARWidgets.itemTicker(glasses, x, y, w)
end end
end end
function ARWidgets.crossHair(glasses, x, y) function ARWidgets.crossHair(glasses, x, y)
local horizontal = ARG.hudRectangle(glasses, x, y+5, 4, 1, workingColour, 0.5) 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 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 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 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 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 center = ARG.hudRectangle(glasses, x + 5, y + 5, 1, 1, hudColour, 0.7)
end end
local initializeCpuMonitor = true local initializeCpuMonitor = true
local cpuLights = {} local cpuLights = {}
function ARWidgets.cpuMonitor(glasses, x, y) function ARWidgets.cpuMonitor(glasses, x, y)
if initializeCpuMonitor then if initializeCpuMonitor then
local cpuBase2 = ARG.hudRectangle(glasses, x+94, y+12, 8, 12, 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 cpuSplitter = ARG.hudRectangle(glasses, x + 89, y + 9, 400, 3, hudColour)
local cpuSplitter2 = ARG.hudRectangle(glasses, x+102, y+18, 380, 6, hudColour) local cpuSplitter2 = ARG.hudRectangle(glasses, x + 102, y + 18, 380, 6, hudColour)
local function createCpuIndicator(cpuX, cpuY) 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 status =
local leftTriangle = ARG.hudTriangle(glasses, {cpuX, cpuY}, {cpuX, cpuY+6}, {cpuX+6, cpuY+6}, hudColour) ARG.hudQuad(
local rightTriangle = ARG.hudQuad(glasses, {cpuX+10, cpuY}, {cpuX+16, cpuY+6}, {cpuX+18, cpuY+6}, {cpuX+18, cpuY}, hudColour) 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 return status
end end
local i = 0 local i = 0
local j = 0 local j = 0
local cpuNumber = 1 local cpuNumber = 1
while i+j < 24 do while i + j < 24 do
if (i+j) % 2 == 1 then if (i + j) % 2 == 1 then
cpuLights[cpuNumber] = createCpuIndicator(x+102+j*17, y+12) cpuLights[cpuNumber] = createCpuIndicator(x + 102 + j * 17, y + 12)
j = j + 1 j = j + 1
else else
cpuLights[cpuNumber] = createCpuIndicator(x+94+i*17, y+3) cpuLights[cpuNumber] = createCpuIndicator(x + 94 + i * 17, y + 3)
i = i + 1 i = i + 1
end end
cpuNumber = cpuNumber + 1 cpuNumber = cpuNumber + 1
end end
local rowStop1 = ARG.hudRectangle(glasses, x+94+i*17, y+3, 300, 6, hudColour) 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 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 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 diagonalStrip =
ARG.hudQuad(
glasses,
{x + 89, y + 11},
{x + 89, y + 12},
{x + 100, y + 23},
{x + 100, y + 22},
workingColour
)
initializeCpuMonitor = false initializeCpuMonitor = false
end end
local cpus = comp.me_interface.getCpus() local cpus = comp.me_interface.getCpus()
@ -415,27 +597,30 @@ local initializeTPS = true
function ARWidgets.displayTPS(glasses, x, y) function ARWidgets.displayTPS(glasses, x, y)
if initializeTPS then if initializeTPS then
initializeTPS = false 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 startBlock = ARG.hudRectangle(glasses, x, y, 40, 23, hudColour)
local top = ARG.hudRectangle(glasses, x+40, y, 65, 4, 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 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 wedge1 =
local wedge2 = ARG.hudQuad(glasses, {x+105, y}, {x+86, y+19}, {x+93, y+19}, {x+112, y}, hudColour) ARG.hudQuad(glasses, {x + 40, y + 19}, {x + 40, y + 23}, {x + 42, y + 23}, {x + 46, y + 19}, hudColour)
local stripe1 = ARG.hudRectangle(glasses, x+2, y+20, 39, 1, workingColour) local wedge2 = ARG.hudQuad(glasses, {x + 105, y}, {x + 86, y + 19}, {x + 93, y + 19}, {x + 112, y}, hudColour)
local stripe2 = ARG.hudRectangle(glasses, x+45, y+16, 48, 1, workingColour) local stripe1 = ARG.hudRectangle(glasses, x + 2, y + 20, 39, 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 stripe2 = ARG.hudRectangle(glasses, x + 45, y + 16, 48, 1, workingColour)
local stripe4 = ARG.hudRectangle(glasses, x+1, y+2, 1, 19, workingColour) local stripe3 =
TPSText = ARG.hudText(glasses, "", x+42, y+6, workingColour, 1) 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 end
local tps = math.min(20.00, get.tps()) local tps = math.min(20.00, get.tps())
if tps > 15 then 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)) TPSText.setColor(ARG.hexToRGB(positiveEUColour))
elseif tps >= 10 then 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)) TPSText.setColor(ARG.hexToRGB(workingColour))
else else
TPSText.setText("TPS: "..string.sub(tps, 1, 4)) TPSText.setText("TPS: " .. string.sub(tps, 1, 4))
TPSText.setColor(ARG.hexToRGB(negativeEUColour)) TPSText.setColor(ARG.hexToRGB(negativeEUColour))
end end
end end

View File

@ -1,7 +1,11 @@
machineBackground = 0x121010; progressBackground = 0x272c2e machineBackground = 0x121010
labelColour = 0xFF00FF; progressBackground = 0x272c2e
errorColour = 0xFF0000; labelColour = 0xFF00FF
idleColour = 0xb300ff; workingColour = 0x00a6ff errorColour = 0xFF0000
positiveEUColour = 0x00CC00; negativeEUColour = 0xCC0000 idleColour = 0xb300ff
timeColour = 0x5500FF; textColor = 0x000000 workingColour = 0x00a6ff
hudColour = 0x1E1E28; positiveEUColour = 0x00CC00
negativeEUColour = 0xCC0000
timeColour = 0x5500FF
textColor = 0x000000
hudColour = 0x1E1E28

View File

@ -1,28 +1,34 @@
comp = require("component"); comp = require("component")
color = { color = {
red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF, red = 0xFF0000,
purple = 0x5500FF, cyan = 0x00A6FF, lightGreen = 0x00CC00, green = 0x00FF00,
lightGray = 0x272c2e, darkGray = 0x121010, white = 0x000000 blue = 0x0000FF,
purple = 0x5500FF,
cyan = 0x00A6FF,
lightGreen = 0x00CC00,
lightGray = 0x272c2e,
darkGray = 0x121010,
white = 0x000000
} }
local graphics = {} local graphics = {}
function pixel(GPU, x, y, color) 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.setForeground(color)
GPU.setBackground(baseBackground) GPU.setBackground(baseBackground)
if y % 2 == 1 then --Upper half of pixel if y % 2 == 1 then --Upper half of pixel
GPU.set(x, screenY, ""); GPU.set(x, screenY, "")
else --Lower half of pixel else --Lower half of pixel
GPU.set(x, screenY, ""); GPU.set(x, screenY, "")
end end
end end
function graphics.rect(GPU, x, y, w, h, color) function graphics.rect(GPU, x, y, w, h, color)
local hLeft = h local hLeft = h
if x > 0 and y > 0 then if x > 0 and y > 0 then
if y % 2 == 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) pixel(GPU, i, y, color)
end end
hLeft = hLeft - 1 hLeft = hLeft - 1
@ -30,50 +36,56 @@ function graphics.rect(GPU, x, y, w, h, color)
GPU.setBackground(color) GPU.setBackground(color)
GPU.setForeground(color) GPU.setForeground(color)
if hLeft % 2 == 1 then if hLeft % 2 == 1 then
GPU.fill(x, math.ceil(y/2)+(h-hLeft), w, (hLeft-1)/2, "") GPU.fill(x, math.ceil(y / 2) + (h - hLeft), w, (hLeft - 1) / 2, "")
for j = x, x+w-1 do for j = x, x + w - 1 do
pixel(GPU, j, y+h-1, color) pixel(GPU, j, y + h - 1, color)
end end
else 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 end
end end
function graphics.text(GPU, x, y, color, string) function graphics.text(GPU, x, y, color, string)
if y % 2 == 0 then error("Text position must be odd on y axis") end if y % 2 == 0 then
local screenY = math.ceil(y/2) error("Text position must be odd on y axis")
GPU.setForeground(color); end
for i = 0, #string-1 do local screenY = math.ceil(y / 2)
local baseChar, baseForeground, baseBackground = GPU.get(x+i, screenY) GPU.setForeground(color)
for i = 0, #string - 1 do
local baseChar, baseForeground, baseBackground = GPU.get(x + i, screenY)
GPU.setBackground(baseBackground) 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
end end
function graphics.centeredText(GPU, x, y, color, string) function graphics.centeredText(GPU, x, y, color, string)
if y % 2 == 0 then error("Text position must be odd on y axis") end if y % 2 == 0 then
local screenY = math.ceil(y/2) error("Text position must be odd on y axis")
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 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 end
function graphics.border(GPU, w, h, color) function graphics.border(GPU, w, h, color)
draw.rect(GPU, 1, 1, w, 1, color) draw.rect(GPU, 1, 1, w, 1, color)
draw.rect(GPU, 1, h*2, w, 1, color) draw.rect(GPU, 1, h * 2, w, 1, color)
draw.rect(GPU, 1, 1, 1, h*2, color) draw.rect(GPU, 1, 1, 1, h * 2, color)
draw.rect(GPU, w, 1, 1, h*2, color) draw.rect(GPU, w, 1, 1, h * 2, color)
end end
currentWindows = {} currentWindows = {}
function graphics.checkCollision(GPU, x, y) function graphics.checkCollision(GPU, x, y)
for window, params in pairs(currentWindows) do for window, params in pairs(currentWindows) do
if x >= params.x and x <= params.x+params.w-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 if y >= params.y and y <= params.y + math.ceil(params.h / 2) - 1 then
return window return window
end end
end end
@ -81,8 +93,8 @@ function graphics.checkCollision(GPU, x, y)
return nil return nil
end end
function graphics.createWindow(GPU, width, height, name) function graphics.createWindow(GPU, width, height, name)
local pageNumber = GPU.allocateBuffer(width, math.ceil(height/2)) local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2))
currentWindows[name] = {page=pageNumber, x=1, y=1, w=width, h=height, GPU = GPU} currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height, GPU = GPU}
return pageNumber return pageNumber
end end
local function copyWindow(GPU, x, y, page, destination) local function copyWindow(GPU, x, y, page, destination)

View File

@ -1,5 +1,9 @@
local draw = require("graphics"); local event = require("event"); local thread = require("thread"); local uc = require("unicode") local draw = require("graphics")
local comp = require("component"); GPU = comp.proxy(comp.get("f26678f4")) 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 gui, quit, editing = {}, false, false
local currentWindows = {} local currentWindows = {}
@ -7,8 +11,8 @@ local activeWindow
local keyInput, mouseInput, drag, inContextMenu local keyInput, mouseInput, drag, inContextMenu
function checkCollision(x, y) function checkCollision(x, y)
for window, params in pairs(currentWindows) do for window, params in pairs(currentWindows) do
if x >= params.x and x <= params.x+params.w-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 if y >= params.y and y <= params.y + math.ceil(params.h / 2) - 1 then
return window return window
end end
end end
@ -18,38 +22,42 @@ end
local contextMenus = 0 local contextMenus = 0
function contextMenu(GPU, x, y, data) function contextMenu(GPU, x, y, data)
function filterClicks(event) return event == "touch" end function filterClicks(event)
return event == "touch"
end
inContextMenu = true inContextMenu = true
contextMenus = contextMenus + 1 contextMenus = contextMenus + 1
local longestData = 0 local longestData = 0
for i, data in pairs(data) do for i, data in pairs(data) do
if #data > longestData then longestData = #data end if #data > longestData then
longestData = #data
end
end end
local contextWindow = createWindow(GPU, longestData, #data*2, "ContextMenu"..contextMenus) local contextWindow = createWindow(GPU, longestData, #data * 2, "ContextMenu" .. contextMenus)
GPU.setActiveBuffer(contextWindow) 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 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 end
currentWindows["ContextMenu"..contextMenus].x = x currentWindows["ContextMenu" .. contextMenus].x = x
currentWindows["ContextMenu"..contextMenus].y = y currentWindows["ContextMenu" .. contextMenus].y = y
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
function keyboardListener() function keyboardListener()
function processKey(event, address, key, code, player) function processKey(event, address, key, code, player)
local value = uc.char(key) local value = uc.char(key)
if value == "." then quit = true end if value == "." then
quit = true
end
if value == "e" then if value == "e" then
if editing then if editing then
editing = false editing = false
else else
editing = true end editing = true
end
end end
end end
return event.listen("key_up", processKey) return event.listen("key_up", processKey)
end end
@ -62,9 +70,15 @@ function processCommand(GPU, window, option)
currentWindows["ColorBox"].y = 10 currentWindows["ColorBox"].y = 10
end end
GPU.setActiveBuffer(currentWindows["ColorBox"].page) GPU.setActiveBuffer(currentWindows["ColorBox"].page)
if option == 1 then draw.rect(GPU, 1, 1, 10, 10, color.red) end if option == 1 then
if option == 2 then draw.rect(GPU, 1, 1, 10, 10, color.blue) end draw.rect(GPU, 1, 1, 10, 10, color.red)
if option == 3 then draw.rect(GPU, 1, 1, 10, 10, color.green) end 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) GPU.setActiveBuffer(0)
end end
@ -72,26 +86,29 @@ local i, xOffset, yOffset = 1, 0, 0
function mouseListener() function mouseListener()
function processClick(event, address, x, y, key, player) function processClick(event, address, x, y, key, player)
activeWindow = checkCollision(x, y) 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 key == 1.0 and editing then
if inContextMenu then contextMenus = 0 end if inContextMenu then
contextMenu(GPU, x, y, {[1]="Red", [2]="Blue", [3]="Green"}) contextMenus = 0
end
contextMenu(GPU, x, y, {[1] = "Red", [2] = "Blue", [3] = "Green"})
else else
if inContextMenu then if inContextMenu then
local cont = currentWindows["ContextMenu1"] 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 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) processCommand(GPU, activeWindow, y - cont.y + 1)
else else
inContextMenu = false inContextMenu = false
for j = 1, contextMenus do for j = 1, contextMenus do
currentWindows["ContextMenu"..j] = nil currentWindows["ContextMenu" .. j] = nil
end end
contextMenus = 0 contextMenus = 0
end end
else else
if activeWindow ~= "None " then end if activeWindow ~= "None " then
xOffset = x - currentWindows[activeWindow].x end
yOffset = y - currentWindows[activeWindow].y xOffset = x - currentWindows[activeWindow].x
yOffset = y - currentWindows[activeWindow].y
end end
end end
end end
@ -111,21 +128,22 @@ end
function dropListener() function dropListener()
function processDrop(event, address, x, y, key, player) function processDrop(event, address, x, y, key, player)
end end
return event.listen("drop", processDrop) return event.listen("drop", processDrop)
end end
function createWindow(GPU, width, height, name) function createWindow(GPU, width, height, name)
local pageNumber = GPU.allocateBuffer(width, math.ceil(height/2)) local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2))
currentWindows[name] = {page=pageNumber, x=1, y=1, w=width, h=height} currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height}
return pageNumber return pageNumber
end end
function compose(GPU) function compose(GPU)
local stateBuffer = currentWindows["State"].page local stateBuffer = currentWindows["State"].page
GPU.setActiveBuffer(stateBuffer) 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 for window, params in pairs(currentWindows) do
if params.w > 0 then if params.w > 0 then
copyWindow(GPU, params.x, params.y, params.page, stateBuffer) copyWindow(GPU, params.x, params.y, params.page, stateBuffer)
@ -133,7 +151,8 @@ function compose(GPU)
end end
if inContextMenu then if inContextMenu then
local cont = currentWindows["ContextMenu1"] 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) GPU.setActiveBuffer(0)
end end
@ -144,7 +163,9 @@ end
--return gui --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() GPU.freeAllBuffers()
keyInput, mouseInput, drag = keyboardListener(), mouseListener(), dragListener() keyInput, mouseInput, drag = keyboardListener(), mouseListener(), dragListener()
createWindow(GPU, 160, 100, "Black") createWindow(GPU, 160, 100, "Black")
@ -162,7 +183,10 @@ GPU.setActiveBuffer(0)
copyWindow(GPU, 1, 1, currentWindows["Black"].page) copyWindow(GPU, 1, 1, currentWindows["Black"].page)
while true do while true do
if quit then event.cancel(keyInput); break end if quit then
event.cancel(keyInput)
break
end
compose(GPU) compose(GPU)
os.sleep(0.1) os.sleep(0.1)
end end

View File

@ -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 = {} local utility = {}
function utility.machine(address) function utility.machine(address)
machineAddress = comp.get(address) machineAddress = comp.get(address)
if(machineAddress ~= nil) then if (machineAddress ~= nil) then
return comp.proxy(machineAddress) return comp.proxy(machineAddress)
else else
return nil return nil
@ -11,46 +14,56 @@ function utility.machine(address)
end end
function utility.getPercent(number) function utility.getPercent(number)
return (math.floor(number*1000)/10).."%" return (math.floor(number * 1000) / 10) .. "%"
end end
function utility.time(number) --Returns a given number formatted as Hours Minutes Seconds 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 end
function utility.splitNumber(number) --Returns given number formatted as XXX,XXX,XXX function utility.splitNumber(number) --Returns given number formatted as XXX,XXX,XXX
local formattedNumber = {} local formattedNumber = {}
local string = tostring(math.abs(number)) local string = tostring(math.abs(number))
local sign = number/math.abs(number) local sign = number / math.abs(number)
for i = 1, #string do for i = 1, #string do
n = string:sub(i, i) n = string:sub(i, i)
formattedNumber[i] = n formattedNumber[i] = n
if ((#string-i) % 3 == 0) and (#string-i > 0) then if ((#string - i) % 3 == 0) and (#string - i > 0) then
formattedNumber[i] = formattedNumber[i] .. "," formattedNumber[i] = formattedNumber[i] .. ","
end end
end
if (sign < 0) then
table.insert(formattedNumber, 1, "-")
end end
if(sign < 0) then table.insert(formattedNumber, 1, "-") end
return table.concat(formattedNumber, "") return table.concat(formattedNumber, "")
end end
function utility.tier(number) function utility.tier(number)
local values = {[1] = "LV", local values = {
[2] = "MV", [1] = "LV",
[3] = "HV", [2] = "MV",
[4] = "EV", [3] = "HV",
[5] = "IV", [4] = "EV",
[6] = "LuV", [5] = "IV",
[7] = "ZPM", [6] = "LuV",
[8] = "UV", [7] = "ZPM",
[9] = "UHV", [8] = "UV",
} [9] = "UHV"
return values[number] }
return values[number]
end end
function utility.exit(key) function utility.exit(key)
local function processKey(event, address, key, code, player) local function processKey(event, address, key, code, player)
local value = uc.char(key) local value = uc.char(key)
if value == "e" then run = false end if value == "e" then
run = false
end
return false return false
end end
event.listen("key_up", processKey) event.listen("key_up", processKey)
@ -64,19 +77,19 @@ function utility.componentChange(broadcastPort)
end end
function utility.progressText(current, max) function utility.progressText(current, max)
return current.."/"..max.."s" return current .. "/" .. max .. "s"
end end
function utility.tps() function utility.tps()
local function time() local function time()
local f = io.open("/tmp/TPS","w") local f = io.open("/tmp/TPS", "w")
f:write("test") f:write("test")
f:close() f:close()
return(require("filesystem").lastModified("/tmp/TPS")) return (require("filesystem").lastModified("/tmp/TPS"))
end end
local realTimeOld = time() local realTimeOld = time()
os.sleep(1) os.sleep(1)
return 20000 / (time() - realTimeOld) return 20000 / (time() - realTimeOld)
end end
return utility return utility

View File

@ -1,5 +1,9 @@
comp = require("component");screen = require("term"); computer = require("computer"); event = require("event") comp = require("component")
draw = require("graphics"); util = require("utility") screen = require("term")
computer = require("computer")
event = require("event")
draw = require("graphics")
util = require("utility")
local widgets = {} local widgets = {}
@ -10,20 +14,24 @@ function widgets.gtMachineInit(GPU, name, address)
draw.text(GPU, 4, 3, mainColor, name) draw.text(GPU, 4, 3, mainColor, name)
if machine ~= nil then if machine ~= nil then
for i = 1, #machine.getSensorInformation() do --Get maintenance index for i = 1, #machine.getSensorInformation() do --Get maintenance index
if string.match(machine.getSensorInformation()[i], "Problems") ~= nil then if string.match(machine.getSensorInformation()[i], "Problems") ~= nil then
maintenanceIndex = i maintenanceIndex = i
end end
end end
if maintenanceIndex ~= 0 and #machine.getSensorInformation() >= 7 then if maintenanceIndex ~= 0 and #machine.getSensorInformation() >= 7 then
--Check for tier on Processing Arrays --Check for tier on Processing Arrays
if string.match(machine.getSensorInformation()[6], "tier") ~= nil then if string.match(machine.getSensorInformation()[6], "tier") ~= nil then
local tier = util.tier((string.gsub(machine.getSensorInformation()[6], "([^0-9]+)", "")-1)/10) 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 if tier ~= nil then
draw.text(GPU, 4, 5, accentB, "" .. tier)
end
end end
--Check for parallel on Processing Arrays --Check for parallel on Processing Arrays
if string.match(machine.getSensorInformation()[7], "Parallel") ~= nil then if string.match(machine.getSensorInformation()[7], "Parallel") ~= nil then
local parallel = string.gsub(machine.getSensorInformation()[7], "([^0-9]+)", "") 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
end end
else else
@ -43,7 +51,7 @@ function widgets.gtMachine(GPU, name, address)
local char, f, b local char, f, b
if machine ~= nil then if machine ~= nil then
if machine.hasWork() 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 local barAmount = currentProgress
--First Straight --First Straight
_, f, _ = GPU.get(3, 1) _, f, _ = GPU.get(3, 1)
@ -55,31 +63,32 @@ function widgets.gtMachine(GPU, name, address)
draw.rect(GPU, 27, 2, 1, 7, barColor) draw.rect(GPU, 27, 2, 1, 7, barColor)
draw.rect(GPU, 3, 8, 20, 1, barColor) draw.rect(GPU, 3, 8, 20, 1, barColor)
draw.rect(GPU, 7, 2, 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) draw.rect(GPU, 24, 8, bars1, 1, mainColor)
end end
_, f, _ = GPU.get(2, 4) _, f, _ = GPU.get(2, 4)
if barAmount > 3 and f ~= mainColor then --Vertical if barAmount > 3 and f ~= mainColor then --Vertical
bars2 = math.max(0, math.min(7, barAmount-3)) bars2 = math.max(0, math.min(7, barAmount - 3))
draw.rect(GPU, 2, 2, 1, 7, barColor) draw.rect(GPU, 2, 2, 1, 7, barColor)
draw.rect(GPU, 27, 2, 1, 7, barColor) draw.rect(GPU, 27, 2, 1, 7, barColor)
draw.rect(GPU, 3, 8, 20, 1, barColor) draw.rect(GPU, 3, 8, 20, 1, barColor)
draw.rect(GPU, 7, 2, 20, 1, barColor) draw.rect(GPU, 7, 2, 20, 1, barColor)
draw.rect(GPU, 2, 2, 1, bars2, mainColor) 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 end
if barAmount > 10 then --Long Straight if barAmount > 10 then --Long Straight
local bars3 = math.max(0, barAmount-10) local bars3 = math.max(0, barAmount - 10)
draw.rect(GPU, 3, 8, 20, 1, barColor) draw.rect(GPU, 3, 8, 20, 1, barColor)
draw.rect(GPU, 7, 2, 20, 1, barColor) draw.rect(GPU, 7, 2, 20, 1, barColor)
draw.rect(GPU, 3, 8, bars3, 1, mainColor) 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 end
progressString = tostring(math.floor(machine.getWorkProgress()/20)).."/"..tostring(math.floor(machine.getWorkMaxProgress()/20)).."s" progressString =
middlePoint = math.min(9, 12-#progressString/2) 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.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 else --No work
_, f, _ = GPU.get(5, 1) _, f, _ = GPU.get(5, 1)
if f ~= barColor then if f ~= barColor then
@ -93,13 +102,16 @@ function widgets.gtMachine(GPU, name, address)
end end
end end
_, f, _ = GPU.get(6, 1) _, 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 if f ~= background then
draw.rect(GPU, 6, 2, 1, 1, background) draw.rect(GPU, 6, 2, 1, 1, background)
draw.rect(GPU, 23, 8, 1, 1, background) draw.rect(GPU, 23, 8, 1, 1, background)
end end
else else
if(machine.isWorkAllowed()) then if (machine.isWorkAllowed()) then
if f ~= accentA then if f ~= accentA then
draw.rect(GPU, 6, 2, 1, 1, accentA) draw.rect(GPU, 6, 2, 1, 1, accentA)
draw.rect(GPU, 23, 8, 1, 1, accentA) draw.rect(GPU, 23, 8, 1, 1, accentA)
@ -110,16 +122,26 @@ function widgets.gtMachine(GPU, name, address)
draw.rect(GPU, 23, 8, 1, 1, errorColor) draw.rect(GPU, 23, 8, 1, 1, errorColor)
end end
end end
end end
end end
end end
function widgets.create(GPU, x, y, name, dataAddress, widget) function widgets.create(GPU, x, y, name, dataAddress, widget)
local width, height = widget.width, widget.height 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) GPU.setActiveBuffer(page)
local widgetData = widget.initialize(GPU, name, dataAddress) 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) GPU.setActiveBuffer(0)
end end

View File

@ -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 AU = require("util")
local AT = require("transport") 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 D = require("dictionary")
local network = comp.modem local network = comp.modem
local id, AD local id, AD
local function requestID() local function requestID()
network.broadcast(100, "requestID") network.broadcast(100, "requestID")
local _, _, _, _, _, messageType, value = event.pull("modem_message"); local _, _, _, _, _, messageType, value = event.pull("modem_message")
while messageType ~= "sendID" do while messageType ~= "sendID" do
_, _, _, _, _, messageType, value = event.pull("modem_message") _, _, _, _, _, messageType, value = event.pull("modem_message")
os.sleep(0.2) os.sleep(0.2)
@ -18,42 +23,75 @@ end
function checkRepeat(recipe) function checkRepeat(recipe)
local correctItems = 0 local correctItems = 0
for i = 1, recipe.inputs, 1 do for i = 1, recipe.inputs, 1 do
if AT.isEmpty(AD["inputTransposer"..i], 16) then 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.check(AD["inputTransposer" .. i], recipe["input" .. i].name, recipe["input" .. i].amount) then
correctItems = correctItems + 1 correctItems = correctItems + 1
else return false end else
else return false end return false
end
else
return false
end
end end
for i = 1, recipe.fluids, 1 do for i = 1, recipe.fluids, 1 do
if AT.isEmpty(AD["fluidTransposer"..i], 1) 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 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 correctItems = correctItems + 1
else return false end else
else return false end return false
end
else
return false
end
end
if correctItems == recipe.inputs + recipe.fluids then
return true
else
return false
end end
if correctItems == recipe.inputs + recipe.fluids then return true else return false end
end end
local function processRecipe(recipe) local function processRecipe(recipe)
local database, interface = AD.database, AD.input1 local database, interface = AD.database, AD.input1
local function insert() 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.fluids, 1 do
for i = 1, recipe.inputs, 1 do AT.move(AD["inputTransposer"..i], recipe["input"..i].amount, 16) end AT.move(
for i = 1, recipe.fluids, 1 do AT.empty(AD["fluidTransposer"..i]) end 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 end
for i = 1, recipe.inputs, 1 do for i = 1, recipe.inputs, 1 do
database.clear(i) 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 end
for i = 1, recipe.fluids, 1 do for i = 1, recipe.fluids, 1 do
database.clear(20+i) database.clear(20 + i)
interface.store({label = fluidMap[recipe["fluid"..i].name].name}, database.address, 20+i, 1) interface.store({label = fluidMap[recipe["fluid" .. i].name].name}, database.address, 20 + i, 1)
end end
for i = 1, recipe.inputs, 1 do 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 end
for i = 1, recipe.fluids, 1 do 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 end
::insertRecipes:: ::insertRecipes::
insert() insert()
@ -69,8 +107,12 @@ local function processRecipe(recipe)
network.broadcast(id, "jammed") network.broadcast(id, "jammed")
else else
screen.write(" ... Assembly Started") screen.write(" ... Assembly Started")
while AD.controller.hasWork() do os.sleep(0.1) end while AD.controller.hasWork() do
if checkRepeat(recipe) then goto insertRecipes end os.sleep(0.1)
end
if checkRepeat(recipe) then
goto insertRecipes
end
end end
AT.clearAll(AD) AT.clearAll(AD)
screen.write(" ... finished task!\n") screen.write(" ... finished task!\n")
@ -80,7 +122,7 @@ end
local function processMessage(localAddress, remoteAddress, port, distance, type, eventType, value2, value3) local function processMessage(localAddress, remoteAddress, port, distance, type, eventType, value2, value3)
if eventType == "startAssembly" then if eventType == "startAssembly" then
local recipe = S.unserialize(value2) local recipe = S.unserialize(value2)
screen.write("Starting assembly of "..recipe.label) screen.write("Starting assembly of " .. recipe.label)
processRecipe(recipe) processRecipe(recipe)
elseif eventType == "clear" then elseif eventType == "clear" then
AT.clearAll(AD) AT.clearAll(AD)
@ -109,7 +151,9 @@ local function startAssembly()
storedID = io.open("ID", "w") storedID = io.open("ID", "w")
storedID:write(id) storedID:write(id)
else else
for line in io.lines("ID") do id = line + 0 end for line in io.lines("ID") do
id = line + 0
end
end end
storedID:close() storedID:close()
network.open(id) network.open(id)

View File

@ -1,21 +1,20 @@
fluidMap = { fluidMap = {
["fluid.molten.solderingalloy"] = {name = "gt.metaitem.99.314.name", size = 144}, ["fluid.molten.solderingalloy"] = {name = "gt.metaitem.99.314.name", size = 144},
["fluid.lubricant"] = {name = "gt.Volumetric_Flask.name", size = 250}, ["fluid.lubricant"] = {name = "gt.Volumetric_Flask.name", size = 250},
["IC2 Coolant"] = {name = "Coolant Cell", size = 1000}, ["IC2 Coolant"] = {name = "Coolant Cell", size = 1000},
["fluid.molten.styrenebutadienerubber"] = {name = "gt.metaitem.99.635.name", size = 144}, ["fluid.molten.styrenebutadienerubber"] = {name = "gt.metaitem.99.635.name", size = 144},
["fluid.molten.niobiumtitanium"] = {name = "gt.metaitem.99.360.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.molten.tritanium"] = {name = "gt.metaitem.99.329.name", size = 144},
["fluid.Neon"] = {name = "Neon Cell", size = 1000}, ["fluid.Neon"] = {name = "Neon Cell", size = 1000},
["fluid.molten.naquadria"] = {name = "gt.metaitem.99.327.name", size = 144} ["fluid.molten.naquadria"] = {name = "gt.metaitem.99.327.name", size = 144}
} }
dictionary = { dictionary = {
["gt.metaitem.01.32705.name"] = "gt.metaitem.03.32084.name", --IV ["gt.metaitem.01.32705.name"] = "gt.metaitem.03.32084.name", --IV
["gt.metaitem.03.32086.name"] = "gt.metaitem.03.32084.name", ["gt.metaitem.03.32086.name"] = "gt.metaitem.03.32084.name",
["gt.metaitem.03.32089.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.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 = { -- dictlist = {

View File

@ -1,17 +1,16 @@
local path = "/home" local path = "/home"
local shell = require("shell") 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/assemblyClient.lua",
"https://raw.githubusercontent.com/S4mpsa/InfOS/master/Programs/Assembly%20Line/dictionary.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/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) shell.setWorkingDirectory(path)
print("Updating Files") print("Updating Files")
for k,v in pairs(download_list) do for k, v in pairs(download_list) do
print("Fetching ",v) print("Fetching ", v)
local command = "wget "..v.." -f" local command = "wget " .. v .. " -f"
shell.execute(command) shell.execute(command)
end end
shell.setWorkingDirectory("/home") shell.setWorkingDirectory("/home")

View File

@ -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") AU = require("util")
local S = require("serialization") local S = require("serialization")
local D = require("dictionary") local D = require("dictionary")
@ -16,20 +21,24 @@ local function getIDs()
else else
for line in io.lines("IDs") do for line in io.lines("IDs") do
knownAssemblyLines = knownAssemblyLines + 1 knownAssemblyLines = knownAssemblyLines + 1
network.open(mainChannel+knownAssemblyLines) network.open(mainChannel + knownAssemblyLines)
assemblyStatus[mainChannel+knownAssemblyLines] = false assemblyStatus[mainChannel + knownAssemblyLines] = false
end end
end end
end end
local function contains(t, value) local function contains(t, value)
for k, v in pairs(t) do for k, v in pairs(t) do
if v == value then return true end if v == value then
return true
end
end end
return false return false
end end
local function getFree() local function getFree()
for i = mainChannel, mainChannel + knownAssemblyLines, 1 do for i = mainChannel, mainChannel + knownAssemblyLines, 1 do
if assemblyStatus[i] == false then return i end if assemblyStatus[i] == false then
return i
end
end end
return nil return nil
end end
@ -41,7 +50,7 @@ local function processMessage(type, localAddress, remoteAddress, port, distance,
assemblyStatus[newID] = false assemblyStatus[newID] = false
network.broadcast(mainChannel, "sendID", newID) network.broadcast(mainChannel, "sendID", newID)
local knownIDs = io.open("IDs", "a") local knownIDs = io.open("IDs", "a")
knownIDs:write(newID.."\n") knownIDs:write(newID .. "\n")
knownIDs:close() knownIDs:close()
elseif eventType == "complete" then elseif eventType == "complete" then
assemblyStatus[port] = false assemblyStatus[port] = false
@ -70,50 +79,80 @@ function startAssembly(assemblyport, recipe)
end end
local function spairs(t, order) local function spairs(t, order)
local keys = {} local keys = {}
for k in pairs(t) do keys[#keys+1] = k end for k in pairs(t) do
if order then table.sort(keys, function(a, b) return order(t, a, b) end) else table.sort(keys) end 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 local i = 0
return function() return function()
i = i + 1 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
end end
function matchRecipe(recipes) function matchRecipe(recipes)
local items = comp.me_interface.getItemsInNetwork() local items = comp.me_interface.getItemsInNetwork()
local foundItems = {} local foundItems = {}
if #items > 0 then for i = 1, #items, 1 do foundItems[items[i].label] = items[i].size end end if #items > 0 then
for outputLabel, recipe in spairs(recipes, function(t,a,b) return t[b].inputs < t[a].inputs end) do 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 found = 0
local craftable = 1000 local craftable = 1000
for i = 1, recipe.inputs, 1 do for i = 1, recipe.inputs, 1 do
local label, requiredAmount = recipe["input"..i].name, recipe["input"..i].amount local label, requiredAmount = recipe["input" .. i].name, recipe["input" .. i].amount
if dictionary[label] ~= nil then label = dictionary[label] end if dictionary[label] ~= nil then
if foundItems[label] == nil then break label = dictionary[label]
end
if foundItems[label] == nil then
break
else else
local existingAmount = foundItems[label] local existingAmount = foundItems[label]
if existingAmount >= requiredAmount then if existingAmount >= requiredAmount then
found = found + 1 found = found + 1
craftable = math.min(math.floor(existingAmount/requiredAmount), craftable) craftable = math.min(math.floor(existingAmount / requiredAmount), craftable)
end end
end end
end end
for i = 1, recipe.fluids, 1 do for i = 1, recipe.fluids, 1 do
local label, requiredAmount local label, requiredAmount
if fluidMap[recipe["fluid"..i].name] ~= nil then 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 label, requiredAmount =
fluidMap[recipe["fluid" .. i].name].name,
recipe["fluid" .. i].amount / fluidMap[recipe["fluid" .. i].name].size
else else
break break
end end
if foundItems[label] == nil then break if foundItems[label] == nil then
break
else else
local existingAmount = foundItems[label] local existingAmount = foundItems[label]
if existingAmount >= requiredAmount then if existingAmount >= requiredAmount then
found = found + 1 found = found + 1
craftable = math.min(math.floor(existingAmount/requiredAmount), craftable) craftable = math.min(math.floor(existingAmount / requiredAmount), craftable)
end end
end 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 end
return nil return nil
end end
@ -125,7 +164,7 @@ local function scheduleTasks()
if not contains(assemblyStatus, recipe.label) then if not contains(assemblyStatus, recipe.label) then
local taskid = getFree() local taskid = getFree()
if taskid ~= nil then 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) startAssembly(taskid, recipe)
else else
screen.write("No free assembly lines.\n") screen.write("No free assembly lines.\n")
@ -137,7 +176,7 @@ local function scheduleTasks()
local taskid = getFree() local taskid = getFree()
if taskid ~= nil then if taskid ~= nil then
startAssembly(taskid, recipe) 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 else
screen.write("No free assembly lines.\n") screen.write("No free assembly lines.\n")
end end

View File

@ -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 = {} local transport = {}
@ -16,22 +20,33 @@ function transport.clear(interface)
end end
function transport.check(transposer, item, amount) function transport.check(transposer, item, amount)
local itemstack = transposer.getStackInSlot(0, 1) local itemstack = transposer.getStackInSlot(0, 1)
if itemstack == nil then return false else if itemstack == nil then
if itemstack.label == item and itemstack.size >= amount then return true else return false end end return false
else
if itemstack.label == item and itemstack.size >= amount then
return true
else
return false
end
end
end end
function transport.isEmpty(transposer, slot) function transport.isEmpty(transposer, slot)
local itemstack = transposer.getStackInSlot(1, slot) local itemstack = transposer.getStackInSlot(1, slot)
if itemstack == nil then return true else return false end if itemstack == nil then
return true
else
return false
end
end end
function transport.clearAll(assemblydata) function transport.clearAll(assemblydata)
for i = 1, 15, 1 do for i = 1, 15, 1 do
if assemblydata["input"..i].getInterfaceConfiguration(1) ~= nil then if assemblydata["input" .. i].getInterfaceConfiguration(1) ~= nil then
transport.clear(assemblydata["input"..i]) transport.clear(assemblydata["input" .. i])
end end
end end
for i = 1, 4, 1 do for i = 1, 4, 1 do
if assemblydata["fluid"..i].getInterfaceConfiguration(1) ~= nil then if assemblydata["fluid" .. i].getInterfaceConfiguration(1) ~= nil then
transport.clear(assemblydata["fluid"..i]) transport.clear(assemblydata["fluid" .. i])
end end
end end
end end

View File

@ -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 assemblyUtil = {}
local function addEntries(file, prompt, amount, type) local function addEntries(file, prompt, amount, type)
local a, b, c local a, b, c
for i = 1, amount, 1 do for i = 1, amount, 1 do
screen.write(prompt.." "..i.." ") screen.write(prompt .. " " .. i .. " ")
a, b, c = event.pull() a, b, c = event.pull()
while a ~= "component_added" do a, b, c = event.pull(); os.sleep() end while a ~= "component_added" do
file:write(type..i..","..b.."\n") a, b, c = event.pull()
screen.write(b.."\n") os.sleep()
end
file:write(type .. i .. "," .. b .. "\n")
screen.write(b .. "\n")
end end
end end
local function addAuxilary(file, proxy, type) local function addAuxilary(file, proxy, type)
if proxy == nil then if proxy == nil then
screen.write("Cant find a valid "..type.."! Exiting...\n") screen.write("Cant find a valid " .. type .. "! Exiting...\n")
os.exit() os.exit()
else else
file:write(type..","..proxy.address.."\n") file:write(type .. "," .. proxy.address .. "\n")
end end
end end
local function split(s, sep) local function split(s, sep)
local fields = {}; local sep = sep or " "; local pattern = string.format("([^%s]+)", sep) local fields = {}
string.gsub(s, pattern, function(c) fields[#fields + 1] = c end) local sep = sep or " "
local pattern = string.format("([^%s]+)", sep)
string.gsub(
s,
pattern,
function(c)
fields[#fields + 1] = c
end
)
return fields return fields
end end
local function proxy(address) local function proxy(address)
machineAddress = comp.get(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 end
local function configureClient() local function configureClient()
local file = io.open("addresses", "w") local file = io.open("addresses", "w")
@ -71,15 +90,29 @@ local function voltageToTier(voltage)
end end
function copyPattern(interface, slot, recipe, database) function copyPattern(interface, slot, recipe, database)
for i = 1, recipe.inputs, 1 do for i = 1, recipe.inputs, 1 do
local item = recipe["input"..i] local item = recipe["input" .. i]
local name = item.name 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) interface.setInterfacePatternInput(slot, database, databaseMap[name], item.amount, i)
end end
end end
function getControllerTier(assemblyData) function getControllerTier(assemblyData)
local controller = assemblyData["controller"] 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 end
local function addRecipe(recipelist, slot, source, sourceSide) local function addRecipe(recipelist, slot, source, sourceSide)
if source.getStackInSlot(sourceSide, slot) ~= nil then if source.getStackInSlot(sourceSide, slot) ~= nil then
@ -93,14 +126,14 @@ local function addRecipe(recipelist, slot, source, sourceSide)
if pattern.inputItems ~= nil then if pattern.inputItems ~= nil then
local items = pattern.inputItems local items = pattern.inputItems
for i = 1, #items, 1 do 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 recipelist[pattern.output]["inputs"] = recipelist[pattern.output]["inputs"] + 1
end end
end end
if pattern.inputFluids ~= nil then if pattern.inputFluids ~= nil then
local fluids = pattern.inputFluids local fluids = pattern.inputFluids
for i = 1, #fluids do 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 recipelist[pattern.output]["fluids"] = recipelist[pattern.output]["fluids"] + 1
end end
end end

View File

@ -1,7 +1,15 @@
comp=require("component");screen=require("term");computer=require("computer");event=require("event"); thread = require("thread"); sides = require("sides") comp = require("component")
get=require("utility"); ARG=require("ARGraphics"); G = require("graphics") 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") S = require("stockerUtil")
local uc = require("unicode"); tx = require("transforms") local uc = require("unicode")
tx = require("transforms")
config = require("config") config = require("config")
local GPU = comp.gpu local GPU = comp.gpu
interface = comp.me_interface interface = comp.me_interface
@ -18,13 +26,27 @@ function mouseListener()
if activeWindow == "Button" then if activeWindow == "Button" then
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
if drawerItem == nil or number == "" then 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 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 if itemsToStock[drawerItem] ~= nil then
S.update(drawerItem, itemsToStock[drawerItem], number) S.update(drawerItem, itemsToStock[drawerItem], number)
itemsToStock[drawerItem] = number itemsToStock[drawerItem] = number
elseif number+0.0 > 0 then elseif number + 0.0 > 0 then
S.addPattern(drawerItem, number) S.addPattern(drawerItem, number)
itemsToStock[drawerItem] = number itemsToStock[drawerItem] = number
else else
@ -37,11 +59,17 @@ function mouseListener()
elseif activeWindow == "Number" then elseif activeWindow == "Number" then
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
if drawerItem == nil then 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() S.refreshCraftables()
end end
inNumberBox = true 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 else
inNumberBox = false inNumberBox = false
number = "" number = ""
@ -62,12 +90,14 @@ function keyboardListener()
if key == 10 then if key == 10 then
inNumberBox = false inNumberBox = false
G.refresh(GPU) 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 end
G.rect(GPU, currentWindows["Number"].x+2, currentWindows["Number"].y*2+1, 46, 6, 0x333333) if key == 8 then
G.text(GPU, currentWindows["Number"].x+4, currentWindows["Number"].y*2+3, workingColour, number) 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
end end
return event.listen("key_down", processKey) return event.listen("key_down", processKey)
@ -100,8 +130,14 @@ function getNewItem(GPU, x, y)
end end
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
if itemsToStock[drawerItem] ~= nil then if itemsToStock[drawerItem] ~= nil then
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.centeredText(GPU, currentWindows["Item"].x+30, currentWindows["Item"].y*2-3, 0xFFFFFF, "Configured: "..itemsToStock[drawerItem]) G.centeredText(
GPU,
currentWindows["Item"].x + 30,
currentWindows["Item"].y * 2 - 3,
0xFFFFFF,
"Configured: " .. itemsToStock[drawerItem]
)
end end
G.refresh(GPU) G.refresh(GPU)
else else
@ -116,8 +152,14 @@ function getNewItem(GPU, x, y)
end end
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
if itemsToStock[drawerItem] ~= nil then if itemsToStock[drawerItem] ~= nil then
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.centeredText(GPU, currentWindows["Item"].x+30, currentWindows["Item"].y*2-3, 0xFFFFFF, "Configured: "..itemsToStock[drawerItem]) G.centeredText(
GPU,
currentWindows["Item"].x + 30,
currentWindows["Item"].y * 2 - 3,
0xFFFFFF,
"Configured: " .. itemsToStock[drawerItem]
)
end end
G.refresh(GPU) G.refresh(GPU)
end end
@ -129,7 +171,7 @@ function getNewItem(GPU, x, y)
G.rect(GPU, 3, 3, 56, 2, 0x000000) G.rect(GPU, 3, 3, 56, 2, 0x000000)
G.centeredText(GPU, 30, 3, 0xFFFFFF, "") G.centeredText(GPU, 30, 3, 0xFFFFFF, "")
GPU.setActiveBuffer(0) 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) G.refresh(GPU)
end end
end end
@ -172,21 +214,21 @@ function craftableBox(GPU, x, y)
S.updateCache() S.updateCache()
for label, amount in pairs(itemsToStock) do for label, amount in pairs(itemsToStock) do
local stockedAmount = S.getAmount(label) local stockedAmount = S.getAmount(label)
local stockedString = string.sub(stockedAmount.."", 1, #(stockedAmount.."")-2) local stockedString = string.sub(stockedAmount .. "", 1, #(stockedAmount .. "") - 2)
local toStock = amount+0.0 local toStock = amount + 0.0
if S.uniques() > 2500 then --Check against rebooted system if S.uniques() > 2500 then --Check against rebooted system
if toStock > 0 then if toStock > 0 then
if drawerItem == label 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 elseif craftables[label] == nil then
G.text(GPU, 4, 3+2*i, negativeEUColour, label); G.text(GPU, 4, 3 + 2 * i, negativeEUColour, label)
else else
G.text(GPU, 4, 3+2*i, 0xFFFFFF, label); G.text(GPU, 4, 3 + 2 * i, 0xFFFFFF, label)
end end
if stockedAmount >= toStock then --In stock 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 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 else --Needs to be ordered
--Add crafting request loop here --Add crafting request loop here
if craftables[label] ~= nil then if craftables[label] ~= nil then
@ -196,9 +238,9 @@ function craftableBox(GPU, x, y)
currentlyCrafting[label] = nil currentlyCrafting[label] = nil
end end
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 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) i = math.min(i + 1, 43)
end end
end end
@ -207,11 +249,17 @@ function craftableBox(GPU, x, y)
G.refresh(GPU) G.refresh(GPU)
end end
mouseListener(); keyboardListener(); GPU.setResolution(160, 46); screen.clear() mouseListener()
keyboardListener()
GPU.setResolution(160, 46)
screen.clear()
G.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) G.refresh(GPU)
S.refreshCraftables(); S.loadPatterns() S.refreshCraftables()
S.loadPatterns()
local timeSinceRefresh = computer.uptime() local timeSinceRefresh = computer.uptime()
while true do while true do
getNewItem(GPU, 100, 38) getNewItem(GPU, 100, 38)

View File

@ -1,6 +1,14 @@
comp=require("component");screen=require("term");computer=require("computer");event=require("event"); thread = require("thread"); sides = require("sides") comp = require("component")
get=require("utility"); ARG=require("ARGraphics"); G = require("graphics") screen = require("term")
local uc = require("unicode"); tx = require("transforms") 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") config = require("config")
local GPU = comp.gpu local GPU = comp.gpu
local sUtil = {} local sUtil = {}
@ -13,60 +21,82 @@ function sUtil.refreshCraftables()
for i, craftable in pairs(c) do for i, craftable in pairs(c) do
if i ~= "n" then if i ~= "n" then
if i % 10 == 0 then if i % 10 == 0 then
G.centeredText(GPU, currentWindows["Number"].x+25, currentWindows["Number"].y*2+3, 0xFFFFFF, "Discovering Patterns: "..i.." / "..#c) G.centeredText(
GPU,
currentWindows["Number"].x + 25,
currentWindows["Number"].y * 2 + 3,
0xFFFFFF,
"Discovering Patterns: " .. i .. " / " .. #c
)
end end
end end
if craftable ~= #c then if craftable ~= #c then
craftables[craftable.getItemStack().label] = craftable.request craftables[craftable.getItemStack().label] = craftable.request
end end
end end
G.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: "..#c) G.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: " .. #c)
end end
local cachedAmounts = {} local cachedAmounts = {}
function sUtil.updateCache() function sUtil.updateCache()
local itemList = interface.getItemsInNetwork() local itemList = interface.getItemsInNetwork()
for i = 1, #itemList, 1 do 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 cachedAmounts[itemList[i].label] = itemList[i].size
itemList[i] = nil itemList[i] = nil
end end
end end
function sUtil.getAmount(itemLabel) 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 end
function sUtil.uniques() function sUtil.uniques()
return #cachedAmounts return #cachedAmounts
end end
function sUtil.update(label, oldAmount, newAmount) function sUtil.update(label, oldAmount, newAmount)
local file = io.open("configured", 'r') local file = io.open("configured", "r")
local fileContent = {} local fileContent = {}
local lineNumber = 0 local lineNumber = 0
local i = 1 local i = 1
for line in file:lines() do for line in file:lines() do
if line == label..","..oldAmount then lineNumber = i end if line == label .. "," .. oldAmount then
table.insert (fileContent, line) lineNumber = i
end
table.insert(fileContent, line)
i = i + 1 i = i + 1
end end
io.close(file) io.close(file)
file = io.open("configured", 'w') file = io.open("configured", "w")
for index, value in ipairs(fileContent) do for index, value in ipairs(fileContent) do
if index ~= lineNumber then if index ~= lineNumber then
file:write(value..'\n') file:write(value .. "\n")
else else
file:write(label..","..newAmount..'\n') file:write(label .. "," .. newAmount .. "\n")
end end
end end
io.close(file) io.close(file)
end end
function sUtil.addPattern(label, amount) function sUtil.addPattern(label, amount)
local file = io.open("configured", "a") local file = io.open("configured", "a")
file:write(label..","..amount.."\n") file:write(label .. "," .. amount .. "\n")
file:close() file:close()
itemsToStock[label] = amount itemsToStock[label] = amount
end end
local function split(s, sep) local function split(s, sep)
local fields = {}; local sep = sep or " "; local pattern = string.format("([^%s]+)", sep) local fields = {}
string.gsub(s, pattern, function(c) fields[#fields + 1] = c end) local sep = sep or " "
local pattern = string.format("([^%s]+)", sep)
string.gsub(
s,
pattern,
function(c)
fields[#fields + 1] = c
end
)
return fields return fields
end end
function sUtil.loadPatterns() function sUtil.loadPatterns()

View File

@ -1,28 +1,35 @@
comp = require("component"); event = require("event") comp = require("component")
event = require("event")
AR = require("ARWidgets") AR = require("ARWidgets")
ARG = require("ARGraphics") ARG = require("ARGraphics")
local wSampsa, hSampsa = 853, 473 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 local glasses = comp.glasses
glasses.removeAll() 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) AR.crossHair(glasses, 422, 231)
screen.clear() screen.clear()
while true do while true do
AR.powerDisplay(glasses, comp.gt_machine, powerHudX, powerHudY, powerHudW, powerHudH) AR.powerDisplay(glasses, comp.gt_machine, powerHudX, powerHudY, powerHudW, powerHudH)
AR.fluidMonitor(glasses, 795, 153, { AR.fluidMonitor(
[0] = {label = "Oxygen Gas", displayName = "Oxygen", color = 0x688690, max = 128}, glasses,
[1] = {label = "Nitrogen Gas", displayName = "Nitrogen", color = 0x976868, max = 128}, 795,
[2] = {label = "Hydrogen Gas", displayName = "Hydrogen", color = 0xa78282, max = 128}, 153,
[3] = {label = "fluid.chlorine", displayName = "Chlorine", color = 0x428282, max = 128}, {
[4] = {label = "fluid.radon", displayName = "Radon", color = 0xff5bff, max = 2}, [0] = {label = "Oxygen Gas", displayName = "Oxygen", color = 0x688690, max = 128},
[5] = {label = "UU-Matter", displayName = "UU Matter", color = 0x4a0946, max = 2}, [1] = {label = "Nitrogen Gas", displayName = "Nitrogen", color = 0x976868, max = 128},
[6] = {label = "fluid.molten.plastic", displayName = "Rubber", color = 0x050505, max = 2}, [2] = {label = "Hydrogen Gas", displayName = "Hydrogen", color = 0xa78282, max = 128},
[7] = {label = "fluid.molten.polytetrafluoroethylene", displayName = "PTFE", color = 0x4d4d4d, max = 2}, [3] = {label = "fluid.chlorine", displayName = "Chlorine", color = 0x428282, max = 128},
[8] = {label = "fluid.molten.styrenebutadienerubber", displayName = "SBR", color = 0x1d1817, max = 2}, [4] = {label = "fluid.radon", displayName = "Radon", color = 0xff5bff, max = 2},
[9] = {label = "fluid.molten.epoxid", displayName = "Epoxid", color = 0x9d6f13, max = 2}, [5] = {label = "UU-Matter", displayName = "UU Matter", color = 0x4a0946, max = 2},
[10] = {label = "fluid.molten.silicone", displayName = "Silicone Rubber", color = 0xa5a5a5, max = 2}, [6] = {label = "fluid.molten.plastic", displayName = "Rubber", color = 0x050505, max = 2},
[11] = {label = "fluid.molten.polybenzimidazole", displayName = "PBI", color = 0x262626, 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() os.sleep()

View File

@ -1,4 +1,5 @@
comp = require("component"); event = require("event") comp = require("component")
event = require("event")
AR = require("ARWidgets") AR = require("ARWidgets")
while true do while true do

View File

@ -1,4 +1,5 @@
comp = require("component"); event = require("event") comp = require("component")
event = require("event")
AR = require("ARWidgets") AR = require("ARWidgets")
while true do while true do

View File

@ -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 local GPU = comp.gpu
GPU.setResolution(54, 26) GPU.setResolution(54, 26)
@ -14,8 +18,10 @@ function checkHeatLevels()
local i = 1 local i = 1
for address, type in pairs(comp.list()) do for address, type in pairs(comp.list()) do
if type == "reactor_chamber" then if type == "reactor_chamber" then
screen.write("Reactor "..i) screen.write("Reactor " .. i)
if i < 10 then screen.write(" ") end if i < 10 then
screen.write(" ")
end
local reactor = comp.proxy(address) local reactor = comp.proxy(address)
if reactor.getHeat() > 0 then if reactor.getHeat() > 0 then
GPU.setForeground(0xFF0000) GPU.setForeground(0xFF0000)

View File

@ -7,22 +7,25 @@ destinations = {
[6] = {name = "Test", id = 3004} [6] = {name = "Test", id = 3004}
} }
local comp=require("component"); local event=require("event"); local screen=require("term"); local computer = require("computer") local comp = require("component")
local util = require("utility"); local draw=require("graphics") local event = require("event")
local screen = require("term")
local computer = require("computer")
local util = require("utility")
local draw = require("graphics")
local GPU = comp.gpu local GPU = comp.gpu
GPU.setResolution(80, 25) GPU.setResolution(80, 25)
local boundingBoxes = { local boundingBoxes = {}
}
function createDestination(x, y, index) function createDestination(x, y, index)
local width, height = 18, 6 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) GPU.setActiveBuffer(page)
draw.rect(GPU, 1, 1, 18, 6, 0x111111) draw.rect(GPU, 1, 1, 18, 6, 0x111111)
local destinationColor = destinations[index].color or 0x0055FF local destinationColor = destinations[index].color or 0x0055FF
draw.rect(GPU, 3, 3, 14, 2, 0x000000) draw.rect(GPU, 3, 3, 14, 2, 0x000000)
draw.centeredText(GPU, 10, 3, destinationColor ,destinations[index].name) draw.centeredText(GPU, 10, 3, destinationColor, destinations[index].name)
windows[index] = {GPU = GPU, page=page, address = "", x=x, y=y, w=width, h=height} windows[index] = {GPU = GPU, page = page, address = "", x = x, y = y, w = width, h = height}
GPU.setActiveBuffer(0) GPU.setActiveBuffer(0)
end end
function setDestination(code) function setDestination(code)
@ -36,7 +39,7 @@ function checkClick(_, address, x, y, button, name)
for i = 1, #boundingBoxes, 1 do for i = 1, #boundingBoxes, 1 do
local xb, yb = boundingBoxes[i].x, math.ceil(boundingBoxes[i].y / 2) 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 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 local destinationColor = destinations[i].color or 0x0055FF
setDestination(destinations[i].id) setDestination(destinations[i].id)
draw.rect(GPU, 30, 43, 22, 2, 0x000000) draw.rect(GPU, 30, 43, 22, 2, 0x000000)
@ -62,7 +65,7 @@ GPU.fill(0, 0, 100, 100, " ")
draw.rect(GPU, 28, 41, 26, 6, 0x111111) draw.rect(GPU, 28, 41, 26, 6, 0x111111)
draw.rect(GPU, 30, 43, 22, 2, 0x000000) draw.rect(GPU, 30, 43, 22, 2, 0x000000)
draw.text(GPU, 31, 39, 0xFFFFFF, "Current Destination") draw.text(GPU, 31, 39, 0xFFFFFF, "Current Destination")
for i = 1 , #destinations, 1 do for i = 1, #destinations, 1 do
addBoundingBox(i) addBoundingBox(i)
createDestination(boundingBoxes[i].x, boundingBoxes[i].y, i) createDestination(boundingBoxes[i].x, boundingBoxes[i].y, i)
draw.update() draw.update()

View File

@ -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() function cycle()
comp.redstone.setOutput(2, 15) comp.redstone.setOutput(2, 15)
@ -20,7 +23,6 @@ local ticket = 1
--end --end
function setDestination(destination) function setDestination(destination)
end end
function unload(index) function unload(index)
@ -56,8 +58,9 @@ function doStartupSequence()
local gpu = comp.gpu local gpu = comp.gpu
gpu.freeAllBuffers() gpu.freeAllBuffers()
local colors = { local colors = {
[0] = 0x00a6ff, [0] = 0x00a6ff,
[1] = 0x000000} [1] = 0x000000
}
local buffer = gpu.allocateBuffer() local buffer = gpu.allocateBuffer()
gpu.setActiveBuffer(buffer) gpu.setActiveBuffer(buffer)
for i = 2, 20, 1 do for i = 2, 20, 1 do
@ -65,11 +68,7 @@ function doStartupSequence()
copyWindow(gpu, 0, 0, buffer, 0) copyWindow(gpu, 0, 0, buffer, 0)
end end
gpu.setForeground(colors[i % 2]) gpu.setForeground(colors[i % 2])
comp.gpu.fill(2 + i * 2, comp.gpu.fill(2 + i * 2, 1 + i, 80 - i * 4, 40 - i * 2, "")
1 + i,
80 - i * 4,
40 - i * 2,
"")
os.sleep(0.1) os.sleep(0.1)
end end
gpu.setActiveBuffer(0) gpu.setActiveBuffer(0)

View File

@ -1,4 +1,5 @@
comp = require("component"); event = require("event") comp = require("component")
event = require("event")
local transposer = comp.transposer local transposer = comp.transposer
local dark = 2 local dark = 2

View File

@ -1,17 +1,25 @@
Comp=require("component") Comp = require("component")
local transposer = Comp.transposer local transposer = Comp.transposer
local players = {["Sampsa"] = 3, ["Dark"] = 2} local players = {["Sampsa"] = 3, ["Dark"] = 2}
local function findEmptyCans(player) local function findEmptyCans(player)
local allItems = transposer.getAllStacks(players[player]).getAll() local allItems = transposer.getAllStacks(players[player]).getAll()
if #allItems > 30 then 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 end
return nil return nil
end end
local function checkLevel(player) local function checkLevel(player)
local itemStack = transposer.getStackInSlot(players[player], 28) 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 end
local function transferFood(player) local function transferFood(player)
@ -19,14 +27,18 @@ local function transferFood(player)
end end
local function transferEmpty(player) local function transferEmpty(player)
local slot = findEmptyCans(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 end
local function check(player) local function check(player)
if transposer.getInventorySize(players[player]) == 40 then if transposer.getInventorySize(players[player]) == 40 then
local inInventory = checkLevel(player) local inInventory = checkLevel(player)
if inInventory ~= nil then if inInventory ~= nil then
if inInventory < 40 then transferFood(player) end if inInventory < 40 then
transferFood(player)
end
os.sleep(0.2) os.sleep(0.2)
transferEmpty(player) transferEmpty(player)
end end

View File

@ -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 = {} local transposers = {}
function configureTransposers() function configureTransposers()
@ -22,7 +25,7 @@ function configureTransposers()
end end
end 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 end
function countTransposers() function countTransposers()
local count = 0 local count = 0

View File

@ -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 LSC = comp.gt_machine
local engaged = false local engaged = false
local function machine(address) local function machine(address)
machineAddress = comp.get(address) machineAddress = comp.get(address)
if(machineAddress ~= nil) then if (machineAddress ~= nil) then
return comp.proxy(machineAddress) return comp.proxy(machineAddress)
else else
return nil return nil
end end
end end
local function getPercentage() 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) local maxEU = math.floor(string.gsub(LSC.getSensorInformation()[3], "([^0-9]+)", "") + 0)
return currentEU/maxEU return currentEU / maxEU
end end
local turbineRedstone = { local turbineRedstone = {
@ -34,9 +39,13 @@ end
local function checkLevels() local function checkLevels()
local fill = getPercentage() local fill = getPercentage()
if fill < 0.15 then if fill < 0.15 then
if not engaged then engage() end if not engaged then
engage()
end
elseif fill > 0.95 then elseif fill > 0.95 then
if engaged then disengage() end if engaged then
disengage()
end
end end
end end

View File

@ -1,19 +1,16 @@
local path = "/lib"
local shell = require("shell") local shell = require("shell")
local download_list =
{ local tarMan = "https://raw.githubusercontent.com/mpmxyz/ocprograms/master/usr/man/tar.man"
"https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/ARWidgets.lua", local tarBin = "https://raw.githubusercontent.com/mpmxyz/ocprograms/master/home/bin/tar.lua"
"https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/config.lua", local InfOS = "https://github.com/gordominossi/InfOS/releases/download/v0/InfOS.tar"
"https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/graphics.lua",
"https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/utility.lua", shell.setWorkingDirectory("/usr/man")
"https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/widgets.lua", shell.execute("wget " .. tarMan .. " -f")
"https://raw.githubusercontent.com/S4mpsa/InfOS/master/Libraries/ARGraphics.lua"
} shell.setWorkingDirectory("/bin")
shell.setWorkingDirectory(path) shell.execute("wget " .. tarBin .. " -f")
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") shell.setWorkingDirectory("/home")
print("Updating InfOS")
shell.execute("wget " .. InfOS .. " -f")
shell.execute("tar -xf InfOS.tar")