From 11f46f354d28031318c38a9d877bce90db30292a Mon Sep 17 00:00:00 2001 From: Christian Treffs Date: Wed, 9 Oct 2024 20:52:56 +0200 Subject: [PATCH] Raise minimum Swift version to 5.8 (#67) * Raise Swift tools version to 5.8 * Update README * Add Swift version file * Format code for 5.8 * Update swiftformat config --- .swift-version | 1 + .swiftformat | 4 +++- Package.swift | 2 +- README.md | 6 +++--- Sources/FirebladeECS/ComponentIdentifier.swift | 4 ++-- Sources/FirebladeECS/Entity.swift | 12 ++++++------ Sources/FirebladeECS/EntityIdentifierGenerator.swift | 2 +- Sources/FirebladeECS/FSM.swift | 6 +++--- Sources/FirebladeECS/Nexus+Component.swift | 4 ++-- Sources/FirebladeECS/Nexus+Entity.swift | 2 +- Sources/FirebladeECS/Nexus+Internal.swift | 4 ++-- Sources/FirebladeECS/Single.swift | 2 +- 12 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..3659ea2 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +5.8 diff --git a/.swiftformat b/.swiftformat index 72f3230..884cbf3 100644 --- a/.swiftformat +++ b/.swiftformat @@ -8,4 +8,6 @@ --stripunusedargs closure-only --commas inline --self remove ---selfrequired get \ No newline at end of file +--selfrequired get +--disable preferKeyPath +--disable opaqueGenericParameters \ No newline at end of file diff --git a/Package.swift b/Package.swift index 36f03a2..b547d04 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.8 import PackageDescription let package = Package( diff --git a/README.md b/README.md index 081d175..d554942 100644 --- a/README.md +++ b/README.md @@ -25,19 +25,19 @@ These instructions will get you a copy of the project up and running on your loc ### 💻 Installing -Fireblade ECS is available for all platforms that support [Swift 5.1](https://swift.org/) and higher and the [Swift Package Manager (SPM)](https://github.com/apple/swift-package-manager). +Fireblade ECS is available for all platforms that support [Swift 5.8](https://swift.org/) and higher and the [Swift Package Manager (SPM)](https://github.com/apple/swift-package-manager). Extend the following lines in your `Package.swift` file or use it to create a new project. ```swift -// swift-tools-version:5.1 +// swift-tools-version:5.8 import PackageDescription let package = Package( name: "YourPackageName", dependencies: [ - .package(url: "https://github.com/fireblade-engine/ecs.git", from: "0.17.4") + .package(url: "https://github.com/fireblade-engine/ecs.git", from: "0.17.5") ], targets: [ .target( diff --git a/Sources/FirebladeECS/ComponentIdentifier.swift b/Sources/FirebladeECS/ComponentIdentifier.swift index 9a7a5d2..79e6247 100644 --- a/Sources/FirebladeECS/ComponentIdentifier.swift +++ b/Sources/FirebladeECS/ComponentIdentifier.swift @@ -13,12 +13,12 @@ public struct ComponentIdentifier { extension ComponentIdentifier { @usableFromInline - init(_ componentType: C.Type) where C: Component { + init(_ componentType: (some Component).Type) { id = Self.makeRuntimeHash(componentType) } /// object identifier hash (only stable during runtime) - arbitrary hash is ok. - static func makeRuntimeHash(_ componentType: C.Type) -> Identifier where C: Component { + static func makeRuntimeHash(_ componentType: (some Component).Type) -> Identifier { ObjectIdentifier(componentType).hashValue } } diff --git a/Sources/FirebladeECS/Entity.swift b/Sources/FirebladeECS/Entity.swift index 5601834..6ab62cf 100644 --- a/Sources/FirebladeECS/Entity.swift +++ b/Sources/FirebladeECS/Entity.swift @@ -38,13 +38,13 @@ public struct Entity { } @discardableResult - public func createEntity(with components: C) -> Entity where C: Collection, C.Element == Component { + public func createEntity(with components: some Collection) -> Entity { nexus.createEntity(with: components) } /// Checks if a component with given type is assigned to this entity. /// - Parameter type: the component type. - public func has(_ type: C.Type) -> Bool where C: Component { + public func has(_ type: (some Component).Type) -> Bool { has(type.identifier) } @@ -78,13 +78,13 @@ public struct Entity { /// Add a typed component to this entity. /// - Parameter component: the typed component. @discardableResult - public func assign(_ component: C) -> Entity where C: Component { + public func assign(_ component: some Component) -> Entity { assign(component) return self } @discardableResult - public func assign(_ components: C) -> Entity where C: Collection, C.Element == Component { + public func assign(_ components: some Collection) -> Entity { nexus.assign(components: components, to: self) return self } @@ -92,14 +92,14 @@ public struct Entity { /// Remove a component from this entity. /// - Parameter component: the component. @discardableResult - public func remove(_ component: C) -> Entity where C: Component { + public func remove(_ component: some Component) -> Entity { remove(component.identifier) } /// Remove a component by type from this entity. /// - Parameter compType: the component type. @discardableResult - public func remove(_ compType: C.Type) -> Entity where C: Component { + public func remove(_ compType: (some Component).Type) -> Entity { remove(compType.identifier) } diff --git a/Sources/FirebladeECS/EntityIdentifierGenerator.swift b/Sources/FirebladeECS/EntityIdentifierGenerator.swift index 39a12f3..1d6434b 100644 --- a/Sources/FirebladeECS/EntityIdentifierGenerator.swift +++ b/Sources/FirebladeECS/EntityIdentifierGenerator.swift @@ -49,7 +49,7 @@ public struct LinearIncrementingEntityIdGenerator: EntityIdentifierGenerator { @usableFromInline init(startProviding initialEntityIds: EntityIds) where EntityIds: BidirectionalCollection, EntityIds.Element == EntityIdentifier { - let initialInUse: [EntityIdentifier.Identifier] = initialEntityIds.map { $0.id } + let initialInUse: [EntityIdentifier.Identifier] = initialEntityIds.map(\.id) let maxInUseValue = initialInUse.max() ?? 0 let inUseSet = Set(initialInUse) // a set of all eIds in use let allSet = Set(0 ... maxInUseValue) // all eIds from 0 to including maxInUseValue diff --git a/Sources/FirebladeECS/FSM.swift b/Sources/FirebladeECS/FSM.swift index c33790b..4324ada 100644 --- a/Sources/FirebladeECS/FSM.swift +++ b/Sources/FirebladeECS/FSM.swift @@ -251,7 +251,7 @@ extension EntityState { /// - Returns: This EntityState, so more modifications can be applied. @inline(__always) @discardableResult - public func addProvider(type: C.Type, provider: ComponentProvider) -> Self { + public func addProvider(type: (some ComponentInitializable).Type, provider: ComponentProvider) -> Self { addMapping(for: type).withProvider(provider) return self } @@ -316,7 +316,7 @@ public class StateComponentMapping { /// - Parameter closure: The Closure instance to return the component instance /// - Returns: This ComponentMapping, so more modifications can be applied @discardableResult - public func withMethod(_ closure: DynamicComponentProvider.Closure) -> Self { + public func withMethod(_ closure: DynamicComponentProvider.Closure) -> Self { setProvider(DynamicComponentProvider(closure: closure)) return self } @@ -401,7 +401,7 @@ public class EntityStateMachine { var toAdd: [ComponentIdentifier: ComponentProvider] - if let currentState = currentState { + if let currentState { toAdd = .init() for (identifier, provider) in newState.providers { toAdd[identifier] = provider diff --git a/Sources/FirebladeECS/Nexus+Component.swift b/Sources/FirebladeECS/Nexus+Component.swift index a707f78..271f6f0 100644 --- a/Sources/FirebladeECS/Nexus+Component.swift +++ b/Sources/FirebladeECS/Nexus+Component.swift @@ -28,12 +28,12 @@ extension Nexus { } @discardableResult - public final func assign(component: C, to entity: Entity) -> Bool where C: Component { + public final func assign(component: some Component, to entity: Entity) -> Bool { assign(component: component, to: entity) } @discardableResult - public final func assign(components: C, to entity: Entity) -> Bool where C: Collection, C.Element == Component { + public final func assign(components: some Collection, to entity: Entity) -> Bool { assign(components: components, to: entity.identifier) } diff --git a/Sources/FirebladeECS/Nexus+Entity.swift b/Sources/FirebladeECS/Nexus+Entity.swift index 777b3c9..cc0fe7f 100644 --- a/Sources/FirebladeECS/Nexus+Entity.swift +++ b/Sources/FirebladeECS/Nexus+Entity.swift @@ -22,7 +22,7 @@ extension Nexus { } @discardableResult - public func createEntity(with components: C) -> Entity where C: Collection, C.Element == Component { + public func createEntity(with components: some Collection) -> Entity { let entity = createEntity() assign(components: components, to: entity.identifier) return entity diff --git a/Sources/FirebladeECS/Nexus+Internal.swift b/Sources/FirebladeECS/Nexus+Internal.swift index adf0c63..b387303 100644 --- a/Sources/FirebladeECS/Nexus+Internal.swift +++ b/Sources/FirebladeECS/Nexus+Internal.swift @@ -8,7 +8,7 @@ extension Nexus { @usableFromInline @discardableResult - func assign(components: C, to entityId: EntityIdentifier) -> Bool where C: Collection, C.Element == Component { + func assign(components: some Collection, to entityId: EntityIdentifier) -> Bool { var iter = components.makeIterator() while let component = iter.next() { let componentId = component.identifier @@ -103,7 +103,7 @@ extension Nexus { return } - let isMember: Bool = self.isMember(entity: entityId, inFamilyWithTraits: traits) + let isMember: Bool = isMember(entity: entityId, inFamilyWithTraits: traits) if !exists(entity: entityId), isMember { remove(entityWithId: entityId, fromFamilyWithTraits: traits) return diff --git a/Sources/FirebladeECS/Single.swift b/Sources/FirebladeECS/Single.swift index c14b114..2d64936 100644 --- a/Sources/FirebladeECS/Single.swift +++ b/Sources/FirebladeECS/Single.swift @@ -38,7 +38,7 @@ extension Single where A: SingleComponent { extension Nexus { public func single(_ component: S.Type) -> Single where S: SingleComponent { - let family = self.family(requires: S.self) + let family = 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 {