From d251b3d388171958fd9ec67314a13fc1bdc821fb Mon Sep 17 00:00:00 2001 From: Christian Treffs Date: Wed, 5 Aug 2020 10:29:51 +0200 Subject: [PATCH] Re-order single --- Sources/FirebladeECS/Single.swift | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/FirebladeECS/Single.swift b/Sources/FirebladeECS/Single.swift index d71d931..88aeb55 100644 --- a/Sources/FirebladeECS/Single.swift +++ b/Sources/FirebladeECS/Single.swift @@ -9,20 +9,6 @@ public protocol SingleComponent: Component { init() } -extension Nexus { - public func single(_ component: S.Type) -> Single where S: SingleComponent { - let family = self.family(requires: S.self) - precondition(family.count <= 1, "Singleton count of \(S.self) must be 0 or 1: \(family.count)") - let entityId: EntityIdentifier - if family.isEmpty { - entityId = createEntity(with: S()).identifier - } else { - entityId = family.memberIds.first.unsafelyUnwrapped - } - return Single(nexus: self, traits: family.traits, entityId: entityId) - } -} - public struct Single where A: SingleComponent { public let nexus: Nexus public let traits: FamilyTraitSet @@ -49,3 +35,17 @@ extension Single where A: SingleComponent { nexus.get(entity: entityId).unsafelyUnwrapped } } + +extension Nexus { + public func single(_ component: S.Type) -> Single where S: SingleComponent { + let family = self.family(requires: S.self) + precondition(family.count <= 1, "Singleton count of \(S.self) must be 0 or 1: \(family.count)") + let entityId: EntityIdentifier + if family.isEmpty { + entityId = createEntity(with: S()).identifier + } else { + entityId = family.memberIds.first.unsafelyUnwrapped + } + return Single(nexus: self, traits: family.traits, entityId: entityId) + } +}