From f881257ca09f07ca60039869dfb7fb7e196325df Mon Sep 17 00:00:00 2001 From: Io Date: Mon, 28 Sep 2026 21:51:22 +0000 Subject: [PATCH] AI: Add in-game galaxy map as MapEditor canvas background --- .../Services/MapBackground.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ZeroSpace/ZeroSpace.MapEditor/Services/MapBackground.cs diff --git a/ZeroSpace/ZeroSpace.MapEditor/Services/MapBackground.cs b/ZeroSpace/ZeroSpace.MapEditor/Services/MapBackground.cs new file mode 100644 index 0000000..c84652c --- /dev/null +++ b/ZeroSpace/ZeroSpace.MapEditor/Services/MapBackground.cs @@ -0,0 +1,39 @@ +using Microsoft.Maui.Graphics; +using Microsoft.Maui.Storage; + +namespace ZeroSpace.MapEditor.Services; + +/// +/// Loads the in-game galaxy map screenshot as the canvas background. +/// The PNG lives in Resources/Raw and is deployed as a MauiAsset. +/// +public static class MapBackground +{ + private const string AssetName = "galaxymap.png"; + + public static async Task LoadAsync() + { + try + { + await using var packageStream = await FileSystem.OpenAppPackageFileAsync(AssetName); + // Copy into memory and leave the buffer undisposed: some platform + // image implementations read from the stream lazily. + var buffer = new MemoryStream(); + await packageStream.CopyToAsync(buffer); + buffer.Position = 0; +#if WINDOWS + return new Microsoft.Maui.Graphics.Platform.PlatformImage(buffer); +#elif MACCATALYST + return new Microsoft.Maui.Graphics.Platform.PlatformImage(buffer); +#else + return null; +#endif + } + catch + { + // No map image available (missing asset, unsupported platform): + // the editor works fine without the background. + return null; + } + } +}