Skip to content

Commit

Permalink
forgot to implement the addFile methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Secre-C committed Nov 9, 2023
1 parent 64ab45e commit 02d455a
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions Emulator/SPD.File.Emulator/Sprite/SpriteBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace SPD.File.Emulator.Sprite;
public class SpriteBuilderFactory
{
internal List<RouteGroupTuple> _routeGroupTuples = new();
internal List<RouteFileTuple> _routeFileTuples = new();
private readonly Logger _log;

/// <summary>
Expand All @@ -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);

Expand All @@ -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) });
}

/// <summary>
/// Tries to create an SPD from a given route.
/// </summary>
Expand All @@ -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))
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -93,4 +118,17 @@ internal struct RouteGroupTuple
/// Files bound by this route.
/// </summary>
public DirectoryFilesGroup Files;
}

internal struct RouteFileTuple
{
/// <summary>
/// Route associated with this tuple.
/// </summary>
public Route Route;

/// <summary>
/// Path to the file bound by this route.
/// </summary>
public string FilePath;
}

0 comments on commit 02d455a

Please sign in to comment.