Capitalizing or encapsulating global variables

Making the linter happy
This commit is contained in:
Gabriel Moreira Minossi 2021-01-06 13:02:12 -03:00
parent 8fdf6b73e8
commit 4c11905281
44 changed files with 762 additions and 677 deletions

View File

@ -7,7 +7,7 @@ function AR.cube(glasses, x, y, z, color, alpha, scale)
alpha = alpha or 1
local cube = glasses.addCube3D()
cube.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z)
cube.setColor(table.unpack(color))
cube.setColor(color)
cube.setAlpha(alpha)
cube.setScale(scale)
return cube
@ -19,7 +19,7 @@ function AR.line(glasses, source, dest, color, alpha, scale)
local line = glasses.addLine3D()
line.setVertex(1, source.x - terminal.x + 0.5, source.y - terminal.y + 0.5, source.z - terminal.z + 0.5)
line.setVertex(2, dest.x - terminal.x + 0.5, dest.y - terminal.y + 0.5, dest.z - terminal.z + 0.5)
line.setColor(table.unpack(color))
line.setColor(color)
line.setAlpha(alpha)
line.setScale(scale)
return line
@ -30,7 +30,7 @@ function AR.worldText(glasses, name, x, y, z, color, alpha, scale)
alpha = alpha or 1
local text = glasses.addFloatingText()
text.set3DPos(x - terminal.x, y - terminal.y, z - terminal.z)
text.setColor(table.unpack(color))
text.setColor(color)
text.setAlpha(alpha)
text.setScale(scale)
text.setText(name)
@ -40,7 +40,7 @@ end
function AR.hudTriangle(glasses, a, b, c, color, alpha)
alpha = alpha or 1.0
local triangle = glasses.addTriangle()
triangle.setColor(table.unpack(color))
triangle.setColor(color)
triangle.setAlpha(alpha)
triangle.setVertex(1, a[1], a[2])
triangle.setVertex(2, b[1], b[2])
@ -51,7 +51,7 @@ end
function AR.hudQuad(glasses, a, b, c, d, color, alpha)
alpha = alpha or 1.0
local quad = glasses.addQuad()
quad.setColor(table.unpack(color))
quad.setColor(color)
quad.setAlpha(alpha)
quad.setVertex(1, a[1], a[2])
quad.setVertex(2, b[1], b[2])
@ -65,7 +65,7 @@ function AR.hudRectangle(glasses, x, y, w, h, color, alpha)
local rect = glasses.addRect()
rect.setPosition(x, y)
rect.setSize(h, w)
rect.setColor(table.unpack(color))
rect.setColor(color)
rect.setAlpha(alpha)
return rect
end
@ -83,7 +83,7 @@ function AR.hudText(glasses, displayText, x, y, color, scale)
local text = glasses.addTextLabel()
text.setText(displayText)
text.setPosition(x, y)
text.setColor(table.unpack(color))
text.setColor(color)
AR.textSize(text, scale)
return text
end

View File

