Skip to content

Commit ba0cec2

Browse files
Stream player data from Bluemap with realtime timer
1 parent 4f2eb7c commit ba0cec2

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

Alidade.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MCMaps/Legacy/Views/CartographyOrnamentMap.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct CartographyOrnamentMap: View {
9292
Marker(
9393
location: pin.position,
9494
title: pin.name,
95+
id: pin.id,
9596
color: pin.color?.swiftUIColor ?? Color.accentColor,
9697
systemImage: pin.icon?.resolveSFSymbol(in: .pin) ?? "mappin"
9798
)
@@ -127,6 +128,9 @@ struct CartographyOrnamentMap: View {
127128
.onReceive(clock.bluemap) { _ in
128129
Task { await updateIntegrationData() }
129130
}
131+
.onReceive(clock.realtime) { _ in
132+
Task { await updateRealtimeIntegrationData() }
133+
}
130134
.onDisappear {
131135
clock.cancelTimers()
132136
}
@@ -189,6 +193,22 @@ struct CartographyOrnamentMap: View {
189193
}
190194
}
191195
}
196+
197+
private func updateRealtimeIntegrationData() async {
198+
let service = CartographyIntegrationService(serviceType: .bluemap, integrationSettings: file.integrations)
199+
do {
200+
let result: BluemapResults? = try await service.sync(
201+
dimension: viewModel.worldDimension,
202+
syncType: .realtime
203+
)
204+
guard let result else { return }
205+
if let currentData = integrationData[.bluemap] as? BluemapResults {
206+
integrationData[.bluemap] = result.merged(with: currentData)
207+
}
208+
} catch {
209+
print(error)
210+
}
211+
}
192212
}
193213

194214
private struct OrnamentButtonModifier: ViewModifier {

MCMaps/Red Window/Views/Detail/RedWindowPinDetailView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ struct RedWindowPinDetailView: View {
202202
Group {
203203
if let world = try? MinecraftWorld(version: "1.21.3", seed: 184_719_632_014) {
204204
MinecraftMap(world: world, centerCoordinate: .constant(pin.position)) {
205-
Marker(location: .zero, title: "#nodraw")
205+
Marker(location: .zero, title: "#nodraw", id: "nodraw")
206206
Marker(
207207
location: pin.position,
208208
title: pin.name,
209+
id: pin.id,
209210
color: pin.color?.swiftUIColor ?? .accent,
210211
systemImage: pin.icon?.resolveSFSymbol(in: .pin) ?? "mappin"
211212
)

MCMaps/Red Window/Views/Map/RedWindowMapView.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct RedWindowMapView: View {
7777
Marker(
7878
location: mapPin.position,
7979
title: mapPin.name,
80+
id: mapPin.id,
8081
color: mapPin.color?.swiftUIColor ?? .accent,
8182
systemImage: mapPin.icon?.resolveSFSymbol(in: .pin) ?? "mappin"
8283
)
@@ -98,6 +99,9 @@ struct RedWindowMapView: View {
9899
.onReceive(clock.bluemap) { _ in
99100
Task { await updateIntegrationData() }
100101
}
102+
.onReceive(clock.realtime) { _ in
103+
Task { await updateRealtimeIntegrationData() }
104+
}
101105
.onChange(of: env.currentDimension, initial: false) { _, _ in
102106
Task { await updateIntegrationData() }
103107
}
@@ -211,4 +215,20 @@ struct RedWindowMapView: View {
211215
}
212216
}
213217
}
218+
219+
private func updateRealtimeIntegrationData() async {
220+
let service = CartographyIntegrationService(serviceType: .bluemap, integrationSettings: file.integrations)
221+
do {
222+
let result: BluemapResults? = try await service.sync(
223+
dimension: redWindowEnvironment.currentDimension,
224+
syncType: .realtime
225+
)
226+
guard let result else { return }
227+
if let currentData = integrationData[.bluemap] as? BluemapResults {
228+
integrationData[.bluemap] = result.merged(with: currentData)
229+
}
230+
} catch {
231+
print(error)
232+
}
233+
}
214234
}

MCMaps/Shared/Models/Bluemap/BluemapResults.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extension BluemapResults: CartographyIntegrationServiceData {
6565
Marker(
6666
location: CGPoint(x: annotation.position.x, y: annotation.position.z),
6767
title: annotation.label,
68+
id: id,
6869
color: .gray,
6970
systemImage: "xmark.circle",
7071
clusterIdentifier: "bmap-death-marker"
@@ -78,6 +79,7 @@ extension BluemapResults: CartographyIntegrationServiceData {
7879
Marker(
7980
location: CGPoint(x: annotation.position.x, y: annotation.position.z),
8081
title: annotation.label,
82+
id: id,
8183
clusterIdentifier: "bmap-server-marker")
8284
}
8385
annotations.append(contentsOf: mapMarkers)

MCMaps/Shared/Services/CartographyClock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CartographyClock {
2222
/// If the service is disabled or hasn't been set up with ``setupTimer(for:with:)``, this will almost never fire.
2323
var bluemap: Publishers.Autoconnect<Timer.TimerPublisher>
2424

25-
private let realtimeTimer = Timer.publish(every: 0.250, on: .main, in: .common)
25+
private let realtimeTimer = Timer.publish(every: 0.5, on: .main, in: .common)
2626
private var bluemapTimer: Timer.TimerPublisher?
2727
private let stillFrame = Timer.publish(every: .greatestFiniteMagnitude, on: .main, in: .default)
2828

0 commit comments

Comments
 (0)