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:
parent
2f76ae1639
commit
fd6f958344
15 changed files with 157 additions and 62 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 ────────────────────────────────────────────────────────────
|
||||
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue