crossmate

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

PlayerColor.swift (1888B)


      1 import SwiftUI
      2 
      3 /// A player's chosen highlight colour. Each player picks one of these so that
      4 /// — once collaborative play is wired up — both players' selections can be
      5 /// shown side-by-side without ambiguity.
      6 struct PlayerColor: Sendable, Identifiable, Hashable {
      7     let id: String
      8     let name: String
      9     let tint: Color
     10 
     11     /// Opacity used when this player's cell is the active selection.
     12     var selectedOpacity: Double { 0.55 }
     13 
     14     /// Opacity used for the rest of this player's active word.
     15     var highlightedOpacity: Double { 0.18 }
     16 
     17     /// Fill for UI tied to this player's active selection (the selected cell).
     18     var selectionFill: Color { tint.opacity(selectedOpacity) }
     19 
     20     /// Fill for UI tied to this player's passive highlight — the rest of the
     21     /// active word and the clue bar. Change this to retint both at once.
     22     var highlightFill: Color { tint.opacity(highlightedOpacity) }
     23 }
     24 
     25 extension PlayerColor {
     26     static let red = PlayerColor(id: "red", name: "Red", tint: .red)
     27     static let orange = PlayerColor(id: "orange", name: "Orange", tint: .orange)
     28     static let yellow = PlayerColor(id: "yellow", name: "Yellow", tint: .yellow)
     29     static let green = PlayerColor(id: "green", name: "Green", tint: .green)
     30     static let blue = PlayerColor(id: "blue", name: "Blue", tint: .blue)
     31     static let purple = PlayerColor(id: "purple", name: "Purple", tint: .purple)
     32     static let brown = PlayerColor(
     33         id: "brown",
     34         name: "Brown",
     35         tint: Color(red: 0.76, green: 0.60, blue: 0.42)
     36     )
     37 
     38     /// Order in which colours appear in any picker UI.
     39     static let palette: [PlayerColor] = [.red, .orange, .yellow, .green, .blue, .purple, .brown]
     40 
     41     /// Look up a colour by its stored identifier, falling back to blue.
     42     static func color(for id: String) -> PlayerColor {
     43         palette.first { $0.id == id } ?? .blue
     44     }
     45 }
     46