Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ocal component = require("component")
- local term = require("term")
- local gpu = component.gpu
- local color = require("colors")
- -- Naming
- local version = 0.1
- local name = "ROIS"
- local formattedName = name, " v" , version
- --Screen resolution
- local scrWidth, scrHeight = gpu.getResolution()
- --Drawing values
- local startY = 2 -- Minimum y value to start drawing at
- local endY = scrHeight -- Maximum y value to draw at.
- --Status
- local status_normal = "[C]=Close"
- --Table to store all machines in
- local machines = {}
- --Variables to store currently selected machine information.
- local selected = 1 -- Stores the list int value of the selected machine. Think list[1], list[2]...etc
- local selectedName = "" -- Stores the currently selected machines name
- local selectedInformation = {} -- Stores the currently selectes machines information.
- --Colors to use for drawing to the screen
- local colors =
- {
- bars = 0x00264D
- text_normal = 0xFFFFFF
- text_highlight = 0xFFFFFF
- item_cwd = 0x660066
- item_highlight = 0x803300
- item_saved = 0x004400
- }
- --Returns a table of information about the specified machine. Args. component address.
- local function getMachineInformation(address)
- info = {}
- theComponent = component.proxy(address)
- info["componentObject"] = theComponent
- info["xCoordinate"], info["yCoordinate"], info["zCoordinate"] = theComponent.getCoords()
- info["componentName"] = theComponent.getName()
- info["componentAddress"] = address
- if(theComponent.getTanks() == nil) then
- info["canStoreLiquid"] = false
- else
- info["canStoreLiquid"] = true
- info["storedLiquidType"], info["storedLiquidAmount"], info["storedLiquidMax"] = theComponent.getTanks()
- end
- info["powerTotal"], info["powerTorque"], info["powerSpeed"] = theComponent.getPower()
- return info
- end
- --Updates the current list of machines. Does not change display names.
- local function updateMachines()
- newMachines = {}
- for machineName, machineInformation in pairs(machines) do
- newMachines[machineName] = getMachineInformation(machineInformation["componentAddress"])
- end
- machines = newMachines
- end
- --Finds all machines, will reset display names. Use only for program initialization.
- local function findMachines()
- allMachines = {}
- for address, componentType in component.list() do
- if(componentType == "Extractor" or componentType == "AdvancedGears") then
- allMachines[componentType] = getMachineInformation(address)
- end
- end
- machines = allMachines
- end
- --Returns the machines information associated with the specified address. Will return nil if there is no machine associated with that address.
- local function getMachineInformation(address)
- for key,value in pairs(machines) do
- if(value["componentAddress"] == address) then
- return value
- end
- end
- end
- --Returns the amount of machines added.
- local function getMachineListSize()
- i = 1
- for key,value in pairs(machines) do i = i + 1 end
- return i
- end
- --Draws the list of machines to the screen
- local function drawMachineList()
- i = 1
- term.clear() -- Clear the screen
- for displayName, machineInfo in ipairs(machines) do -- We use ipairs to make sure that machines are always in the same order.
- if(i == selected) then
- gpu.setBackground(colors.item_highlighted)
- gpu.setForeground(colors.text_highlighted)
- selectedName = displayName
- selectedInformation = machineInfo
- end
- term.setCursor(1, startY + i - 1) -- xValue, yValue
- print(displayName)
- gpu.setBackground(0x000000)
- gpu.setForeground(colors.text_normal)
- end
- end
- findMachines()
- drawMachineList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement