Skip to content

Commit 1071283

Browse files
Replace version text field with picker
This helps ensure that players don't accidentally type bad versions and wonder why the version isn't supported or is considered invalid.
1 parent 53e1415 commit 1071283

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

CubiomesKit/Sources/CubiomesKit/MinecraftVersion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public extension MinecraftVersion {
3333

3434
extension MinecraftVersion: @retroactive CaseIterable {
3535
public static var allCases: [MinecraftVersion] {
36-
return (MC_UNDEF.rawValue...MC_NEWEST.rawValue).map {
36+
return (MC_B1_7.rawValue...MC_NEWEST.rawValue).map {
3737
MCVersion($0)
3838
}
3939
}

MCMaps/Resources/Localizable.xcstrings

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,6 @@
214214
},
215215
"No view was defined for route %@" : {
216216

217-
},
218-
"Not a valid Minecraft version." : {
219-
220217
},
221218
"Ocean Ruin" : {
222219

@@ -338,6 +335,9 @@
338335
},
339336
"Welcome to %@" : {
340337

338+
},
339+
"World Generation" : {
340+
341341
},
342342
"Write a description..." : {
343343

MCMaps/Views/Forms/MapCreatorForm.swift

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by Marquis Kurt on 01-02-2025.
66
//
77

8-
import CubiomesInternal
98
import CubiomesKit
109
import SwiftUI
1110

@@ -25,10 +24,10 @@ struct MapCreatorForm: View {
2524
/// A binding to the seed used for world generation.
2625
@Binding var seed: Int64
2726

28-
@State private var versionString = ""
2927
@State private var seedString = ""
3028
@State private var invalidVersion = false
3129
@State private var autoconvert = false
30+
@State private var version = MC_1_21_WD
3231

3332
#if DEBUG
3433
internal var didAppear: ((Self) -> Void)?
@@ -38,45 +37,37 @@ struct MapCreatorForm: View {
3837
Form {
3938
TextField("Name", text: $worldName)
4039
Section {
41-
TextField("Minecraft Version", text: $versionString)
42-
} header: {
43-
Text("Minecraft Version")
44-
} footer: {
45-
if invalidVersion {
46-
Label("Not a valid Minecraft version.", systemImage: "xmark.circle.fill")
47-
.foregroundStyle(Color.red)
48-
}
49-
}
50-
.onSubmit {
51-
let mcVersion = str2mc(versionString)
52-
invalidVersion = mcVersion == MC_UNDEF.rawValue
53-
if !invalidVersion {
54-
self.mcVersion = versionString
40+
Picker("Minecraft Version", selection: $version) {
41+
ForEach(MinecraftVersion.allCases, id: \.rawValue) { ver in
42+
Text(String(ver) ?? "?").tag(ver)
43+
}
5544
}
56-
}
57-
58-
Section {
5945
TextField("Seed", text: $seedString)
46+
.onSubmit {
47+
if let realNumber = Int64(seedString) {
48+
seed = realNumber
49+
autoconvert = false
50+
} else {
51+
seed = Int64(seedString.hashValue)
52+
autoconvert = true
53+
}
54+
}
6055
} header: {
61-
Text("Seed")
56+
Text("World Generation")
6257
} footer: {
6358
if autoconvert {
6459
let hashedString = String(seedString.hashValue)
6560
Text("This seed will be converted to: `\(hashedString)`")
6661
}
6762
}
68-
.onSubmit {
69-
if let realNumber = Int64(seedString) {
70-
seed = realNumber
71-
autoconvert = false
72-
} else {
73-
seed = Int64(seedString.hashValue)
74-
autoconvert = true
63+
.onChange(of: version) { _, newValue in
64+
if let verString = String(newValue) {
65+
self.mcVersion = verString
7566
}
7667
}
7768
}
7869
.onAppear {
79-
versionString = mcVersion
70+
version = MinecraftVersion(mcVersion)
8071
seedString = String(seed)
8172
#if DEBUG
8273
self.didAppear?(self)
@@ -106,7 +97,6 @@ struct MapCreatorForm: View {
10697
self.target = target
10798
}
10899

109-
var versionString: String { target.versionString }
110100
var seedString: String { target.seedString }
111101
var invalidVersion: Bool { target.invalidVersion }
112102
var autoconvert: Bool { target.autoconvert }

MCMapsTests/Views/MapCreatorFormTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ struct MapCreatorFormTests {
2323
let minecraftVersion: Binding<String> = .init(wrappedValue: "1.21")
2424
let minecraftSeed: Binding<Int64> = .init(wrappedValue: 123)
2525
let view = MapCreatorForm(worldName: worldName, mcVersion: minecraftVersion, seed: minecraftSeed) { newView in
26-
#expect(newView.testHooks.versionString == "1.21")
2726
#expect(newView.testHooks.seedString == "123")
2827
}
2928
defer { ViewHosting.expel() }

0 commit comments

Comments
 (0)