// // Entity+Component.swift // FirebladeECS // // Created by Christian Treffs on 22.10.17. // extension Entity { @inlinable public func get() -> C? where C: Component { nexus.get(for: identifier) } @inlinable public func get(component compType: A.Type = A.self) -> A? where A: Component { nexus.get(for: identifier) } @inlinable public func get(components _: A.Type, _: B.Type) -> (A?, B?) where A: Component, B: Component { let compA: A? = get(component: A.self) let compB: B? = get(component: B.self) return (compA, compB) } // swiftlint:disable large_tuple @inlinable public func get(components _: A.Type, _: B.Type, _: C.Type) -> (A?, B?, C?) where A: Component, B: Component, C: Component { let compA: A? = get(component: A.self) let compB: B? = get(component: B.self) let compC: C? = get(component: C.self) return (compA, compB, compC) } @inlinable public subscript(_ componentKeyPath: WritableKeyPath) -> Value? { nonmutating set { guard var comp = self.get(component: C.self), let value = newValue else { return } comp[keyPath: componentKeyPath] = value } get { self.get(component: C.self)?[keyPath: componentKeyPath] } } @inlinable public subscript(_ componentType: C.Type) -> C? { self.get(component: componentType) } }