Skip to content

Commit 858c9d9

Browse files
Migrate to CartographyMapPin
The future of the format will store pins in a separate location instead of as part of the manifest. This mega-commit updates the app to point to both the new type and location, respectively. Incidentally, this fixes #45 because the pin route under Red Window now has a stable identity that doesn't get edited magically.
1 parent bcaba84 commit 858c9d9

File tree

42 files changed

+191
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+191
-164
lines changed

Alidade.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MCMaps/Legacy/View Models/CartographyPinViewModel.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CartographyPinViewModel {
3636
/// The pin that will be edited through this view model.
3737
///
3838
/// Changes to this property will automatically propagate to the file.
39-
var pin: Binding<MCMapManifestPin>
39+
var pin: Binding<CartographyMapPin>
4040

4141
/// A binding to the pin's about description.
4242
///
@@ -81,35 +81,31 @@ class CartographyPinViewModel {
8181
self.file = file
8282
self.index = index
8383
self.pin = Binding {
84-
return file.wrappedValue.manifest.pins[index]
84+
return file.wrappedValue.pins[index]
8585
} set: { newPin in
86-
file.wrappedValue.manifest.pins[index] = newPin
86+
file.wrappedValue.pins[index] = newPin
8787
}
8888

89-
self.pinAboutDescription = Binding {
90-
return file.wrappedValue.manifest.pins[index].aboutDescription ?? ""
91-
} set: { newValue in
92-
file.wrappedValue.manifest.pins[index].aboutDescription = newValue
93-
}
89+
self.pinAboutDescription = file.pins[index].description
9490

9591
self.pinTags = Binding {
9692
guard file.wrappedValue.supportedFeatures.contains(.pinTagging) else {
9793
return []
9894
}
99-
return file.wrappedValue.manifest.pins[index].tags ?? []
95+
return file.wrappedValue.pins[index].tags ?? []
10096
} set: { newValue in
10197
guard file.wrappedValue.supportedFeatures.contains(.pinTagging) else {
10298
return
10399
}
104-
file.wrappedValue.manifest.pins[index].tags = newValue
100+
file.wrappedValue.pins[index].tags = newValue
105101
}
106102
}
107103

108104
/// Retrieves data blobs for the images associated with this pin.
109105
///
110106
/// Images consist of player-uploaded screenshots that can be displayed alongside pins.
111107
func images() -> [Data] {
112-
let pin = file.wrappedValue.manifest.pins[index]
108+
let pin = file.wrappedValue.pins[index]
113109
guard let images = pin.images else { return [] }
114110
return images.compactMap { name in
115111
file.wrappedValue.images[name]
@@ -126,10 +122,10 @@ class CartographyPinViewModel {
126122
func uploadImage(_ data: Data, completion: (() -> Void)? = nil) {
127123
let imageName = UUID().uuidString + ".heic"
128124
file.wrappedValue.images[imageName] = data
129-
if file.wrappedValue.manifest.pins[index].images == nil {
130-
file.wrappedValue.manifest.pins[index].images = [imageName]
125+
if file.wrappedValue.pins[index].images == nil {
126+
file.wrappedValue.pins[index].images = [imageName]
131127
} else {
132-
file.wrappedValue.manifest.pins[index].images?.append(imageName)
128+
file.wrappedValue.pins[index].images?.insert(imageName)
133129
}
134130
completion?()
135131
}

MCMaps/Legacy/View Models/CartographyRoute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum CartographyRoute: Equatable, Hashable, Identifiable {
1818
var id: UUID { UUID() }
1919

2020
/// A player-pinned location at a specified index in the file.
21-
case pin(Int, pin: MCMapManifestPin)
21+
case pin(Int, pin: CartographyMapPin)
2222

2323
/// A location the player has visited before.
2424
case recent(CGPoint)

MCMaps/Legacy/Views/CartographyOrnamentMap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct CartographyOrnamentMap: View {
8787
centerCoordinate: $centerCoordinate,
8888
dimension: viewModel.worldDimension
8989
) {
90-
file.manifest.pins.map { pin in
90+
file.pins.map { pin in
9191
Marker(
9292
location: pin.position,
9393
title: pin.name,

MCMaps/Legacy/Views/LegacyContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct LegacyContentView: View {
5858
case .createPin(let cgPoint):
5959
NavigationStack {
6060
PinCreatorForm(location: cgPoint) { pin in
61-
file.manifest.pins.append(pin)
61+
file.pins.append(pin)
6262
}
6363
.formStyle(.grouped)
6464
}

MCMaps/Legacy/Views/Navigation/CartographyMapSplitView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct CartographyMapSplitView: View {
3838
switch viewModel.currentRoute {
3939
case let .pin(index, _):
4040
Group {
41-
if (file.manifest.pins.indices).contains(index) {
41+
if (file.pins.indices).contains(index) {
4242
CartographyMapPinDetailView(
4343
viewModel: CartographyPinViewModel(
4444
file: $file, index: index))

MCMaps/Legacy/Views/Pins/CartographyMapPinColorPicker.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@ import SwiftUI
1818
/// back-propagate the color value to the pin.
1919
struct CartographyMapPinColorPicker: View {
2020
/// The color the picker will select.
21-
@Binding var color: MCMapManifestPin.Color?
21+
@Binding var color: CartographyMapPin.Color?
2222
@State private var swiftUIColor = Color.blue
2323

2424
var availableColors: [Color] {
25-
MCMapManifestPin.Color.allCases.map(\.swiftUIColor)
25+
CartographyMapPin.Color.allCases.map(\.swiftUIColor)
2626
}
2727

2828
var body: some View {
2929
FiniteColorPicker("", selection: $swiftUIColor, in: availableColors)
3030
.onChange(of: swiftUIColor) { _, newValue in
31-
for suiColor in MCMapManifest.Pin.Color.allCases where suiColor.swiftUIColor == newValue {
31+
for suiColor in CartographyMapPin.Color.allCases where suiColor.swiftUIColor == newValue {
3232
color = suiColor
3333
return
3434
}
3535
}
3636
}
3737
}
38+
39+
extension CartographyMapPin.Color: @retroactive CaseIterable {
40+
public static var allCases: [CartographyMapPin.Color] {
41+
[.red, .orange, .yellow, .green, .blue, .indigo, .gray, .pink, .brown]
42+
}
43+
}

MCMaps/Legacy/Views/Pins/CartographyNamedLocationView.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ import SwiftUI
1212
extension NamedLocationView {
1313
/// Create a named location view using a player-created pin.
1414
/// - Parameter pin: The pin to create a named location view from.
15-
init(pin: MCMapManifestPin) {
15+
init(pin: CartographyMapPin) {
16+
let systemImage =
17+
switch pin.icon {
18+
case .default, nil, .emoji:
19+
"mappin"
20+
default:
21+
pin.icon?.rawValue
22+
}
23+
1624
self.init(
1725
name: pin.name,
1826
location: pin.position,
19-
systemImage: "mappin",
27+
systemImage: systemImage ?? "mappin",
2028
color: pin.color?.swiftUIColor ?? .accent
2129
)
2230
}
31+
2332
}
2433

2534
/// A view that displays a location with a specified name.

MCMaps/Legacy/Views/Sidebar/CartographyMapSidebar.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct CartographyMapSidebar: View {
6565
}
6666
.frame(minWidth: 175, idealWidth: 200)
6767
.onAppear {
68-
if file.manifest.pins.isEmpty {
68+
if file.pins.isEmpty {
6969
Task {
7070
await PinActionOnboardingTip.libraryEmpty.donate()
7171
}
@@ -82,7 +82,7 @@ struct CartographyMapSidebar: View {
8282
}
8383
}
8484

85-
.onChange(of: file.manifest.pins) { _, newValue in
85+
.onChange(of: file.pins) { _, newValue in
8686
if !newValue.isEmpty {
8787
LocalTips.emptyLibrary.invalidate(reason: .actionPerformed)
8888
}
@@ -148,8 +148,8 @@ struct CartographyMapSidebar: View {
148148
viewModel.go(to: position, relativeTo: file)
149149
}
150150
}
151-
if !file.manifest.pins.isEmpty {
152-
PinnedLibrarySection(pins: file.manifest.pins, viewModel: $viewModel, file: $file)
151+
if !file.pins.isEmpty {
152+
PinnedLibrarySection(pins: file.pins, viewModel: $viewModel, file: $file)
153153
}
154154
}
155155
}

MCMaps/Legacy/Views/Sidebar/CartographyMapSidebarSheet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct CartographyMapSidebarSheet<T: ToolbarContent>: View {
7474
}
7575
case let .createPin(location):
7676
PinCreatorForm(location: location) { newPin in
77-
file.manifest.pins.append(newPin)
77+
file.pins.append(newPin)
7878
}
7979
case .editWorld:
8080
MapCreatorForm(

0 commit comments

Comments
 (0)