remora-kit

RemoraKit, shared dive computer engine (Buhlmann ZHL-16C + GF) and SwiftUI components for Open Remora and Open Merou
git clone https://git.schurger.org/remora-kit.git
Log | Files | Refs | README | LICENSE

Labels.swift (2808B)


      1 // SPDX-License-Identifier: GPL-2.0-only
      2 import SwiftUI
      3 import RemoraDeco
      4 
      5 extension DiveComputer.Warning {
      6     public var label: String {
      7         switch self {
      8         case .ascentFast: String(localized: "Fast ascent", bundle: .module)
      9         case .ascentTooFast: String(localized: "Ascent too fast", bundle: .module)
     10         case .ceilingViolated: String(localized: "Ceiling broken", bundle: .module)
     11         case .ppO2High: String(localized: "High ppO2", bundle: .module)
     12         case .ppO2Critical: String(localized: "Critical ppO2", bundle: .module)
     13         case .missedSafetyStop: String(localized: "Safety stop missed", bundle: .module)
     14         case .depthLimit: String(localized: "Depth limit", bundle: .module)
     15         case .lowNoDecompression: String(localized: "Low NDL", bundle: .module)
     16         }
     17     }
     18 
     19     /// Alarms (violations) are red, warnings orange.
     20     public var color: Color { isViolation ? .red : .orange }
     21 }
     22 
     23 extension Water {
     24     public var label: String {
     25         switch self {
     26         case .fresh: String(localized: "Fresh", bundle: .module)
     27         case .en13319: String(localized: "Standard (EN 13319)", bundle: .module)
     28         case .salt: String(localized: "Salt", bundle: .module)
     29         }
     30     }
     31 }
     32 
     33 extension UserSettings.Conservatism {
     34     public var label: String {
     35         switch self {
     36         case .high: String(localized: "High (GF 30/70)", bundle: .module)
     37         case .medium: String(localized: "Medium (GF 40/80)", bundle: .module)
     38         case .low: String(localized: "Low (GF 50/85)", bundle: .module)
     39         case .custom: String(localized: "Custom", bundle: .module)
     40         }
     41     }
     42 }
     43 
     44 /// The values of the settings as text, for any presentation of them (pickers, a read-only summary, a
     45 /// button-driven menu).
     46 public enum SettingsText {
     47     /// ppO2 values offered by the advanced settings.
     48     public static let ppO2Choices = [1.2, 1.3, 1.4, 1.5, 1.6]
     49 
     50     public static func oxygen(_ percent: Int) -> String {
     51         percent == 21 ? String(localized: "\(percent)% (air)", bundle: .module) : Format.percent(percent)
     52     }
     53 
     54     public static func ndlAlarm(_ minutes: Int) -> String {
     55         minutes == 0 ? String(localized: "Off", bundle: .module)
     56                      : String(localized: "Below \(minutes) min", bundle: .module)
     57     }
     58 
     59     public static func conservatism(_ settings: UserSettings) -> String {
     60         settings.conservatism == .custom
     61             ? String(localized: "Custom (\(settings.gradientFactors.description))", bundle: .module)
     62             : settings.conservatism.label
     63     }
     64 
     65     public static func ppO2(_ bar: Double) -> String { "\(Format.decimal(bar, digits: 1)) bar" }
     66 
     67     public static func maximumOperatingDepth(_ settings: UserSettings) -> String {
     68         "\(Format.depth(settings.maximumOperatingDepth())) m"
     69     }
     70 }