1import Foundation
2
3/// Version of the rules used to encode and merge a collaborative game's
4/// durable state. Owners may advance an existing game to a newer version;
5/// app releases may support more than one version during that transition.
6enum GameSyncVersion {
7 /// Games created before the field existed are version 1.
8 static let legacy: Int64 = 1
9
10 /// Per-cell logical ticks, with timestamp-only cells accepted as legacy
11 /// input from older clients.
12 static let logicalTicks: Int64 = 2
13
14 /// Version assigned to newly-created games by this app release. Owned
15 /// legacy games advance to this version when their owner opens them.
16 static let current: Int64 = logicalTicks
17
18 /// Exact protocol versions this app can safely read and edit.
19 static let supported: Set<Int64> = [legacy, logicalTicks]
20
21 /// Core Data test fixtures and pre-migration rows can surface zero before
22 /// the default is materialised. Treat every non-positive value as legacy,
23 /// matching an absent `syncVersion` field on CloudKit records.
24 static func normalized(_ version: Int64) -> Int64 {
25 version > 0 ? version : legacy
26 }
27
28 static func supports(_ version: Int64) -> Bool {
29 supported.contains(normalized(version))
30 }
31}