using System.Linq; using Cthangover.Core.Mods; using Cthangover.Core.Utils; using Godot; namespace Cthangover.Tools.Tests.NovelFlow { /// /// Entry point of the novel_flow test: adds the driver to the tree root when the exact /// flag --itest=novel_flow is given (the driver quits the process). Optional /// --shots=<dir> makes the driver save a screenshot per step. /// public class NovelFlowTestInitializer : 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=novel_flow")) return; driverQueued = true; var shots = args.Where(a => a.StartsWith("--shots=", System.StringComparison.Ordinal)) .Select(a => a.Substring("--shots=".Length)) .FirstOrDefault(); GameLogger.Log("TEST", $"NovelFlowTestInitializer: activating novel_flow, shots={shots ?? "off"}"); (Godot.Engine.GetMainLoop() as SceneTree)?.Root?.CallDeferred("add_child", new NovelFlowTestDriver(shots)); } } }