rainbow-dragon/Sources/ForgeCamera/SlotRegistry.swift

41 lines
1 KiB
Swift
Raw Permalink Normal View History

import Foundation
/// A camera slot: named position (A-Cam, B-Cam...) bound to a driver.
public struct CameraSlot: Identifiable, Sendable {
public let id: UUID
public var name: String
public let driver: any CameraDriver
public init(id: UUID = UUID(), name: String, driver: any CameraDriver) {
self.id = id
self.name = name
self.driver = driver
}
}
/// Registry of active camera slots.
public actor SlotRegistry {
public private(set) var slots: [CameraSlot] = []
public init() {}
@discardableResult
public func addSlot(name: String, driver: any CameraDriver) -> CameraSlot {
let slot = CameraSlot(name: name, driver: driver)
slots.append(slot)
return slot
}
public func removeSlot(id: UUID) {
slots.removeAll { $0.id == id }
}
public func slot(id: UUID) -> CameraSlot? {
slots.first { $0.id == id }
}
public func slot(named name: String) -> CameraSlot? {
slots.first { $0.name == name }
}
}