Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. ocal component = require("component")
  2. local term = require("term")
  3. local gpu = component.gpu
  4. local color = require("colors")  
  5.  
  6. -- Naming
  7. local version = 0.1
  8. local name = "ROIS"
  9. local formattedName = name, " v" , version
  10.  
  11. --Screen resolution
  12. local scrWidth, scrHeight = gpu.getResolution()
  13.  
  14. --Drawing values
  15. local startY = 2 -- Minimum y value to start drawing at
  16. local endY = scrHeight -- Maximum y value to draw at.
  17.  
  18. --Status
  19. local status_normal = "[C]=Close"
  20.  
  21. --Table to store all machines in
  22. local machines = {}
  23.  
  24. --Variables to store currently selected machine information.
  25. local selected = 1 -- Stores the list int value of the selected machine. Think list[1], list[2]...etc
  26. local selectedName = "" -- Stores the currently selected machines name
  27. local selectedInformation = {} -- Stores the currently selectes machines information.
  28.  
  29. --Colors to use for drawing to the screen
  30. local colors =
  31. {
  32.   bars                  = 0x00264D
  33.   text_normal       = 0xFFFFFF
  34.   text_highlight        = 0xFFFFFF
  35.   item_cwd          = 0x660066
  36.   item_highlight    = 0x803300
  37.   item_saved        = 0x004400
  38. }
  39.  
  40.  
  41. --Returns a table of information about the specified machine. Args. component address.
  42. local function getMachineInformation(address)
  43.     info = {}
  44.     theComponent = component.proxy(address)
  45.     info["componentObject"] = theComponent
  46.     info["xCoordinate"], info["yCoordinate"], info["zCoordinate"] = theComponent.getCoords()
  47.     info["componentName"] = theComponent.getName()
  48.     info["componentAddress"] = address
  49.     if(theComponent.getTanks() == nil)  then
  50.         info["canStoreLiquid"] = false
  51.     else
  52.         info["canStoreLiquid"] = true
  53.         info["storedLiquidType"], info["storedLiquidAmount"], info["storedLiquidMax"] = theComponent.getTanks()
  54.     end
  55.     info["powerTotal"], info["powerTorque"], info["powerSpeed"] = theComponent.getPower()
  56.     return info
  57. end
  58.  
  59. --Updates the current list of machines. Does not change display names.
  60. local function updateMachines()
  61.     newMachines = {}
  62.     for machineName, machineInformation in pairs(machines) do
  63.         newMachines[machineName] = getMachineInformation(machineInformation["componentAddress"])
  64.     end
  65.     machines = newMachines
  66. end
  67.  
  68. --Finds all machines, will reset display names. Use only for program initialization.
  69. local function findMachines()
  70.     allMachines = {}
  71.     for address, componentType in component.list()  do
  72.         if(componentType == "Extractor" or componentType == "AdvancedGears") then
  73.             allMachines[componentType] = getMachineInformation(address)
  74.         end
  75.     end
  76.     machines = allMachines
  77. end
  78.  
  79. --Returns the machines information associated with the specified address. Will return nil if there is no machine associated with that address.
  80. local function getMachineInformation(address)
  81.     for key,value in pairs(machines) do
  82.         if(value["componentAddress"] == address) then
  83.             return value
  84.         end
  85.     end
  86. end
  87.  
  88. --Returns the amount of machines added.
  89. local function getMachineListSize()
  90.     i = 1
  91.     for key,value in pairs(machines) do i = i + 1 end
  92.     return i
  93. end
  94.  
  95. --Draws the list of machines to the screen
  96. local function drawMachineList()
  97.     i = 1
  98.     term.clear() -- Clear the screen
  99.     for displayName, machineInfo in ipairs(machines) do -- We use ipairs to make sure that machines are always in the same order.
  100.         if(i == selected) then
  101.             gpu.setBackground(colors.item_highlighted)
  102.             gpu.setForeground(colors.text_highlighted)
  103.             selectedName = displayName
  104.             selectedInformation = machineInfo
  105.         end
  106.        
  107.         term.setCursor(1, startY + i - 1) -- xValue, yValue
  108.         print(displayName)
  109.         gpu.setBackground(0x000000)
  110.         gpu.setForeground(colors.text_normal)
  111.     end
  112. end
  113.  
  114. findMachines()
  115. drawMachineList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement