AI: Add in-game galaxy map as MapEditor canvas background
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user