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.
This commit is contained in:
Paweł Orzech 2026-01-17 18:05:37 +00:00
parent 455f9f3916
commit 802fdfa1a3
No known key found for this signature in database
3 changed files with 29 additions and 126 deletions

View file

@ -2,23 +2,44 @@ import Foundation
// MARK: - Root Response // MARK: - Root Response
struct TornResponse: Codable { struct TornResponse: Codable {
let bars: Bars? let energy: Bar?
let nerve: Bar?
let life: Bar?
let happy: Bar?
let cooldowns: Cooldowns? let cooldowns: Cooldowns?
let travel: Travel? let travel: Travel?
let error: TornError? 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 { struct Bar: Codable, Equatable {
let current: Int let current: Int
let maximum: Int let maximum: Int
let increment: Double let increment: Double?
let interval: Int let interval: Int?
let ticktime: Int let ticktime: Int?
let fulltime: 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 energy: Bar
let nerve: Bar let nerve: Bar
let life: Bar let life: Bar

View file

@ -3,7 +3,6 @@ import SwiftUI
struct SettingsView: View { struct SettingsView: View {
@EnvironmentObject var appState: AppState @EnvironmentObject var appState: AppState
@State private var inputKey: String = "" @State private var inputKey: String = ""
@State private var showShortcutsEditor = false
var body: some View { var body: some View {
VStack(spacing: 16) { VStack(spacing: 16) {
@ -53,20 +52,6 @@ struct SettingsView: View {
} }
.toggleStyle(.switch) .toggleStyle(.switch)
.padding(.horizontal) .padding(.horizontal)
// Shortcuts Editor
Button {
showShortcutsEditor.toggle()
} label: {
Label("Edit Shortcuts", systemImage: "keyboard")
}
.buttonStyle(.plain)
.foregroundColor(.accentColor)
if showShortcutsEditor {
ShortcutsEditorView()
.environmentObject(appState)
}
} }
.padding() .padding()
.onAppear { .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)
}
}
}
}
}

View file

@ -34,7 +34,7 @@ struct StatusView: View {
} }
.padding() .padding()
} }
.frame(maxHeight: 400) .fixedSize(horizontal: false, vertical: true)
} }
// MARK: - Header // MARK: - Header