Skip to content
0.2.0-dev Download ZIP
38 lines ·1.3 KB Raw
1namespace EvilEngine.Mounts.Tests.Support;
2
3public sealed class SyntheticGame(string game, Func<IFileSource, MountPlan>? plan = null) : IGameAdapter
4{
5 public static readonly Platform Pc = new("pc", ByteOrder.Little, CaseRule.Insensitive);
6
7 public VirtualPath VersionFile => $"{Game}.ver";
8
9 public IReadOnlyList<External> Declares { get; init; } = [];
10
11 public Func<IFileSource, Externals, MountPlan>? PlanWith { get; init; }
12
13 public Externals? LastExternals { get; private set; }
14
15 public string Game { get; } = game;
16
17 public IReadOnlyList<Platform> Platforms { get; } = [Pc];
18
19 public MountProbe? Probe(IFileSource tree)
20 {
21 return tree.Exists(VersionFile)
22 ? new MountProbe(new MountId(Game, Pc.Id, tree.ReadAllText(VersionFile).Trim()), ProbeStatus.Known, tree)
23 { Externals = Declares }
24 : null;
25 }
26
27 public MountPlan Open(MountProbe probe, Externals externals)
28 {
29 LastExternals = externals;
30 return PlanWith?.Invoke(probe.Tree, externals) ?? plan?.Invoke(probe.Tree) ??
31 new MountPlan(CaseRule.Insensitive)
32 {
33 Layers = [new LayerPlan("base", "base", new LayerSource.Tree(probe.Tree))],
34 Parts = [new PartPlan("content", [VersionFile])],
35 BuildFiles = [VersionFile]
36 };
37 }
38}