From 8d91b1874561aba03c49af9dee8532fb5f626148 Mon Sep 17 00:00:00 2001 From: devilmaker20 <322856132+devilmaker20@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:43:44 +0000 Subject: [PATCH] Fix world.tod_changed firing every frame while a world.tod hook is active OverworldState:timeOfDay() compared the hooked period with the raw clock period instead of the period last reported. A world.tod hook that returns a different period than the clock (e.g. EVENING while the clock says DAY) therefore re-emitted world.tod_changed on every call, i.e. every frame. Compare with self.tod, as the unhooked path already does. Co-Authored-By: Claude Opus 5.5 --- src/world/OverworldController.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/world/OverworldController.lua b/src/world/OverworldController.lua index 2eab2e4bf..859d45e37 100644 --- a/src/world/OverworldController.lua +++ b/src/world/OverworldController.lua @@ -2493,15 +2493,17 @@ function OverworldState:timeOfDay() steps = self.todSteps or 0, }) if type(nextTod) ~= "string" or nextTod == "" then nextTod = tod end - if nextTod ~= tod then - self.tod = nextTod - if Runtime.wants("world.tod_changed") then - Runtime.emit("world.tod_changed", { - tod = nextTod, previous = tod, mapId = map and map.id, - }) - end - else - self.tod = nextTod + -- Compare with the period this state last reported, not with the raw + -- clock: a hook that keeps returning a period other than the clock's (for + -- example EVENING while the clock says DAY) would otherwise re-announce the + -- same change on every call, i.e. every frame. Same rule as the unhooked + -- path above: a first assignment (previous == nil) is not a change. + local previous = self.tod + self.tod = nextTod + if nextTod ~= previous and previous and Runtime.wants("world.tod_changed") then + Runtime.emit("world.tod_changed", { + tod = nextTod, previous = previous, mapId = map and map.id, + }) end self:syncGen2Tod(self.tod) return self.tod