Fix bulk entity creation with component builder

This commit is contained in:
Christian Treffs 2020-11-25 11:16:53 +01:00
parent 1737af9a71
commit c0dae11e23
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
2 changed files with 3 additions and 3 deletions

View File

@ -85,7 +85,7 @@ extension Nexus {
/// - builder: The component builder providing context.
/// - Returns: The newly created entities with the provided components assigned.
@discardableResult
public func createEntities(count: Int, @ComponentsBuilder using builder: (ComponentsBuilder.Context) -> [Component]) -> [Entity] {
public func createEntities(count: Int, @ComponentsBuilder using builder: (ComponentsBuilder.Context) -> [Component] = { _ in [] }) -> [Entity] {
(0..<count).map { self.createEntity(with: builder(ComponentsBuilder.Context(index: $0))) }
}
}

View File

@ -34,7 +34,7 @@ final class NexusEventDelegateTests: XCTestCase {
XCTAssertEqual(entityCreatedEvents.count, 0)
nexus.createEntity()
XCTAssertEqual(entityCreatedEvents.count, 1)
nexus.createEntities(count: 100, using: { _ in })
nexus.createEntities(count: 100)
XCTAssertEqual(entityCreatedEvents.count, 101)
}
@ -54,7 +54,7 @@ final class NexusEventDelegateTests: XCTestCase {
nexus.delegate = delegateTester
XCTAssertEqual(events.count, 0)
nexus.createEntities(count: 100, using: { _ in })
nexus.createEntities(count: 100)
XCTAssertEqual(events.count, 0)
for entitiy in nexus.makeEntitiesIterator() {
entitiy.destroy()