The HUD's office rows: will and stress bars, blood, consciousness, goal, death cause, last cut, and a Silence button per stressor

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 03:11:46 +01:00
commit a61611d7ce
4 changed files with 107 additions and 8 deletions

View file

@ -26,7 +26,7 @@ public partial class Chamber : Node3D
public float Glow { get; private set; }
/// <summary>The office has no chamber: hidden, and the glow light it casts off.</summary>
public void Hide()
public new void Hide()
{
Visible = false;
Glow = 0f;

View file

@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Text;
using BadDay.Core;
using BadDay.Ymir;
@ -18,8 +19,16 @@ public partial class Hud : CanvasLayer
public Hud(Main main) => _main = main;
private readonly VBoxContainer _chamberControls = new();
private readonly VBoxContainer _officeControls = new();
private readonly Dictionary<string, Button> _silence = new();
public OptionButton ScenarioPicker { get; } = new();
/// <summary>His will, 0 to 1 (lodur:ruling:bds-will-visible).</summary>
public ProgressBar WillBar { get; } = new() { MinValue = 0, MaxValue = 1, Step = 0, ShowPercentage = false, CustomMinimumSize = new Vector2(220, 18) };
/// <summary>His arousal, 0 to 1 (lodur:ruling:stress-bar-shows-arousal-calm-silences).</summary>
public ProgressBar StressBar { get; } = new() { MinValue = 0, MaxValue = 1, Step = 0, ShowPercentage = false, CustomMinimumSize = new Vector2(220, 18) };
/// <summary>One button per stressor of the office's cause, by id.</summary>
public IReadOnlyDictionary<string, Button> SilenceButtons => _silence;
public SpinBox SeedBox { get; } = new() { MinValue = 0, MaxValue = 999999999, Step = 1, Value = 1 };
public Button ResetButton { get; } = new() { Text = "Reset" };
public HSlider IntensitySlider { get; } = new() { MinValue = 0, MaxValue = PainBox.MaxLevel, Step = 0.05, CustomMinimumSize = new Vector2(220, 24) };
@ -61,6 +70,21 @@ public partial class Hud : CanvasLayer
ScenarioPicker.ItemSelected += i => _main.SetScenario((Scenario)ScenarioPicker.GetItemId((int)i));
controls.AddChild(ScenarioPicker);
controls.AddChild(_officeControls);
_officeControls.AddChild(new Label { Text = "Will", Modulate = Ink });
_officeControls.AddChild(WillBar);
_officeControls.AddChild(new Label { Text = "Stress", Modulate = Ink });
_officeControls.AddChild(StressBar);
_officeControls.AddChild(new Label { Text = "Silence", Modulate = Ink });
foreach (var stressor in Main.OfficeParameters.Cause.Stressors)
{
var id = stressor.Id;
var button = new Button { Text = id };
button.Pressed += () => _main.Silence(id);
_silence[id] = button;
_officeControls.AddChild(button);
}
controls.AddChild(_chamberControls);
_chamberControls.AddChild(new Label { Text = "Intensity", Modulate = Ink });
IntensitySlider.Value = _main.Intensity;
@ -82,11 +106,11 @@ public partial class Hud : CanvasLayer
}
_chamberControls.Visible = _main.Scenario == Scenario.Chamber;
_officeControls.Visible = _main.Scenario == Scenario.Office;
_text.Clear();
if (_main.Scenario == Scenario.Office)
{
_text.Append($"office seed {_main.Seed} t {_main.Run.TickIndex * OfficeBody.TickSeconds:F2} s (tick {_main.Run.TickIndex})\n");
_readout.Text = _text.ToString();
OfficeReadout(_main.Office);
return;
}
@ -107,5 +131,24 @@ public partial class Hud : CanvasLayer
_readout.Text = _text.ToString();
}
private void OfficeReadout(OfficeBodySession o)
{
WillBar.Value = o.Will;
StressBar.Value = o.Arousal;
_text.Append($"office seed {_main.Seed} t {o.TickIndex * OfficeBody.TickSeconds:F2} s (tick {o.TickIndex})\n");
_text.Append($"will {o.Will:F2} stress {o.Arousal:F2} goal {o.Goal}\n");
_text.Append($"blood loss {o.BloodLoss * 100:F0} % of lethal blood spilled {o.BloodEmitted * 1000:F2} L\n");
_text.Append($"consciousness {o.Consciousness:F2} air hunger {o.AirHunger:F2}\n");
if (o.Dead) _text.Append($"DEAD: {o.DeathCause}\n");
else _text.Append(o.Finished ? "finished\n" : "running\n");
_text.Append(_main.Cuts.Count > 0 ? $"last cut: {_main.Cuts[^1].Part} at tick {_main.Cuts[^1].Tick}\n" : "no cuts yet\n");
var events = _main.Events;
for (int i = System.Math.Max(0, events.Count - LogLines); i < events.Count; i++)
{
_text.Append($"{events[i].Tick * OfficeBody.TickSeconds,6:F2} s {events[i].Events}\n");
}
_readout.Text = _text.ToString();
}
private static string Ms(long? ms) => ms is { } v ? $"{v / 1000.0:F2} s" : "-";
}

View file

