AI: Add in-game galaxy map as MapEditor canvas background

This commit is contained in:
Io
2026-09-28 21:51:22 +00:00
parent 2c4dc0ff5c
commit 8011b36955
@@ -0,0 +1,39 @@
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Storage;
namespace ZeroSpace.MapEditor.Services;
/// <summary>
/// Loads the in-game galaxy map screenshot as the canvas background.
/// The PNG lives in Resources/Raw and is deployed as a MauiAsset.
/// </summary>
public static class MapBackground
{
private const string AssetName = "galaxymap.png";
public static async Task<IImage?> 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;
}
}
}