Add awesome component handling
This commit is contained in:
parent
ccdb9545db
commit
fb2d011c8d
|
|
@ -90,21 +90,36 @@ extension Family {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Iterator
|
// MARK: - entity accessors
|
||||||
extension Family {
|
extension Family {
|
||||||
|
public func entities(_ apply: (Entity) -> Void ) {
|
||||||
func forEach(_ body: (Entity) -> Void ) {
|
members.lazy.forEach(apply)
|
||||||
members.forEach(body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Entity) throws -> Result) rethrows -> Result {
|
public func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Entity) throws -> Result) rethrows -> Result {
|
||||||
return try members.reduce(initialResult, nextPartialResult)
|
return try members.lazy.reduce(initialResult, nextPartialResult)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func zip(_ componentTypes: Component.Type) {
|
// MARK: - component accessors
|
||||||
|
extension Family {
|
||||||
let a = members.map { $0.componentMap.values }
|
public func component<A: Component>(_ apply: (A) -> Void) {
|
||||||
|
members.lazy.forEach { $0.component(apply) }
|
||||||
|
}
|
||||||
|
public func components<A: Component, B: Component>(_ apply: (A, B) -> Void) {
|
||||||
|
members.lazy.forEach { $0.components(apply) }
|
||||||
|
}
|
||||||
|
public func components<A: Component, B: Component, C: Component>(_ apply: (A, B, C) -> Void) {
|
||||||
|
members.lazy.forEach { $0.components(apply) }
|
||||||
|
}
|
||||||
|
public func components<A: Component, B: Component, C: Component, D: Component>(_ apply: (A, B, C, D) -> Void) {
|
||||||
|
members.lazy.forEach { $0.components(apply) }
|
||||||
|
}
|
||||||
|
public func components<A: Component, B: Component, C: Component, D: Component, E: Component>(_ apply: (A, B, C, D, E) -> Void) {
|
||||||
|
members.lazy.forEach { $0.components(apply) }
|
||||||
|
}
|
||||||
|
public func components<A: Component, B: Component, C: Component, D: Component, E: Component, F: Component>(_ apply: (A, B, C, D, E, F) -> Void) {
|
||||||
|
members.lazy.forEach { $0.components(apply) }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,12 @@ class FamilyTests: XCTestCase {
|
||||||
|
|
||||||
let e3 = entityHub.createEntity()
|
let e3 = entityHub.createEntity()
|
||||||
e3 += EmptyComponent()
|
e3 += EmptyComponent()
|
||||||
|
e3 += Name(name: "Michael")
|
||||||
|
|
||||||
e2.remove(EmptyComponent.self)
|
e2.remove(EmptyComponent.self)
|
||||||
|
|
||||||
|
family.components { (name: Name, empty: EmptyComponent) in
|
||||||
|
print(name, empty)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue