sprint A cleanup: accessibility, signals, race, debris

G: large_text scales global theme font (14→20 at 1.4×) via new
GameState.get_font_scale + EventBus.settings_changed. reduce_motion
gates ResumeToast fade (HintOverlay already gated).

I: InspectTooltip long-press wired (500ms hold, 12px drift cancel,
tap-to-clear pin). Stale Phase 19 TODO replaced with accurate doc.

H: Pawn.arrived_at_destination now also emitted on
EventBus.pawn_arrived_at_destination; DirtinessSystem subscribes and
bumps indoor traffic dirt (BUMP_INDOOR_TRAFFIC = 0.2). Outdoor-tracked
bump needs Pawn.prev_tile — flagged for Phase 20.

P: CraftingProvider caches ingredient item ref on Job.ingredient_item;
JobRunner._tick_pickup validates is_instance_valid + not being_carried
before the tile scan, cancels cleanly if another pawn grabbed it.

J: rest_provider.gd deleted. Removed @onready + register call from
world.gd, ext_resource + node from world.tscn. Provider count comment
updated to 9.

M: DIRTY_THRESHOLD extracted — cleaning_provider and job_runner now
reference DirtinessSystem.DIRT_DIRTY_THRESHOLD.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-05-16 18:38:14 +01:00
parent 2f76ae1639
commit fd6f958344
15 changed files with 157 additions and 62 deletions

View file

@ -33,6 +33,7 @@ signal tile_beauty_changed(tile: Vector2i, beauty: float) ## Emitted when beaut
signal tile_dirtiness_changed(tile: Vector2i, dirt: float) ## Emitted when dirtiness crosses a tier threshold (clean/dirty/filthy).
# Phase 14 — Death + corpses + burial.
signal pawn_arrived_at_destination(pawn, tile: Vector2i) ## Emitted by Pawn when a walk-toil completes. DirtinessSystem uses this for traffic-dirt bumps.
signal pawn_died(pawn, cause: StringName) ## Emitted right before Pawn is unregistered; corpse spawn handler listens here.
signal corpse_spawned(corpse) ## Emitted when a Corpse entity is added to the world (right after pawn_died handler).
signal corpse_buried(corpse, grave_marker) ## Emitted when a corpse reaches a GraveSlot and converts to a permanent GraveMarker.
@ -71,6 +72,9 @@ signal help_requested ## Settings "Help" button →
signal hint_dismissed(hint_id: StringName) ## Emitted by HintOverlay when player closes a hint; HintSystem persists the dismissal.
signal ui_panel_opened(panel_id: StringName) ## Emitted by UI panels (build_drawer, work_matrix, ...) when they become visible. HintSystem subscribes for tour gating.
# Accessibility (Phase 19 completion).
signal settings_changed ## Emitted by SettingsMenu._on_save_pressed() after GameState.apply_settings(); UI panels that honour accessibility flags re-read them here.
# Phase 18 — Alert wiring (dangling signals surfaced to AlertsLog).
signal no_stockpile_accepts(item_type: StringName, tile: Vector2i) ## Emitted by HaulingProvider when an item needs haul but no stockpile accepts it (rate-limited per item_type).
signal stockpile_layout_changed ## Emitted when any stockpile is added, removed, or has its filter/priority edited. HaulingProvider listens to reset haul_rejected items.

View file

@ -60,6 +60,12 @@ func save_dict() -> Dictionary:
}
## Returns a font-scale multiplier based on the accessibility_large_text setting.
## 1.0 = normal, 1.4 = large. Multiply any hardcoded font size by this value.
func get_font_scale() -> float:
return 1.4 if bool(settings.get("accessibility_large_text", false)) else 1.0
func apply_dict(d: Dictionary) -> void:
if d.has("current_map_id"):
current_map_id = StringName(d["current_map_id"])

View file

@ -17,9 +17,6 @@ class_name CleaningProvider extends WorkProvider
##
## Audit.log fires on job start and on toil completion (via JobRunner).
## Dirt level at or above which a tile is worth cleaning.
const DIRTY_THRESHOLD: float = 25.0
## Base number of sim ticks to clean a tile from any level to 0.
## No skill modifier for now; Phase 17 wires skill × speed.
const CLEAN_TICKS: int = 40
@ -48,7 +45,7 @@ func find_best_for(pawn) -> Job:
for tile in ds.dirt_map.keys():
var dirt_val: float = float(ds.dirt_map[tile])
if dirt_val < DIRTY_THRESHOLD:
if dirt_val < DirtinessSystem.DIRT_DIRTY_THRESHOLD:
continue
# target_node stores the Vector2i tile coordinate (field is untyped — accepts
# non-Node values). Dirty tiles have no scene Node; the tile position itself

