SPB Git

Repository Public License

Tokens.swift 5.6 KB 135 lines swift

1// ORIX Arcade2// File: DesignSystem/Tokens.swift3// Description: Design tokens — colors, per-game themes, typography, spacing, radii and motion curves.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI8import UIKit910extension Color {11    nonisolated init(hex: UInt32, opacity: Double = 1) {12        self.init(.sRGB,13                  red: Double((hex >> 16) & 0xFF) / 255,14                  green: Double((hex >> 8) & 0xFF) / 255,15                  blue: Double(hex & 0xFF) / 255,16                  opacity: opacity)17    }18}1920extension UIColor {21    nonisolated convenience init(hex: UInt32, alpha: CGFloat = 1) {22        self.init(red: CGFloat((hex >> 16) & 0xFF) / 255,23                  green: CGFloat((hex >> 8) & 0xFF) / 255,24                  blue: CGFloat(hex & 0xFF) / 255,25                  alpha: alpha)26    }27}2829/// Global appearance switches driven by Settings and by the system accessibility options.30enum OrixAppearance {31    static var highContrast = false32    static var reduceMotionOverride = false33    static var reduceMotion: Bool { reduceMotionOverride || UIAccessibility.isReduceMotionEnabled }34}3536enum OrixColor {37    static let void = Color(hex: 0x05060D)38    static let midnight = Color(hex: 0x0A0C1A)39    static let surface = Color(hex: 0x12152A)40    static let surfaceRaised = Color(hex: 0x1B2040)41    static let ink = Color(hex: 0x0A0C1A)42    static let textPrimary = Color(hex: 0xF4F5FF)43    static var textSecondary: Color { OrixAppearance.highContrast ? Color(hex: 0xE3E6FF) : Color(hex: 0xA9AED3) }44    static var textTertiary: Color { OrixAppearance.highContrast ? Color(hex: 0xC5C9EA) : Color(hex: 0x767BA6) }45    static var stroke: Color { Color.white.opacity(OrixAppearance.highContrast ? 0.32 : 0.09) }46    static let iris = Color(hex: 0x8B7BFF)47    static let cyan = Color(hex: 0x4DD8FF)48    static let gold = Color(hex: 0xFFC94D)49    static let success = Color(hex: 0x4DE3A1)50    static let danger = Color(hex: 0xFF5470)5152    enum Hex {53        static let void: UInt32 = 0x05060D54        static let midnight: UInt32 = 0x0A0C1A55        static let surface: UInt32 = 0x12152A56        static let gold: UInt32 = 0xFFC94D57        static let success: UInt32 = 0x4DE3A158        static let danger: UInt32 = 0xFF547059        static let text: UInt32 = 0xF4F5FF60    }61}6263/// A per-game accent palette, usable from SwiftUI (`Color`) and SpriteKit (`UIColor`).64nonisolated struct GameTheme: Sendable, Equatable {65    let primaryHex: UInt3266    let secondaryHex: UInt3267    let deepHex: UInt326869    var primary: Color { Color(hex: primaryHex) }70    var secondary: Color { Color(hex: secondaryHex) }71    var deep: Color { Color(hex: deepHex) }72    var uiPrimary: UIColor { UIColor(hex: primaryHex) }73    var uiSecondary: UIColor { UIColor(hex: secondaryHex) }74    var uiDeep: UIColor { UIColor(hex: deepHex) }75    var gradient: LinearGradient {76        LinearGradient(colors: [primary, secondary], startPoint: .topLeading, endPoint: .bottomTrailing)77    }7879    static let orix = GameTheme(primaryHex: 0x8B7BFF, secondaryHex: 0x4DD8FF, deepHex: 0x141033)80    static let domino = GameTheme(primaryHex: 0xFFB341, secondaryHex: 0xFF5E7E, deepHex: 0x2B1230)81    static let dig = GameTheme(primaryHex: 0x3DE8C5, secondaryHex: 0xB6F24A, deepHex: 0x062A26)82    static let traffic = GameTheme(primaryHex: 0x4DA3FF, secondaryHex: 0xC86BFF, deepHex: 0x0B1640)83}8485enum OrixSpace {86    static let xxs: CGFloat = 487    static let xs: CGFloat = 888    static let sm: CGFloat = 1289    static let md: CGFloat = 1690    static let lg: CGFloat = 2491    static let xl: CGFloat = 3292    static let xxl: CGFloat = 4893    /// Minimum comfortable touch target.94    static let hit: CGFloat = 4895}9697enum OrixRadius {98    static let sm: CGFloat = 1099    static let md: CGFloat = 16100    static let lg: CGFloat = 24101    static let xl: CGFloat = 32102}103104/// Menu typography scales with Dynamic Type; HUD typography is fixed so gameplay layouts stay stable.105enum OrixFont {106    static let display = Font.system(.largeTitle, design: .rounded, weight: .black)107    static let title = Font.system(.title2, design: .rounded, weight: .heavy)108    static let headline = Font.system(.headline, design: .rounded, weight: .bold)109    static let body = Font.system(.body, design: .rounded, weight: .medium)110    static let callout = Font.system(.callout, design: .rounded, weight: .medium)111    static let caption = Font.system(.caption, design: .rounded, weight: .semibold)112    static let button = Font.system(.headline, design: .rounded, weight: .heavy)113    static let overline = Font.system(.caption2, design: .rounded, weight: .heavy)114115    static func hud(_ size: CGFloat, weight: Font.Weight = .heavy) -> Font {116        Font.system(size: size, weight: weight, design: .rounded).monospacedDigit()117    }118    /// Rounded system font for SpriteKit labels (`SKLabelNode.orixLabel`); the rounded face has no stable font name.119    static func rounded(_ size: CGFloat, weight: UIFont.Weight = .heavy) -> UIFont {120        let base = UIFont.systemFont(ofSize: size, weight: weight)121        return base.fontDescriptor.withDesign(.rounded).map { UIFont(descriptor: $0, size: size) } ?? base122    }123}124125enum OrixMotion {126    static let press = Animation.spring(response: 0.22, dampingFraction: 0.7)127    static let snappy = Animation.spring(response: 0.34, dampingFraction: 0.8)128    static let bouncy = Animation.spring(response: 0.5, dampingFraction: 0.62)129    static let gentle = Animation.easeInOut(duration: 0.45)130    /// Use for decorative motion; collapses to a quick fade when Reduce Motion is on.131    static func decorative(_ animation: Animation) -> Animation {132        OrixAppearance.reduceMotion ? .easeOut(duration: 0.15) : animation133    }134}135
Files main
Menu

Theme