crossmate

A collaborative crossword app for iOS
Log | Files | Refs | LICENSE

PlayerSelection.swift (896B)


      1 import Foundation
      2 
      3 /// A peer player's current cursor: the cell they have focused and the
      4 /// direction (across/down) of the word they're working on. Carried inside
      5 /// `Player` records on CloudKit so the local client can render the peer's
      6 /// selection as an outline on the grid.
      7 struct PlayerSelection: Sendable, Equatable {
      8     let row: Int
      9     let col: Int
     10     let direction: Puzzle.Direction
     11 }
     12 
     13 extension Puzzle.Direction {
     14     /// Wire-format raw value used in the `selDir` field on `Player` records.
     15     /// Stable: do not renumber.
     16     var rawValue: Int {
     17         switch self {
     18         case .across: return 0
     19         case .down: return 1
     20         }
     21     }
     22 
     23     init?(rawValue: Int) {
     24         switch rawValue {
     25         case 0: self = .across
     26         case 1: self = .down
     27         default: return nil
     28         }
     29     }
     30 }
     31 
     32 extension PlayerSelection {
     33     typealias Direction = Puzzle.Direction
     34 }