Advertisement
blunty666

baseMonitorAlpha

May 8th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.14 KB | None | 0 0
  1. local tArgs = {...}
  2. local bridge
  3. if type(tArgs[1]) == "string" and peripheral.getType(tArgs[1]) == "openperipheral_bridge" then
  4.     bridge = peripheral.wrap(tArgs[1])
  5.     bridge.clear()
  6. else
  7.     error("could not find bridge on side: "..tostring(tArgs[1]))
  8. end
  9.  
  10. local requiredAPIs = {
  11.     "tiles",
  12.     "guiTiles",
  13.     "advancedTiles",
  14.     "remotePeripheralClient",
  15. }
  16.  
  17. for _, apiName in ipairs(requiredAPIs) do
  18.     if not _G.apiName then
  19.         if not os.loadAPI(apiName) then
  20.             error("Could not load API: ", apiName)
  21.         end
  22.     end
  23. end
  24.  
  25. local function textToSize(text, width)
  26.     if width <= 6 then
  27.         return "..."
  28.     elseif tiles.getMaxStringLength(text, width, 1) < string.len(text) then
  29.         return string.sub(text, 1, tiles.getMaxStringLength(text, width - 6, 1)).."..."
  30.     end
  31.     return text
  32. end
  33.  
  34. local remotePeripherals = remotePeripheralClient.new()
  35.  
  36. local function newPlayerHandler(playerUUID, surfaceHandler)
  37.     return function()
  38.  
  39.         local guiHandler = guiTiles.newGuiHandler(surfaceHandler)
  40.  
  41.         local windowHandler = guiTiles.newBasicWindowHandler()
  42.  
  43.         local minWidth, minHeight = 50, 20
  44.         local function newGraphWindow(uniqueID, width, height, updateName, objectType)
  45.             local width, height = math.max(width, minWidth), math.max(height, minHeight)
  46.  
  47.             local window = windowHandler:New(surfaceHandler:AddTile(-(width/2), -(height/2), 1), width, height, true)
  48.             window:SetScreenAnchor("MIDDLE", "MIDDLE")
  49.            
  50.             local textBox = window:AddTextBox(1, 1, 1, width - 10, function(text) updateName(objectType, uniqueID, text) end)
  51.             textBox.background:SetVisible(false)
  52.             textBox:SetText(uniqueID)
  53.             textBox:SetOnDeselect(function(text) updateName(objectType, uniqueID, textBox:GetText()) end)
  54.  
  55.             local closeButton = window:AddButton(width - 8, 1, 1, "X", 0xff0000, 0xffffff, 0x00ff00, 0x000000)
  56.             closeButton:SetOnRelease(function() window:SetDrawn(false) end)
  57.            
  58.             return window
  59.         end
  60.        
  61.         local selectionWindow = guiTiles.newBasicWindow(surfaceHandler:AddTile(10, 10, 1), 80, 50)
  62.         local peripheralTypes = {}
  63.         local sourceTypes = {}
  64.        
  65.         local peripheralButton = selectionWindow:AddButton(10, 10, 1, "Peripherals", 0x7fcc19, 0x000000, 0x57a64e, 0x000000)
  66.         peripheralButton:SetOnRelease(
  67.             function()
  68.                 sourceTypes.listWindow:SetVisible(false)
  69.                 sourceTypes.listWindow:SetClickable(false)
  70.                 peripheralTypes.listWindow:SetVisible(true)
  71.                 peripheralTypes.listWindow:SetClickable(true)
  72.             end
  73.         )
  74.         local sourceButton = selectionWindow:AddButton(17, 30, 1, "Sources", 0x7fcc19, 0x000000, 0x57a64e, 0x000000)
  75.         sourceButton:SetOnRelease(
  76.             function()
  77.                 peripheralTypes.listWindow:SetVisible(false)
  78.                 peripheralTypes.listWindow:SetClickable(false)
  79.                 sourceTypes.listWindow:SetVisible(true)
  80.                 sourceTypes.listWindow:SetClickable(true)
  81.             end
  82.         )
  83.        
  84.         do -- peripheralTypes
  85.             peripheralTypes.list = {}
  86.             peripheralTypes.selectedTypeList = false
  87.            
  88.             peripheralTypes.listWindow = guiTiles.newBasicWindow(selectionWindow:AddSubTile(selectionWindow:GetWidth() + 5, 0, 1), 150, 80)
  89.             peripheralTypes.listWindow:SetVisible(false)
  90.             peripheralTypes.listWindow:SetClickable(false)
  91.             peripheralTypes.listWindow:AddFancyText(6, 6, 1, "Peripherals", 0x000000, 1)
  92.            
  93.             local function onListSelect(index, peripheralType)
  94.                 if peripheralTypes.selectedTypeList then
  95.                     peripheralTypes.selectedTypeList:SetVisible(false)
  96.                     peripheralTypes.selectedTypeList:SetClickable(false)
  97.                 end
  98.                 local sourceList = peripheralTypes.list[peripheralType].listWindow
  99.                 if sourceList then
  100.                     sourceList:SetVisible(true)
  101.                     sourceList:SetClickable(true)
  102.                     peripheralTypes.selectedTypeList = sourceList
  103.                 end
  104.             end
  105.             peripheralTypes.listObject = peripheralTypes.listWindow:AddList(5, 25, 1, 140, 50, onListSelect, {})
  106.            
  107.             peripheralTypes.add = function(peripheralType, name)
  108.                 local peripheralData = peripheralTypes.list[peripheralType]
  109.                 if peripheralData then
  110.                     local window = newGraphWindow(name, peripheralData.width, peripheralData.height, peripheralTypes.update, peripheralType)
  111.                     local object = peripheralTypes.list[peripheralType].add(name, window)
  112.                     peripheralTypes.list[peripheralType].list[name] = object
  113.                     peripheralTypes.list[peripheralType].listObject:AddItem(1, {name, name})
  114.                 end
  115.             end
  116.             peripheralTypes.update = function(peripheralType, peripheralName, peripheralNewName)
  117.                 if peripheralTypes.list[peripheralType] then
  118.                     local list = peripheralTypes.list[peripheralType].listObject
  119.                    
  120.                     for index, itemData in ipairs(list.items) do
  121.                         if itemData[1] == peripheralName then
  122.                             list:SetItem(index, {itemData[1], peripheralNewName})
  123.                             break
  124.                         end
  125.                     end
  126.                 end
  127.             end
  128.             peripheralTypes.remove = function(peripheralType, name)
  129.                 local object = peripheralTypes.list[peripheralType].list[name]
  130.                 if object then
  131.                     windowHandler:Delete(object.windowID)
  132.                     for index, itemName in ipairs(peripheralTypes.list[peripheralType].listObject.items) do
  133.                         if itemName[1] == name then
  134.                             peripheralTypes.list[peripheralType].listObject:RemoveItem(index)
  135.                             break
  136.                         end
  137.                     end
  138.                     peripheralTypes.list[peripheralType].list[name] = nil
  139.                 end
  140.             end
  141.         end
  142.        
  143.         do -- sourceTypes
  144.             sourceTypes.list = {}
  145.             sourceTypes.selectedTypeList = false
  146.            
  147.             sourceTypes.listWindow = guiTiles.newBasicWindow(selectionWindow:AddSubTile(selectionWindow:GetWidth() + 5, 0, 1), 150, 80)
  148.             sourceTypes.listWindow:SetVisible(false)
  149.             sourceTypes.listWindow:SetClickable(false)
  150.             sourceTypes.listWindow:AddFancyText(6, 6, 1, "Sources", 0x000000, 1)
  151.            
  152.             local function onListSelect(index, sourceType)
  153.                 if sourceTypes.selectedTypeList then
  154.                     sourceTypes.selectedTypeList:SetVisible(false)
  155.                     sourceTypes.selectedTypeList:SetClickable(false)
  156.                 end
  157.                 local sourceList = sourceTypes.list[sourceType].listWindow
  158.                 if sourceList then
  159.                     sourceList:SetVisible(true)
  160.                     sourceList:SetClickable(true)
  161.                     sourceTypes.selectedTypeList = sourceList
  162.                 end
  163.             end
  164.             sourceTypes.listObject = sourceTypes.listWindow:AddList(5, 25, 1, 140, 50, onListSelect, {})
  165.            
  166.             sourceTypes.add = function(sourceType, name)
  167.                 local sourceData = sourceTypes.list[sourceType]
  168.                 if sourceData then
  169.                     local window = newGraphWindow(name, sourceData.width, sourceData.height, sourceTypes.update, sourceType)
  170.                     local sourceObject = sourceTypes.list[sourceType].add(name, window)
  171.                     sourceTypes.list[sourceType].list[name] = sourceObject
  172.                     sourceTypes.list[sourceType].listObject:AddItem(1, {name, name})
  173.                 end
  174.             end
  175.             sourceTypes.update = function(sourceType, sourceName, sourceNewName)
  176.                 if sourceTypes.list[sourceType] then
  177.                     local list = sourceTypes.list[sourceType].listObject
  178.                    
  179.                     for index, itemData in ipairs(list.items) do
  180.                         if itemData[1] == sourceName then
  181.                             list:SetItem(index, {itemData[1], sourceNewName})
  182.                             break
  183.                         end
  184.                     end
  185.                 end
  186.             end
  187.             sourceTypes.remove = function(sourceType, name)
  188.                 local sourceObject = sourceTypes.list[sourceType].list[name]
  189.                 if sourceObject then
  190.                     windowHandler:Delete(sourceObject.windowID)
  191.                     for index, itemName in ipairs(sourceTypes.list[sourceType].listObject.items) do
  192.                         if itemName[1] == name then
  193.                             sourceTypes.list[sourceType].listObject:RemoveItem(index)
  194.                             break
  195.                         end
  196.                     end
  197.                     sourceTypes.list[sourceType].list[name] = nil
  198.                 end
  199.             end
  200.         end
  201.  
  202.         local peripherals = {
  203.             furnace = {
  204.                 display_name = "Vanilla Furnace",
  205.                 width = 100,
  206.                 height = 80,
  207.                 add = function(name, window)
  208.                     local sourceObject = {
  209.                         windowID = window:GetUserdata()[2],
  210.                         displays = {
  211.                             fuelProgress = advancedTiles.addSimpleFluidBar(window, 10, 55, 1, 20, 10, "lava", 1),
  212.                             cookProgress = advancedTiles.addComplexBar(window, 30, 40, 1, 40, 10, 0xff0000, 1),
  213.                             [1] = window:AddItemSlot(15, 25, 1),
  214.                             [2] = window:AddItemSlot(15, 65, 1),
  215.                             [3] = window:AddItemSlot(85, 45, 1),
  216.                         },
  217.                     }
  218.                     sourceObject.displays.fuelProgress:SetRotation(270)
  219.                    
  220.                     return sourceObject
  221.                 end,
  222.                 update = function(name, sourceObject)
  223.                     local curBurn, maxBurn
  224.                     local isCooking, curCook
  225.                     local maxCook = 200
  226.                     local furnaceData = remotePeripherals:GetSourceData(name, "vanilla_furnace")
  227.                     if furnaceData then
  228.                         curBurn, maxBurn = furnaceData.getBurnTime, furnaceData.getCurrentItemBurnTime
  229.                         isCooking, curCook = furnaceData.isBurning, furnaceData.getCookTime
  230.                     end
  231.                    
  232.                     if type(curBurn) == "number" and type(maxBurn) == "number" then
  233.                         sourceObject.displays.fuelProgress:SetPercent(curBurn/maxBurn)
  234.                     else
  235.                         sourceObject.displays.fuelProgress:SetPercent(0)
  236.                     end
  237.                     if isCooking and type(curCook) == "number" then
  238.                         sourceObject.displays.cookProgress:SetPercent(curCook/maxCook)
  239.                     else
  240.                         sourceObject.displays.cookProgress:SetPercent(0)
  241.                     end
  242.                    
  243.                     local items
  244.                     local itemData = remotePeripherals:GetSourceData(name, "inventory")
  245.                     if itemData then
  246.                         items = itemData.getAllStacks
  247.                     end
  248.                     for i = 1, 3 do
  249.                         if items and items[i] then
  250.                             sourceObject.displays[i]:SetItemId(items[i].id)
  251.                             sourceObject.displays[i]:SetMeta(items[i].dmg)
  252.                             sourceObject.displays[i]:SetAmount(items[i].qty)
  253.                             if items[i].health_bar then
  254.                                 sourceObject.displays[i]:SetDamageBar(items[i].health_bar)
  255.                             else
  256.                                 sourceObject.displays[i]:SetDamageBar(0)
  257.                             end
  258.                         else
  259.                             sourceObject.displays[i]:SetAmount(false)
  260.                         end
  261.                     end
  262.                 end,
  263.             },
  264.             tile_thermalexpansion_machine_furnace_name = {
  265.                 display_name = "Redstone Furnace",
  266.                 width = 100,
  267.                 height = 80,
  268.                 add = function(name, window)
  269.                     local sourceObject = {
  270.                         windowID = window:GetUserdata()[2],
  271.                         cookProgress = 0,
  272.                         displays = {
  273.                             energy = advancedTiles.addComplexBar(window, 10, 70, 1, 50, 10, 0xff0000, 1),
  274.                             cookProgress = advancedTiles.addSimpleBoxBar(window, 50, 42, 1, 20, 6, 0xffffff, 1),
  275.                             [1] = window:AddItemSlot(40, 45, 1),
  276.                             [2] = window:AddItemSlot(80, 45, 1),
  277.                         },
  278.                     }
  279.                     sourceObject.displays.energy:SetRotation(270)
  280.                    
  281.                     return sourceObject
  282.                 end,
  283.                 update = function(name, sourceObject)
  284.                     local curEnergy, maxEnergy
  285.                     local energyPerTick
  286.                     local rfData = remotePeripherals:GetSourceData(name, "rf_info")
  287.                     if rfData then
  288.                         curEnergy = rfData.getEnergyInfo
  289.                         maxEnergy = rfData.getMaxEnergyInfo
  290.                         energyPerTick = rfData.getEnergyPerTickInfo
  291.                     end
  292.  
  293.                     if type(curEnergy) == "number" and type(maxEnergy) == "number" then
  294.                         sourceObject.displays.energy:SetPercent(curEnergy/maxEnergy)
  295.                     else
  296.                         sourceObject.displays.energy:SetPercent(0)
  297.                     end
  298.  
  299.                     if type(energyPerTick) == "number" and energyPerTick > 0 then
  300.                         sourceObject.cookProgress = (sourceObject.cookProgress + 1) % 5
  301.                         sourceObject.displays.cookProgress:SetPercent(sourceObject.cookProgress/4)
  302.                     else
  303.                         sourceObject.displays.cookProgress:SetPercent(0)
  304.                     end
  305.                    
  306.                     local items
  307.                     local itemData = remotePeripherals:GetSourceData(name, "inventory")
  308.                     if itemData then
  309.                         items = itemData.getAllStacks
  310.                     end
  311.                     for i = 1, 2 do
  312.                         if items and items[i] then
  313.                             sourceObject.displays[i]:SetItemId(items[i].id)
  314.                             sourceObject.displays[i]:SetMeta(items[i].dmg)
  315.                             sourceObject.displays[i]:SetAmount(items[i].qty)
  316.                             if items[i].health_bar then
  317.                                 sourceObject.displays[i]:SetDamageBar(items[i].health_bar)
  318.                             else
  319.                                 sourceObject.displays[i]:SetDamageBar(0)
  320.                             end
  321.                         else
  322.                             sourceObject.displays[i]:SetAmount(false)
  323.                         end
  324.                     end
  325.                 end,
  326.             },
  327.         }
  328.         for peripheralType, peripheralData in pairs(peripherals) do
  329.        
  330.             local name = peripheralData.display_name or peripheralType
  331.        
  332.             peripheralData.list = {}
  333.            
  334.             peripheralData.listWindow = guiTiles.newBasicWindow(peripheralTypes.listWindow:AddSubTile(155, 0, 1), 150, 80)
  335.             peripheralData.listWindow:SetVisible(false)
  336.             peripheralData.listWindow:SetClickable(false)
  337.            
  338.             peripheralData.listWindow:AddFancyText(6, 6, 1, textToSize(name, 138), 0x000000, 1)
  339.            
  340.             local function onListSelect(index, name)
  341.                 peripheralData.listObject:SetSelected(false, true)
  342.                 peripheralData.listObject:SetHighlighted(false, true)
  343.                 local windowID = peripheralData.list[name] and peripheralData.list[name].windowID
  344.                 if windowID then
  345.                     local window = windowHandler:GetWindow(windowID)
  346.                     if window then
  347.                         windowHandler:ToFront(windowID)
  348.                         if not window:GetDrawn() then
  349.                             window:SetDrawn(true)
  350.                         else
  351.                             window:SetX(-(window:GetWidth()/2))
  352.                             window:SetY(-(window:GetHeight()/2))
  353.                         end
  354.                     end
  355.                 end
  356.             end
  357.             peripheralData.listObject = peripheralData.listWindow:AddList(5, 25, 1, 140, 50, onListSelect, {})
  358.            
  359.             peripheralTypes.listObject:AddItem(1, {peripheralType, name})
  360.            
  361.             peripheralTypes.list[peripheralType] = peripheralData
  362.         end
  363.        
  364.         local sources = {
  365.             rf_receiver = {
  366.                 width = 100,
  367.                 height = 80,
  368.                 add = function(name, window)
  369.                     local graph = advancedTiles.addBoxBarGraph(window, 5, 15, 1, 90, 60, 0xff0000, 1, 1)
  370.                     graph:GetBackground():SetClickable(false)
  371.                     local sourceObject = {
  372.                         windowID = window:GetUserdata()[2],
  373.                         displays = {
  374.                             mainGraph = graph,
  375.                         },
  376.                         backgroundUpdate = true,
  377.                     }
  378.                     return sourceObject
  379.                 end,
  380.                 update = function(name, sourceObject)
  381.                     local percent = 0
  382.                     local data = remotePeripherals:GetSourceData(name, "rf_receiver")
  383.                     if data then
  384.                         local curEnergy = data.getEnergyStored
  385.                         local maxEnergy = data.getMaxEnergyStored
  386.                         if type(curEnergy) == "number" and type(maxEnergy) == "number" then
  387.                             percent = curEnergy / maxEnergy
  388.                         end
  389.                     end
  390.                     sourceObject.displays.mainGraph:Update(percent)
  391.                 end,
  392.             },
  393.             fluid_handler = {
  394.                 width = 100,
  395.                 height = 80,
  396.                 add = function(name, window)
  397.                     local graph = advancedTiles.addBoxBarGraph(window, 5, 15, 1, 90, 60, 0xff0000, 1, 1)
  398.                     graph:GetBackground():SetClickable(false)
  399.                     local sourceObject = {
  400.                         windowID = window:GetUserdata()[2],
  401.                         displays = {
  402.                             mainGraph = graph,
  403.                         },
  404.                         backgroundUpdate = true,
  405.                     }
  406.                     return sourceObject
  407.                 end,
  408.                 update = function(name, sourceObject)
  409.                     local percent = 0
  410.                     local data = remotePeripherals:GetSourceData(name, "fluid_handler")
  411.                     if data then
  412.                         local tankInfo = data.getTankInfo
  413.                         if tankInfo and tankInfo[1] then
  414.                             if tankInfo[1].contents then
  415.                                 percent = tankInfo[1].contents.amount / tankInfo[1].capacity
  416.                             end
  417.                         end
  418.                     end
  419.                     sourceObject.displays.mainGraph:Update(percent)
  420.                 end,
  421.             },
  422.         }
  423.         for sourceType, sourceData in pairs(sources) do
  424.        
  425.             local name = sourceData.display_name or sourceType
  426.        
  427.             sourceData.list = {}
  428.            
  429.             sourceData.listWindow = guiTiles.newBasicWindow(sourceTypes.listWindow:AddSubTile(155, 0, 1), 150, 80)
  430.             sourceData.listWindow:SetVisible(false)
  431.             sourceData.listWindow:SetClickable(false)
  432.  
  433.             sourceData.listWindow:AddFancyText(6, 6, 1, textToSize(name, 138), 0x000000, 1)
  434.  
  435.             local function onListSelect(index, name)
  436.                 sourceData.listObject:SetSelected(false, true)
  437.                 sourceData.listObject:SetHighlighted(false, true)
  438.                 local windowID = sourceData.list[name] and sourceData.list[name].windowID
  439.                 if windowID then
  440.                     local window = windowHandler:GetWindow(windowID)
  441.                     if window then
  442.                         windowHandler:ToFront(windowID)
  443.                         if not window:GetDrawn() then
  444.                             window:SetDrawn(true)
  445.                         else
  446.                             window:SetX(-(window:GetWidth()/2))
  447.                             window:SetY(-(window:GetHeight()/2))
  448.                         end
  449.                     end
  450.                 end
  451.             end
  452.             sourceData.listObject = sourceData.listWindow:AddList(5, 25, 1, 140, 50, onListSelect, {})
  453.            
  454.             sourceTypes.listObject:AddItem(1, {sourceType, name})
  455.            
  456.             sourceTypes.list[sourceType] = sourceData
  457.         end
  458.  
  459.         local function peripheralChecker()
  460.             while true do
  461.                 local eventType, peripheralName = os.pullEvent()
  462.                 if eventType == "remote_peripheral_add" then
  463.                     print("adding peripheral = ", peripheralName)
  464.                     local peripheralData = remotePeripherals:GetAllData(peripheralName)
  465.                     if peripheralTypes.list[peripheralData.type] then
  466.                         peripheralTypes.add(peripheralData.type, peripheralName)
  467.                     end
  468.                     if peripheralData.sources then
  469.                         for source, _ in pairs(peripheralData.sources) do
  470.                             if sourceTypes.list[source] then
  471.                                 sourceTypes.add(source, peripheralName)
  472.                             end
  473.                         end
  474.                     end
  475.                 elseif eventType == "remote_peripheral_remove" then
  476.                     for peripheralType, peripheralTypeData in pairs(peripheralTypes.list) do
  477.                         if peripheralTypeData.list[peripheralName] then
  478.                             peripheralTypes.remove(peripheralType, peripheralName)
  479.                         end
  480.                     end
  481.                     for sourceType, sourceTypeData in pairs(sourceTypes.list) do
  482.                         if sourceTypeData.list[peripheralName] then
  483.                             sourceTypes.remove(sourceType, peripheralName)
  484.                         end
  485.                     end
  486.                 end
  487.             end
  488.         end
  489.  
  490.         local function main()
  491.  
  492.             selectionWindow:SetDrawn(true)
  493.  
  494.             local UPDATE_INTERVAL = 1
  495.            
  496.             local updateTimer = os.startTimer(0)
  497.             local nullClickTime, nullClickButton = -math.huge, false
  498.             while true do
  499.                 local event = {os.pullEvent()}
  500.                 guiHandler:HandleEvent(event)
  501.                 if event[1] == "glasses_capture" then
  502.                     selectionWindow:SetVisible(true)
  503.                     for _, window in pairs(windowHandler:GetAllWindows()) do
  504.                         window:SetOpacity(1)
  505.                     end
  506.                 elseif event[1] == "glasses_release" then
  507.                     selectionWindow:SetVisible(false)
  508.                     for _, window in pairs(windowHandler:GetAllWindows()) do
  509.                         window:SetOpacity(0.75)
  510.                     end
  511.                 elseif event[1] == "glasses_mouse_down" then
  512.                     local newClickTime = os.clock()
  513.                     if nullClickButton == event[5] and newClickTime - nullClickTime < 0.25 then
  514.                         if nullClickButton == 0 then
  515.                             -- exit capture mode
  516.                             local capture = surfaceHandler:GetCapture()
  517.                             if capture then
  518.                                 capture.stopCapturing()
  519.                             end
  520.                         elseif nullClickButton == 1 then
  521.                             -- reset window positions to centre of the screen
  522.                             for _, window in pairs(windowHandler:GetAllWindows()) do
  523.                                 window:SetX(-(window:GetWidth()/2))
  524.                                 window:SetY(-(window:GetHeight()/2))
  525.                             end
  526.                         end
  527.                         nullClickTime, nullClickButton = -math.huge, false
  528.                     else
  529.                         if event[5] == 1 then
  530.                             if peripheralTypes.listWindow:GetVisible() and peripheralTypes.selectedTypeList then
  531.                                 peripheralTypes.selectedTypeList:SetVisible(false)
  532.                                 peripheralTypes.selectedTypeList:SetClickable(false)
  533.                                 peripheralTypes.selectedTypeList = false
  534.                             elseif sourceTypes.listWindow:GetVisible() and sourceTypes.selectedTypeList then
  535.                                 sourceTypes.selectedTypeList:SetVisible(false)
  536.                                 sourceTypes.selectedTypeList:SetClickable(false)
  537.                                 sourceTypes.selectedTypeList = false
  538.                             else
  539.                                 peripheralTypes.listWindow:SetVisible(false)
  540.                                 peripheralTypes.listWindow:SetClickable(false)
  541.                                 sourceTypes.listWindow:SetVisible(false)
  542.                                 sourceTypes.listWindow:SetClickable(false)
  543.                             end
  544.                         end
  545.                     end
  546.                     nullClickTime = newClickTime
  547.                     nullClickButton = event[5]
  548.                 elseif event[1] == "timer" and event[2] == updateTimer then
  549.                     for _, peripheralData in pairs(peripheralTypes.list) do
  550.                         for name, object in pairs(peripheralData.list) do
  551.                             local window = windowHandler:GetWindow(object.windowID)
  552.                             if object.backgroundUpdate or (window and window:GetDrawn()) then
  553.                                 peripheralData.update(name, object)
  554.                             end
  555.                         end
  556.                     end
  557.                     for _, sourceData in pairs(sourceTypes.list) do
  558.                         for name, object in pairs(sourceData.list) do
  559.                             local window = windowHandler:GetWindow(object.windowID)
  560.                             if object.backgroundUpdate or (window and window:GetDrawn()) then
  561.                                 sourceData.update(name, object)
  562.                             end
  563.                         end
  564.                     end
  565.                     updateTimer = os.startTimer(UPDATE_INTERVAL)
  566.                 end
  567.             end
  568.         end
  569.        
  570.         parallel.waitForAny(main, peripheralChecker)
  571.     end
  572. end
  573.  
  574. local handler = tiles.newMultiSurfaceHandler(bridge, newPlayerHandler)
  575.  
  576. parallel.waitForAny(function() handler:Run() end, function() remotePeripherals:Run() end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement