Event-driven dialog queue, story flag command, mod unit tests

Push-based event chains, runtime fixes (single end, goto lifecycle, if,
busy box, held delay, empty options, timed/animated/effect actions), the
'flag name value' DSL command, autoplay --dialogs=N, 19 mod unit tests.
This commit is contained in:
cthangover committed 2026-10-21 12:31:52 +02:00
1 parent 9f86bdbb0c
commit bd55716349
86 files changed
+3173 -2181

No files matched your search

@@ -1,7 +1,6 @@
using System.Collections.Generic;
using Cthangover.Mods.Effects.Animation;
using Cthangover.Core.Factories.Impls;
using Cthangover.Mods.Dialog.Action;
using Cthangover.Core.UI.Event;
using Cthangover.Mods.Interface.View;
using Godot;
using Cthangover.Core.UI;
@@ -15,106 +14,150 @@ namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Frame-animates the scene foreground by swapping ViewBox textures at a
/// configurable speed. Loads frames from SpriteIDs on construction
/// (OnStartQueue). Unlike AnimationController which crossfades, this does
/// hard cuts — simpler but acceptable for foreground effects. The speed
/// switches to NextFrameSpeed after the first frame so first-frame delay
/// can differ from subsequent frames. Registers as IOnUpdateEvent for
/// per-frame advancement. Non-looping mode auto-stops at last frame.
/// configurable speed: the first frame lasts 1/<see cref="Speed"/> seconds,
/// every later one 1/<see cref="NextFrameSpeed"/>. Hard cuts, no crossfade.
/// Frames come from <see cref="Textures"/> or are resolved from
/// <see cref="SpriteIDs"/> through <see cref="BackgroundFactory"/> (the same
/// texture names a <c>foreground</c> command takes) on construction
/// (OnStartQueue).
/// <para/>
/// Event-driven: each frame schedules one <see cref="SceneTreeTimer"/> for the
/// next cut — no per-frame update. The dialog does not wait (NoWait); the
/// animation keeps playing while the dialog goes on and stops when the queue
/// ends (OnEndQueue), when another animation starts or when a
/// <c>foreground</c> command replaces the picture (<see cref="StopActive"/>).
/// </summary>
public class ActionAnimatedForeground : ActionCommand, IOnUpdateEvent
public class ActionAnimatedForeground : ActionCommand
{
/// <summary>Update priority. Runs after higher-priority listeners. Value 0.</summary>
public int Priority => 0;
private static ActionAnimatedForeground active;
/// <summary>List of sprite resource paths to display as animation frames. Loaded in <see cref="DoConstruct"/>.</summary>
/// <summary>Texture names resolved through <see cref="BackgroundFactory"/>; ignored when <see cref="Textures"/> is set.</summary>
public List<string> SpriteIDs { get; set; }
/// <summary>Initial frame rate multiplier for the first frame.</summary>
/// <summary>Ready frames used instead of resolving <see cref="SpriteIDs"/> (bypasses the factory like ActionForeground.Texture).</summary>
public List<Texture2D> Textures { get; set; }
/// <summary>Frames per second of the first frame.</summary>
public float Speed { get; set; } = 1f;
/// <summary>Frame rate multiplier for subsequent frames after the first. Allows different pacing for the initial frame.</summary>
/// <summary>Frames per second of every frame after the first one.</summary>
public float NextFrameSpeed { get; set; } = 1f;
/// <summary>Whether the animation wraps after the last frame. When false, playback stops at the final frame.</summary>
/// <summary>Whether playback restarts from the first frame after the last one; otherwise it stops on the last frame.</summary>
public bool IsLoop { get; set; } = true;
private int currentFrame;
private float elapsed;
private bool isAnimating;
private List<Texture2D> frames;
/// <summary>Whether the animation is still cutting frames.</summary>
public bool IsAnimating { get; private set; }
/// <summary>Preloads frames when the dialog queue is first loaded, so textures are ready before playback.</summary>
private int currentFrame;
private List<Texture2D> frames;
private SceneTreeTimer frameTimer;
/// <summary>Frames are resolved when the queue starts, so the first cut does not stall on loading.</summary>
public override ConstructType ConstructType { get; set; } = ConstructType.OnStartQueue;
/// <summary>Animation runs in the background — the dialog queue continues immediately.</summary>
/// <summary>The animation lives until the dialog ends, not until the next action.</summary>
public override DestructType DestructType { get; set; } = DestructType.OnEndQueue;
/// <summary>The dialog goes on while the foreground animates.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Preloads every sprite in <see cref="SpriteIDs"/> into memory so playback never stalls on I/O.</summary>
/// <summary>Stops the animation that currently drives the foreground, if any; the shown frame stays.</summary>
public static void StopActive()
{
active?.Stop();
}
/// <summary>Resolves the frames.</summary>
public override void DoConstruct()
{
base.DoConstruct();
LoadFrames();
}
/// <summary>Stops the animation loop; the last shown frame stays on screen.</summary>
/// <summary>Stops the frame timer; the last shown frame stays on the ViewBox.</summary>
public override void DoDestruct()
{
base.DoDestruct();
isAnimating = false;
Stop();
}
private void LoadFrames()
{
frames = new List<Texture2D>();
var source = Textures;
if (source != null)
{
foreach (var tex in source)
if (tex != null)
frames.Add(tex);
return;
}
if (SpriteIDs == null)
return;
foreach (var id in SpriteIDs)
{
var tex = GD.Load<Texture2D>(id);
var tex = BackgroundFactory.Instance.Get(id);
if (tex != null)
frames.Add(tex);
}
}
/// <summary>Resets playback to the first frame and shows it on the ViewBox; per-frame stepping happens through <see cref="IOnUpdateEvent.OnUpdate"/>.</summary>
/// <summary>Stops a previous animation, shows the first frame on the ViewBox and schedules the next cut.</summary>
public override void DoRun(DialogRuntime runtime)
{
StopActive();
currentFrame = 0;
elapsed = 0f;
isAnimating = frames != null && frames.Count > 0;
IsAnimating = frames != null && frames.Count > 0;
if (!IsAnimating)
return;
if (isAnimating)
{
var viewBox = Scene.Find<ViewBox>("ViewBox");
viewBox?.SetForegroundTexture(frames[0]);
}
active = this;
ShowFrame();
ScheduleNextFrame(Speed);
}
void IOnUpdateEvent.OnUpdate()
private void ShowFrame()
{
if (!isAnimating || frames == null || frames.Count == 0)
return;
var viewBox = Scene.Find<ViewBox>("ViewBox");
if (viewBox == null)
viewBox?.SetForegroundTexture(frames[currentFrame]);
}
private void ScheduleNextFrame(float speed)
{
if (Godot.Engine.GetMainLoop() is not SceneTree tree)
return;
elapsed += 1f / 60f;
var frameDuration = 1f / Mathf.Max(Speed, 0.01f);
if (elapsed >= frameDuration)
frameTimer = tree.CreateTimer(1f / Mathf.Max(speed, 0.01f));
frameTimer.Timeout += OnFrameTimeout;
}
private void OnFrameTimeout()
{
frameTimer = null;
if (!IsAnimating)
return;
currentFrame++;
if (currentFrame >= frames.Count)
{
elapsed -= frameDuration;
currentFrame++;
if (currentFrame >= frames.Count)
if (!IsLoop)
{
if (IsLoop)
currentFrame = 0;
else
{
isAnimating = false;
return;
}
Stop();
return;
}
viewBox.SetForegroundTexture(frames[currentFrame]);
Speed = NextFrameSpeed;
currentFrame = 0;
}
ShowFrame();
ScheduleNextFrame(NextFrameSpeed);
}
private void Stop()
{
IsAnimating = false;
if (frameTimer != null)
{
frameTimer.Timeout -= OnFrameTimeout;
frameTimer = null;
}
if (active == this)
active = null;
}
}
}
+81 -81
View File
@@ -1,81 +1,81 @@
using Cthangover.Core.Factories.Impls;
using Cthangover.Core.Scenes;
using Cthangover.Mods.Dialog.Action;
using Cthangover.Mods.Time;
using Cthangover.Mods.Interface.View;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Sets the scene background on the ViewBox, including depth and albedo maps
/// for the lighting system. Resolves textures through BackgroundFactory on
/// construction (OnStartQueue) — depth and albedo are loaded from the same
/// sprite ID with "_depth" / "_albedo" suffixes. Kills any in-progress
/// background transition before setting the new texture. Textures are nulled
/// after application to prevent stale reuse across dialog restarts.
/// Sets SceneContextNode.LastBackgroundID so the scene manager can restore
/// the correct background on scene revisit.
/// </summary>
public class ActionBackground : ActionCommand
{
/// <summary>Sprite resource ID resolved through <see cref="BackgroundFactory"/> on construction. Also loads depth (_depth) and albedo (_albedo) variants.</summary>
public string SpriteID { get; set; }
/// <summary>Direct texture override. When non-null, bypasses factory resolution. Set to null after application to prevent stale reuse.</summary>
public Texture2D Texture { get; set; }
/// <summary>Depth map for the lighting system, loaded from <see cref="SpriteID"/> + "_depth".</summary>
public Texture2D DepthTexture { get; set; }
/// <summary>Albedo color map for the lighting system, loaded from <see cref="SpriteID"/> + "_albedo".</summary>
public Texture2D AlbedoTexture { get; set; }
/// <summary>Preloads textures when the dialog queue is first created, resolving SpriteID through the factory.</summary>
public override ConstructType ConstructType { get; set; } = ConstructType.OnStartQueue;
/// <summary>Background is set imperatively — the dialog continues immediately.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Resolves <see cref="SpriteID"/> plus its <c>_depth</c>/<c>_albedo</c> variants through the background factory.</summary>
public override void DoConstruct()
{
base.DoConstruct();
if (Texture == null && !string.IsNullOrEmpty(SpriteID))
Texture = BackgroundFactory.Instance.Get(SpriteID);
if (!string.IsNullOrEmpty(SpriteID))
{
DepthTexture = BackgroundFactory.Instance.Get(SpriteID + "_depth");
AlbedoTexture = BackgroundFactory.Instance.Get(SpriteID + "_albedo");
}
}
/// <summary>
/// Applies the background to the ViewBox, kills any in-flight background
/// transition and feeds the depth/albedo maps to the light controller.
/// Consumed textures are nulled so a reused action cannot re-apply stale data.
/// </summary>
public override void DoRun(DialogRuntime runtime)
{
if (Texture == null)
return;
SceneContextNode.LastBackgroundID = SpriteID;
var viewBox = Scene.Find<ViewBox>("ViewBox");
viewBox?.KillTransitionTween();
viewBox?.SetBackgroundTexture(Texture);
var controller = UiLightController.Instance;
controller?.SetupDepthMap(DepthTexture);
controller?.SetupAlbedoMap(AlbedoTexture);
Texture = null;
DepthTexture = null;
AlbedoTexture = null;
}
}
}
using Cthangover.Core.Factories.Impls;
using Cthangover.Core.Scenes;
using Cthangover.Mods.Dialog.Action;
using Cthangover.Mods.Time;
using Cthangover.Mods.Interface.View;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Sets the scene background on the ViewBox, including depth and albedo maps
/// for the lighting system. Resolves textures through BackgroundFactory on
/// construction (OnStartQueue) — depth and albedo are loaded from the same
/// sprite ID with "_depth" / "_albedo" suffixes. Kills any in-progress
/// background transition before setting the new texture. Textures are nulled
/// after application to prevent stale reuse across dialog restarts.
/// Sets SceneContextNode.LastBackgroundID so the scene manager can restore
/// the correct background on scene revisit.
/// </summary>
public class ActionBackground : ActionCommand
{
/// <summary>Sprite resource ID resolved through <see cref="BackgroundFactory"/> on construction. Also loads depth (_depth) and albedo (_albedo) variants.</summary>
public string SpriteID { get; set; }
/// <summary>Direct texture override. When non-null, bypasses factory resolution. Set to null after application to prevent stale reuse.</summary>
public Texture2D Texture { get; set; }
/// <summary>Depth map for the lighting system, loaded from <see cref="SpriteID"/> + "_depth".</summary>
public Texture2D DepthTexture { get; set; }
/// <summary>Albedo color map for the lighting system, loaded from <see cref="SpriteID"/> + "_albedo".</summary>
public Texture2D AlbedoTexture { get; set; }
/// <summary>Preloads textures when the dialog queue is first created, resolving SpriteID through the factory.</summary>
public override ConstructType ConstructType { get; set; } = ConstructType.OnStartQueue;
/// <summary>Background is set imperatively — the dialog continues immediately.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Resolves <see cref="SpriteID"/> plus its <c>_depth</c>/<c>_albedo</c> variants through the background factory.</summary>
public override void DoConstruct()
{
base.DoConstruct();
if (Texture == null && !string.IsNullOrEmpty(SpriteID))
Texture = BackgroundFactory.Instance.Get(SpriteID);
if (!string.IsNullOrEmpty(SpriteID))
{
DepthTexture = BackgroundFactory.Instance.Get(SpriteID + "_depth");
AlbedoTexture = BackgroundFactory.Instance.Get(SpriteID + "_albedo");
}
}
/// <summary>
/// Applies the background to the ViewBox, kills any in-flight background
/// transition and feeds the depth/albedo maps to the light controller.
/// Consumed textures are nulled so a reused action cannot re-apply stale data.
/// </summary>
public override void DoRun(DialogRuntime runtime)
{
if (Texture == null)
return;
SceneContextNode.LastBackgroundID = SpriteID;
var viewBox = Scene.Find<ViewBox>("ViewBox");
viewBox?.KillTransitionTween();
viewBox?.SetBackgroundTexture(Texture);
var controller = UiLightController.Instance;
controller?.SetupDepthMap(DepthTexture);
controller?.SetupAlbedoMap(AlbedoTexture);
Texture = null;
DepthTexture = null;
AlbedoTexture = null;
}
}
}
@@ -1,5 +1,5 @@
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
@@ -8,26 +8,26 @@ using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Scenes;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Sets the background tint color. DoRun is currently a no-op — the Color
/// property is stored for external systems to read. Likely intended as a
/// declarative instruction consumed by a background-rendering node rather
/// than applied imperatively.
/// </summary>
public class ActionBackgroundColor : ActionCommand
{
/// <summary>Target tint color. Stored declaratively — consumed by background-rendering nodes rather than applied imperatively here.</summary>
public Color Color { get; set; } = Colors.Black;
/// <summary>Imperative — the dialog continues immediately after this action is processed.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Deliberate no-op: the tint is declarative data for background-rendering nodes, not applied here.</summary>
public override void DoRun(DialogRuntime runtime)
{
}
}
}
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Sets the background tint color. DoRun is currently a no-op — the Color
/// property is stored for external systems to read. Likely intended as a
/// declarative instruction consumed by a background-rendering node rather
/// than applied imperatively.
/// </summary>
public class ActionBackgroundColor : ActionCommand
{
/// <summary>Target tint color. Stored declaratively — consumed by background-rendering nodes rather than applied imperatively here.</summary>
public Color Color { get; set; } = Colors.Black;
/// <summary>Imperative — the dialog continues immediately after this action is processed.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Deliberate no-op: the tint is declarative data for background-rendering nodes, not applied here.</summary>
public override void DoRun(DialogRuntime runtime)
{
}
}
}
@@ -13,10 +13,13 @@ namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Tween-driven background fade in/out. Animates the modulate alpha of the
/// dialog box's parent Control over Duration seconds. Creates and manages
/// its own Tween internally, killing any previous tween before starting a
/// new one to prevent overlap. Can optionally set WaitType to WaitTime with
/// a matching duration so the dialog pauses during the transition.
/// dialog box's parent Control over Duration seconds. The fade belongs to the
/// background, not to the action: by default (NoWait) the runtime destructs the
/// action right after it runs, and the fade must go on. So the tween is shared
/// by all instances — a new fade kills the previous one to prevent overlap —
/// and destructing the action leaves it running; the tween is bound to the
/// background node and dies with it. Can optionally set WaitType to WaitTime
/// with a matching duration so the dialog pauses during the transition.
/// </summary>
public class ActionBackgroundShowHide : ActionCommand
{
@@ -25,7 +28,7 @@ namespace Cthangover.Mods.Dialog.Action.Impls
/// <summary>Duration of the fade tween in seconds.</summary>
public float Duration { get; set; } = 1f;
private Tween activeTween;
private static Tween activeTween;
/// <summary>Default NoWait — overridden by the DialogQueue builder if the wait flag is set, changing to WaitTime to pause during transition.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
@@ -47,18 +50,12 @@ namespace Cthangover.Mods.Dialog.Action.Impls
}
}
/// <summary>Kills the fade tween so a destructed action cannot keep animating.</summary>
public override void DoDestruct()
{
base.DoDestruct();
StopTween();
}
private void StopTween()
private static void StopTween()
{
if (activeTween != null)
{
activeTween.Kill();
if (GodotObject.IsInstanceValid(activeTween))
activeTween.Kill();
activeTween = null;
}
}
+48 -48
View File
@@ -1,5 +1,5 @@
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
@@ -8,49 +8,49 @@ using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Scenes;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Waits for a fixed duration. When HiddenMode is true, hides the dialog
/// body for the duration (for dramatic pauses or cutscene beats). ShowText,
/// if set, displays a temporary message during the wait. DoDestruct is a
/// no-op because body visibility is implicitly restored on next Show.
/// </summary>
public class ActionDelay : ActionCommand
{
/// <summary>When true, hides the dialog body for the duration of the wait (dramatic pauses, cutscene beats).</summary>
public bool HiddenMode { get; set; }
/// <summary>Optional temporary text displayed while waiting. Set to null to keep the current dialog text.</summary>
public string ShowText { get; set; }
/// <summary>Pauses the dialog until <see cref="WaitTime"/> elapses.</summary>
public override WaitType WaitType { get; set; } = WaitType.WaitTime;
/// <summary>Duration of the pause in seconds. Default 1.0.</summary>
public override float WaitTime { get; set; } = 1f;
/// <summary>Shows the optional <see cref="ShowText"/> and, in <see cref="HiddenMode"/>, hides the dialog body for the pause duration.</summary>
public override void DoRun(DialogRuntime runtime)
{
var dialogBox = runtime.DialogBox;
if (dialogBox == null)
return;
if (ShowText != null)
dialogBox.SetText(ShowText);
if (HiddenMode)
dialogBox.Body.SetDeferred("visible", false);
}
/// <summary>No-op: the dialog body hidden by <see cref="HiddenMode"/> is restored implicitly by the next show.</summary>
public override void DoDestruct()
{
base.DoDestruct();
if (HiddenMode)
{
// Body restored on next Show
}
}
}
}
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Waits for a fixed duration. When HiddenMode is true, hides the dialog
/// body for the duration (for dramatic pauses or cutscene beats). ShowText,
/// if set, displays a temporary message during the wait. DoDestruct is a
/// no-op because body visibility is implicitly restored on next Show.
/// </summary>
public class ActionDelay : ActionCommand
{
/// <summary>When true, hides the dialog body for the duration of the wait (dramatic pauses, cutscene beats).</summary>
public bool HiddenMode { get; set; }
/// <summary>Optional temporary text displayed while waiting. Set to null to keep the current dialog text.</summary>
public string ShowText { get; set; }
/// <summary>Pauses the dialog until <see cref="WaitTime"/> elapses.</summary>
public override WaitType WaitType { get; set; } = WaitType.WaitTime;
/// <summary>Duration of the pause in seconds. Default 1.0.</summary>
public override float WaitTime { get; set; } = 1f;
/// <summary>Shows the optional <see cref="ShowText"/> and, in <see cref="HiddenMode"/>, hides the dialog body for the pause duration.</summary>
public override void DoRun(DialogRuntime runtime)
{
var dialogBox = runtime.DialogBox;
if (dialogBox == null)
return;
if (ShowText != null)
dialogBox.SetText(ShowText);
if (HiddenMode)
dialogBox.Body.SetDeferred("visible", false);
}
/// <summary>No-op: the dialog body hidden by <see cref="HiddenMode"/> is restored implicitly by the next show.</summary>
public override void DoDestruct()
{
base.DoDestruct();
if (HiddenMode)
{
// Body restored on next Show
}
}
}
}
+41 -15
View File
@@ -9,57 +9,83 @@ using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Scenes;
using Cthangover.Core.Interactive;
using Cthangover.Mods.Interface.View;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Spawns a visual effect from the EffectFactory by ID. The spawned node
/// persists until the action is destructed. Uses DestructType.OnDelayed
/// because the effect must outlive the action's run — the effect node's own
/// animation or lifetime controls when it disappears. DoRun is a no-op
/// because construction handles spawning.
/// Spawns a visual effect from the EffectFactory by ID (or a ready
/// <see cref="Prefab"/>, bypassing the factory like ActionBackground.Texture).
/// The scene is instantiated on construction and put into the ViewBox's UI
/// layer (above all scene visuals, below the dialog) when the action runs; the
/// node persists until the action is destructed. Uses DestructType.OnDelayed
/// because the effect must outlive the action's run: the runtime frees it when
/// the dialog ends (End destructs every constructed action), unless the effect
/// node frees itself first.
/// </summary>
public class ActionEffect : ActionCommand
{
/// <summary>Identifier resolved through <see cref="EffectFactory"/> to a PackedScene. The spawned node persists until destructed.</summary>
public string EffectID { get; set; }
/// <summary>Effect scene to spawn instead of resolving <see cref="EffectID"/>; null resolves through the factory.</summary>
public PackedScene Prefab { get; set; }
private Node spawnedEffect;
/// <summary>The dialog continues immediately — the spawned effect plays independently.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>OnDelayed ensures the effect node outlives the action's run phase. Destruct is called manually when the effect finishes.</summary>
/// <summary>OnDelayed keeps the effect node alive past the action's run; it is freed when the dialog ends.</summary>
public override DestructType DestructType { get; set; } = DestructType.OnDelayed;
/// <summary>Resolves <see cref="EffectID"/> through <see cref="EffectFactory"/> and instantiates the effect scene.</summary>
/// <summary>Resolves the effect scene (<see cref="Prefab"/> or <see cref="EffectID"/> through <see cref="EffectFactory"/>) and instantiates it.</summary>
public override void DoConstruct()
{
base.DoConstruct();
if (string.IsNullOrEmpty(EffectID))
return;
var packedScene = EffectFactory.Instance.Get(EffectID);
var packedScene = Prefab;
if (packedScene == null)
{
GameLogger.Log("DIALOG", $"ActionEffect: effect '{EffectID}' not found", LogLevel.Error);
return;
if (string.IsNullOrEmpty(EffectID))
return;
packedScene = EffectFactory.Instance.Get(EffectID);
if (packedScene == null)
{
GameLogger.Log("DIALOG", $"ActionEffect: effect '{EffectID}' not found", LogLevel.Error);
return;
}
}
spawnedEffect = packedScene.Instantiate();
}
/// <summary>No-op: spawning happens during construction so the effect is ready before the queue reaches this point.</summary>
/// <summary>Shows the instantiated effect: adds it to the ViewBox UI layer. Without a ViewBox the effect is dropped with an error.</summary>
public override void DoRun(DialogRuntime runtime)
{
if (spawnedEffect == null || spawnedEffect.IsInsideTree())
return;
var layer = Scene.Find<ViewBox>("ViewBox")?.GetInteractiveLayer("ui");
if (layer == null)
{
GameLogger.Log("DIALOG", $"ActionEffect: no ViewBox to show effect '{EffectID}'", LogLevel.Error);
spawnedEffect.QueueFree();
spawnedEffect = null;
return;
}
layer.AddChild(spawnedEffect);
}
/// <summary>Frees the spawned effect node; paired with the OnDelayed destruct so effects outlive the action's run.</summary>
/// <summary>Frees the spawned effect node (unless it already freed itself); paired with the OnDelayed destruct so effects outlive the action's run.</summary>
public override void DoDestruct()
{
base.DoDestruct();
if (spawnedEffect != null)
{
spawnedEffect.QueueFree();
if (GodotObject.IsInstanceValid(spawnedEffect))
spawnedEffect.QueueFree();
spawnedEffect = null;
}
}
+21 -21
View File
@@ -1,5 +1,5 @@
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
@@ -8,22 +8,22 @@ using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Scenes;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// No-op placeholder action. Used as a labeled jump target (Point) for GoTo
/// commands — provides an addressable marker in the dialog sequence without
/// any visible effect. NoWait so the dialog skips through labels instantly.
/// </summary>
public class ActionEmpty : ActionCommand
{
/// <summary>Label actions skip immediately so the dialog doesn't pause on markers.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>No-op: the action exists only to carry the jump-target ID.</summary>
public override void DoRun(DialogRuntime runtime)
{
}
}
}
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// No-op placeholder action. Used as a labeled jump target (Point) for GoTo
/// commands — provides an addressable marker in the dialog sequence without
/// any visible effect. NoWait so the dialog skips through labels instantly.
/// </summary>
public class ActionEmpty : ActionCommand
{
/// <summary>Label actions skip immediately so the dialog doesn't pause on markers.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>No-op: the action exists only to carry the jump-target ID.</summary>
public override void DoRun(DialogRuntime runtime)
{
}
}
}
+22 -22
View File
@@ -1,5 +1,5 @@
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
@@ -8,23 +8,23 @@ using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Scenes;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Terminates the dialog queue immediately. Calls Runtime.End() which
/// destructs all remaining actions, processes the cleanup queue, hides
/// the dialog box, and fires the dialog-end event.
/// </summary>
public class ActionEnd : ActionCommand
{
/// <summary>Ends the dialog queue immediately — no pause, no return.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Terminates the queue via <see cref="DialogRuntime.End"/> — destructs remainders, runs cleanup, hides the box, fires the end event.</summary>
public override void DoRun(DialogRuntime runtime)
{
runtime.End();
}
}
}
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Terminates the dialog queue immediately. Calls Runtime.End() which
/// destructs all remaining actions, processes the cleanup queue, hides
/// the dialog box, and fires the dialog-end event.
/// </summary>
public class ActionEnd : ActionCommand
{
/// <summary>Ends the dialog queue immediately — no pause, no return.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Terminates the queue via <see cref="DialogRuntime.End"/> — destructs remainders, runs cleanup, hides the box, fires the end event.</summary>
public override void DoRun(DialogRuntime runtime)
{
runtime.End();
}
}
}
@@ -38,9 +38,10 @@ namespace Cthangover.Mods.Dialog.Action.Impls
Texture = BackgroundFactory.Instance.Get(SpriteID);
}
/// <summary>Applies the preloaded texture to the ViewBox foreground, then nulls it so a reused action cannot re-apply stale data.</summary>
/// <summary>Stops a running foreground animation (it would overwrite the picture), applies the preloaded texture to the ViewBox foreground, then nulls it so a reused action cannot re-apply stale data.</summary>
public override void DoRun(DialogRuntime runtime)
{
ActionAnimatedForeground.StopActive();
var viewBox = Scene.Find<ViewBox>("ViewBox");
viewBox?.SetForegroundTexture(Texture);
Texture = null;
+25 -25
View File
@@ -1,5 +1,5 @@
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Mods.Dialog.Action;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
@@ -8,26 +8,26 @@ using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Scenes;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Unconditional jump to a labeled action in the dialog queue. NoWait so
/// the jump happens transparently. The target is resolved by action ID
/// (set via ActionCommand.SetID or the Point()/Empty() fluent methods).
/// </summary>
public class ActionGoTo : ActionCommand
{
/// <summary>Target action ID to jump to. Resolved by linear search through the dialog queue.</summary>
public string GoTo { get; set; }
/// <summary>Jump happens transparently — the dialog continues from the target without pausing.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Jumps the queue index to the action whose ID matches <see cref="GoTo"/>.</summary>
public override void DoRun(DialogRuntime runtime)
{
runtime.TryGoTo(GoTo);
}
}
}
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Unconditional jump to a labeled action in the dialog queue. NoWait so
/// the jump happens transparently. The target is resolved by action ID
/// (set via ActionCommand.SetID or the Point()/Empty() fluent methods).
/// </summary>
public class ActionGoTo : ActionCommand
{
/// <summary>Target action ID to jump to. Resolved by linear search through the dialog queue.</summary>
public string GoTo { get; set; }
/// <summary>Jump happens transparently — the dialog continues from the target without pausing.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Jumps the queue index to the action whose ID matches <see cref="GoTo"/>.</summary>
public override void DoRun(DialogRuntime runtime)
{
runtime.TryGoTo(GoTo);
}
}
}
+24 -24
View File
@@ -1,24 +1,24 @@
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Hides the dialog box. Used in cutscenes where UI chrome should be
/// temporarily hidden while animations or background transitions play.
/// Paired with ActionShowDialog to restore visibility.
/// </summary>
public class ActionHideDialog : ActionCommand
{
/// <summary>Hides the dialog immediately — the queue continues without pause.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Hides the dialog box chrome while keeping the queue running.</summary>
public override void DoRun(DialogRuntime runtime)
{
var dialogBox = runtime.DialogBox;
if (dialogBox == null)
return;
dialogBox.Visible = false;
}
}
}
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Hides the dialog box. Used in cutscenes where UI chrome should be
/// temporarily hidden while animations or background transitions play.
/// Paired with ActionShowDialog to restore visibility.
/// </summary>
public class ActionHideDialog : ActionCommand
{
/// <summary>Hides the dialog immediately — the queue continues without pause.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Hides the dialog box chrome while keeping the queue running.</summary>
public override void DoRun(DialogRuntime runtime)
{
var dialogBox = runtime.DialogBox;
if (dialogBox == null)
return;
dialogBox.Visible = false;
}
}
}
+4 -4
View File
@@ -14,7 +14,10 @@ namespace Cthangover.Mods.Dialog.Action.Impls
/// <summary>
/// Conditional branch: evaluates a Func&lt;bool&gt; and jumps to TrueGoTo or
/// FalseGoTo based on the result. If the chosen target is null/empty, falls
/// through to Next(). NoWait so branching is transparent to the player.
/// through to the next action. NoWait so branching is transparent to the player:
/// the runtime itself advances past a NoWait action, so the branch never calls
/// <see cref="DialogRuntime.Next"/> — doing it here as well skipped the action
/// after the <c>if</c> without running it.
/// </summary>
public class ActionIf : ActionCommand
{
@@ -34,7 +37,6 @@ namespace Cthangover.Mods.Dialog.Action.Impls
if (Condition == null)
{
GameLogger.Log("DIALOG", "ActionIf: Condition delegate is null", LogLevel.Error);
runtime.Next();
return;
}
@@ -43,8 +45,6 @@ namespace Cthangover.Mods.Dialog.Action.Impls
if (!string.IsNullOrEmpty(goTo))
runtime.TryGoTo(goTo);
else
runtime.Next();
}
}
}
+40 -40
View File
@@ -1,40 +1,40 @@
using Cthangover.Mods.Time;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Applies static lights from a JSON string to the UiLightController.
/// An empty or null string clears all static lights. The JSON is deserialized
/// into LightDef objects with viewport-relative coordinates, which are then
/// converted to pixel positions. Supports up to 10 static lights plus the
/// player's dynamic lamp.
/// </summary>
public class ActionLightSet : ActionCommand
{
/// <summary>JSON string defining static light positions and properties. Empty or null clears all static lights.</summary>
public string LightsJson { get; set; }
/// <summary>Lights are set imperatively — the dialog continues immediately.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Clears static lights when <see cref="LightsJson"/> is empty, otherwise parses and applies the light definitions to the scene's <see cref="UiLightController"/>.</summary>
public override void DoRun(DialogRuntime runtime)
{
var controller = Scene.Find<UiLightController>("Lights");
if (controller == null)
return;
if (string.IsNullOrEmpty(LightsJson))
controller.ClearStaticLights();
else
controller.SetStaticLights(LightsJson);
}
}
}
using Cthangover.Mods.Time;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Applies static lights from a JSON string to the UiLightController.
/// An empty or null string clears all static lights. The JSON is deserialized
/// into LightDef objects with viewport-relative coordinates, which are then
/// converted to pixel positions. Supports up to 10 static lights plus the
/// player's dynamic lamp.
/// </summary>
public class ActionLightSet : ActionCommand
{
/// <summary>JSON string defining static light positions and properties. Empty or null clears all static lights.</summary>
public string LightsJson { get; set; }
/// <summary>Lights are set imperatively — the dialog continues immediately.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Clears static lights when <see cref="LightsJson"/> is empty, otherwise parses and applies the light definitions to the scene's <see cref="UiLightController"/>.</summary>
public override void DoRun(DialogRuntime runtime)
{
var controller = Scene.Find<UiLightController>("Lights");
if (controller == null)
return;
if (string.IsNullOrEmpty(LightsJson))
controller.ClearStaticLights();
else
controller.SetStaticLights(LightsJson);
}
}
}
@@ -1,33 +1,33 @@
using Cthangover.Mods.Dialog.Action;
using Cthangover.Mods.Time;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Toggles the light controller's time-of-day mode. When UseTime is false,
/// static lighting is used; when true, lighting responds to the in-game clock.
/// </summary>
public class ActionLightUseTime : ActionCommand
{
/// <summary>True = lights respond to in-game time of day; false = static lighting mode.</summary>
public bool UseTime { get; set; } = true;
/// <summary>Time mode toggle is instant — the dialog continues without pause.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Switches the scene's <see cref="UiLightController"/> between time-of-day lighting and static lights.</summary>
public override void DoRun(DialogRuntime runtime)
{
var controller = Scene.Find<UiLightController>("Lights");
if (controller != null)
controller.IsUseLight = UseTime;
}
}
}
using Cthangover.Mods.Dialog.Action;
using Cthangover.Mods.Time;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Toggles the light controller's time-of-day mode. When UseTime is false,
/// static lighting is used; when true, lighting responds to the in-game clock.
/// </summary>
public class ActionLightUseTime : ActionCommand
{
/// <summary>True = lights respond to in-game time of day; false = static lighting mode.</summary>
public bool UseTime { get; set; } = true;
/// <summary>Time mode toggle is instant — the dialog continues without pause.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Switches the scene's <see cref="UiLightController"/> between time-of-day lighting and static lights.</summary>
public override void DoRun(DialogRuntime runtime)
{
var controller = Scene.Find<UiLightController>("Lights");
if (controller != null)
controller.IsUseLight = UseTime;
}
}
}
+37 -37
View File
@@ -1,37 +1,37 @@
using Cthangover.Core.Audio;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Starts background music playback via IAudioService. Uses MusicType.Ambient
/// so the music layer is treated as atmospheric background rather than UI
/// feedback. If the same music track is already playing, the audio service handles
/// deduplication.
/// </summary>
public class ActionMusic : ActionCommand
{
/// <summary>Music track identifier resolved through the audio system. Empty strings are silently ignored.</summary>
public string Music { get; set; }
/// <summary>Music starts playing in the background — the dialog continues immediately.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Starts the named track as ambient background music through <see cref="IAudioService"/>; empty names are ignored.</summary>
public override void DoRun(DialogRuntime runtime)
{
if (string.IsNullOrEmpty(Music))
return;
var audioService = Scene.Find<Node>("AudioService") as IAudioService;
audioService?.PlayMusic(Music, MusicType.Ambient);
}
}
}
using Cthangover.Core.Audio;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Starts background music playback via IAudioService. Uses MusicType.Ambient
/// so the music layer is treated as atmospheric background rather than UI
/// feedback. If the same music track is already playing, the audio service handles
/// deduplication.
/// </summary>
public class ActionMusic : ActionCommand
{
/// <summary>Music track identifier resolved through the audio system. Empty strings are silently ignored.</summary>
public string Music { get; set; }
/// <summary>Music starts playing in the background — the dialog continues immediately.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Starts the named track as ambient background music through <see cref="IAudioService"/>; empty names are ignored.</summary>
public override void DoRun(DialogRuntime runtime)
{
if (string.IsNullOrEmpty(Music))
return;
var audioService = Scene.Find<Node>("AudioService") as IAudioService;
audioService?.PlayMusic(Music, MusicType.Ambient);
}
}
}
+29 -29
View File
@@ -1,29 +1,29 @@
using Cthangover.Core.Audio;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Pauses background music playback via IAudioService without stopping the
/// track. Can be resumed with ActionMusicPlay.
/// </summary>
public class ActionMusicPause : ActionCommand
{
/// <summary>Pause is instant — the dialog continues without waiting for audio acknowledgment.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Pauses the current music track without stopping it, so <see cref="ActionMusicPlay"/> can resume it.</summary>
public override void DoRun(DialogRuntime runtime)
{
var audioService = Scene.Find<Node>("AudioService") as IAudioService;
audioService?.PauseMusic(true);
}
}
}
using Cthangover.Core.Audio;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Pauses background music playback via IAudioService without stopping the
/// track. Can be resumed with ActionMusicPlay.
/// </summary>
public class ActionMusicPause : ActionCommand
{
/// <summary>Pause is instant — the dialog continues without waiting for audio acknowledgment.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Pauses the current music track without stopping it, so <see cref="ActionMusicPlay"/> can resume it.</summary>
public override void DoRun(DialogRuntime runtime)
{
var audioService = Scene.Find<Node>("AudioService") as IAudioService;
audioService?.PauseMusic(true);
}
}
}
+28 -28
View File
@@ -1,28 +1,28 @@
using Cthangover.Core.Audio;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Resumes paused background music. Paired with ActionMusicPause.
/// </summary>
public class ActionMusicPlay : ActionCommand
{
/// <summary>Resume is instant — the dialog continues without waiting for audio.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Resumes music paused by <see cref="ActionMusicPause"/>.</summary>
public override void DoRun(DialogRuntime runtime)
{
var audioService = Scene.Find<Node>("AudioService") as IAudioService;
audioService?.PauseMusic(false);
}
}
}
using Cthangover.Core.Audio;
using Godot;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
using Cthangover.Core.UI.Event;
using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Resumes paused background music. Paired with ActionMusicPause.
/// </summary>
public class ActionMusicPlay : ActionCommand
{
/// <summary>Resume is instant — the dialog continues without waiting for audio.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Resumes music paused by <see cref="ActionMusicPause"/>.</summary>
public override void DoRun(DialogRuntime runtime)
{
var audioService = Scene.Find<Node>("AudioService") as IAudioService;
audioService?.PauseMusic(false);
}
}
}
+31 -31
View File
@@ -1,4 +1,4 @@
using Cthangover.Core.Utils;
using Cthangover.Core.Utils;
using Cthangover.Core.UI;
using Cthangover.Mods.Interface.Base.Lists;
using Cthangover.Core.UI.Dialog;
@@ -7,33 +7,33 @@ using Cthangover.Core.UI.Executable;
using Cthangover.Core.Scenarios;
using Cthangover.Core.Scenes;
using Cthangover.Core.Interactive;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Executes an arbitrary Action delegate inside the dialog queue.
/// Allows imperative code injection (e.g. quest state changes, UI toggles)
/// without creating a dedicated action class. NoWait so the queue advances
/// immediately after the delegate returns.
/// </summary>
public class ActionRun : ActionCommand
{
/// <summary>Arbitrary delegate executed during dialog sequencing. Null delegates are logged and skipped.</summary>
public System.Action Executable { get; set; }
/// <summary>The delegate runs and the dialog advances — no pausing.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Invokes <see cref="Executable"/>; a null delegate is logged and skipped so the queue keeps flowing.</summary>
public override void DoRun(DialogRuntime runtime)
{
if (Executable == null)
{
GameLogger.Log("DIALOG", "ActionRun: Executable delegate is null", LogLevel.Error);
return;
}
Executable();
}
}
}
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Executes an arbitrary Action delegate inside the dialog queue.
/// Allows imperative code injection (e.g. quest state changes, UI toggles)
/// without creating a dedicated action class. NoWait so the queue advances
/// immediately after the delegate returns.
/// </summary>
public class ActionRun : ActionCommand
{
/// <summary>Arbitrary delegate executed during dialog sequencing. Null delegates are logged and skipped.</summary>
public System.Action Executable { get; set; }
/// <summary>The delegate runs and the dialog advances — no pausing.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Invokes <see cref="Executable"/>; a null delegate is logged and skipped so the queue keeps flowing.</summary>
public override void DoRun(DialogRuntime runtime)
{
if (Executable == null)
{
GameLogger.Log("DIALOG", "ActionRun: Executable delegate is null", LogLevel.Error);
return;
}
Executable();
}
}
}
@@ -0,0 +1,25 @@
using Cthangover.Core.Scenes;
namespace Cthangover.Mods.Dialog.Action.Impls
{
/// <summary>
/// Sets a story flag of the running game (<see cref="ScenarioCondition.SetFlag"/>).
/// Unlike <see cref="ActionSet"/>, whose variables end with the dialog, a
/// flag is game state: it is saved, read by scenario conditions
/// (<c>condition: door == "open"</c>) and its change rescans the scene's
/// event chain, so a scenario waiting for it can start right after.
/// </summary>
public class ActionSetFlag : ActionCommand
{
/// <summary>Flag name, as used in conditions.</summary>
public string Name { get; set; }
/// <summary>Flag value; numeric values compare as integers in conditions.</summary>
public string Value { get; set; }
/// <summary>Setting a flag is instant — the dialog continues without pause.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <inheritdoc/>
public override void DoRun(DialogRuntime runtime) => ScenarioCondition.SetFlag(Name, Value ?? string.Empty);
}
}
@@ -35,7 +35,7 @@ namespace Cthangover.Mods.Dialog.Action.Impls
/// <summary>Scene switch is deferred — the dialog ends immediately with no return.</summary>
public override WaitType WaitType { get; set; } = WaitType.NoWait;
/// <summary>Marks the dialog locker as OneRun and defers <c>SceneManager.SwitchScene</c> so the tree is not mutated mid-queue.</summary>
/// <summary>Defers <c>SceneManager.SwitchScene</c> so the tree is not mutated mid-queue; the owning scenario is not forced into OneRun.</summary>
public override void DoRun(DialogRuntime runtime)
{
if (string.IsNullOrEmpty(SceneName))
+25 -15
View File
@@ -14,10 +14,12 @@ namespace Cthangover.Mods.Dialog.Action.Impls
/// subscriber and fires OnUpdateCallback(float t) each frame with a normalized
/// progress value (0→1) over WaitTime seconds. WaitType is WaitEvent so the
/// dialog runtime pauses until elapsed >= WaitTime, at which point the action
/// advances the runtime directly (event-driven — no DialogBox poll) and
/// destructs itself. OnStartCallback/OnFinishCallback bracket the animation
/// for setup/teardown. Fixed 60fps step for deterministic progress regardless
/// of actual frame rate.
/// completes itself through <see cref="DialogBox.CompleteAction"/> (event-driven —
/// no DialogBox poll) and the box advances the queue, scheduling the timer of a
/// following <c>delay</c> like any other advance. OnStartCallback/OnFinishCallback
/// bracket the animation for setup/teardown. Progress follows the controller's
/// process delta, so the timeline lasts WaitTime seconds of game time at any frame
/// rate (and scales with <c>Engine.TimeScale</c> exactly like <c>delay</c> timers).
/// </summary>
public class ActionTimedUpdate : ActionCommand, IOnUpdateEvent
{
@@ -31,7 +33,7 @@ namespace Cthangover.Mods.Dialog.Action.Impls
/// <summary>Fires once when the elapsed time exceeds <see cref="WaitTime"/> or when destructed.</summary>
public System.Action OnFinishCallback { get; set; }
/// <summary>Pauses the dialog until the elapsed time meets WaitTime — the action then advances the runtime itself.</summary>
/// <summary>Pauses the dialog until the elapsed time meets WaitTime — the action then completes itself.</summary>
public override WaitType WaitType { get; set; } = WaitType.WaitEvent;
/// <summary>Total duration in seconds over which <see cref="OnUpdateCallback"/> receives normalized progress.</summary>
public override float WaitTime { get; set; } = 1f;
@@ -39,12 +41,13 @@ namespace Cthangover.Mods.Dialog.Action.Impls
private float elapsed;
private bool isRunning;
private DialogRuntime runtime;
private SceneEventController controller;
/// <summary>Registers this action as an <see cref="IOnUpdateEvent"/> listener on the scene's event controller.</summary>
public override void DoConstruct()
{
base.DoConstruct();
var controller = Scene.Find<SceneEventController>("EventController");
controller = Scene.Find<SceneEventController>("EventController");
controller?.AddUpdateEventListener(this);
}
@@ -63,8 +66,8 @@ namespace Cthangover.Mods.Dialog.Action.Impls
base.DoDestruct();
isRunning = false;
runtime = null;
var controller = Scene.Find<SceneEventController>("EventController");
controller?.RemoveUpdateEventListener(this);
controller = null;
OnFinishCallback?.Invoke();
}
@@ -73,19 +76,26 @@ namespace Cthangover.Mods.Dialog.Action.Impls
if (!isRunning)
return;
elapsed += 1f / 60f;
elapsed += (float)(controller?.GetProcessDeltaTime() ?? 0d);
var t = WaitTime > 0f ? Mathf.Min(elapsed / WaitTime, 1f) : 1f;
OnUpdateCallback?.Invoke(t);
if (elapsed >= WaitTime)
if (elapsed < WaitTime)
return;
// Advancing destructs this action, which clears the runtime field:
// keep the runtime in a local for the whole completion.
isRunning = false;
var owner = runtime;
if (owner?.DialogBox != null)
{
// Advances the runtime directly instead of relying on a DialogBox poll.
// Next() destructs this action (firing OnFinishCallback and detaching the
// update listener), then Run() continues the queue past the WaitEvent point.
isRunning = false;
runtime?.Next();
runtime?.Run();
owner.DialogBox.CompleteAction(this);
}
else if (owner != null)
{
owner.Next();
owner.Run();
}
}
}