using System.Linq;
using Cthangover.Core.Mods;
using Cthangover.Core.Utils;
using Godot;
namespace Cthangover.Mods.Rpg.Tests
{
///
/// Entry point of the rpg_walk integration test: adds the driver to the tree
/// root when the exact flag --itest=rpg_walk is given (the driver
/// quits the process, so it must never run in another test). Optional
/// --shots=<dir> makes the driver save screenshots.
///
public class RpgWalkTestInitializer : 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=rpg_walk"))
return;
driverQueued = true;
var shots = args.Where(a => a.StartsWith("--shots=", System.StringComparison.Ordinal))
.Select(a => a.Substring("--shots=".Length))
.FirstOrDefault();
GameLogger.Log("TEST", $"RpgWalkTestInitializer: activating rpg_walk, shots={shots ?? "off"}");
(Godot.Engine.GetMainLoop() as SceneTree)?.Root?.CallDeferred("add_child", new RpgWalkTestDriver(shots));
}
}
}