mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
fixed match error; adding a tiny delay when switching primary components. this is mainly required for term.read, sh and lua to react to screens/gpu disappearing and reappearing
This commit is contained in:
parent
3097d7657b
commit
110d15ff50
@ -36,6 +36,7 @@ trait Component extends network.Component with Node {
|
||||
case peripheral: PeripheralCallback =>
|
||||
multi.environments.find {
|
||||
case (_, environment: ManagedPeripheral) => environment.methods.contains(peripheral.name)
|
||||
case _ => false
|
||||
} match {
|
||||
case Some((_, environment)) => method -> Some(environment)
|
||||
case _ => method -> None
|
||||
|
@ -2,6 +2,7 @@ local component = require("component")
|
||||
local computer = require("computer")
|
||||
local event = require("event")
|
||||
|
||||
local adding = {}
|
||||
local removing = {}
|
||||
local primaries = {}
|
||||
|
||||
@ -57,12 +58,27 @@ function component.setPrimary(componentType, address)
|
||||
if wasAvailable and address == primaries[componentType].address then
|
||||
return
|
||||
end
|
||||
primaries[componentType] = address and component.proxy(address) or nil
|
||||
primaries[componentType] = nil
|
||||
local wasAdding = adding[componentType]
|
||||
if wasAdding then
|
||||
event.cancel(wasAdding)
|
||||
adding[componentType] = nil
|
||||
end
|
||||
local primary = address and component.proxy(address) or nil
|
||||
if wasAvailable then
|
||||
computer.pushSignal("component_unavailable", componentType)
|
||||
end
|
||||
if component.isAvailable(componentType) then
|
||||
computer.pushSignal("component_available", componentType)
|
||||
if primary then
|
||||
if wasAvailable or wasAdding then
|
||||
adding[componentType] = event.timer(0.1, function()
|
||||
primaries[componentType] = primary
|
||||
adding[componentType] = nil
|
||||
computer.pushSignal("component_available", componentType)
|
||||
end)
|
||||
else
|
||||
primaries[componentType] = primary
|
||||
computer.pushSignal("component_available", componentType)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user