@ -52,6 +52,14 @@ public partial class Main : Node3D
/// <summary>The parameters of an office run: every default except the 1/120 s tick the body needs.</summary>
public static StressParameters OfficeParameters { get; } = new() { TickSeconds = OfficeBody.TickSeconds };
/// <summary>A cut the knife opened: the part's label and the tick.</summary>
public readonly record struct Cut(string Part, long Tick);
private readonly List<Cut> _cuts = new();
/// <summary>Every cut opened since the last Reset, oldest first: a log for the HUD.</summary>
public IReadOnlyList<Cut> Cuts => _cuts;
public bool SlowMotion { get; private set; }
/// <summary>Every event the session has reported since the last Reset, oldest first.</summary>
@ -136,6 +144,7 @@ public partial class Main : Node3D
_run = null;
Failure = null;
_events.Clear();
_cuts.Clear();
Seed = seed;
try
{
@ -159,6 +168,9 @@ public partial class Main : Node3D
_intensity = level;
}
/// <summary>The player silences a stressor of the office.</summary>
public void Silence(string stressorId) => Office.Silence(stressorId);
public void SwitchOff() => (_run as BodyPainBoxSession)?.SwitchOff();
/// <summary>

View file

@ -21,7 +21,7 @@ public partial class Smoke : Node
private readonly List<string> _failures = new();
private Main _main = null!;
private BodyPainBoxSession? _lastSession;
private IBodyRun? _lastSession;
private long _lastTick;
private bool _done;
@ -47,7 +47,7 @@ public partial class Smoke : Node
_main = GD.Load<PackedScene>("res://Main.tscn").Instantiate<Main>();
AddChild(_main);
if (_main.Failure is { } failure) Check(false, "Main could not start a session: " + failure);
else await Scenario();
else await ChamberScenario();
}
catch (Exception e)
{
@ -56,7 +56,7 @@ public partial class Smoke : Node
Finish();
}
private async Task Scenario()
private async Task ChamberScenario()
{
CheckEngineAndScene();
if (_failures.Count > 0) return;
@ -164,6 +164,50 @@ public partial class Smoke : Node
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
Check(!Session.BoxOn && _main.Chamber.Glow == 0f && Hud.Readout.Contains("box intensity 0.00 off"), $"after Box off on a finished run: on {Session.BoxOn}, glow {_main.Chamber.Glow}");
await OfficeScenario();
}
/// <summary>The office, chosen through the HUD's picker: the bars, Silence, and the way back to the chamber.</summary>
private async Task OfficeScenario()
{
Hud.SeedBox.Value = Seed;
Hud.ScenarioPicker.Select((int)Scenario.Office);
Hud.ScenarioPicker.EmitSignal(OptionButton.SignalName.ItemSelected, (long)Scenario.Office);
Check(_main.Scenario == Scenario.Office && _main.Seed == Seed, $"the picker left Main in {_main.Scenario}, seed {_main.Seed}");
var office = Office;
Check(!_main.Chamber.Visible && _main.Chamber.Glow == 0f, "the chamber is drawn in the office");
await UntilTick(600);
// The bars are the session's will and arousal, to the bit, once a frame has drawn them (stepping paused so the session holds still).
_main.SetPhysicsProcess(false);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
Check(Hud.WillBar.Value == office.Will && Hud.StressBar.Value == office.Arousal,
$"bars show will {Hud.WillBar.Value} and stress {Hud.StressBar.Value}; the session has {office.Will} and {office.Arousal}");
_main.SetPhysicsProcess(true);
_lastSession = null;
// Silence is the HUD's button for the stressor, and the session logs it.
Check(Hud.SilenceButtons.Count == Main.OfficeParameters.Cause.Stressors.Count, $"{Hud.SilenceButtons.Count} Silence buttons for {Main.OfficeParameters.Cause.Stressors.Count} stressors");
int silenced = office.Result().Timeline.Count(e => e.Kind == StressEntryKind.Silenced);
Hud.SilenceButtons["printer"].EmitSignal(BaseButton.SignalName.Pressed);
Check(office.Result().Timeline.Count(e => e.Kind == StressEntryKind.Silenced) == silenced + 1, "Silence did not put a Silenced row in the result");
await Frame();
// Back to the chamber: the office run is gone and the chamber is drawn.
Hud.ScenarioPicker.Select((int)Scenario.Chamber);
Hud.ScenarioPicker.EmitSignal(OptionButton.SignalName.ItemSelected, (long)Scenario.Chamber);
await Frame();
Check(_main.Scenario == Scenario.Chamber && _main.Run is BodyPainBoxSession, "switching back did not make the pain box the live run");
Check(_main.Chamber.Visible, "the chamber is hidden after switching back");
Check(Throws(() => _ = office.TickIndex), "the office run was not disposed by the switch");
}
private static bool Throws(Action a)
{
try { a(); return false; }
catch (ObjectDisposedException) { return true; }
}
private void CheckEngineAndScene()
@ -246,7 +290,7 @@ public partial class Smoke : Node
{
await ToSignal(GetTree(), SceneTree.SignalName.PhysicsFrame);
if (_main.Failure is { } failure) throw new InvalidOperationException(failure);
var s = Session;
var s = _main.Run;
if (ReferenceEquals(s, _lastSession) && !s.Finished) Check(s.TickIndex == _lastTick + 1, $"{s.TickIndex - _lastTick} steps in one physics frame");
_lastSession = s;
_lastTick = s.TickIndex;
@ -259,7 +303,7 @@ public partial class Smoke : Node
private async Task UntilTick(long tick)
{
while (Session.TickIndex < tick && !Session.Finished) await Frame();
while (_main.Run.TickIndex < tick && !_main.Run.Finished) await Frame();
}
/// <summary>Session steps per real second over the next <paramref name="milliseconds"/>.</summary>