From 07b8db1683d8ec71b4295fb59e21e9955a96b20e Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Sun, 8 Nov 2026 20:19:15 +0000 Subject: [PATCH] The tutorial's sun waits for you (Gitea #5): the afternoon goes no later than 16:30 until the torch step brings dusk --- scripts/core/guide.gd | 22 ++++++++++++++++++++++ tests/test_tutorial.gd | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/scripts/core/guide.gd b/scripts/core/guide.gd index c4f7429..7fe60a9 100644 --- a/scripts/core/guide.gd +++ b/scripts/core/guide.gd @@ -324,12 +324,34 @@ func _process(delta: float) -> void: if d > 0.01 and d < 5.0: # (not a teleport or a respawn) _count("walk", d) _last_pos = p + hold_daylight() _marker_t -= delta if _marker_t <= 0.0: _marker_t = 0.5 _marker = find_marker() poll() +## The sun waits for you (Gitea #5): until a step that sets the clock comes +## up (the torch step, at dusk), the afternoon goes no later than +## DAYLIGHT_UNTIL, however long the earlier steps take. Then dusk comes on +## when the tutorial means it to. +const DAYLIGHT_UNTIL := 16.5 +func hold_daylight() -> void: + if not active or world == null or not is_instance_valid(world) or world.day_night == null: + return + if _clock_step_reached(): + return + var latest := DAYLIGHT_UNTIL / 24.0 + if world.day_night.time > latest: + world.day_night.time = latest + +## Whether the current step, or one before it, moves the clock on. +func _clock_step_reached() -> bool: + for i in range(mini(index + 1, steps.size())): + if Dictionary(steps[i].get("setup", {})).has("time"): + return true + return false + ## Goals that are states, not events: checked twice a second. func poll() -> void: if not active or world == null or not is_instance_valid(world): diff --git a/tests/test_tutorial.gd b/tests/test_tutorial.gd index 033284f..49caa32 100644 --- a/tests/test_tutorial.gd +++ b/tests/test_tutorial.gd @@ -135,6 +135,23 @@ func _starts() -> void: "\"%s\" / \"%s\"" % [pn._chapter.text, pn._title.text]) check(G.guide_name == "Old Tam" and pn._text.text.begins_with("Old Tam: \""), "Old Tam the hermit talks you through it: %s" % pn._text.text) check(G.find_marker() == Vector3.INF, "(no marker for that one)") + # Gitea #5: the sun waits for you until the torch step brings dusk. + var dn: Node = world.day_night + var t0: float = dn.time + dn.time = 19.0 / 24.0 + G.hold_daylight() + check(absf(dn.time * 24.0 - G.DAYLIGHT_UNTIL) < 0.01, "early in the tutorial the afternoon goes no later than %.1f h (%.2f)" % [G.DAYLIGHT_UNTIL, dn.time * 24.0]) + var torch_i := -1 + for i in range(G.steps.size()): + if String(G.steps[i].id) == "torch": + torch_i = i + var was_i: int = G.index + G.index = torch_i + dn.time = 19.0 / 24.0 + G.hold_daylight() + check(torch_i > 0 and absf(dn.time * 24.0 - 19.0) < 0.01, "from the torch step on, night comes as usual") + G.index = was_i + dn.time = t0 func _chapter_one() -> void: print("1. look around")