using System.Linq;
using Cthangover.Core.Mods;
using Cthangover.Core.Utils;
using Godot;
namespace Cthangover.Mods.Dialog.DocShots
{
///
/// Entry point of the doc_shots suite: adds the driver when the exact flag
/// --itest=doc_shots is given. --doc-steps=<file> is the
/// steps file, --shots=<dir> where the pictures go.
///
public class DocShotsTestInitializer : IModInitializer
{
private static bool driverQueued;
/// Nothing per mod.
public void OnModLoaded(string modId)
{
}
/// Queues the driver once.
public void OnModResourcesReady()
{
var args = OS.GetCmdlineUserArgs();
if (driverQueued || !args.Any(a => a == "--itest=doc_shots"))
return;
driverQueued = true;
var steps = ArgValue(args, "--doc-steps=");
var shots = ArgValue(args, "--shots=");
GameLogger.Log("TEST", $"DocShotsTestInitializer: steps={steps ?? "none"}, shots={shots ?? "off"}");
ModRoot.AddDeferred(new DocShotsDriver(steps, shots));
}
private static string ArgValue(string[] args, string prefix) =>
args.Where(a => a.StartsWith(prefix, System.StringComparison.Ordinal))
.Select(a => a.Substring(prefix.Length))
.FirstOrDefault();
}
}