From 802fdfa1a3772de1b479bf9d0cffe9a5cc3bbca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Orzech?= Date: Sat, 17 Jan 2026 18:05:37 +0000 Subject: [PATCH] Refactor TornResponse model and remove shortcuts editor Updated TornResponse to use separate bar properties for energy, nerve, life, and happy, with a computed Bars property for internal use. Made Bar properties optional where appropriate and removed Codable conformance from Bars. Removed the Shortcuts Editor and related views from SettingsView. Adjusted StatusView to use fixedSize for better layout handling. --- MacTorn/MacTorn/Models/TornModels.swift | 35 +++++-- MacTorn/MacTorn/Views/SettingsView.swift | 118 ----------------------- MacTorn/MacTorn/Views/StatusView.swift | 2 +- 3 files changed, 29 insertions(+), 126 deletions(-) diff --git a/MacTorn/MacTorn/Models/TornModels.swift b/MacTorn/MacTorn/Models/TornModels.swift index 6a2e6dc..0cebaba 100644 --- a/MacTorn/MacTorn/Models/TornModels.swift +++ b/MacTorn/MacTorn/Models/TornModels.swift @@ -2,23 +2,44 @@ import Foundation // MARK: - Root Response struct TornResponse: Codable { - let bars: Bars? + let energy: Bar? + let nerve: Bar? + let life: Bar? + let happy: Bar? let cooldowns: Cooldowns? let travel: Travel? let error: TornError? + + // Convenience computed property + var bars: Bars? { + guard let energy = energy, + let nerve = nerve, + let life = life, + let happy = happy else { return nil } + return Bars(energy: energy, nerve: nerve, life: life, happy: happy) + } } -// MARK: - Bars +// MARK: - Bars (for internal use) struct Bar: Codable, Equatable { let current: Int let maximum: Int - let increment: Double - let interval: Int - let ticktime: Int - let fulltime: Int + let increment: Double? + let interval: Int? + let ticktime: Int? + let fulltime: Int? + + init(current: Int, maximum: Int, increment: Double? = nil, interval: Int? = nil, ticktime: Int? = nil, fulltime: Int? = nil) { + self.current = current + self.maximum = maximum + self.increment = increment + self.interval = interval + self.ticktime = ticktime + self.fulltime = fulltime + } } -struct Bars: Codable, Equatable { +struct Bars: Equatable { let energy: Bar let nerve: Bar let life: Bar diff --git a/MacTorn/MacTorn/Views/SettingsView.swift b/MacTorn/MacTorn/Views/SettingsView.swift index 3f987f8..b5a3ef7 100644 --- a/MacTorn/MacTorn/Views/SettingsView.swift +++ b/MacTorn/MacTorn/Views/SettingsView.swift @@ -3,7 +3,6 @@ import SwiftUI struct SettingsView: View { @EnvironmentObject var appState: AppState @State private var inputKey: String = "" - @State private var showShortcutsEditor = false var body: some View { VStack(spacing: 16) { @@ -53,20 +52,6 @@ struct SettingsView: View { } .toggleStyle(.switch) .padding(.horizontal) - - // Shortcuts Editor - Button { - showShortcutsEditor.toggle() - } label: { - Label("Edit Shortcuts", systemImage: "keyboard") - } - .buttonStyle(.plain) - .foregroundColor(.accentColor) - - if showShortcutsEditor { - ShortcutsEditorView() - .environmentObject(appState) - } } .padding() .onAppear { @@ -74,106 +59,3 @@ struct SettingsView: View { } } } - -// MARK: - Shortcuts Editor -struct ShortcutsEditorView: View { - @EnvironmentObject var appState: AppState - @State private var editingShortcut: KeyboardShortcut? - - var body: some View { - VStack(alignment: .leading, spacing: 8) { - HStack { - Text("Quick Links") - .font(.caption.bold()) - - Spacer() - - Button("Reset") { - appState.shortcutsManager.resetToDefaults() - } - .font(.caption2) - .buttonStyle(.plain) - .foregroundColor(.red) - } - - ForEach(appState.shortcutsManager.shortcuts) { shortcut in - ShortcutRowView(shortcut: shortcut) { updated in - appState.shortcutsManager.updateShortcut(updated) - } - } - } - .padding() - .background(Color.gray.opacity(0.1)) - .cornerRadius(8) - } -} - -struct ShortcutRowView: View { - let shortcut: KeyboardShortcut - let onUpdate: (KeyboardShortcut) -> Void - - @State private var isEditing = false - @State private var editedName: String = "" - @State private var editedURL: String = "" - @State private var editedKey: String = "" - - var body: some View { - VStack(spacing: 4) { - HStack { - if isEditing { - TextField("Name", text: $editedName) - .textFieldStyle(.roundedBorder) - .font(.caption) - .frame(width: 60) - - TextField("URL", text: $editedURL) - .textFieldStyle(.roundedBorder) - .font(.caption2) - - TextField("Key", text: $editedKey) - .textFieldStyle(.roundedBorder) - .font(.caption) - .frame(width: 30) - - Button("Save") { - var updated = shortcut - updated.name = editedName - updated.url = editedURL - updated.keyEquivalent = editedKey - onUpdate(updated) - isEditing = false - } - .font(.caption2) - .buttonStyle(.borderedProminent) - } else { - Text(shortcut.name) - .font(.caption) - .frame(width: 60, alignment: .leading) - - Text(shortcut.url) - .font(.caption2) - .foregroundColor(.secondary) - .lineLimit(1) - .truncationMode(.middle) - - Spacer() - - Text("⌘⇧\(shortcut.keyEquivalent.uppercased())") - .font(.caption2.monospaced()) - .foregroundColor(.secondary) - - Button { - editedName = shortcut.name - editedURL = shortcut.url - editedKey = shortcut.keyEquivalent - isEditing = true - } label: { - Image(systemName: "pencil") - .font(.caption2) - } - .buttonStyle(.plain) - } - } - } - } -} diff --git a/MacTorn/MacTorn/Views/StatusView.swift b/MacTorn/MacTorn/Views/StatusView.swift index 12a348f..bc96e6b 100644 --- a/MacTorn/MacTorn/Views/StatusView.swift +++ b/MacTorn/MacTorn/Views/StatusView.swift @@ -34,7 +34,7 @@ struct StatusView: View { } .padding() } - .frame(maxHeight: 400) + .fixedSize(horizontal: false, vertical: true) } // MARK: - Header