View file

@ -141,6 +141,9 @@ func find_best_for(pawn) -> Job:
var j := Job.new()
j.label = "Craft %s at %s" % [best_bill.recipe.label, best_wb.get("label_text") if best_wb.get("label_text") != null else "workbench"]
j.target_node = best_wb
# Cache the primary ingredient ref so _tick_pickup can validate it is still
# available when the pawn arrives (guards against concurrent haul/crafting races).
j.ingredient_item = best_src1
if not ing2_items.is_empty():
# Two-ingredient path: deposit ingredient2 item(s) at workbench buffer,

View file

@ -25,6 +25,13 @@ var current_toil_index: int = 0
## on restored JobRunner state.
var target_node = null
## NOT serialized: the specific Item node reserved for the first PICKUP toil in a
## crafting job. Set by CraftingProvider.find_best_for() at proposal time.
## _tick_pickup validates via is_instance_valid + being_carried before picking up;
## aborts the job if the item is gone so the pawn re-routes rather than stealing
## a random item. null for all non-crafting jobs.
var ingredient_item = null
# ── claim helpers ────────────────────────────────────────────────────────────

View file

@ -316,7 +316,23 @@ func _tick_build(t) -> void:
## Finds the first unheld Item at pawn.tile in World.items.
## Transfers it into pawn.carried_item via set_being_carried(true).
## Completes in a single tick.
##
## Crafting-job race guard: if job.ingredient_item is set (cached at proposal time by
## CraftingProvider), validate that the cached item is still valid and not being carried
## before picking it up. If the item was taken by another pawn (or freed), cancel the
## job so Decision re-routes — prevents picking up the wrong item type.
func _tick_pickup(t) -> void:
# Validate cached ingredient ref (crafting jobs only).
if job != null and job.get("ingredient_item") != null:
var cached = job.ingredient_item
if not is_instance_valid(cached) or cached.being_carried:
Audit.log(
"job_runner",
"%s pickup: cached ingredient gone/taken — cancelling job" % pawn.pawn_name
)
cancel_job()
return
var item = null
for it in World.items:
if it.tile == pawn.tile and not it.being_carried:
@ -856,9 +872,8 @@ func _tick_treat(t) -> void:
## - Reduce dirt at the tile by DIRT_REDUCTION_PER_TICK via DirtinessSystem.bump_clean().
## - Done when dirt <= 0.
##
## DIRTY_THRESHOLD and DIRT_REDUCTION_PER_TICK mirror CleaningProvider constants.
## DIRT_REDUCTION_PER_TICK mirrors CleaningProvider / DirtinessSystem logic.
## 100.0 / 40 ticks = 2.5/tick ensures any tile (max 100 dirt) is clean in 40 ticks.
const _CLEAN_DIRTY_THRESHOLD: float = 25.0
const _DIRT_REDUCTION_PER_TICK: float = 2.5 # 100 / 40 ticks
func _tick_clean(t) -> void:
@ -873,7 +888,7 @@ func _tick_clean(t) -> void:
if not t.data.get("started", false):
# ── first-tick: validate tile is still worth cleaning ─────────────────
var current_dirt: float = ds.dirt_at(tile)
if current_dirt < _CLEAN_DIRTY_THRESHOLD:
if current_dirt < DirtinessSystem.DIRT_DIRTY_THRESHOLD:
Audit.log(
"job_runner",
"%s clean: tile %s already clean (dirt=%.1f) — skipping" % [pawn.pawn_name, tile, current_dirt]

View file

@ -1,31 +0,0 @@
class_name RestProvider extends WorkProvider
## Phase 3 smoke-test WorkProvider: sends every pawn to a shared rest tile.
##
## If the pawn is already at rest_tile, returns a walk-less idle-forever job.
## Otherwise prepends a walk_to toil before the idle toil.
##
## No internal state beyond rest_tile — Decision's log line carries all
## the info needed for debugging (pawn name + provider category + job label).
## The tile pawns walk toward. Set by the world scene on instantiation.
@export var rest_tile: Vector2i = Vector2i(40, 40)
func _init() -> void:
category = &"rest"
priority = 0 # Only provider in Phase 3; no relative ordering needed yet.
## Returns a Job for `pawn`. Never returns null — Rest always has something
## to offer (walk there, or idle in place).
## `pawn` is duck-typed: must expose .tile (Vector2i).
func find_best_for(pawn) -> Job:
var j := Job.new()
j.label = "Rest at %s" % rest_tile
if pawn.tile != rest_tile:
j.toils.append(Toil.walk_to(rest_tile))
j.toils.append(Toil.idle())
return j

View file

@ -214,6 +214,9 @@ func _ready() -> void:
# _ready (PawnDetailPanel, WorkbenchPanel, BuildDrawer) finish first.
call_deferred("_apply_theme_to_canvas_layers")
# Accessibility — live-update the global theme font size when settings change.
EventBus.settings_changed.connect(_on_settings_changed)
## Walks the scene tree and assigns _app_theme to every Control directly under
## a CanvasLayer (the topmost Control in each layer's branch). From there the
@ -237,3 +240,16 @@ func _seed_layer_theme(layer: CanvasLayer) -> void:
func _on_layer_child_added(node: Node) -> void:
if node is Control and node.theme == null:
node.theme = _app_theme
## Accessibility: re-scale the global theme default_font_size when the player
## toggles the "Larger Text" checkbox. Mutating the shared Theme Resource
## triggers Godot's Theme.changed signal, which re-lays-out every Control that
## inherits this theme — no per-panel wiring needed for regular Labels.
## Panels with hardcoded add_theme_font_size_override calls are unaffected here;
## they handle their own overrides by listening to EventBus.settings_changed.
func _on_settings_changed() -> void:
if _app_theme == null:
return
var base_size: int = 14
_app_theme.default_font_size = int(round(float(base_size) * GameState.get_font_scale()))

View file

@ -1139,6 +1139,7 @@ func _advance_walk() -> void:
_state_label.text = Strings.t(&"pawn.state.idle")
walk_completed.emit()
arrived_at_destination.emit(tile)
EventBus.pawn_arrived_at_destination.emit(self, tile)
Audit.log("pawn", "%s arrived at %s" % [pawn_name, tile])

View file

@ -1,24 +1,34 @@
extends CanvasLayer
## InspectTooltip — hover (or long-press) on a world tile to see what's there.
## InspectTooltip — hover (mouse) or long-press (touch) on a world tile to see
## what's there.
##
## Samples the mouse position every frame, maps to a tile, looks for an entity
## or zone at that tile, builds a short description, and renders a small panel
## offset from the cursor. Empty tile or off-map → tooltip hides.
## Mouse path: samples position every frame, maps to a tile, builds a short
## description, renders a small panel offset from the cursor.
## Empty tile or off-map → tooltip hides.
##
## Touch fallback: long-press on a tile triggers the same lookup and pins the
## tooltip until the next click anywhere (Phase 17 long-press inspect from the
## design doc). Desktop hovering is the primary path on PC; the long-press
## path is wired via Selection's long-press detector (TODO Phase 19).
## Touch path: finger held for LONG_PRESS_MS without drifting more than
## LONG_PRESS_DRIFT_PX pins the tooltip at the held tile until the next tap
## anywhere. Touch-down cancels a previous pin. This self-contained path does
## not depend on Selection; it reads the same tile + description helpers.
const TILE_SIZE_PX: int = 16
const CURSOR_OFFSET: Vector2 = Vector2(14, 14)
const EDGE_MARGIN_PX: int = 8
const LONG_PRESS_MS: int = 500 # ms finger must be held to trigger inspect
const LONG_PRESS_DRIFT_PX: float = 12.0 # cancel long-press if finger moves more than this
var _panel: PanelContainer = null
var _label: RichTextLabel = null
var _last_tile: Vector2i = Vector2i(-9999, -9999)
var _last_text: String = ""
# Touch long-press state.
var _touch_pressing: bool = false
var _touch_screen_pos: Vector2 = Vector2.ZERO
var _touch_start_ms: int = 0
var _touch_pinned: bool = false # true while a long-press pin is held open
var _touch_pin_tile: Vector2i = Vector2i(-9999, -9999)
func _ready() -> void:
layer = 50 # below modals (which are 100+), above world
@ -58,10 +68,65 @@ func _ready() -> void:
_panel.add_child(_label)
## Touch-input handler for long-press inspect.
## InputEventScreenTouch press starts the long-press clock; release or excess
## drift cancels it. A subsequent tap anywhere while pinned dismisses the panel.
func _input(event: InputEvent) -> void:
if event is InputEventScreenTouch:
if event.pressed:
if _touch_pinned:
# A new tap clears the pin.
_touch_pinned = false
_panel.visible = false
_last_text = ""
get_viewport().set_input_as_handled()
return
_touch_pressing = true
_touch_screen_pos = event.position
_touch_start_ms = Time.get_ticks_msec()
else:
# Finger lifted — cancel the pending long-press (pin only fires from _process).
_touch_pressing = false
elif event is InputEventScreenDrag and _touch_pressing:
var drift: float = event.position.distance_to(_touch_screen_pos)
if drift > LONG_PRESS_DRIFT_PX:
_touch_pressing = false
func _process(_dt: float) -> void:
var vp := get_viewport()
if vp == null:
return
# ── Touch long-press poll ─────────────────────────────────────────────────
if _touch_pressing and not _touch_pinned:
var held_ms: int = Time.get_ticks_msec() - _touch_start_ms
if held_ms >= LONG_PRESS_MS:
_touch_pressing = false
_touch_pinned = true
# Describe tile under held finger.
var world_touch: Vector2 = vp.get_canvas_transform().affine_inverse() * _touch_screen_pos
_touch_pin_tile = Vector2i(
floori(world_touch.x / float(TILE_SIZE_PX)),
floori(world_touch.y / float(TILE_SIZE_PX)),
)
if _tile_in_map(_touch_pin_tile):
var pin_text: String = _describe_tile(_touch_pin_tile)
if pin_text != "":
_label.text = pin_text
_last_text = pin_text
_panel.reset_size()
_panel.visible = true
_position_near(_touch_screen_pos)
return
# Nothing to show — cancel pin.
_touch_pinned = false
# Pinned: keep the panel up; skip the mouse-hover update.
if _touch_pinned:
return
# ── Mouse hover path ──────────────────────────────────────────────────────
var mouse_screen: Vector2 = vp.get_mouse_position()
# Convert screen → world via canvas transform (selection.gd does the same).
var world_pos: Vector2 = vp.get_canvas_transform().affine_inverse() * mouse_screen

View file

@ -97,6 +97,11 @@ func _on_load_finished(_slot: StringName, ok: bool, real_seconds_away: int) -> v
func _start_fade() -> void:
if bool(GameState.settings.get("accessibility_reduce_motion", false)):
# Snap to hidden immediately — no fade animation.
_root.visible = false
_root.modulate = Color.WHITE
return
_fading = true
_fade_time = FADE_DURATION_SEC

View file

@ -302,6 +302,7 @@ func _unhandled_input(event: InputEvent) -> void:
func _on_save_pressed() -> void:
GameState.apply_settings(_collect_to_dict())
EventBus.settings_changed.emit()
Audit.log("settings_menu", "settings saved")
_set_visible(false)

View file

@ -22,10 +22,9 @@ class_name DirtinessSystem extends Node
## This keeps signal volume low since bumps fire 20×/s per pawn crossing.
##
## Pawn tile-change hook:
## World scene calls bump_pawn_traffic(tile, indoor) each time a pawn advances
## a tile. Indoor traffic adds 0.2; outdoor-tracked-in adds 0.5.
## (world.gd bridges _advance_walk → DirtinessSystem via the arrived_at_destination
## signal on each Pawn — wired in world.gd _spawn_sample_pawns / _on_pawn_ready.)
## _ready() connects to EventBus.pawn_arrived_at_destination. Indoor arrivals bump
## BUMP_INDOOR_TRAFFIC (0.2); outdoor arrivals are skipped. Phase 20 can upgrade to
## BUMP_OUTDOOR_TRACKED (0.5) on outdoor→indoor transitions once Pawn.prev_tile lands.
##
## Wire as child of the World scene (after Pathfinder). world.gd exposes the
## instance on the World autoload as World.dirtiness_system for entity code.
@ -34,6 +33,10 @@ class_name DirtinessSystem extends Node
## Keys = Vector2i tile coords; Values = float in [0, 100].
var dirt_map: Dictionary = {}
func _ready() -> void:
EventBus.pawn_arrived_at_destination.connect(_on_pawn_arrived_at_destination)
## Tier boundaries (thresholds match design.md; tune Phase 20).
const DIRT_DIRTY_THRESHOLD: float = 25.0
const DIRT_FILTHY_THRESHOLD: float = 60.0
@ -71,13 +74,23 @@ func bump_clean(tile: Vector2i, amount: float) -> void:
_set_dirt(tile, old_val, new_val)
## Traffic-driven dirt bump. Called by World when a pawn arrives at a new tile.
## `indoor` = true when the tile is inside a roofed room (World.is_indoor check).
## Traffic-driven dirt bump. Called internally by _on_pawn_arrived_at_destination.
## `indoor` = true when the destination tile is inside a roofed room (World.is_indoor check).
func bump_pawn_traffic(tile: Vector2i, indoor: bool) -> void:
var amount := BUMP_INDOOR_TRAFFIC if indoor else BUMP_OUTDOOR_TRACKED
bump(tile, amount)
## Pawn arrival handler — wired to EventBus.pawn_arrived_at_destination in _ready().
## Skips outdoor arrivals (no floor to dirty); bumps indoor tiles by BUMP_INDOOR_TRAFFIC.
## Phase 20 follow-up: add Pawn.prev_tile tracking so an outdoor→indoor transition can
## instead use BUMP_OUTDOOR_TRACKED (0.5) to model boots tracking mud in.
func _on_pawn_arrived_at_destination(_pawn, dest_tile: Vector2i) -> void:
if not World.is_indoor(dest_tile):
return # Only dirtiness indoor floor tiles.
bump_pawn_traffic(dest_tile, true)
# ── save / load ───────────────────────────────────────────────────────────────
## Serialise the sparse dirt map as an array of {x, y, v} dicts.

View file

@ -129,7 +129,6 @@ const SEASON_TINTS: Dictionary = {
@onready var pathfinder: Pathfinder = $Pathfinder
@onready var selection: Selection = $Selection
@onready var designation_ctl: Designation = $DesignationCtl
@onready var rest_provider: RestProvider = $RestProvider
@onready var chop_provider: ChopProvider = $ChopProvider
@onready var mine_provider: MineProvider = $MineProvider
@onready var hauling_provider: HaulingProvider = $HaulingProvider
@ -216,9 +215,9 @@ func _ready() -> void:
# completion (Tree.fell, Wall._complete, etc.).
World.designation_ctl = designation_ctl
# Register all 10 providers — Decision iterates by .priority desc.
# Register all 9 providers — Decision iterates by .priority desc.
# doctor=9 > sleep=8 > eat=7 > construction=6 > chop=5 ≈ plant=5 > mine=4
# ≈ crafting=4 > haul=3 > rest=0.
# ≈ crafting=4 > haul=3 > clean=2.
# Phase 17 will tune these via the work-priority matrix UI.
World.register_work_provider(doctor_provider)
World.register_work_provider(sleep_provider)
@ -229,8 +228,7 @@ func _ready() -> void:
World.register_work_provider(crafting_provider)
World.register_work_provider(plant_provider)
World.register_work_provider(hauling_provider)
World.register_work_provider(cleaning) # priority 2 — between haul (3) and rest (0)
World.register_work_provider(rest_provider)
World.register_work_provider(cleaning) # priority 2 — between haul (3) and idle
# Phase 5: bridge designation paint events → spawn the ghost-state entity
# at that tile and register it as a build site.

View file

@ -4,7 +4,6 @@
[ext_resource type="PackedScene" uid="uid://rimlike_camera_rig" path="res://scenes/world/camera_rig.tscn" id="2_camera"]
[ext_resource type="Script" path="res://scenes/world/pathfinder.gd" id="3_pathfinder"]
[ext_resource type="Script" path="res://scenes/world/selection.gd" id="4_selection"]
[ext_resource type="Script" path="res://scenes/ai/rest_provider.gd" id="5_rest_provider"]
[ext_resource type="Script" path="res://scenes/ai/chop_provider.gd" id="6_chop_provider"]
[ext_resource type="Script" path="res://scenes/ai/mine_provider.gd" id="7_mine_provider"]
[ext_resource type="Script" path="res://scenes/ai/hauling_provider.gd" id="8_hauling_provider"]
@ -60,10 +59,6 @@ script = ExtResource("4_selection")
[node name="DesignationCtl" type="Node" parent="."]
script = ExtResource("10_designation")
[node name="RestProvider" type="Node" parent="."]
script = ExtResource("5_rest_provider")
rest_tile = Vector2i(50, 50)
[node name="ChopProvider" type="Node" parent="."]
script = ExtResource("6_chop_provider")