1using System.Collections.Concurrent;
3using Microsoft.Extensions.Logging;
10public sealed class SvgResourceManager : IDisposable
12 private static readonly Lazy<SvgResourceManager> _instance =
new(() =>
new SvgResourceManager());
13 private readonly ConcurrentDictionary<string, SvgResource> _svgResources =
new();
14 private bool _disposed;
16 private SvgResourceManager()
23 public static SvgResourceManager
Instance => _instance.Value;
33 ArgumentException.ThrowIfNullOrWhiteSpace(key);
34 ArgumentException.ThrowIfNullOrWhiteSpace(path);
37 return AddOrReplace(key, resource);
47 ArgumentNullException.ThrowIfNull(resourceFile);
48 var loaded =
new List<SvgResource>();
50 foreach (var entry
in resourceFile.GetAllEntries())
52 if (entry.AssetType !=
AssetTypes.Svg || _svgResources.ContainsKey(entry.AssetName))
55 using var stream = resourceFile.Get(entry.AssetType, entry.AssetName);
59 Engine.
Logger.LogWarning(
"Failed to retrieve stream for SVG resource: {Key}", entry.AssetName);
66 loaded.Add(AddOrReplace(entry.AssetName, svg));
72 "Error loading SVG resource from asset file for key: {Key}",
87 public bool Contains(
string key) => _svgResources.ContainsKey(key);
94 public SvgResource?
Get(
string key) => _svgResources.TryGetValue(key, out var resource) ? resource :
null;
100 public Dictionary<string, SvgResource>
GetAll() => _svgResources.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
108 if (_svgResources.TryRemove(key, out var resource))
117 foreach (var resource
in _svgResources.Values)
120 _svgResources.Clear();
135 if (_svgResources.TryGetValue(key, out var existing))
138 _svgResources[key] = resource;
Represents an asset file used by the engine, providing functionality to load, manage,...
static SvgResourceManager Instance
Gets the singleton instance of the SvgResourceManager.
void Unload(string key)
Unloads a resource by key.
List< SvgResource > LoadFromEngineAssetsFile(AssetsFile resourceFile)
Loads all SVG resources from an AssetsFile.
SvgResource? Get(string key)
Gets a resource by key or null when not found.
bool Contains(string key)
Determines whether a resource key is loaded.
Dictionary< string, SvgResource > GetAll()
Gets all loaded resources.
SvgResource LoadFromFile(string key, string path)
Loads an SVG resource from a file path.
void Clear()
Clears all loaded resources.
Represents a loaded SVG asset that can be rasterized into cached bitmaps at requested sizes.
static SvgResource Load(string path)
Loads an SVG resource from a file path.
Represents the core game engine singleton responsible for managing the main update loop,...
static ILogger< Engine > Logger
Gets the logger instance used by the engine for diagnostic and informational messages.
AssetTypes
Defines the types of assets that can be stored and managed by the engine.