diff --git a/Emulator/SPD.File.Emulator/Sprite/SpriteBuilderFactory.cs b/Emulator/SPD.File.Emulator/Sprite/SpriteBuilderFactory.cs index 08e378c..e349f99 100644 --- a/Emulator/SPD.File.Emulator/Sprite/SpriteBuilderFactory.cs +++ b/Emulator/SPD.File.Emulator/Sprite/SpriteBuilderFactory.cs @@ -9,6 +9,7 @@ namespace SPD.File.Emulator.Sprite; public class SpriteBuilderFactory { internal List _routeGroupTuples = new(); + internal List _routeFileTuples = new(); private readonly Logger _log; /// @@ -34,7 +35,7 @@ public void AddFromFolders(string redirectorFolder) foreach (var group in groups) { if (group.Files.Length <= 0) - return; + continue; var route = Route.GetRoute(redirectorFolder, group.Directory.FullPath); @@ -46,6 +47,12 @@ public void AddFromFolders(string redirectorFolder) } } + public void AddFile(string file, string route) + { + _log.Info($"[SpdBuilderFactory] Added file {file} with route {route}"); + _routeFileTuples.Add(new RouteFileTuple { FilePath = file, Route = new Route(route) }); + } + /// /// Tries to create an SPD from a given route. /// @@ -56,6 +63,7 @@ public bool TryCreateFromPath(string path, out SpriteBuilder? builder) { builder = default; var route = new Route(path); + foreach (var group in _routeGroupTuples) { if (!route.Matches(group.Route.FullPath)) @@ -68,7 +76,7 @@ public bool TryCreateFromPath(string path, out SpriteBuilder? builder) else if (routeExtension == ".spr") builder ??= new SprBuilder(_log); else - return false; + return false; // Add files to builder. var dir = group.Files.Directory.FullPath; @@ -78,6 +86,23 @@ public bool TryCreateFromPath(string path, out SpriteBuilder? builder) } } + foreach (var group in _routeFileTuples) + { + if (!route.Matches(group.Route.FullPath)) + continue; + + string routeExtension = Path.GetExtension(route.FullPath).ToLower(); + // Make builder if not made. + if (routeExtension == ".spd") + builder ??= new SpdBuilder(_log); + else if (routeExtension == ".spr") + builder ??= new SprBuilder(_log); + else + return false; + + builder.AddOrReplaceFile(group.FilePath); + } + return builder != null; } } @@ -93,4 +118,17 @@ internal struct RouteGroupTuple /// Files bound by this route. /// public DirectoryFilesGroup Files; +} + +internal struct RouteFileTuple +{ + /// + /// Route associated with this tuple. + /// + public Route Route; + + /// + /// Path to the file bound by this route. + /// + public string FilePath; } \ No newline at end of file