Fix ComponentAdded event emission for multi-component assigns (gh issue #36)

This commit is contained in:
Christian Treffs 2020-11-25 11:08:08 +01:00
parent f8915f1080
commit e3d416a3e2
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
2 changed files with 4 additions and 2 deletions

View File

@ -24,7 +24,6 @@ extension Nexus {
@discardableResult @discardableResult
public final func assign(component: Component, to entity: Entity) -> Bool { public final func assign(component: Component, to entity: Entity) -> Bool {
let entityId: EntityIdentifier = entity.identifier let entityId: EntityIdentifier = entity.identifier
defer { delegate?.nexusEvent(ComponentAdded(component: component.identifier, toEntity: entity.identifier)) }
return assign(component: component, entityId: entityId) return assign(component: component, entityId: entityId)
} }

View File

@ -63,7 +63,10 @@ extension Nexus {
@usableFromInline @usableFromInline
func assign(_ componentId: ComponentIdentifier, _ entityId: EntityIdentifier) { func assign(_ componentId: ComponentIdentifier, _ entityId: EntityIdentifier) {
componentIdsByEntity[entityId]!.insert(componentId) let (inserted, _) = componentIdsByEntity[entityId]!.insert(componentId)
if inserted {
delegate?.nexusEvent(ComponentAdded(component: componentId, toEntity: entityId))
}
} }
@usableFromInline @usableFromInline