@ -1,26 +1,25 @@
component = require("component")
computer = require("computer")
event = require("event")
get = require("easy")
Component = require("component")
Computer = require("computer")
Event = require("event")
Get = require("easy")
ARG = require("ARGraphics")
colors = require("colors")
Colors = require("colors")
local ARWidgets = {}
local firstRead, lastRead, counter, currentIO = 0, 0, 1, 1
local euUpdateInterval = 120
local readings = {}
local function updateEU(LSC)
batteryBuffer = batteryBuffer or false
if counter == 1 then
firstRead = computer.uptime()
firstRead = Computer.uptime()
end
if counter < euUpdateInterval then
readings[counter] = string.gsub(LSC.getSensorInformation()[2], "([^0-9]+)", "") + 0
counter = counter + 1
end
if counter == euUpdateInterval then
lastRead = computer.uptime()
ticks = math.ceil((lastRead - firstRead) * 20)
lastRead = Computer.uptime()
local ticks = math.ceil((lastRead - firstRead) * 20)
currentIO = math.floor((readings[euUpdateInterval - 1] - readings[1]) / ticks)
counter = 1
end
@ -29,25 +28,33 @@ local currentEU, maxEU, percentage, fillTime, fillTimeString = 1, 1, 1, 1, 1
local initializePowerDisplay = true
local maxEnergyObj, currentEnergyObj, currentFillrateObj, percentageObj, timeObj
function ARWidgets.powerDisplay(glasses, data, x, y, w, h)
local powerFill
local powerEmpty
updateEU(data)
currentEU = math.floor(string.gsub(data.getSensorInformation()[2], "([^0-9]+)", "") + 0)
maxEU = math.floor(string.gsub(data.getSensorInformation()[3], "([^0-9]+)", "") + 0)
percentage = currentEU / maxEU
if initializePowerDisplay then
ARG.hudRectangle(glasses, x, y, w, h, colors.hudColor)
ARG.hudRectangle(glasses, x, y + h, w, 12, colors.hudColor, 0.6)
ARG.hudTriangle(glasses, {x + 2, y + 3}, {x + 2, y + 3 + h - 6}, {x + 2 + h - 6, y + 3 + h - 6}, colors.hudColor)
ARG.hudRectangle(glasses, x, y, w, h, Colors.hudColor)
ARG.hudRectangle(glasses, x, y + h, w, 12, Colors.hudColor, 0.6)
ARG.hudTriangle(
glasses,
{x + 2, y + 3},
{x + 2, y + 3 + h - 6},
{x + 2 + h - 6, y + 3 + h - 6},
Colors.hudColor
)
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},
colors.hudColor
Colors.hudColor
)
ARG.hudRectangle(glasses, x, y + h, 25, 12, colors.hudColor)
ARG.hudTriangle(glasses, {x + 25, y + h}, {x + 25, y + h + 12}, {x + 37, y + h + 12}, colors.hudColor)
ARG.hudRectangle(glasses, x + w - 25, y + h, 25, 12, colors.hudColor)
ARG.hudTriangle(glasses, {x + w - 37, y + h}, {x + w - 25, y + h + 12}, {x + w - 25, y + h}, colors.hudColor)
ARG.hudRectangle(glasses, x, y + h, 25, 12, Colors.hudColor)
ARG.hudTriangle(glasses, {x + 25, y + h}, {x + 25, y + h + 12}, {x + 37, y + h + 12}, Colors.hudColor)
ARG.hudRectangle(glasses, x + w - 25, y + h, 25, 12, Colors.hudColor)
ARG.hudTriangle(glasses, {x + w - 37, y + h}, {x + w - 25, y + h + 12}, {x + w - 25, y + h}, Colors.hudColor)
powerFill =
ARG.hudQuad(
glasses,
@ -55,7 +62,7 @@ function ARWidgets.powerDisplay(glasses, data, x, y, w, h)
{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},
colors.workingColor
Colors.workingColor
)
powerEmpty =
ARG.hudQuad(
@ -64,22 +71,22 @@ function ARWidgets.powerDisplay(glasses, data, x, y, w, h)
{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},
colors.machineBackground
Colors.machineBackground
)
maxEnergyObj = ARG.hudText(glasses, "", x + w - 88, y - 8, colors.idleColor)
currentEnergyObj = ARG.hudText(glasses, "", x + 2, y - 8, colors.workingColor)
maxEnergyObj = ARG.hudText(glasses, "", x + w - 88, y - 8, Colors.idleColor)
currentEnergyObj = ARG.hudText(glasses, "", x + 2, y - 8, Colors.workingColor)
currentFillrateObj = ARG.hudText(glasses, "", x + w / 2 - 20, y + h + 1, 0xFFFFFF)
percentageObj = ARG.hudText(glasses, "", x + w / 2 - 5, y - 8, colors.labelColor)
timeObj = ARG.hudText(glasses, "", x + 35, y + h + 1, colors.labelColor)
percentageObj = ARG.hudText(glasses, "", x + w / 2 - 5, y - 8, Colors.labelColor)
timeObj = ARG.hudText(glasses, "", x + 35, y + h + 1, Colors.labelColor)
initializePowerDisplay = false
end
if currentIO >= 0 then
fillTime = math.floor((maxEU - currentEU) / (currentIO * 20))
fillTimeString = "Full: " .. get.time(math.abs(fillTime))
fillTimeString = "Full: " .. Get.time(math.abs(fillTime))
else
fillTime = math.floor((currentEU) / (currentIO * 20))
fillTimeString = "Empty: " .. get.time(math.abs(fillTime))
fillTimeString = "Empty: " .. Get.time(math.abs(fillTime))
end
powerFill.setVertex(1, x + 2, y + 3)
powerFill.setVertex(2, x + 2 + h - 6, y + 3 + h - 6)
@ -89,20 +96,20 @@ function ARWidgets.powerDisplay(glasses, data, x, y, w, h)
powerEmpty.setVertex(2, math.min(x + 2 + w - 5, (w - 4) * percentage), y + 3 + (h - 6))
powerEmpty.setVertex(3, x + 2 + w - 5, y + 3 + h - 6)
powerEmpty.setVertex(4, x + 2 + w - 5 - (h - 6), y + 3)
maxEnergyObj.setText(get.splitNumber(maxEU) .. " EU")
maxEnergyObj.setText(Get.splitNumber(maxEU) .. " EU")
if percentage > 0.995 then
currentEnergyObj.setText(get.splitNumber(maxEU) .. " EU")
percentageObj.setText(get.getPercent(1.0))
currentEnergyObj.setText(Get.splitNumber(maxEU) .. " EU")
percentageObj.setText(Get.getPercent(1.0))
else
currentEnergyObj.setText(get.splitNumber(currentEU) .. " EU")
percentageObj.setText(get.getPercent(percentage))
currentEnergyObj.setText(Get.splitNumber(currentEU) .. " EU")
percentageObj.setText(Get.getPercent(percentage))
end
if currentIO >= 0 then
currentFillrateObj.setText("+" .. get.splitNumber(currentIO) .. " EU/t")
currentFillrateObj.setText("+" .. Get.splitNumber(currentIO) .. " EU/t")
currentFillrateObj.setColor(0, 1, 0)
else
currentFillrateObj.setColor(1, 0, 0)
currentFillrateObj.setText(get.splitNumber(currentIO) .. " EU/t")
currentFillrateObj.setText(Get.splitNumber(currentIO) .. " EU/t")
end
if percentage < 0.985 then
timeObj.setText(fillTimeString)
@ -112,63 +119,79 @@ function ARWidgets.powerDisplay(glasses, data, x, y, w, h)
end
function ARWidgets.minimapOverlay(glasses)
--Minimap Borders
ARG.hudRectangle(glasses, 728, 10, 123, 3, colors.hudColor)
ARG.hudRectangle(glasses, 728, 130, 123, 3, colors.hudColor)
ARG.hudRectangle(glasses, 728, 10, 3, 123, colors.hudColor)
ARG.hudRectangle(glasses, 848, 10, 3, 123, colors.hudColor)
ARG.hudRectangle(glasses, 728, 10, 123, 3, Colors.hudColor)
ARG.hudRectangle(glasses, 728, 130, 123, 3, Colors.hudColor)
ARG.hudRectangle(glasses, 728, 10, 3, 123, Colors.hudColor)
ARG.hudRectangle(glasses, 848, 10, 3, 123, Colors.hudColor)
--Coordinate Borders
ARG.hudTriangle(glasses, {743, 133}, {728, 133}, {743, 143}, colors.hudColor)
ARG.hudRectangle(glasses, 743, 133, 8, 10, colors.hudColor)
ARG.hudRectangle(glasses, 751, 140, 170, 3, colors.hudColor)
ARG.hudTriangle(glasses, {743, 133}, {728, 133}, {743, 143}, Colors.hudColor)
ARG.hudRectangle(glasses, 743, 133, 8, 10, Colors.hudColor)
ARG.hudRectangle(glasses, 751, 140, 170, 3, Colors.hudColor)
--Biome Borders
ARG.hudTriangle(glasses, {768, 143}, {753, 143}, {768, 153}, colors.hudColor)
ARG.hudRectangle(glasses, 768, 150, 170, 3, colors.hudColor)
ARG.hudTriangle(glasses, {768, 143}, {753, 143}, {768, 153}, Colors.hudColor)
ARG.hudRectangle(glasses, 768, 150, 170, 3, Colors.hudColor)
ARG.hudRectangle(glasses, 829, 133, 50, 7, 0, 0.8)
ARG.hudRectangle(glasses, 811, 143, 50, 7, 0, 0.8)
--FPS Borders
ARG.hudRectangle(glasses, 728, 0, 150, 2, colors.hudColor)
ARG.hudRectangle(glasses, 728, 0, 22, 12, colors.hudColor)
ARG.hudRectangle(glasses, 728, 0, 150, 2, Colors.hudColor)
ARG.hudRectangle(glasses, 728, 0, 22, 12, Colors.hudColor)
ARG.hudRectangle(glasses, 750, 2, 28, 8, 0, 0.8)
ARG.hudTriangle(glasses, {758, 2}, {750, 2}, {750, 10}, colors.hudColor)
ARG.hudTriangle(glasses, {758, 2}, {750, 2}, {750, 10}, Colors.hudColor)
ARG.hudRectangle(glasses, 801, 2, 70, 8, 0, 0.8)
ARG.hudRectangle(glasses, 851, 10, 5, 123, 0, 0.8)
end
function ARWidgets.hudOverlayBase(glasses, x, y)
local hotbarSplitter = ARG.hudRectangle(glasses, x, y, 183, 2, colors.hudColor)
local expSplitter = ARG.hudRectangle(glasses, x, y - 6, 183, 2, colors.hudColor)
local expOverlay = ARG.hudRectangle(glasses, x, y - 4, 183, 4, colors.workingColor, 0.5)
local leftBorder = ARG.hudRectangle(glasses, x - 1, y - 13, 3, 38, colors.hudColor)
local rightBorder = ARG.hudRectangle(glasses, x + 182, y - 5, 3, 30, colors.hudColor)
local armorBox = ARG.hudRectangle(glasses, x, y - 27, 90, 15, colors.hudColor, 0.0)
local hpBox = ARG.hudRectangle(glasses, x + 1, y - 15, 94, 10, colors.hudColor, 0.7)
local hotbarSplitter = ARG.hudRectangle(glasses, x, y, 183, 2, Colors.hudColor)
local expSplitter = ARG.hudRectangle(glasses, x, y - 6, 183, 2, Colors.hudColor)
local expOverlay = ARG.hudRectangle(glasses, x, y - 4, 183, 4, Colors.workingColor, 0.5)
local leftBorder = ARG.hudRectangle(glasses, x - 1, y - 13, 3, 38, Colors.hudColor)
local rightBorder = ARG.hudRectangle(glasses, x + 182, y - 5, 3, 30, Colors.hudColor)
local armorBox = ARG.hudRectangle(glasses, x, y - 27, 90, 15, Colors.hudColor, 0.0)
local hpBox = ARG.hudRectangle(glasses, x + 1, y - 15, 94, 10, Colors.hudColor, 0.7)
local hpStopper =
ARG.hudQuad(glasses, {x + 88, y - 16}, {x + 77, y - 5}, {x + 108, y - 5}, {x + 97, y - 16}, colors.hudColor)
local topBorder = ARG.hudRectangle(glasses, x + 4, y - 18, 178, 3, colors.hudColor)
local topWedge = ARG.hudTriangle(glasses, {x + 4, y - 18}, {x - 1, y - 13}, {x + 4, y - 13}, colors.hudColor)
local connector = ARG.hudTriangle(glasses, {x + 182, y - 18}, {x + 182, y}, {x + 200, y}, colors.hudColor)
local topStrip = ARG.hudRectangle(glasses, x + 4, y - 17, 178, 1, colors.workingColor)
local expWedge1 = ARG.hudTriangle(glasses, {x + 179, y - 4}, {x + 183, y}, {x + 183, y - 4}, colors.hudColor)
local expWedge2 = ARG.hudTriangle(glasses, {x + 2, y - 5}, {x + 2, y}, {x + 6, y}, colors.hudColor)
ARG.hudQuad(glasses, {x + 88, y - 16}, {x + 77, y - 5}, {x + 108, y - 5}, {x + 97, y - 16}, Colors.hudColor)
local topBorder = ARG.hudRectangle(glasses, x + 4, y - 18, 178, 3, Colors.hudColor)
local topWedge = ARG.hudTriangle(glasses, {x + 4, y - 18}, {x - 1, y - 13}, {x + 4, y - 13}, Colors.hudColor)
local connector = ARG.hudTriangle(glasses, {x + 182, y - 18}, {x + 182, y}, {x + 200, y}, Colors.hudColor)
local topStrip = ARG.hudRectangle(glasses, x + 4, y - 17, 178, 1, Colors.workingColor)
local expWedge1 = ARG.hudTriangle(glasses, {x + 179, y - 4}, {x + 183, y}, {x + 183, y - 4}, Colors.hudColor)
local expWedge2 = ARG.hudTriangle(glasses, {x + 2, y - 5}, {x + 2, y}, {x + 6, y}, Colors.hudColor)
--CPU Monitor
local base = ARG.hudRectangle(glasses, x + 185, y, 28, 24, colors.hudColor)
local cpuStrip = ARG.hudRectangle(glasses, x + 185, y, 500, 3, colors.hudColor)
local itemBorder1 = ARG.hudRectangle(glasses, x + 28 + 185, y + 3, 1, 21, colors.workingColor, 0.8)
local itemBorder2 = ARG.hudRectangle(glasses, x + 28 + 185, y + 3, 61, 1, colors.workingColor, 0.8)
local itemBorder3 = ARG.hudRectangle(glasses, x + 88 + 185, y + 3, 1, 21, colors.workingColor, 0.8)
local itemBorder4 = ARG.hudRectangle(glasses, x + 28 + 185, y + 23, 61, 1, colors.workingColor, 0.8)
local cpuBase1 = ARG.hudRectangle(glasses, x + 89 + 185, y, 5, 24, colors.hudColor)
local base = ARG.hudRectangle(glasses, x + 185, y, 28, 24, Colors.hudColor)
local cpuStrip = ARG.hudRectangle(glasses, x + 185, y, 500, 3, Colors.hudColor)
local itemBorder1 = ARG.hudRectangle(glasses, x + 28 + 185, y + 3, 1, 21, Colors.workingColor, 0.8)
local itemBorder2 = ARG.hudRectangle(glasses, x + 28 + 185, y + 3, 61, 1, Colors.workingColor, 0.8)
local itemBorder3 = ARG.hudRectangle(glasses, x + 88 + 185, y + 3, 1, 21, Colors.workingColor, 0.8)
local itemBorder4 = ARG.hudRectangle(glasses, x + 28 + 185, y + 23, 61, 1, Colors.workingColor, 0.8)
local cpuBase1 = ARG.hudRectangle(glasses, x + 89 + 185, y, 5, 24, Colors.hudColor)
local connectorStrip =
ARG.hudQuad(glasses, {x + 182, y - 17}, {x + 182, y - 16}, {x + 213, y + 15}, {x + 213, y + 14}, colors.workingColor)
ARG.hudQuad(
glasses,
{x + 182, y - 17},
{x + 182, y - 16},
{x + 213, y + 15},
{x + 213, y + 14},
Colors.workingColor
)
end
function popupText(glasses, text, x, y, color)
function ARWidgets.popupText(glasses, text, x, y, color)
local substringLength = 1
local width = #text * 5
local steps = math.ceil(#text / substringLength)
local stepLength = substringLength * 5
local i = 1
local background =
ARG.hudQuad(glasses, {x - 5, y}, {x - 5, y + 9}, {x - 5 + 1, y + 9}, {x - 5 + 1, y}, colors.machineBackground, 0.5)
local top = ARG.hudQuad(glasses, {x - 5, y - 1}, {x - 5, y}, {x - 5 + 1, y}, {x - 5 + 1, y - 1}, colors.machineBackground)
ARG.hudQuad(
glasses,
{x - 5, y},
{x - 5, y + 9},
{x - 5 + 1, y + 9},
{x - 5 + 1, y},
Colors.machineBackground,
0.5
)
local top =
ARG.hudQuad(glasses, {x - 5, y - 1}, {x - 5, y}, {x - 5 + 1, y}, {x - 5 + 1, y - 1}, Colors.machineBackground)
local bottom =
ARG.hudQuad(
glasses,
@ -176,7 +199,7 @@ function popupText(glasses, text, x, y, color)
{x - 5, y + 10},
{x - 5 + 1, y + 10},
{x - 5 + 1, y + 9},
colors.machineBackground
Colors.machineBackground
)
local hudText = ARG.hudText(glasses, "", x + 1, y + 1, color)
local wedge =
@ -186,7 +209,7 @@ function popupText(glasses, text, x, y, color)
{x - 5, y - 1},
{x - 5, y + 10},
{x - 5 + 11, y + 10},
colors.machineBackground
Colors.machineBackground
)
local direction = 1
local function advance()
@ -212,19 +235,19 @@ function popupText(glasses, text, x, y, color)
end
local function retract()
direction = -1
event.timer(0.03, advance, steps + 2)
Event.timer(0.03, advance, steps + 2)
end
event.timer(0.03, advance, steps)
Event.timer(0.03, advance, steps)
return retract
end
local initFluidMap = true
local fillLevels = {}
local lastRefresh = computer.uptime() - 30
local lastRefresh = Computer.uptime() - 30
function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
local w = 60
local h = 9
local entries = 0
local fluids = component.me_interface.getFluidsInNetwork()
local fluids = Component.me_interface.getFluidsInNetwork()
if initFluidMap then
for i = 0, #fluidMap, 1 do
local background =
@ -234,7 +257,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x - 8, y + 8 + i * h},
{x + w, y + 8 + i * h},
{x + w, y + i * h},
colors.hudColor,
Colors.hudColor,
0.5
)
local top =
@ -244,7 +267,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x - 10, y + i * h},
{x + w, y + i * h},
{x + w, y - 1 + i * h},
colors.hudColor
Colors.hudColor
)
local bottom =
ARG.hudQuad(
@ -253,7 +276,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x - 8, y + 9 + i * h},
{x + w, y + 9 + i * h},
{x + w, y + 8 + i * h},
colors.hudColor
Colors.hudColor
)
local fill =
ARG.hudQuad(
@ -276,7 +299,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x - 10, y + 9 + i * h},
{x - 6, y + 9 + i * h},
{x + 3, y + i * h},
colors.hudColor
Colors.hudColor
)
else
local wedge =
@ -286,7 +309,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x - 10, y + 9 + i * h},
{x + 3, y + 9 + i * h},
{x - 6, y + i * h},
colors.hudColor
Colors.hudColor
)
end
entries = i
@ -299,7 +322,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x - 2, y + 8 + entries * h},
{x + w, y + 8 + entries * h},
{x + w, y + entries * h},
colors.hudColor
Colors.hudColor
)
local verticalStrip =
ARG.hudQuad(
@ -308,7 +331,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x - 8, y - 2 + entries * h},
{x - 7, y - 2 + entries * h},
{x - 7, y},
colors.workingColor
Colors.workingColor
)
local diagonalStrip =
ARG.hudQuad(
@ -317,7 +340,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x, y + 6 + entries * h},
{x, y + 5 + entries * h},
{x - 7, y - 2 + entries * h},
colors.workingColor
Colors.workingColor
)
local horizontalStrip =
ARG.hudQuad(
@ -326,10 +349,10 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
{x, y + 6 + entries * h},
{x + w, y + 6 + entries * h},
{x + w, y + 5 + entries * h},
colors.workingColor
Colors.workingColor
)
initFluidMap = false
elseif computer.uptime() - lastRefresh > 30 then
elseif Computer.uptime() - lastRefresh > 30 then
for i = 0, #fluidMap, 1 do
local fillQuad = fillLevels[fluidMap[i].label]
local currentLevel = 0
@ -342,7 +365,7 @@ function ARWidgets.fluidMonitor(glasses, x, y, fluidMap)
fillQuad.setVertex(1, x + w - fillPercentage * (w + 8), y + i * h)
fillQuad.setVertex(2, x + w - fillPercentage * (w + 8), y + 8 + i * h)
end
lastRefresh = computer.uptime()
lastRefresh = Computer.uptime()
end
end
local function refreshDatabase(itemList)
@ -362,11 +385,12 @@ local rollingTextObjects = {}
local function rollingText(glasses, text, start, stop, y, color)
local textObject = ARG.hudText(glasses, "", start, y, color)
textObject.setAlpha(0.8)
local backgroundEndWedge = ARG.hudTriangle(glasses, {stop, y - 2}, {stop, y + 10}, {stop + 12, y + 10}, colors.hudColor)
local backgroundEndWedge =
ARG.hudTriangle(glasses, {stop, y - 2}, {stop, y + 10}, {stop + 12, y + 10}, Colors.hudColor)
local backgroundStartWedge =
ARG.hudTriangle(glasses, {start - 12, y - 2}, {start, y + 10}, {start + 12, y - 2}, colors.hudColor)
ARG.hudTriangle(glasses, {start - 12, y - 2}, {start, y + 10}, {start + 12, y - 2}, Colors.hudColor)
local startWedge =
ARG.hudQuad(glasses, {start, y - 2}, {start, y + 8}, {start + 30, y + 8}, {start + 30, y - 2}, colors.hudColor)
ARG.hudQuad(glasses, {start, y - 2}, {start, y + 8}, {start + 30, y + 8}, {start + 30, y - 2}, Colors.hudColor)
rollingTextObjects[#rollingTextObjects + 1] = {
t = textObject,
bew = backgroundEndWedge,
@ -393,15 +417,15 @@ local function rollingText(glasses, text, start, stop, y, color)
textObject.setPosition(start - (step * stepSize), y)
step = step + 1
if step > steps then
event.timer(0.07, truncate, #text + 3)
Event.timer(0.07, truncate, #text + 3)
end
end
local function generate()
textObject.setText(string.sub(text, 0, #text - textRemaining))
textRemaining = textRemaining - 1
end
event.timer(0.10, generate, #text + 1)
event.timer(0.02, roll, steps + 1)
Event.timer(0.10, generate, #text + 1)
Event.timer(0.02, roll, steps + 1)
end
local function clearTicker(glasses)
for i = 1, #rollingTextObjects do
@ -420,8 +444,8 @@ local function clearTicker(glasses)
end
rollingTextObjects = {}
end
local cachedAmounts = refreshDatabase(component.me_interface.getItemsInNetwork())
function difference(new)
local cachedAmounts = refreshDatabase(Component.me_interface.getItemsInNetwork())
local function difference(new)
local differenceArray = {}
for label, amount in pairs(cachedAmounts) do
if new[label] ~= nil then
@ -435,8 +459,9 @@ function difference(new)
end
local initializeTicker = true
local allItems, itemsInNetwork, craftables
local lastUpdate = computer.uptime() - 60
local lastUpdate = Computer.uptime() - 60
function ARWidgets.itemTicker(glasses, x, y, w)
local uniqueItems, totalItems, patterns
local function formatMillions(number)
local millions = number / 1000000
if millions >= 10 then
@ -457,27 +482,41 @@ function ARWidgets.itemTicker(glasses, x, y, w)
end
if initializeTicker then
local background =
ARG.hudQuad(glasses, {x, y + 2}, {x, y + 14}, {x + w, y + 14}, {x + w, y + 2}, colors.machineBackground, 0.5)
local top = ARG.hudQuad(glasses, {x, y}, {x, y + 2}, {x + w, y + 2}, {x + w, y}, colors.hudColor)
local bottom = ARG.hudQuad(glasses, {x, y + 14}, {x, y + 20}, {x + w, y + 20}, {x + w, y + 14}, colors.hudColor)
ARG.hudQuad(
glasses,
{x, y + 2},
{x, y + 14},
{x + w, y + 14},
{x + w, y + 2},
Colors.machineBackground,
0.5
)
local top = ARG.hudQuad(glasses, {x, y}, {x, y + 2}, {x + w, y + 2}, {x + w, y}, Colors.hudColor)
local bottom = ARG.hudQuad(glasses, {x, y + 14}, {x, y + 20}, {x + w, y + 20}, {x + w, y + 14}, Colors.hudColor)
local bottomStripe =
ARG.hudQuad(glasses, {x, y + 17}, {x, y + 18}, {x + w, y + 18}, {x + w, y + 17}, colors.workingColor)
local wedge = ARG.hudTriangle(glasses, {x - 20, y}, {x, y + 20}, {x, y}, colors.hudColor)
local backgroundEndWedge = ARG.hudTriangle(glasses, {x, y + 2}, {x, y + 14}, {x + 12, y + 14}, colors.hudColor)
ARG.hudQuad(glasses, {x, y + 17}, {x, y + 18}, {x + w, y + 18}, {x + w, y + 17}, Colors.workingColor)
local wedge = ARG.hudTriangle(glasses, {x - 20, y}, {x, y + 20}, {x, y}, Colors.hudColor)
local backgroundEndWedge = ARG.hudTriangle(glasses, {x, y + 2}, {x, y + 14}, {x + 12, y + 14}, Colors.hudColor)
local backgroundStartWedge =
ARG.hudTriangle(glasses, {x + w - 12, y + 2}, {x + w, y + 14}, {x + w + 12, y + 2}, colors.hudColor)
ARG.hudTriangle(glasses, {x + w - 12, y + 2}, {x + w, y + 14}, {x + w + 12, y + 2}, Colors.hudColor)
local diagonalStripe =
ARG.hudQuad(glasses, {x - 16, y + 2}, {x, y + 18}, {x, y + 17}, {x - 15, y + 2}, colors.workingColor)
local bottomBorder = ARG.hudRectangle(glasses, x + w - 170, y + 28, 170, 4, colors.hudColor)
local dataBorder = ARG.hudRectangle(glasses, x + w - 170, 20, 170, 12, colors.hudColor, 0.5)
ARG.hudQuad(glasses, {x - 16, y + 2}, {x, y + 18}, {x, y + 17}, {x - 15, y + 2}, Colors.workingColor)
local bottomBorder = ARG.hudRectangle(glasses, x + w - 170, y + 28, 170, 4, Colors.hudColor)
local dataBorder = ARG.hudRectangle(glasses, x + w - 170, 20, 170, 12, Colors.hudColor, 0.5)
local endWedge =
ARG.hudTriangle(glasses, {x + w - 182, y + 20}, {x + w - 170, y + 32}, {x + w - 170, y + 20}, colors.hudColor)
local divisor1 = ARG.hudRectangle(glasses, x + w - 118, y + 20, 2, 12, colors.hudColor)
local divisor2 = ARG.hudRectangle(glasses, x + w - 64, y + 20, 2, 12, colors.hudColor)
local bottomDataStripe = ARG.hudRectangle(glasses, x + w - 168, y + 30, 168, 1, colors.workingColor)
uniqueItems = ARG.hudText(glasses, "", x, y, colors.workingColor, 0.75)
totalItems = ARG.hudText(glasses, "", x, y, colors.workingColor, 0.75)
patterns = ARG.hudText(glasses, "", x, y, colors.workingColor, 0.75)
ARG.hudTriangle(
glasses,
{x + w - 182, y + 20},
{x + w - 170, y + 32},
{x + w - 170, y + 20},
Colors.hudColor
)
local divisor1 = ARG.hudRectangle(glasses, x + w - 118, y + 20, 2, 12, Colors.hudColor)
local divisor2 = ARG.hudRectangle(glasses, x + w - 64, y + 20, 2, 12, Colors.hudColor)
local bottomDataStripe = ARG.hudRectangle(glasses, x + w - 168, y + 30, 168, 1, Colors.workingColor)
uniqueItems = ARG.hudText(glasses, "", x, y, Colors.workingColor, 0.75)
totalItems = ARG.hudText(glasses, "", x, y, Colors.workingColor, 0.75)
patterns = ARG.hudText(glasses, "", x, y, Colors.workingColor, 0.75)
uniqueItems.setPosition((x + w - 114) * 1.33333, (y + 22) * 1.33333)
totalItems.setPosition((x + w - 168) * 1.33333, (y + 22) * 1.33333)
patterns.setPosition((x + w - 60) * 1.33333, (y + 22) * 1.33333)
@ -487,12 +526,12 @@ function ARWidgets.itemTicker(glasses, x, y, w)
rollingText(glasses, name, x + w, x, y + 4, 0xAAAAAA)
local function showChange()
if amount > 0 then
rollingText(glasses, "+" .. amount, x + w, x, y + 4, colors.positiveEUColor)
rollingText(glasses, "+" .. amount, x + w, x, y + 4, Colors.positiveEUColor)
else
rollingText(glasses, "" .. amount, x + w, x, y + 4, colors.negativeEUColor)
rollingText(glasses, "" .. amount, x + w, x, y + 4, Colors.negativeEUColor)
end
end
event.timer(#name * 0.12, showChange, 1)
Event.timer(#name * 0.12, showChange, 1)
end
local changedItems = {}
local i = 1
@ -500,35 +539,35 @@ function ARWidgets.itemTicker(glasses, x, y, w)
showTicker(changedItems[i][1], changedItems[i][2])
i = i + 1
end
if computer.uptime() - lastUpdate > 60 then
lastUpdate = computer.uptime()
allItems = component.me_interface.getItemsInNetwork()
if Computer.uptime() - lastUpdate > 60 then
lastUpdate = Computer.uptime()
allItems = Component.me_interface.getItemsInNetwork()
itemsInNetwork = #allItems
craftables = #component.me_interface.getCraftables()
craftables = #Component.me_interface.getCraftables()
totalItems.setText("Total: " .. formatMillions(getTotalItemCount(allItems)))
patterns.setText("Patterns: " .. craftables)
uniqueItems.setText("Unique: " .. itemsInNetwork)
changedItems = difference(refreshDatabase(allItems))
i = 1
clearTicker(glasses)
event.timer(5, processQueue, #changedItems)
Event.timer(5, processQueue, #changedItems)
end
end
function ARWidgets.crossHair(glasses, x, y)
local horizontal = ARG.hudRectangle(glasses, x, y + 5, 4, 1, colors.workingColor, 0.5)
local vertical = ARG.hudRectangle(glasses, x + 5, y, 1, 4, colors.workingColor, 0.5)
local horizontal2 = ARG.hudRectangle(glasses, x + 7, y + 5, 4, 1, colors.workingColor, 0.5)
local vertical2 = ARG.hudRectangle(glasses, x + 5, y + 7, 1, 4, colors.workingColor, 0.5)
local middle = ARG.hudRectangle(glasses, x + 4, y + 4, 3, 3, colors.hudColor, 0.0)
local center = ARG.hudRectangle(glasses, x + 5, y + 5, 1, 1, colors.hudColor, 0.7)
local horizontal = ARG.hudRectangle(glasses, x, y + 5, 4, 1, Colors.workingColor, 0.5)
local vertical = ARG.hudRectangle(glasses, x + 5, y, 1, 4, Colors.workingColor, 0.5)
local horizontal2 = ARG.hudRectangle(glasses, x + 7, y + 5, 4, 1, Colors.workingColor, 0.5)
local vertical2 = ARG.hudRectangle(glasses, x + 5, y + 7, 1, 4, Colors.workingColor, 0.5)
local middle = ARG.hudRectangle(glasses, x + 4, y + 4, 3, 3, Colors.hudColor, 0.0)
local center = ARG.hudRectangle(glasses, x + 5, y + 5, 1, 1, Colors.hudColor, 0.7)
end
local initializeCpuMonitor = true
local cpuLights = {}
function ARWidgets.cpuMonitor(glasses, x, y)
if initializeCpuMonitor then
local cpuBase2 = ARG.hudRectangle(glasses, x + 94, y + 12, 8, 12, colors.hudColor)
local cpuSplitter = ARG.hudRectangle(glasses, x + 89, y + 9, 400, 3, colors.hudColor)
local cpuSplitter2 = ARG.hudRectangle(glasses, x + 102, y + 18, 380, 6, colors.hudColor)
local cpuBase2 = ARG.hudRectangle(glasses, x + 94, y + 12, 8, 12, Colors.hudColor)
local cpuSplitter = ARG.hudRectangle(glasses, x + 89, y + 9, 400, 3, Colors.hudColor)
local cpuSplitter2 = ARG.hudRectangle(glasses, x + 102, y + 18, 380, 6, Colors.hudColor)
local function createCpuIndicator(cpuX, cpuY)
local status =
ARG.hudQuad(
@ -537,11 +576,11 @@ function ARWidgets.cpuMonitor(glasses, x, y)
{cpuX + 6, cpuY + 6},
{cpuX + 16, cpuY + 6},
{cpuX + 10, cpuY},
colors.hudColor,
Colors.hudColor,
1.0
)
local leftTriangle =
ARG.hudTriangle(glasses, {cpuX, cpuY}, {cpuX, cpuY + 6}, {cpuX + 6, cpuY + 6}, colors.hudColor)
ARG.hudTriangle(glasses, {cpuX, cpuY}, {cpuX, cpuY + 6}, {cpuX + 6, cpuY + 6}, Colors.hudColor)
local rightTriangle =
ARG.hudQuad(
glasses,
@ -549,7 +588,7 @@ function ARWidgets.cpuMonitor(glasses, x, y)
{cpuX + 16, cpuY + 6},
{cpuX + 18, cpuY + 6},
{cpuX + 18, cpuY},
colors.hudColor
Colors.hudColor
)
return status
end
@ -566,9 +605,9 @@ function ARWidgets.cpuMonitor(glasses, x, y)
end
cpuNumber = cpuNumber + 1
end
local rowStop1 = ARG.hudRectangle(glasses, x + 94 + i * 17, y + 3, 300, 6, colors.hudColor)
local rowStop2 = ARG.hudRectangle(glasses, x + 102 + j * 17, y + 12, 300, 6, colors.hudColor)
local horizontalStrip = ARG.hudRectangle(glasses, x + 100, y + 22, 210, 1, colors.workingColor)
local rowStop1 = ARG.hudRectangle(glasses, x + 94 + i * 17, y + 3, 300, 6, Colors.hudColor)
local rowStop2 = ARG.hudRectangle(glasses, x + 102 + j * 17, y + 12, 300, 6, Colors.hudColor)
local horizontalStrip = ARG.hudRectangle(glasses, x + 100, y + 22, 210, 1, Colors.workingColor)
local diagonalStrip =
ARG.hudQuad(
glasses,
@ -576,17 +615,17 @@ function ARWidgets.cpuMonitor(glasses, x, y)
{x + 89, y + 12},
{x + 100, y + 23},
{x + 100, y + 22},
colors.workingColor
Colors.workingColor
)
initializeCpuMonitor = false
end
local cpus = component.me_interface.getCpus()
local cpus = Component.me_interface.getCpus()
for i = 1, #cpus, 1 do
if cpus[i].busy then
cpuLights[i].setColor(colors.positiveEUColor)
cpuLights[i].setColor(Colors.positiveEUColor)
else
cpuLights[i].setAlpha(0.7)
cpuLights[i].setColor(colors.workingColor)
cpuLights[i].setColor(Colors.workingColor)
end
end
end
@ -596,30 +635,53 @@ function ARWidgets.displayTPS(glasses, x, y)
if initializeTPS then
initializeTPS = false
local background =
ARG.hudQuad(glasses, {x + 40, y + 4}, {x + 40, y + 15}, {x + 93, y + 15}, {x + 105, y + 4}, colors.hudColor, 0.6)
local startBlock = ARG.hudRectangle(glasses, x, y, 40, 23, colors.hudColor)
local top = ARG.hudRectangle(glasses, x + 40, y, 65, 4, colors.hudColor)
local bottom = ARG.hudRectangle(glasses, x + 40, y + 14, 50, 5, colors.hudColor)
ARG.hudQuad(
glasses,
{x + 40, y + 4},
{x + 40, y + 15},
{x + 93, y + 15},
{x + 105, y + 4},
Colors.hudColor,
0.6
)
local startBlock = ARG.hudRectangle(glasses, x, y, 40, 23, Colors.hudColor)
local top = ARG.hudRectangle(glasses, x + 40, y, 65, 4, Colors.hudColor)
local bottom = ARG.hudRectangle(glasses, x + 40, y + 14, 50, 5, Colors.hudColor)
local wedge1 =
ARG.hudQuad(glasses, {x + 40, y + 19}, {x + 40, y + 23}, {x + 42, y + 23}, {x + 46, y + 19}, colors.hudColor)
local wedge2 = ARG.hudQuad(glasses, {x + 105, y}, {x + 86, y + 19}, {x + 93, y + 19}, {x + 112, y}, colors.hudColor)
local stripe1 = ARG.hudRectangle(glasses, x + 2, y + 20, 39, 1, colors.workingColor)
local stripe2 = ARG.hudRectangle(glasses, x + 45, y + 16, 48, 1, colors.workingColor)
ARG.hudQuad(
glasses,
{x + 40, y + 19},
{x + 40, y + 23},
{x + 42, y + 23},
{x + 46, y + 19},
Colors.hudColor
)
local wedge2 =
ARG.hudQuad(glasses, {x + 105, y}, {x + 86, y + 19}, {x + 93, y + 19}, {x + 112, y}, Colors.hudColor)
local stripe1 = ARG.hudRectangle(glasses, x + 2, y + 20, 39, 1, Colors.workingColor)
local stripe2 = ARG.hudRectangle(glasses, x + 45, y + 16, 48, 1, Colors.workingColor)
local stripe3 =
ARG.hudQuad(glasses, {x + 41, y + 20}, {x + 41, y + 21}, {x + 45, y + 17}, {x + 45, y + 16}, colors.workingColor)
local stripe4 = ARG.hudRectangle(glasses, x + 1, y + 2, 1, 19, colors.workingColor)
TPSText = ARG.hudText(glasses, "", x + 42, y + 6, colors.workingColor, 1)
ARG.hudQuad(
glasses,
{x + 41, y + 20},
{x + 41, y + 21},
{x + 45, y + 17},
{x + 45, y + 16},
Colors.workingColor
)
local stripe4 = ARG.hudRectangle(glasses, x + 1, y + 2, 1, 19, Colors.workingColor)
TPSText = ARG.hudText(glasses, "", x + 42, y + 6, Colors.workingColor, 1)
end
local tps = math.min(20.00, get.tps())
local tps = math.min(20.00, Get.tps())
if tps > 15 then
TPSText.setText("TPS: " .. string.sub(tps, 1, 5))
TPSText.setColor(colors.positiveEUColor)
TPSText.setColor(Colors.positiveEUColor)
elseif tps >= 10 then
TPSText.setText("TPS: " .. string.sub(tps, 1, 5))
TPSText.setColor(colors.workingColor)
TPSText.setColor(Colors.workingColor)
else
TPSText.setText("TPS: " .. string.sub(tps, 1, 4))
TPSText.setColor(colors.negativeEUColor)
TPSText.setColor(Colors.negativeEUColor)
end
end
function ARWidgets.clear()
@ -629,8 +691,8 @@ function ARWidgets.clear()
initializeCpuMonitor = true
initializeTPS = true
fillLevels = {}
lastRefresh = computer.uptime() - 30
lastUpdate = computer.uptime() - 60
lastRefresh = Computer.uptime() - 30
lastUpdate = Computer.uptime() - 60
end
return ARWidgets

View File

@ -15,25 +15,31 @@ local colors = {
lightGray = 0xD3D3D3,
darkGray = 0xA9A9A9,
darkSlateGrey = 0x2F4F4F,
black = 0x000000,
machineBackground = colors.darkGray,
progressBackground = colors.lightGray,
labelColor = colors.chocolate,
errorColor = colors.red,
idleColor = colors.purple,
workingColor = colors.steelBlue,
positiveEUColor = colors.lime,
negativeEUColor = colors.brown,
timeColor = colors.purple,
textColor = colors.black,
hudColor = colors.darkSlateGrey,
mainColor = colors.rosyBrown,
background = colors.black,
accentA = colors.cyan,
accentB = colors.magenta,
barColor = colors.blue
black = 0x000000
}
table.concat(
colors,
{
machineBackground = colors.darkGray,
progressBackground = colors.lightGray,
labelColor = colors.chocolate,
errorColor = colors.red,
idleColor = colors.purple,
workingColor = colors.steelBlue,
positiveEUColor = colors.lime,
negativeEUColor = colors.brown,
timeColor = colors.purple,
textColor = colors.black,
hudColor = colors.darkSlateGrey,
mainColor = colors.rosyBrown,
background = colors.black,
accentA = colors.cyan,
accentB = colors.magenta,
barColor = colors.blue
}
)
local RGB = {}
for name, value in pairs(colors) do
@ -52,7 +58,7 @@ setmetatable(
colors,
{
__index = function(self, color)
return self.RGB[color] or {0, 0, 0}
return self.RGB[color] or 0, 0, 0
end
}
)

View File

@ -21,8 +21,8 @@ function graphics.rectangle(GPU, x, y, w, h, color)
end
hLeft = hLeft - 1
end
GPU.setBackground(table.unpack(color))
GPU.setForeground(table.unpack(color))
GPU.setBackground(color)
GPU.setForeground(color)
if hLeft % 2 == 1 then
GPU.fill(x, math.ceil(y / 2) + (h - hLeft), w, (hLeft - 1) / 2, "")
for j = x, x + w - 1 do
@ -39,7 +39,7 @@ function graphics.text(GPU, x, y, color, string)
error("Text position must be odd on y axis")
end
local screenY = math.ceil(y / 2)
GPU.setForeground(table.unpack(color))
GPU.setForeground(color)
for i = 0, #string - 1 do
local baseChar, baseForeground, baseBackground = GPU.get(x + i, screenY)
GPU.setBackground(baseBackground)
@ -52,7 +52,7 @@ function graphics.centeredText(GPU, x, y, color, string)
error("Text position must be odd on y axis")
end
local screenY = math.ceil(y / 2)
local oldForeground = GPU.setForeground(table.unpack(color))
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)
@ -80,15 +80,18 @@ function graphics.checkCollision(GPU, x, y)
end
return nil
end
function graphics.createWindow(GPU, width, height, name)
local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2))
graphics.currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height, GPU = GPU}
return pageNumber
end
local function copyWindow(GPU, x, y, page, destination)
destination = 0 or destination
GPU.bitblt(destination, x, y, 160, 50, page, 1, 1)
end
function graphics.refresh(GPU)
for window, params in pairs(graphics.currentWindows) do
if params.w > 0 then
@ -113,6 +116,7 @@ function graphics.update()
redraw()
os.sleep()
end
function graphics.clear()
graphics.currentWindows = {}
end

View File

@ -1,16 +1,16 @@
graphics = require("graphics")
event = require("event")
Graphics = require("graphics.graphics")
Event = require("event")
local uc = require("unicode")
component = require("component")
GPU = component.proxy(component.get("f26678f4"))
colors = require("colors")
Component = require("component")
GPU = Component.gpu
Colors = require("colors")
local gui, quit, editing = {}, false, false
local currentWindows = {}
local activeWindow
local keyInput, mouseInput, drag, inContextMenu
gui.checkCollision = function(x, y)
function gui.checkCollision(x, y)
for window, params in pairs(currentWindows) do
if x >= params.x and x <= params.x + params.w - 1 then
if y >= params.y and y <= params.y + math.ceil(params.h / 2) - 1 then
@ -23,7 +23,7 @@ end
local contextMenus = 0
gui.contextMenu = function(GPU, x, y, data)
function gui.contextMenu (GPU, x, y, data)
local function filterClicks(event)
return event == "touch"
end
@ -37,16 +37,16 @@ gui.contextMenu = function(GPU, x, y, data)
end
local contextWindow = gui.createWindow(GPU, longestData, #data * 2, "ContextMenu" .. contextMenus)
GPU.setActiveBuffer(contextWindow)
graphics.rectangle(GPU, 1, 1, longestData, #data * 2, colors.lightGray)
Graphics.rectangle(GPU, 1, 1, longestData, #data * 2, Colors.lightGray)
for i = 1, #data do
graphics.text(GPU, 1, 1 + i * 2 - 2, colors.cyan, data[i])
Graphics.text(GPU, 1, 1 + i * 2 - 2, Colors.cyan, data[i])
end
currentWindows["ContextMenu" .. contextMenus].x = x
currentWindows["ContextMenu" .. contextMenus].y = y
GPU.setActiveBuffer(0)
end
gui.keyboardListener = function()
function gui.keyboardListener ()
local function processKey(event, address, key, code, player)
local value = uc.char(key)
if value == "." then
@ -60,34 +60,34 @@ gui.keyboardListener = function()
end
end
end
return event.listen("key_up", processKey)
return Event.listen("key_up", processKey)
end
gui.processCommand = function(GPU, window, option)
function gui.processCommand(GPU, window, option)
local pageNumber = currentWindows[window].page
if currentWindows["ColorBox"] == nil then
gui.createWindow(GPU, 10, 10, "ColorBox")
Graphics.createWindow(GPU, 10, 10, "ColorBox")
currentWindows["ColorBox"].x = 10
currentWindows["ColorBox"].y = 10
end
GPU.setActiveBuffer(currentWindows["ColorBox"].page)
if option == 1 then
graphics.rectangle(GPU, 1, 1, 10, 10, colors.red)
Graphics.rectangle(GPU, 1, 1, 10, 10, Colors.red)
end
if option == 2 then
graphics.rectangle(GPU, 1, 1, 10, 10, colors.blue)
Graphics.rectangle(GPU, 1, 1, 10, 10, Colors.blue)
end
if option == 3 then
graphics.rectangle(GPU, 1, 1, 10, 10, colors.green)
Graphics.rectangle(GPU, 1, 1, 10, 10, Colors.green)
end
GPU.setActiveBuffer(0)
end
local i, xOffset, yOffset = 1, 0, 0
gui.mouseListener = function()
function gui.mouseListener()
local function processClick(event, address, x, y, key, player)
activeWindow = gui.checkCollision(x, y)
graphics.text(GPU, 1, 1, colors.cyan, "Active window: " .. activeWindow)
Graphics.text(GPU, 1, 1, Colors.cyan, "Active window: " .. activeWindow)
if key == 1.0 and editing then
if inContextMenu then
contextMenus = 0
@ -113,10 +113,10 @@ gui.mouseListener = function()
end
end
end
return event.listen("touch", processClick)
return Event.listen("touch", processClick)
end
gui.dragListener = function()
function gui.dragListener()
local function processDrag(event, address, x, y, key, player)
if editing and inContextMenu == false then
local window = currentWindows[activeWindow]
@ -124,68 +124,53 @@ gui.dragListener = function()
currentWindows[activeWindow].y = y - yOffset
end
end
return event.listen("drag", processDrag)
return Event.listen("drag", processDrag)
end
gui.dropListener = function()
function gui.dropListener()
local function processDrop(event, address, x, y, key, player)
end
return event.listen("drop", processDrop)
return Event.listen("drop", processDrop)
end
gui.createWindow = function(GPU, width, height, name)
local pageNumber = GPU.allocateBuffer(width, math.ceil(height / 2))
currentWindows[name] = {page = pageNumber, x = 1, y = 1, w = width, h = height}
return pageNumber
end
gui.compose = function(GPU)
function gui.compose(GPU)
local stateBuffer = currentWindows["State"].page
GPU.setActiveBuffer(stateBuffer)
if editing then
copyWindow(GPU, 1, 1, currentWindows["Black"].page)
Graphics.copyWindow(GPU, 1, 1, currentWindows["Black"].page)
end
for window, params in pairs(currentWindows) do
if params.w > 0 then
copyWindow(GPU, params.x, params.y, params.page, stateBuffer)
Graphics.copyWindow(GPU, params.x, params.y, params.page, stateBuffer)
end
end
if inContextMenu then
local cont = currentWindows["ContextMenu1"]
copyWindow(GPU, cont.x, cont.y, cont.page)
Graphics.copyWindow(GPU, cont.x, cont.y, cont.page)
end
GPU.setActiveBuffer(0)
end
gui.copyWindow = function(GPU, x, y, page, destination)
destination = 0 or destination
GPU.bitblt(destination, x, y, 160, 50, page, 1, 1)
end
--return gui
GPU = component.proxy(component.get("de837fec"))
term = component.get("48ce2988")
GPU.bind(term)
GPU.freeAllBuffers()
keyInput, mouseInput, drag = gui.keyboardListener(), gui.mouseListener(), gui.dragListener()
gui.createWindow(GPU, 160, 100, "Black")
Graphics.createWindow(GPU, 160, 100, "Black")
GPU.setActiveBuffer(currentWindows["Black"].page)
graphics.rectangle(GPU, 1, 1, 160, 100, 0x000000)
Graphics.rectangle(GPU, 1, 1, 160, 100, 0x000000)
currentWindows["Black"].w = 0
currentWindows["Black"].h = 0
GPU.setActiveBuffer(0)
gui.createWindow(GPU, 160, 100, "State")
Graphics.createWindow(GPU, 160, 100, "State")
GPU.setActiveBuffer(currentWindows["State"].page)
graphics.rectangle(GPU, 1, 1, 160, 100, 0x000000)
Graphics.rectangle(GPU, 1, 1, 160, 100, 0x000000)
currentWindows["State"].w = 0
currentWindows["State"].h = 0
GPU.setActiveBuffer(0)
copyWindow(GPU, 1, 1, currentWindows["Black"].page)
Graphics.copyWindow(GPU, 1, 1, currentWindows["Black"].page)
while true do
if quit then
event.cancel(keyInput)
Event.cancel(keyInput)
break
end
gui.compose(GPU)

View File

@ -1,14 +1,14 @@
graphics = require("graphics")
util = require("utility")
colors = require("colors")
Graphics = require("graphics")
local util = require("utility")
Colors = require("colors")
local widgets = {}
function widgets.gtMachineInit(GPU, name, address)
local maintenanceIndex = 0
local machine = util.machine(address)
graphics.rectangle(GPU, 1, 1, 28, 9, colors.background)
graphics.text(GPU, 4, 3, colors.mainColor, name)
Graphics.rectangle(GPU, 1, 1, 28, 9, Colors.background)
Graphics.text(GPU, 4, 3, Colors.mainColor, name)
if machine ~= nil then
for i = 1, #machine.getSensorInformation() do --Get maintenance index
if string.match(machine.getSensorInformation()[i], "Problems") ~= nil then
@ -20,26 +20,26 @@ function widgets.gtMachineInit(GPU, name, address)
if string.match(machine.getSensorInformation()[6], "tier") ~= nil then
local tier = util.tier((string.gsub(machine.getSensorInformation()[6], "([^0-9]+)", "") - 1) / 10)
if tier ~= nil then
graphics.text(GPU, 4, 5, colors.accentB, "" .. tier)
Graphics.text(GPU, 4, 5, Colors.accentB, "" .. tier)
end
end
--Check for parallel on Processing Arrays
if string.match(machine.getSensorInformation()[7], "Parallel") ~= nil then
local parallel = string.gsub(machine.getSensorInformation()[7], "([^0-9]+)", "")
if parallel ~= nil then
graphics.text(GPU, 11 + -(#parallel) .. "", 5, colors.mainColor, parallel .. "x")
Graphics.text(GPU, 11 + -(#parallel) .. "", 5, Colors.mainColor, parallel .. "x")
end
end
end
else
graphics.text(GPU, 4, 5, colors.errorColor, "Unknown")
Graphics.text(GPU, 4, 5, Colors.errorColor, "Unknown")
end
graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
graphics.rectangle(GPU, 7, 2, 21, 1, colors.barColor)
Graphics.rectangle(GPU, 3, 2, 3, 1, Colors.barColor)
Graphics.rectangle(GPU, 2, 2, 1, 7, Colors.barColor)
Graphics.rectangle(GPU, 3, 8, 20, 1, Colors.barColor)
Graphics.rectangle(GPU, 24, 8, 3, 1, Colors.barColor)
Graphics.rectangle(GPU, 27, 2, 1, 7, Colors.barColor)
Graphics.rectangle(GPU, 7, 2, 21, 1, Colors.barColor)
return maintenanceIndex
end
@ -52,71 +52,70 @@ function widgets.gtMachine(GPU, name, address)
local barAmount = currentProgress
--First Straight
_, f, _ = GPU.get(3, 1)
if f ~= colors.mainColor then
if f ~= Colors.mainColor then
local bars1 = math.max(0, math.min(3, barAmount))
graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
graphics.rectangle(GPU, 6 - bars1, 2, bars1, 1, colors.mainColor)
graphics.rectangle(GPU, 24, 8, bars1, 1, colors.mainColor)
Graphics.rectangle(GPU, 3, 2, 3, 1, Colors.barColor)
Graphics.rectangle(GPU, 24, 8, 3, 1, Colors.barColor)
Graphics.rectangle(GPU, 2, 2, 1, 7, Colors.barColor)
Graphics.rectangle(GPU, 27, 2, 1, 7, Colors.barColor)
Graphics.rectangle(GPU, 3, 8, 20, 1, Colors.barColor)
Graphics.rectangle(GPU, 7, 2, 20, 1, Colors.barColor)
Graphics.rectangle(GPU, 6 - bars1, 2, bars1, 1, Colors.mainColor)
Graphics.rectangle(GPU, 24, 8, bars1, 1, Colors.mainColor)
end
_, f, _ = GPU.get(2, 4)
if barAmount > 3 and f ~= colors.mainColor then --Vertical
bars2 = math.max(0, math.min(7, barAmount - 3))
graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
graphics.rectangle(GPU, 2, 2, 1, bars2, colors.mainColor)
graphics.rectangle(GPU, 27, 9 - bars2, 1, bars2, colors.mainColor)
if barAmount > 3 and f ~= Colors.mainColor then --Vertical
local bars2 = math.max(0, math.min(7, barAmount - 3))
Graphics.rectangle(GPU, 2, 2, 1, 7, Colors.barColor)
Graphics.rectangle(GPU, 27, 2, 1, 7, Colors.barColor)
Graphics.rectangle(GPU, 3, 8, 20, 1, Colors.barColor)
Graphics.rectangle(GPU, 7, 2, 20, 1, Colors.barColor)
Graphics.rectangle(GPU, 2, 2, 1, bars2, Colors.mainColor)
Graphics.rectangle(GPU, 27, 9 - bars2, 1, bars2, Colors.mainColor)
end
if barAmount > 10 then --Long Straight
local bars3 = math.max(0, barAmount - 10)
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
graphics.rectangle(GPU, 3, 8, bars3, 1, colors.mainColor)
graphics.rectangle(GPU, 27 - bars3, 2, bars3, 1, colors.mainColor)
Graphics.rectangle(GPU, 3, 8, 20, 1, Colors.barColor)
Graphics.rectangle(GPU, 7, 2, 20, 1, Colors.barColor)
Graphics.rectangle(GPU, 3, 8, bars3, 1, Colors.mainColor)
Graphics.rectangle(GPU, 27 - bars3, 2, bars3, 1, Colors.mainColor)
end
progressString =
local progressString =
tostring(math.floor(machine.getWorkProgress() / 20)) ..
"/" .. tostring(math.floor(machine.getWorkMaxProgress() / 20)) .. "s"
middlePoint = math.min(9, 12 - #progressString / 2)
graphics.rectangle(GPU, 18, 5, 8, 2, colors.background)
graphics.text(GPU, 26 - #progressString, 5, colors.accentA, progressString)
Graphics.rectangle(GPU, 18, 5, 8, 2, Colors.background)
Graphics.text(GPU, 26 - #progressString, 5, Colors.accentA, progressString)
else --No work
_, f, _ = GPU.get(5, 1)
if f ~= colors.barColor then
graphics.rectangle(GPU, 18, 5, 8, 2, colors.background)
graphics.rectangle(GPU, 3, 2, 3, 1, colors.barColor)
graphics.rectangle(GPU, 2, 2, 1, 7, colors.barColor)
graphics.rectangle(GPU, 3, 8, 20, 1, colors.barColor)
graphics.rectangle(GPU, 24, 8, 3, 1, colors.barColor)
graphics.rectangle(GPU, 27, 2, 1, 7, colors.barColor)
graphics.rectangle(GPU, 7, 2, 20, 1, colors.barColor)
if f ~= Colors.barColor then
Graphics.rectangle(GPU, 18, 5, 8, 2, Colors.background)
Graphics.rectangle(GPU, 3, 2, 3, 1, Colors.barColor)
Graphics.rectangle(GPU, 2, 2, 1, 7, Colors.barColor)
Graphics.rectangle(GPU, 3, 8, 20, 1, Colors.barColor)
Graphics.rectangle(GPU, 24, 8, 3, 1, Colors.barColor)
Graphics.rectangle(GPU, 27, 2, 1, 7, Colors.barColor)
Graphics.rectangle(GPU, 7, 2, 20, 1, Colors.barColor)
end
end
_, f, _ = GPU.get(6, 1)
if
((windows[name].data == 0 or string.match(machine.getSensorInformation()[windows[name].data], ".*c0.*")) and
((Graphics.windows[name].data == 0 or string.match(machine.getSensorInformation()[Graphics.windows[name].data], ".*c0.*")) and
machine.isWorkAllowed()) == true
then
if f ~= colors.background then
graphics.rectangle(GPU, 6, 2, 1, 1, colors.background)
graphics.rectangle(GPU, 23, 8, 1, 1, colors.background)
if f ~= Colors.background then
Graphics.rectangle(GPU, 6, 2, 1, 1, Colors.background)
Graphics.rectangle(GPU, 23, 8, 1, 1, Colors.background)
end
else
if (machine.isWorkAllowed()) then
if f ~= colors.accentA then
graphics.rectangle(GPU, 6, 2, 1, 1, colors.accentA)
graphics.rectangle(GPU, 23, 8, 1, 1, colors.accentA)
if f ~= Colors.accentA then
Graphics.rectangle(GPU, 6, 2, 1, 1, Colors.accentA)
Graphics.rectangle(GPU, 23, 8, 1, 1, Colors.accentA)
end
else
if f ~= colors.errorColor then
graphics.rectangle(GPU, 6, 2, 1, 1, colors.errorColor)
graphics.rectangle(GPU, 23, 8, 1, 1, colors.errorColor)
if f ~= Colors.errorColor then
Graphics.rectangle(GPU, 6, 2, 1, 1, Colors.errorColor)
Graphics.rectangle(GPU, 23, 8, 1, 1, Colors.errorColor)
end
end
end
@ -128,7 +127,7 @@ function widgets.create(GPU, x, y, name, dataAddress, widget)
local page = GPU.allocateBuffer(width, math.ceil(height / 2))
GPU.setActiveBuffer(page)
local widgetData = widget.initialize(GPU, name, dataAddress)
windows[name] = {
Graphics.windows[name] = {
GPU = GPU,
page = page,
address = dataAddress,
@ -142,6 +141,4 @@ function widgets.create(GPU, x, y, name, dataAddress, widget)
GPU.setActiveBuffer(0)
end
GTMachine = {width = 28, height = 9, initialize = widgets.gtMachineInit, update = widgets.gtMachine}
return widgets

View File

@ -1,15 +1,15 @@
component = require("component")
event = require("event")
local modem = component.modem
Component = require("component")
Event = require("event")
local modem = Component.modem
local util = require("utility")
AR = require("AR")
glasses = util.machine("3770e3f9")
Glasses = util.machine("3770e3f9")
local componentText = AR.hudText(glasses, " ", 0, 20)
local componentText = AR.hudText(Glasses, " ", 0, 20)
local function receive(localAddress, remoteAddress, port, distance, type, value1, value2, value3)
componentText.setText(value2)
end
event.listen("modem_message", receive)
Event.listen("modem_message", receive)
modem.open(1)

View File

@ -1,5 +1,5 @@
-- Import section
computer = require("computer")
Computer = require("computer")
--
local notes = {
@ -49,7 +49,7 @@ local notes = {
local function playTune(tune)
return function()
for i, note in ipairs(tune) do
computer.beep(notes[note.pitch or note], note.duration or 0.1)
Computer.beep(notes[note.pitch or note], note.duration or 0.1)
os.sleep(note.wait or 0.01)
end
end

View File

@ -1,43 +1,55 @@
local Parser = {
parseProgress = function(progressString)
local a = "Progress: §a2§r s / §e5§r s"
return {current = 0, max = 1}
end,
parseStoredEnergy = function(storedEnergyString)
local noCommaString = string.gsub(storedEnergyString, ",", "")
local Parser = {}
local current = string.sub(noCommaString, string.find(noCommaString, "%ba§"))
current = tonumber((string.gsub(string.gsub(current, "a", ""), "§", "")))
function Parser.parseProgress(progressString)
local current = string.sub(progressString, string.find(progressString, "%ba§"))
current = tonumber((string.gsub(string.gsub(current, "a", ""), "§", "")))
local maximum = string.sub(noCommaString, string.find(noCommaString, "%be§"))
maximum = tonumber((string.gsub(string.gsub(maximum, "e", ""), "§", "")))
local maximum = string.sub(progressString, string.find(progressString, "%be§"))
maximum = tonumber((string.gsub(string.gsub(maximum, "e", ""), "§", "")))
return {current = current, maximum = maximum}
end,
parseAverageInput = function(averageInputString)
local noCommaString = string.gsub(averageInputString, ",", "")
return tonumber((string.sub(noCommaString, string.find(noCommaString, "%d+"))))
end,
parseAverageOutput = function(averageOutputString)
local noCommaString = string.gsub(averageOutputString, ",", "")
return tonumber((string.sub(noCommaString, string.find(noCommaString, "%d+"))))
end,
parseProblems = function(problemsString)
local problems = string.sub(problemsString, string.find(problemsString, "c%d"))
return tonumber((string.gsub(problems, "c", "")))
end,
parseEfficiency = function(efficiencyString)
local noParagraphMarkString = string.gsub(efficiencyString, "§r", "")
local efficiency = string.sub(noParagraphMarkString, string.find(noParagraphMarkString, "%d+%.*%d*%s%%"))
return tonumber((string.gsub(efficiency, "%s%%", "")))
end,
parseName = function(nameString)
return string.gsub(string.gsub(nameString, "§9", ""), "§r", "")
end,
parseWorkArea = function(worAreaString)
local size = string.sub(worAreaString, string.find(worAreaString, "§a%d+x%d+§r"))
return string.gsub(string.gsub(size, "§a", ""), "§r", "")
end
}
return {current = current, maximum = maximum}
end
function Parser.parseStoredEnergy(storedEnergyString)
local noCommaString = string.gsub(storedEnergyString, ",", "")
local current = string.sub(noCommaString, string.find(noCommaString, "%ba§"))
current = tonumber((string.gsub(string.gsub(current, "a", ""), "§", "")))
local maximum = string.sub(noCommaString, string.find(noCommaString, "%be§"))
maximum = tonumber((string.gsub(string.gsub(maximum, "e", ""), "§", "")))
return {current = current, maximum = maximum}
end
function Parser.parseAverageInput(averageInputString)
local noCommaString = string.gsub(averageInputString, ",", "")
return tonumber((string.sub(noCommaString, string.find(noCommaString, "%d+"))))
end
function Parser.parseAverageOutput(averageOutputString)
local noCommaString = string.gsub(averageOutputString, ",", "")
return tonumber((string.sub(noCommaString, string.find(noCommaString, "%d+"))))
end
function Parser.parseProblems(problemsString)
local problems = string.sub(problemsString, string.find(problemsString, "c%d"))
return tonumber((string.gsub(problems, "c", "")))
end
function Parser.parseEfficiency(efficiencyString)
local noParagraphMarkString = string.gsub(efficiencyString, "§r", "")
local efficiency = string.sub(noParagraphMarkString, string.find(noParagraphMarkString, "%d+%.*%d*%s%%"))
return tonumber((string.gsub(efficiency, "%s%%", "")))
end
function Parser.parseName(nameString)
return string.gsub(string.gsub(nameString, "§9", ""), "§r", "")
end
function Parser.parseWorkArea(worAreaString)
local size = string.sub(worAreaString, string.find(worAreaString, "§a%d+x%d+§r"))
return string.gsub(string.gsub(size, "§a", ""), "§r", "")
end
return Parser

View File

@ -1,13 +1,13 @@
component = require("component")
event = require("event")
Component = require("component")
Event = require("event")
local uc = require("unicode")
local utility = {}
local modem = component.modem
local modem = Component.modem
function utility.machine(address)
machineAddress = component.get(address)
local machineAddress = Component.get(address)
if (machineAddress ~= nil) then
return component.proxy(machineAddress)
return Component.proxy(machineAddress)
else
return nil
end
@ -31,7 +31,7 @@ function utility.splitNumber(number) --Returns given number formatted as XXX,XXX
local string = tostring(math.abs(number))
local sign = number / math.abs(number)
for i = 1, #string do
n = string:sub(i, i)
local n = string:sub(i, i)
formattedNumber[i] = n
if ((#string - i) % 3 == 0) and (#string - i > 0) then
formattedNumber[i] = formattedNumber[i] .. ","
@ -62,18 +62,18 @@ function utility.exit(key)
local function processKey(event, address, key, code, player)
local value = uc.char(key)
if value == "e" then
run = false
Run = false
end
return false
end
event.listen("key_up", processKey)
Event.listen("key_up", processKey)
end
function utility.componentChange(broadcastPort)
local function sendAddress(event, address, type)
modem.broadcast(broadcastPort, event, address, type)
end
event.listen("component_added", sendAddress)
Event.listen("component_added", sendAddress)
end
function utility.progressText(current, max)

View File

@ -1,22 +1,23 @@
event = require("event")
term = require("term")
Event = require("event")
Term = require("term")
local AU = require("util")
local AT = require("transport")
local S = require("serialization")
local uc = require("unicode")
local network = component.modem
local fluidMap = (require("dictionary"))
local network = Component.modem
local id, AD
local function requestID()
network.broadcast(100, "requestID")
local _, _, _, _, _, messageType, value = event.pull("modem_message")
local _, _, _, _, _, messageType, value = Event.pull("modem_message")
while messageType ~= "sendID" do
_, _, _, _, _, messageType, value = event.pull("modem_message")
_, _, _, _, _, messageType, value = Event.pull("modem_message")
os.sleep(0.2)
end
return value
end
function checkRepeat(recipe)
local function checkRepeat(recipe)
local correctItems = 0
for i = 1, recipe.inputs, 1 do
if AT.isEmpty(AD["inputTransposer" .. i], 16) then
@ -94,15 +95,15 @@ local function processRecipe(recipe)
while checkRepeat(recipe) do
insert()
end
local wait = computer.uptime()
while not AD.controller.hasWork() and computer.uptime() < wait + 5 do
local wait = Computer.uptime()
while not AD.controller.hasWork() and Computer.uptime() < wait + 5 do
os.sleep(0.2)
end
if not AD.controller.hasWork() then
term.write(" ... Error with starting assembly!")
Term.write(" ... Error with starting assembly!")
network.broadcast(id, "jammed")
else
term.write(" ... Assembly Started")
Term.write(" ... Assembly Started")
while AD.controller.hasWork() do
os.sleep(0.1)
end
@ -111,28 +112,29 @@ local function processRecipe(recipe)
end
end
AT.clearAll(AD)
term.write(" ... finished task!\n")
Term.write(" ... finished task!\n")
network.broadcast(id, "complete")
end
local function processMessage(localAddress, remoteAddress, port, distance, type, eventType, value2, value3)
if eventType == "startAssembly" then
local recipe = S.unserialize(value2)
term.write("Starting assembly of " .. recipe.label)
Term.write("Starting assembly of " .. recipe.label)
processRecipe(recipe)
elseif eventType == "clear" then
AT.clearAll(AD)
end
end
local processKey = {}
local function quit()
term.write("Quitting...")
event.ignore("modem_message", processMessage)
event.ignore("key_up", processKey)
Term.write("Quitting...")
Event.ignore("modem_message", processMessage)
Event.ignore("key_up", processKey)
os.exit()
end
function processKey(event, address, key, code, player)
local function processKey(event, address, key, code, player)
local value = uc.char(key)
if value == "." then
quit()
@ -158,5 +160,5 @@ local function startAssembly()
end
startAssembly()
event.listen("modem_message", processMessage)
event.listen("key_up", processKey)
Event.listen("modem_message", processMessage)
Event.listen("key_up", processKey)

View File

@ -1,4 +1,4 @@
fluidMap = {
local fluidMap = {
["fluid.molten.solderingalloy"] = {name = "gt.metaitem.99.314.name", size = 144},
["fluid.lubricant"] = {name = "gt.Volumetric_Flask.name", size = 250},
["IC2 Coolant"] = {name = "Coolant Cell", size = 1000},
@ -9,7 +9,7 @@ fluidMap = {
["fluid.molten.naquadria"] = {name = "gt.metaitem.99.327.name", size = 144}
}
dictionary = {
local dictionary = {
["gt.metaitem.01.32705.name"] = "gt.metaitem.03.32084.name", --IV
["gt.metaitem.03.32086.name"] = "gt.metaitem.03.32084.name",
["gt.metaitem.03.32089.name"] = "gt.metaitem.03.32084.name",
@ -36,3 +36,5 @@ dictionary = {
-- {"gt.metaitem.03.32095.name","gt.metaitem.03.32099.name"}, -- UHV
-- {"gt.metaitem.03.32120.name"} -- UEV
-- }
return fluidMap, dictionary

View File

@ -1,10 +1,11 @@
component = require("component")
event = require("event")
term = require("term")
Component = require("component")
Event = require("event")
Term = require("term")
AU = require("util")
local uc = require("unicode")
local S = require("serialization")
local network = component.modem
local fluidMap, dictionary = require("dictionary")
local network = Component.modem
local mainChannel = 100
-- mainChannel = Main channel for bi-directional communication
@ -54,14 +55,16 @@ local function processMessage(type, localAddress, remoteAddress, port, distance,
end
end
local processKey = {}
local function quit()
term.write("Quitting...")
event.ignore("modem_message", processMessage)
event.ignore("key_up", processKey)
Term.write("Quitting...")
Event.ignore("modem_message", processMessage)
Event.ignore("key_up", processKey)
run = false
end
function processKey(event, address, key, code, player)
local function processKey(event, address, key, code, player)
local value = uc.char(key)
if value == "." then
quit()
@ -70,7 +73,7 @@ function processKey(event, address, key, code, player)
end
end
function startAssembly(assemblyport, recipe)
local function startAssembly(assemblyport, recipe)
assemblyStatus[assemblyport] = recipe.label
network.broadcast(assemblyport, "startAssembly", S.serialize(recipe))
end
@ -97,8 +100,8 @@ local function spairs(t, order)
end
end
end
function matchRecipe(recipes)
local items = component.me_interface.getItemsInNetwork()
local function matchRecipe(recipes)
local items = Component.me_interface.getItemsInNetwork()
local foundItems = {}
if #items > 0 then
for i = 1, #items, 1 do
@ -161,10 +164,10 @@ local function scheduleTasks()
if not contains(assemblyStatus, recipe.label) then
local taskid = getFree()
if taskid ~= nil then
term.write("Started assembly of " .. recipe.label .. " with AL #" .. taskid .. "\n")
Term.write("Started assembly of " .. recipe.label .. " with AL #" .. taskid .. "\n")
startAssembly(taskid, recipe)
else
term.write("No free assembly lines.\n")
Term.write("No free assembly lines.\n")
end
end
return true
@ -173,9 +176,9 @@ local function scheduleTasks()
local taskid = getFree()
if taskid ~= nil then
startAssembly(taskid, recipe)
term.write("Started assembly of " .. recipe.label .. " with AL #" .. taskid .. "\n")
Term.write("Started assembly of " .. recipe.label .. " with AL #" .. taskid .. "\n")
else
term.write("No free assembly lines.\n")
Term.write("No free assembly lines.\n")
end
craftable = craftable - 8
end
@ -194,8 +197,8 @@ local function initializeServer()
end
initializeServer()
event.listen("modem_message", processMessage)
event.listen("key_up", processKey)
Event.listen("modem_message", processMessage)
Event.listen("key_up", processKey)
while run do
scheduleTasks()

View File

@ -1,4 +1,4 @@
component = require("component")
Component = require("component")
local transport = {}
@ -12,7 +12,7 @@ function transport.empty(transposer)
transposer.transferItem(1, 0, 64, 2, 9)
end
function transport.clear(interface)
interface.setInterfaceConfiguration(1, component.database.address, 1, 0)
interface.setInterfaceConfiguration(1, Component.database.address, 1, 0)
end
function transport.check(transposer, item, amount)
local itemstack = transposer.getStackInSlot(0, 1)

View File

@ -1,25 +1,25 @@
component = require("component")
event = require("event")
term = require("term")
Component = require("component")
Event = require("event")
Term = require("term")
local assemblyUtil = {}
local function addEntries(file, prompt, amount, type)
local a, b, c
for i = 1, amount, 1 do
term.write(prompt .. " " .. i .. " ")
a, b, c = event.pull()
Term.write(prompt .. " " .. i .. " ")
a, b, c = Event.pull()
while a ~= "component_added" do
a, b, c = event.pull()
a, b, c = Event.pull()
os.sleep()
end
file:write(type .. i .. "," .. b .. "\n")
term.write(b .. "\n")
Term.write(b .. "\n")
end
end
local function addAuxilary(file, proxy, type)
if proxy == nil then
term.write("Cant find a valid " .. type .. "! Exiting...\n")
Term.write("Cant find a valid " .. type .. "! Exiting...\n")
os.exit()
else
file:write(type .. "," .. proxy.address .. "\n")
@ -39,9 +39,9 @@ local function split(s, sep)
return fields
end
local function proxy(address)
machineAddress = component.get(address)
local machineAddress = Component.get(address)
if (machineAddress ~= nil) then
return component.proxy(machineAddress)
return Component.proxy(machineAddress)
else
return nil
end
@ -52,27 +52,27 @@ local function configureClient()
addEntries(file, "Add fluid interface", 4, "fluid")
addEntries(file, "Add item transposer", 15, "inputTransposer")
addEntries(file, "Add fluid transposer", 4, "fluidTransposer")
addAuxilary(file, component.me_interface, "items")
addAuxilary(file, component.database, "database")
addAuxilary(file, component.gt_machine, "controller")
addAuxilary(file, Component.me_interface, "items")
addAuxilary(file, Component.database, "database")
addAuxilary(file, Component.gt_machine, "controller")
end
function assemblyUtil.buildClient()
term.write("Starting Assembly Line initalization...")
Term.write("Starting Assembly Line initalization...")
local assemblyStructure = {}
local file = io.open("addresses", "r")
if file == nil then
term.write(" no address configuration found, configuring:\n")
Term.write(" no address configuration found, configuring:\n")
configureClient()
file = io.lines("addresses")
else
file = io.lines("addresses")
end
for line in file do
term.write(".")
Term.write(".")
local tokens = split(line, ",")
assemblyStructure[tokens[1]] = proxy(tokens[2])
end
term.write("\n")
Term.write("\n")
return assemblyStructure
end
local function voltageToTier(voltage)
@ -98,7 +98,7 @@ function copyPattern(interface, slot, recipe, database)
end
end
--]]
function getControllerTier(assemblyData)
local function getControllerTier(assemblyData)
local controller = assemblyData["controller"]
return voltageToTier(
math.floor(
@ -140,7 +140,7 @@ local function addRecipe(recipelist, slot, source, sourceSide)
end
end
function assemblyUtil.getRecipes(recipelist)
for address, type in pairs(component.list()) do
for address, type in pairs(Component.list()) do
if type == "transposer" then
local dataSource = proxy(address)
for side = 0, 5 do

View File

@ -1,13 +1,13 @@
component = require("component")
term = require("term")
computer = require("computer")
event = require("event")
Component = require("component")
Term = require("term")
Computer = require("computer")
Event = require("event")
local sides = require("sides")
graphics = require("graphics")
Graphics = require("graphics.graphics")
S = require("stockerUtil")
local uc = require("unicode")
local GPU = component.gpu
local transposer = component.transposer
GPU = Component.gpu
local transposer = Component.transposer
local itemsToStock = {}
local craftables = {}
local currentlyCrafting = {}
@ -16,27 +16,27 @@ local number = ""
local inNumberBox = false
local function mouseListener()
local function processClick(event, address, x, y, key, player)
local activeWindow = graphics.checkCollision(nil, x, y)
local activeWindow = Graphics.checkCollision(nil, x, y)
if activeWindow ~= nil then
if activeWindow == "Button" then
GPU.setActiveBuffer(0)
if drawerItem == nil or number == "" then
graphics.rectangle(
Graphics.rectangle(
GPU,
graphics.currentWindows["Button"].x + 2,
graphics.currentWindows["Button"].y * 2 + 1,
Graphics.currentWindows["Button"].x + 2,
Graphics.currentWindows["Button"].y * 2 + 1,
6,
6,
colors.negativeEUColor
Colors.negativeEUColor
)
else
graphics.rectangle(
Graphics.rectangle(
GPU,
graphics.currentWindows["Button"].x + 2,
graphics.currentWindows["Button"].y * 2 + 1,
Graphics.currentWindows["Button"].x + 2,
Graphics.currentWindows["Button"].y * 2 + 1,
6,
6,
colors.positiveEUColor
Colors.positiveEUColor
)
if itemsToStock[drawerItem] ~= nil then
S.update(drawerItem, itemsToStock[drawerItem], number)
@ -50,24 +50,24 @@ local function mouseListener()
end
number = ""
os.sleep(0.3)
graphics.refresh(GPU)
Graphics.refresh(GPU)
elseif activeWindow == "Number" then
GPU.setActiveBuffer(0)
if drawerItem == nil then
graphics.centeredText(
Graphics.centeredText(
GPU,
graphics.currentWindows["Number"].x + 25,
graphics.currentWindows["Number"].y * 2 + 3,
Graphics.currentWindows["Number"].x + 25,
Graphics.currentWindows["Number"].y * 2 + 3,
0xFFFFFF,
"Pattern refresh requested..."
)
S.refreshCraftables()
end
inNumberBox = true
graphics.rectangle(
Graphics.rectangle(
GPU,
graphics.currentWindows["Number"].x + 2,
graphics.currentWindows["Number"].y * 2 + 1,
Graphics.currentWindows["Number"].x + 2,
Graphics.currentWindows["Number"].y * 2 + 1,
46,
6,
0x333333
@ -75,15 +75,15 @@ local function mouseListener()
else
inNumberBox = false
number = ""
graphics.refresh(GPU)
Graphics.refresh(GPU)
end
else
inNumberBox = false
number = ""
graphics.refresh(GPU)
Graphics.refresh(GPU)
end
end
return event.listen("touch", processClick)
return Event.listen("touch", processClick)
end
local function keyboardListener()
local function processKey(event, address, key, code, player)
@ -91,133 +91,133 @@ local function keyboardListener()
local value = uc.char(key)
if key == 10 then
inNumberBox = false
graphics.refresh(GPU)
Graphics.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
graphics.rectangle(GPU, graphics.currentWindows["Number"].x + 2, graphics.currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333)
graphics.text(
Graphics.rectangle(GPU, Graphics.currentWindows["Number"].x + 2, Graphics.currentWindows["Number"].y * 2 + 1, 46, 6, 0x333333)
Graphics.text(
GPU,
graphics.currentWindows["Number"].x + 4,
graphics.currentWindows["Number"].y * 2 + 3,
colors.workingColor,
Graphics.currentWindows["Number"].x + 4,
Graphics.currentWindows["Number"].y * 2 + 3,
Colors.workingColor,
number
)
end
end
return event.listen("key_down", processKey)
return Event.listen("key_down", processKey)
end
local function getNewItem(GPU, x, y)
if graphics.currentWindows["Item"] == nil then
local itemWindow = graphics.createWindow(GPU, 60, 6, "Item")
graphics.currentWindows["Item"].x = x
graphics.currentWindows["Item"].y = y
if Graphics.currentWindows["Item"] == nil then
local itemWindow = Graphics.createWindow(GPU, 60, 6, "Item")
Graphics.currentWindows["Item"].x = x
Graphics.currentWindows["Item"].y = y
GPU.setActiveBuffer(itemWindow)
graphics.rectangle(GPU, 2, 2, 58, 4, colors.hudColor)
graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
Graphics.rectangle(GPU, 2, 2, 58, 4, Colors.hudColor)
Graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
GPU.setActiveBuffer(0)
end
local newDrawerItem = transposer.getStackInSlot(sides.top, 2)
if newDrawerItem ~= nil then
if craftables[newDrawerItem] ~= nil then
GPU.setForeground(colors.workingColor)
GPU.setForeground(Colors.workingColor)
else
GPU.setActiveBuffer(colors.negativeEUColor)
GPU.setActiveBuffer(Colors.negativeEUColor)
end
if drawerItem == nil then
drawerItem = newDrawerItem.label
GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
GPU.setActiveBuffer(Graphics.currentWindows["Item"].page)
Graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
if craftables[drawerItem] ~= nil then
graphics.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem)
Graphics.centeredText(GPU, 30, 3, Colors.positiveEUColor, drawerItem)
else
graphics.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem)
Graphics.centeredText(GPU, 30, 3, Colors.negativeEUColor, drawerItem)
end
GPU.setActiveBuffer(0)
if itemsToStock[drawerItem] ~= nil then
graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
graphics.centeredText(
Graphics.rectangle(GPU, Graphics.currentWindows["Item"].x, Graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
Graphics.centeredText(
GPU,
graphics.currentWindows["Item"].x + 30,
graphics.currentWindows["Item"].y * 2 - 3,
Graphics.currentWindows["Item"].x + 30,
Graphics.currentWindows["Item"].y * 2 - 3,
0xFFFFFF,
"Configured: " .. itemsToStock[drawerItem]
)
end
graphics.refresh(GPU)
Graphics.refresh(GPU)
else
if drawerItem ~= newDrawerItem.label then
drawerItem = newDrawerItem.label
GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
GPU.setActiveBuffer(Graphics.currentWindows["Item"].page)
Graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
if craftables[drawerItem] ~= nil then
graphics.centeredText(GPU, 30, 3, colors.positiveEUColor, drawerItem)
Graphics.centeredText(GPU, 30, 3, Colors.positiveEUColor, drawerItem)
else
graphics.centeredText(GPU, 30, 3, colors.negativeEUColor, drawerItem)
Graphics.centeredText(GPU, 30, 3, Colors.negativeEUColor, drawerItem)
end
GPU.setActiveBuffer(0)
if itemsToStock[drawerItem] ~= nil then
graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
graphics.centeredText(
Graphics.rectangle(GPU, Graphics.currentWindows["Item"].x, Graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
Graphics.centeredText(
GPU,
graphics.currentWindows["Item"].x + 30,
graphics.currentWindows["Item"].y * 2 - 3,
Graphics.currentWindows["Item"].x + 30,
Graphics.currentWindows["Item"].y * 2 - 3,
0xFFFFFF,
"Configured: " .. itemsToStock[drawerItem]
)
end
graphics.refresh(GPU)
Graphics.refresh(GPU)
end
end
else
if drawerItem ~= nil then
drawerItem = nil
GPU.setActiveBuffer(graphics.currentWindows["Item"].page)
graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
graphics.centeredText(GPU, 30, 3, 0xFFFFFF, "")
GPU.setActiveBuffer(Graphics.currentWindows["Item"].page)
Graphics.rectangle(GPU, 3, 3, 56, 2, 0x000000)
Graphics.centeredText(GPU, 30, 3, 0xFFFFFF, "")
GPU.setActiveBuffer(0)
graphics.rectangle(GPU, graphics.currentWindows["Item"].x, graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
graphics.refresh(GPU)
Graphics.rectangle(GPU, Graphics.currentWindows["Item"].x, Graphics.currentWindows["Item"].y * 2 - 3, 60, 2, 0x000000)
Graphics.refresh(GPU)
end
end
end
local function numberBox(GPU, x, y)
if graphics.currentWindows["Number"] == nil then
local itemWindow = graphics.createWindow(GPU, 50, 10, "Number")
graphics.currentWindows["Number"].x = x
graphics.currentWindows["Number"].y = y
if Graphics.currentWindows["Number"] == nil then
local itemWindow = Graphics.createWindow(GPU, 50, 10, "Number")
Graphics.currentWindows["Number"].x = x
Graphics.currentWindows["Number"].y = y
GPU.setActiveBuffer(itemWindow)
graphics.rectangle(GPU, 2, 2, 48, 8, colors.hudColor)
graphics.rectangle(GPU, 3, 3, 46, 6, 0x000000)
Graphics.rectangle(GPU, 2, 2, 48, 8, Colors.hudColor)
Graphics.rectangle(GPU, 3, 3, 46, 6, 0x000000)
GPU.setActiveBuffer(0)
end
end
local function button(GPU, x, y)
if graphics.currentWindows["Button"] == nil then
local button = graphics.createWindow(GPU, 10, 10, "Button")
graphics.currentWindows["Button"].x = x
graphics.currentWindows["Button"].y = y
if Graphics.currentWindows["Button"] == nil then
local button = Graphics.createWindow(GPU, 10, 10, "Button")
Graphics.currentWindows["Button"].x = x
Graphics.currentWindows["Button"].y = y
GPU.setActiveBuffer(button)
graphics.rectangle(GPU, 2, 2, 8, 8, colors.hudColor)
graphics.rectangle(GPU, 3, 3, 6, 6, colors.workingColor)
Graphics.rectangle(GPU, 2, 2, 8, 8, Colors.hudColor)
Graphics.rectangle(GPU, 3, 3, 6, 6, Colors.workingColor)
GPU.setActiveBuffer(0)
end
end
local function craftableBox(GPU, x, y)
if graphics.currentWindows["Craft"] == nil then
local crafts = graphics.createWindow(GPU, 72, 100, "Craft")
graphics.currentWindows["Craft"].x = x
graphics.currentWindows["Craft"].y = y
if Graphics.currentWindows["Craft"] == nil then
local crafts = Graphics.createWindow(GPU, 72, 100, "Craft")
Graphics.currentWindows["Craft"].x = x
Graphics.currentWindows["Craft"].y = y
GPU.setActiveBuffer(crafts)
graphics.rectangle(GPU, 2, 2, 70, 94, colors.hudColor)
Graphics.rectangle(GPU, 2, 2, 70, 94, Colors.hudColor)
GPU.setActiveBuffer(0)
end
GPU.setActiveBuffer(graphics.currentWindows["Craft"].page)
graphics.rectangle(GPU, 3, 4, 68, 90, 0x000000)
graphics.rectangle(GPU, 48, 2, 1, 94, colors.hudColor)
GPU.setActiveBuffer(Graphics.currentWindows["Craft"].page)
Graphics.rectangle(GPU, 3, 4, 68, 90, 0x000000)
Graphics.rectangle(GPU, 48, 2, 1, 94, Colors.hudColor)
local i = 1
S.updateCache()
for label, amount in pairs(itemsToStock) do
@ -227,16 +227,16 @@ local function craftableBox(GPU, x, y)
if S.uniques() > 2500 then --Check against rebooted system
if toStock > 0 then
if drawerItem == label then
graphics.text(GPU, 4, 3 + 2 * i, colors.workingColor, label)
Graphics.text(GPU, 4, 3 + 2 * i, Colors.workingColor, label)
elseif craftables[label] == nil then
graphics.text(GPU, 4, 3 + 2 * i, colors.negativeEUColor, label)
Graphics.text(GPU, 4, 3 + 2 * i, Colors.negativeEUColor, label)
else
graphics.text(GPU, 4, 3 + 2 * i, 0xFFFFFF, label)
Graphics.text(GPU, 4, 3 + 2 * i, 0xFFFFFF, label)
end
if stockedAmount >= toStock then --In stock
graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, 0xFFFFFF, stockedString)
Graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, 0xFFFFFF, stockedString)
elseif stockedAmount >= toStock * 0.85 then --Edit hysteresis here, slightly below stock
graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, colors.workingColor, stockedString)
Graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, Colors.workingColor, stockedString)
else --Needs to be ordered
--Add crafting request loop here
if craftables[label] ~= nil then
@ -246,33 +246,33 @@ local function craftableBox(GPU, x, y)
currentlyCrafting[label] = nil
end
end
graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, colors.negativeEUColor, stockedString)
Graphics.text(GPU, 59 - (#stockedString + 1), 3 + 2 * i, Colors.negativeEUColor, stockedString)
end
graphics.text(GPU, 59, 3 + 2 * i, 0xFFFFFF, "| " .. amount)
Graphics.text(GPU, 59, 3 + 2 * i, 0xFFFFFF, "| " .. amount)
i = math.min(i + 1, 43)
end
end
end
GPU.setActiveBuffer(0)
graphics.refresh(GPU)
Graphics.refresh(GPU)
end
mouseListener()
keyboardListener()
GPU.setResolution(160, 46)
term.clear()
graphics.clear()
Term.clear()
Graphics.clear()
numberBox(GPU, 100, 41)
button(GPU, 150, 41)
craftableBox(GPU, 0, 0)
graphics.refresh(GPU)
Graphics.refresh(GPU)
S.refreshCraftables()
S.loadPatterns()
local timeSinceRefresh = computer.uptime()
local timeSinceRefresh = Computer.uptime()
while true do
getNewItem(GPU, 100, 38)
if computer.uptime() - timeSinceRefresh > 900 then
timeSinceRefresh = computer.uptime()
if Computer.uptime() - timeSinceRefresh > 900 then
timeSinceRefresh = Computer.uptime()
craftableBox(GPU, 0, 0)
end
os.sleep(0.5)

View File

@ -1,8 +1,8 @@
component = require("component")
graphics = require("graphics")
Component = require("component")
Graphics = require("graphics.graphics")
local tx = require("transforms")
GPU = component.gpu
local interface = component.me_interface
GPU = Component.gpu
local interface = Component.me_interface
local sUtil = {}
local itemsToStock = {}
function sUtil.refreshCraftables()
@ -14,10 +14,10 @@ function sUtil.refreshCraftables()
for i, craftable in pairs(craftables) do
if i ~= "n" then
if i % 10 == 0 then
graphics.centeredText(
Graphics.centeredText(
GPU,
graphics.currentWindows["Number"].x + 25,
graphics.currentWindows["Number"].y * 2 + 3,
Graphics.currentWindows["Number"].x + 25,
Graphics.currentWindows["Number"].y * 2 + 3,
0xFFFFFF,
"Discovering Patterns: " .. i .. " / " .. #craftables
)
@ -27,7 +27,7 @@ function sUtil.refreshCraftables()
craftables[craftable.getItemStack().label] = craftable.request
end
end
graphics.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: " .. #craftables)
Graphics.centeredText(GPU, 86, 85, 0xFFFFFF, "Patterns in memory: " .. #craftables)
end
local cachedAmounts = {}
function sUtil.updateCache()

View File

@ -1,16 +1,16 @@
component = require("component")
Component = require("component")
AR = require("ARWidgets")
local wSampsa, hSampsa = 853, 473
local powerHudX, powerHudY, powerHudW, powerHudH = 0, hSampsa - 24, wSampsa * 0.39 + 3, 14
local glasses = component.glasses
local glasses = Component.glasses
glasses.removeAll()
AR.minimapOverlay(glasses)
AR.hudOverlayBase(glasses, 335, 449)
AR.clear()
AR.crossHair(glasses, 422, 231)
term.clear()
Term.clear()
while true do
AR.powerDisplay(glasses, component.gt_machine, powerHudX, powerHudY, powerHudW, powerHudH)
AR.powerDisplay(glasses, Component.gt_machine, powerHudX, powerHudY, powerHudW, powerHudH)
AR.fluidMonitor(
glasses,
795,

View File

@ -1,6 +1,6 @@
component = require("component")
Component = require("component")
AR = require("ARWidgets")
while true do
AR.itemTicker(component.glasses, 348, 0, 380)
AR.itemTicker(Component.glasses, 348, 0, 380)
end

View File

@ -1,7 +1,7 @@
component = require("component")
Component = require("component")
AR = require("ARWidgets")
while true do
AR.displayTPS(component.glasses, 0, 0)
AR.cpuMonitor(component.glasses, 520, 449)
AR.displayTPS(Component.glasses, 0, 0)
AR.cpuMonitor(Component.glasses, 520, 449)
end

View File

@ -1,47 +1,47 @@
component = require("component")
term = require("term")
Component = require("component")
Term = require("term")
local GPU = component.gpu
GPU = Component.gpu
GPU.setResolution(54, 26)
local function enableReactors()
component.redstone.setOutput(1, 15)
Component.redstone.setOutput(1, 15)
end
local function disableReactors()
component.redstone.setOutput(1, 0)
Component.redstone.setOutput(1, 0)
end
local function checkHeatLevels()
term.setCursor(1, 1)
Term.setCursor(1, 1)
local i = 1
for address, type in pairs(component.list()) do
for address, type in pairs(Component.list()) do
if type == "reactor_chamber" then
term.write("Reactor " .. i)
Term.write("Reactor " .. i)
if i < 10 then
term.write(" ")
Term.write(" ")
end
local reactor = component.proxy(address)
local reactor = Component.proxy(address)
if reactor.getHeat() > 0 then
GPU.setForeground(0xFF0000)
term.write(" REACTOR HEATING! SHUTTING DOWN")
Term.write(" REACTOR HEATING! SHUTTING DOWN")
disableReactors()
GPU.setForeground(0xFFFFFF)
os.sleep(1)
os.exit()
else
if reactor.getReactorEUOutput() > 0 then
term.write(" status: ")
Term.write(" status: ")
GPU.setForeground(0x00FF00)
term.write("NOMINAL")
Term.write("NOMINAL")
GPU.setForeground(0xFFFFFF)
term.write(" - Producing ")
Term.write(" - Producing ")
GPU.setForeground(0xFF00FF)
term.write(math.floor(reactor.getReactorEUOutput()))
Term.write(math.floor(reactor.getReactorEUOutput()))
GPU.setForeground(0xFFFFFF)
term.write(" EU/t\n")
Term.write(" EU/t\n")
else
term.write(" status: ")
Term.write(" status: ")
GPU.setForeground(0xFFFF00)
term.write("INACTIVE\n")
Term.write("INACTIVE\n")
end
end
i = i + 1
@ -50,7 +50,7 @@ local function checkHeatLevels()
end
enableReactors()
term.clear()
Term.clear()
while true do
checkHeatLevels()
os.sleep(1)

View File

@ -1,4 +1,4 @@
destinations = {
local destinations = {
[1] = {name = "Earth", id = 3001, color = 0xFF0022},
[2] = {name = "Pluto", id = 3002, color = 0x22FF00},
[3] = {name = "Venus", id = 3003},
@ -8,63 +8,63 @@ destinations = {
}
local util = require("utility")
graphics = require("graphics")
local GPU = component.gpu
Graphics = require("graphics.graphics")
GPU = Component.gpu
GPU.setResolution(80, 25)
local boundingBoxes = {}
function createDestination(x, y, index)
local function createDestination(x, y, index)
local width, height = 18, 6
local page = GPU.allocateBuffer(width, math.ceil(height / 2))
GPU.setActiveBuffer(page)
graphics.rectangle(GPU, 1, 1, 18, 6, 0x111111)
Graphics.rectangle(GPU, 1, 1, 18, 6, 0x111111)
local destinationColor = destinations[index].color or 0x0055FF
graphics.rectangle(GPU, 3, 3, 14, 2, 0x000000)
graphics.centeredText(GPU, 10, 3, destinationColor, destinations[index].name)
windows[index] = {GPU = GPU, page = page, address = "", x = x, y = y, w = width, h = height}
Graphics.rectangle(GPU, 3, 3, 14, 2, 0x000000)
Graphics.centeredText(GPU, 10, 3, destinationColor, destinations[index].name)
Graphics.windows[index] = {GPU = GPU, page = page, address = "", x = x, y = y, w = width, h = height}
GPU.setActiveBuffer(0)
end
function setDestination(code)
for address, type in pairs(component.list()) do
local function setDestination(code)
for address, type in pairs(Component.list()) do
if type == "ender_chest" then
util.machine(address).setFrequency(code)
end
end
end
function checkClick(_, address, x, y, button, name)
local function checkClick(_, address, x, y, button, name)
for i = 1, #boundingBoxes, 1 do
local xb, yb = boundingBoxes[i].x, math.ceil(boundingBoxes[i].y / 2)
if x >= xb and x < xb + 21 and y >= yb and y < yb + 3 then
graphics.rectangle(GPU, boundingBoxes[i].x + 2, boundingBoxes[i].y + 2, 14, 2, 0x00CC00)
Graphics.rectangle(GPU, boundingBoxes[i].x + 2, boundingBoxes[i].y + 2, 14, 2, 0x00CC00)
local destinationColor = destinations[i].color or 0x0055FF
setDestination(destinations[i].id)
graphics.rectangle(GPU, 30, 43, 22, 2, 0x000000)
graphics.centeredText(GPU, 40, 43, destinationColor, destinations[i].name)
event.timer(0.2, graphics.update)
Graphics.rectangle(GPU, 30, 43, 22, 2, 0x000000)
Graphics.centeredText(GPU, 40, 43, destinationColor, destinations[i].name)
Event.timer(0.2, Graphics.update)
return i
end
end
end
function addBoundingBox(index)
local function addBoundingBox(index)
boundingBoxes[index] = {x = 2 + ((index - 1) % 5) * 20, y = 3 + math.floor((index - 1) / 4) * 8}
end
function getDestination()
for address, type in pairs(component.list()) do
local function getDestination()
for address, type in pairs(Component.list()) do
if type == "ender_chest" then
return util.machine(address).getFrequency()
end
end
end
event.listen("touch", checkClick)
Event.listen("touch", checkClick)
GPU.freeAllBuffers()
GPU.fill(0, 0, 100, 100, " ")
graphics.rectangle(GPU, 28, 41, 26, 6, 0x111111)
graphics.rectangle(GPU, 30, 43, 22, 2, 0x000000)
graphics.text(GPU, 31, 39, 0xFFFFFF, "Current Destination")
Graphics.rectangle(GPU, 28, 41, 26, 6, 0x111111)
Graphics.rectangle(GPU, 30, 43, 22, 2, 0x000000)
Graphics.text(GPU, 31, 39, 0xFFFFFF, "Current Destination")
for i = 1, #destinations, 1 do
addBoundingBox(i)
createDestination(boundingBoxes[i].x, boundingBoxes[i].y, i)
graphics.update()
Graphics.update()
end
while true do
os.sleep()

View File

@ -1,13 +1,15 @@
component = require("component")
computer = require("computer")
Component = require("component")
Computer = require("computer")
Graphics = require("graphics.graphics")
GPU = Component.gpu
function cycle()
component.redstone.setOutput(2, 15)
local function cycle()
Component.redstone.setOutput(2, 15)
os.sleep(1)
component.redstone.setOutput(2, 0)
Component.redstone.setOutput(2, 0)
end
component.gpu.setResolution(80, 40)
Component.gpu.setResolution(80, 40)
local incoming = 4
local sending = 3
@ -20,11 +22,11 @@ local ticket = 1
-- end
--end
function setDestination(destination)
local function setDestination(destination)
end
function unload(index)
local transposer = component.transposer
local function unload(index)
local transposer = Component.transposer
if transposer.getStackInSlot(controller, 1) ~= nil then
--Using a return ticket
cycle()
@ -47,37 +49,32 @@ function unload(index)
transposer.transferItem(incoming, controller, 1, index, 1)
end
end
function copyWindow(GPU, x, y, page, destination)
destination = 0 or destination
GPU.bitblt(destination, x, y, 160, 46, page, 1, 1)
end
windows = {}
function doStartupSequence()
local gpu = component.gpu
gpu.freeAllBuffers()
Graphics.windows = {}
local function doStartupSequence()
GPU.freeAllBuffers()
local colors = {
[0] = colors.steelBlue,
[1] = colors.black
[0] = Colors.steelBlue,
[1] = Colors.black
}
local buffer = gpu.allocateBuffer()
gpu.setActiveBuffer(buffer)
local buffer = GPU.allocateBuffer()
GPU.setActiveBuffer(buffer)
for i = 2, 20, 1 do
if i % 2 == 0 then
copyWindow(gpu, 0, 0, buffer, 0)
Graphics.copyWindow(GPU, 0, 0, buffer, 0)
end
gpu.setForeground(colors[i % 2])
component.gpu.fill(2 + i * 2, 1 + i, 80 - i * 4, 40 - i * 2, "")
GPU.setForeground(colors[i % 2])
Component.gpu.fill(2 + i * 2, 1 + i, 80 - i * 4, 40 - i * 2, "")
os.sleep(0.1)
end
gpu.setActiveBuffer(0)
GPU.setActiveBuffer(0)
os.sleep(0.5)
gpu.setForeground(0x000000)
gpu.fill(0, 0, 100, 50, "")
gpu.setForeground(0xFFFFFF)
GPU.setForeground(0x000000)
GPU.fill(0, 0, 100, 50, "")
GPU.setForeground(0xFFFFFF)
end
local starting = false
function send()
local transposer = component.transposer
local function send()
local transposer = Component.transposer
if transposer.getStackInSlot(controller, 1) == nil then
--screen.write("The operating cell is missing!\n")
else
@ -87,8 +84,8 @@ function send()
transposer.transferItem(controller, sending, 1, 2, 1)
end
end
function checkArrivals()
local transposer = component.transposer
local function checkArrivals()
local transposer = Component.transposer
for i = 1, 26 do
if transposer.getStackInSlot(incoming, i) ~= nil then
return i
@ -97,24 +94,24 @@ function checkArrivals()
return 0
end
local lastActivation = 0
function setStarting()
local function setStarting()
starting = false
end
function activateTeleporter()
local function activateTeleporter()
if starting == false then
starting = true
send()
event.timer(10, setStarting)
Event.timer(10, setStarting)
end
lastActivation = computer.uptime()
lastActivation = Computer.uptime()
end
event.listen("walk", activateTeleporter)
component.gpu.fill(0, 0, 100, 50, " ")
Event.listen("walk", activateTeleporter)
Component.gpu.fill(0, 0, 100, 50, " ")
while true do
local arrival = checkArrivals()
if arrival ~= 0 then
starting = true
event.timer(10, setStarting)
Event.timer(10, setStarting)
unload(arrival)
end
os.sleep(0.5)

View File

@ -1,10 +0,0 @@
component = require("component")
local transposer = component.transposer
local dark = 2
local charger = 3
function swap()
transposer.transferItem(dark, charger, 1, 39, 5)
transposer.transferItem(charger, dark, 1, 1, 39)
transposer.transferItem(charger, charger, 1, 5, 1)
end

View File

@ -1,5 +1,5 @@
component = require("component")
local transposer = component.transposer
Component = require("component")
local transposer = Component.transposer
local players = {["Sampsa"] = 3, ["Dark"] = 2}
local function findEmptyCans(player)
local allItems = transposer.getAllStacks(players[player]).getAll()

View File

@ -1,11 +1,20 @@
component = require("component")
term = require("term")
Component = require("component")
Term = require("term")
local transposers = {}
function configureTransposers()
for address, type in pairs(component.list()) do
local function countTransposers()
local count = 0
for address, type in pairs(Component.list()) do
if type == "transposer" then
local transposer = component.proxy(component.get(address))
count = count + 1
end
end
return count
end
local function configureTransposers()
for address, type in pairs(Component.list()) do
if type == "transposer" then
local transposer = Component.proxy(Component.get(address))
local foundTanks = {}
for side = 0, 5, 1 do
if transposer.getTankCapacity(side) > 0 then
@ -19,24 +28,15 @@ function configureTransposers()
transposers[address] = {source = foundTanks[1].side, sink = foundTanks[2].side}
end
else
term.write("Some transposers have more than two tanks! FIX IT!\n")
Term.write("Some transposers have more than two tanks! FIX IT!\n")
end
end
end
term.write("Found " .. countTransposers() .. " output hatches to keep at 50%\n")
Term.write("Found " .. countTransposers() .. " output hatches to keep at 50%\n")
end
function countTransposers()
local count = 0
for address, type in pairs(component.list()) do
if type == "transposer" then
count = count + 1
end
end
return count
end
function tick()
local function tick()
for address, sides in pairs(transposers) do
local transposer = component.proxy(component.get(address))
local transposer = Component.proxy(Component.get(address))
local sourceCurrent, sourceMax = transposer.getTankLevel(sides.source), transposer.getTankCapacity(sides.source)
if sourceCurrent / sourceMax > 0.5 then
local fluidToRemove = sourceCurrent - sourceMax / 2

View File

@ -1,11 +1,11 @@
component = require("component")
Component = require("component")
local LSC = component.gt_machine
local LSC = Component.gt_machine
local engaged = false
local function machine(address)
machineAddress = component.get(address)
local machineAddress = Component.get(address)
if (machineAddress ~= nil) then
return component.proxy(machineAddress)
return Component.proxy(machineAddress)
else
return nil
end

View File

@ -0,0 +1,5 @@
local function render()
end
return render

View File

@ -1,12 +1,12 @@
-- Import section
parser = require("utils.parser")
inherits = require("utils.inherits")
Parser = require("utils.parser")
Inherits = require("utils.inherits")
SingleBlock = require("data.datasource.single-block")
local mock = require("data.mock.mock-energy-provider")
--
local EnergyProvider =
inherits(
Inherits(
SingleBlock,
{
mock = mock,
@ -56,17 +56,17 @@ end
function EnergyProvider:getTotalEnergy()
local sensorInformation = self:getSensorInformation()
return parser.parseStoredEnergy(sensorInformation[3])
return Parser.parseStoredEnergy(sensorInformation[3])
end
function EnergyProvider:getAverageInput()
local sensorInformation = self:getSensorInformation()
return parser.parseAverageInput(sensorInformation[5])
return Parser.parseAverageInput(sensorInformation[5])
end
function EnergyProvider:getAverageOutput()
local sensorInformation = self:getSensorInformation()
return parser.parseAverageOutput(sensorInformation[7])
return Parser.parseAverageOutput(sensorInformation[7])
end
return EnergyProvider

View File

@ -1,12 +1,12 @@
-- Import section
parser = require("utils.parser")
inherits = require("utils.inherits")
Parser = require("utils.parser")
Inherits = require("utils.inherits")
SingleBlock = require("data.datasource.single-block")
local mock = require("data.mock.mock-miner")
--
local Miner =
inherits(
Inherits(
SingleBlock,
{
mock = mock,
@ -16,12 +16,12 @@ local Miner =
function Miner:getName()
local sensorInformation = self:getSensorInformation()
return parser.parseName(sensorInformation[1])
return Parser.parseName(sensorInformation[1])
end
function Miner:getWorkArea()
local sensorInformation = self:getSensorInformation()
return parser.parseWorkArea(sensorInformation[2])
return Parser.parseWorkArea(sensorInformation[2])
end
return Miner

View File

@ -1,12 +1,12 @@
-- Import section
parser = require("utils.parser")
inherits = require("utils.inherits")
Parser = require("utils.parser")
Inherits = require("utils.inherits")
SingleBlock = require("data.datasource.single-block")
local mock = require("data.mock.mock-multi-block")
--
local MultiBlock =
inherits(
Inherits(
SingleBlock,
{
mock = mock,
@ -16,12 +16,12 @@ local MultiBlock =
function MultiBlock:getNumberOfProblems()
local sensorInformation = self:getSensorInformation()
return parser.parseProblems(sensorInformation[5])
return Parser.parseProblems(sensorInformation[5])
end
function MultiBlock:getEfficiencyPercentage()
local sensorInformation = self:getSensorInformation()
return parser.parseEfficiency(sensorInformation[5])
return Parser.parseEfficiency(sensorInformation[5])
end
return MultiBlock

View File

@ -1,5 +1,5 @@
-- Import section
component = require("component")
Component = require("component")
local mock = require("data.mock.mock-single-block")
--
@ -91,7 +91,7 @@ function SingleBlock:new(partialAdress)
local successfull =
pcall(
function()
machine.block = component.proxy(component.get(partialAdress))
machine.block = Component.proxy(Component.get(partialAdress))
end
)
if (not successfull) then

View File

@ -1,10 +1,10 @@
-- Import section
inherits = require("utils.inherits")
Inherits = require("utils.inherits")
MockSingleBlock = require("data.mock.mock-single-block")
--
local MockEnergyProvider =
inherits(
Inherits(
MockSingleBlock,
{
name = "MockEnergyProvider"

View File

@ -1,10 +1,10 @@
-- Import section
inherits = require("utils.inherits")
Inherits = require("utils.inherits")
MockSingleBlock = require("data.mock.mock-single-block")
--
local MockMiner =
inherits(
Inherits(
MockSingleBlock,
{
name = "MockMiner"

View File

@ -1,10 +1,10 @@
-- Import section
inherits = require("utils.inherits")
Inherits = require("utils.inherits")
MockSingleBlock = require("data.mock.mock-single-block")
--
local MockMultiBlock =
inherits(
Inherits(
MockSingleBlock,
{
name = "MockMultiBlock"

View File

@ -1,5 +1,5 @@
-- Import section
new = require("utils.new")
New = require("utils.new")
--
local MockSingleBlock = {
@ -89,7 +89,7 @@ end
MockSingleBlock.__index = MockSingleBlock
function MockSingleBlock:new()
return new(self)
return New(self)
end
function MockSingleBlock:getEfficiencyPercentage()

View File

@ -1,17 +1,17 @@
-- Import section
local alarm = require('resources.sound.alarm')
Alarm = require("api.sound.alarm")
--
local function halt(machines)
alarm()
for i = 1, #machines do
machines[i]:setWorkAllowed(false)
Alarm()
for _, machine in ipairs(machines) do
machine:setWorkAllowed(false)
end
end
local function resume(machines)
for i = 1, #machines do
machines[i]:setWorkAllowed(true)
for _, machine in ipairs(machines) do
machine:setWorkAllowed(true)
end
end

View File

@ -8,12 +8,23 @@ local function exec(energyProducers, energyBuffer)
-- local production = getProduction(energyBuffer)
local consumption = energyBuffer:getAverageInput()
local production = energyBuffer:getAverageOutput()
local energyCapacity = energyBuffer:getTotalEnergy().maximum
local timeToFull = (production - consumption) ~= 0 and energyCapacity / (production - consumption) or "-"
local changeRate = production - consumption
local totalEnergy = energyBuffer:getTotalEnergy()
local maximumEnergy = totalEnergy.maximum
local currentEnergy = totalEnergy.current
local energyLimit = changeRate > 0 and maximumEnergy or 0
local timeToFull = changeRate > 0 and (energyLimit - currentEnergy) / changeRate or nil
local timeToEmpty = changeRate < 0 and (energyLimit - currentEnergy) / changeRate or nil
return {
consumption = consumption,
production = production,
timeToFull = timeToFull,
timeToEmpty = timeToEmpty
}
end

View File

@ -1,7 +1,7 @@
-- Import section
event = require("event")
Event = require("event")
local minerDatasource = require("data.datasource.miner")
local oneUp = require("resources.sound.mario-one-up")
local oneUp = require("api.sound.mario-one-up")
--
local minerList = {}
@ -18,9 +18,9 @@ local function removeMinerFromList(_, address, machine)
end
end
event.listen("touch", require("resources.sound.mario-one-up"))
event.listen("component_added", addToMinerList)
event.listen("component_removed", removeMinerFromList)
Event.listen("touch", oneUp)
Event.listen("component_added", addToMinerList)
Event.listen("component_removed", removeMinerFromList)
local function exec()
return minerList

View File

@ -1,8 +1,17 @@
-- Import section
Alarm = require("api.sound.alarm")
--
local function exec(multiblocks)
local statuses = {}
for _, multiblock in ipairs(multiblocks) do
local problems = multiblock:getNumberOfProblems()
if problems > 0 then
Alarm()
end
statuses[multiblock.name] = {
problems = multiblock:getNumberOfProblems(),
problems = problems,
efficiencyPercentage = multiblock:getEfficiencyPercentage()
}
end

View File

@ -50,4 +50,4 @@ for multiblock, status in pairs(multiblocksStatuses) do
problems: " .. status.problems .. "\
efficiency: " .. status.efficiencyPercentage)
end
require("resources.sound.zelda-secret")()
require("api.sound.zelda-secret")()