-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentView.swift
More file actions
92 lines (80 loc) · 2.97 KB
/
ContentView.swift
File metadata and controls
92 lines (80 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import SwiftUI
import UniformTypeIdentifiers
struct ContentView: View {
@StateObject private var manager = GBAManager()
@State private var isImporting = false
var body: some View {
VStack(spacing: 20) {
Text("GBAed - GBA header Examiner & Debugger")
.font(.title2).bold()
if let info = manager.romInfo {
VStack(spacing: 10) {
InfoRow(label: "Game Title", value: info.title)
InfoRow(label: "Game Code", value: info.gameCode)
InfoRow(label: "Maker", value: info.makerCode)
Divider()
HStack {
Text("Nintendo Logo:")
Spacer()
Text(info.isLogoValid ? "✅ OK" : "❌ BAD")
.foregroundColor(info.isLogoValid ? .green : .red)
.bold()
}
HStack {
Text("Checksum:")
Spacer()
Text("0x\(String(format: "%02X", info.checksum))")
Text(info.isChecksumValid ? "✅ OK" : "❌ BAD")
.foregroundColor(info.isChecksumValid ? .green : .red)
.bold()
}
}
.padding()
.background(RoundedRectangle(cornerRadius: 12).fill(Color.secondary.opacity(0.1)))
}
Text(manager.statusMessage)
.font(.footnote)
.foregroundColor(.secondary)
HStack {
Button("Load") {
isImporting = true
}
.buttonStyle(.bordered)
if let info = manager.romInfo, (!info.isChecksumValid || !info.isLogoValid) {
Button("Fix") {
manager.fixHeaderAndLogo()
}
.buttonStyle(.borderedProminent)
.tint(.orange)
}
}
}
.padding()
.frame(width: 400, height: 350)
.fileImporter(
isPresented: $isImporting,
allowedContentTypes: [UTType.data, UTType(filenameExtension: "gba")!].compactMap { $0 },
allowsMultipleSelection: false
) { result in
switch result {
case .success(let urls):
if let url = urls.first {
manager.loadROM(at: url)
}
case .failure(let error):
manager.statusMessage = "FAILED: \(error.localizedDescription)"
}
}
}
}
struct InfoRow: View {
let label: String
let value: String
var body: some View {
HStack {
Text(label).foregroundColor(.secondary)
Spacer()
Text(value).monospaced()
}
}
}