rimlike/scenes/world/designation.gd
megaproxy 9cf9b7dbfd Phase 13: Rooms + Auto-roof + Beauty + Dirtiness + Cleaning
Three-agent fan-out — Opus pre-wrote Room class, World.rooms/room_at_tile/is_indoor,
4 EventBus signals before dispatch so the slices ran fully parallel.

DECISION: Big-room UX = bump auto-roof cap to 16, banner above. Cabin
(24 tiles) intentionally exceeds cap to exercise the warning path; a
5×5 test shed (9 interior tiles) was added to exercise the roof path.

Room detection (Agent A):
- scenes/world/room.gd — class_name Room, tiles/bounds/is_under_roof,
  contains_tile() bounds-then-list-checked, recompute_bounds()
- scenes/world/room_detector.gd — class_name RoomDetector, BFS 4-dir
  from floor/door tiles, walls/terrain as boundary, doors counted as
  room interior. Detects up to 4× cap; auto-roofs only ≤16.
- World.mark_wall_tile/mark_floor_tile/mark_door_tile hook BFS recompute
- Door._complete() now erases wall-layer stamp + registers door tile
- Designation.TOOL_NO_ROOF paint mode wired (UI button deferred Phase 17)
- EventBus.room_changed / room_too_large signals

Indoor/Shelter (Agent B):
- Pawn._is_sheltered() rerouted: World.is_indoor() first, floor-proxy fallback
- IndoorTintOverlay Node2D — _draw fills roofed-room tiles at α=0.10 warm
- Crop._on_sim_tick skips stage advance when World.is_indoor(tile)

Beauty + Dirtiness + Cleaning + Room thoughts (Agent C):
- BeautySystem sparse map, linear falloff radius=3, Quality multiplier
  (SHODDY 0.5 → LEGENDARY 2.5). Base: Bed +2, Workbench +1, Torch +3, Hearth +4
- DirtinessSystem 0-100, tier crossings (clean<25/dirty<60/filthy≥60)
  emit tile_dirtiness_changed. bump/bump_clean/bump_pawn_traffic API
- CleaningProvider priority=2, KIND_CLEAN toil, 2.5 dirt/tick for ~40 ticks
- Bed/Torch/Workbench _complete() now register with BeautySystem
- 7 room mood thoughts: clean_room (+2), dirty_room (-3), filthy_room (-6),
  beautiful_room (+4), ugly_room (-3), slept_in_room (+3 EVENT, wires Ph 17),
  ate_without_table (-3 EVENT, wires Ph 17)
- Pawn._sync_room_thoughts called from _process_thoughts after cold block,
  defensive against null rooms/systems

Integration recovery (Opus):
- Agent C's BeautySystem/DirtinessSystem/CleaningProvider/IndoorTintOverlay
  instantiation in world.gd never landed (only field declarations + entity
  hooks survived). Added preloads + runtime add_child + autoload bindings +
  CleaningProvider registration + furniture pre-seed in _ready
- Added _prestamp_test_shed_for_room_detector with _spawn_complete_wall/floor
  helpers so a 5×5 visible shed exercises the auto-roof path at boot

MCP runtime verified:
- Rooms: cabin Room#2 size=24 roofed=false (room_too_large fires),
  shed Room#3 size=9 roofed=true (auto-roof active)
- beauty_map size=50 around prebuilt furniture; bed at (47,24) beauty=4.0
- Bram teleported to (36, 25) in shed → indoor=true, sheltered=true,
  thoughts=[clean_room +2], mood=52.0
- Screenshot: shed walls + brown floor visible; cabin warmly torch-lit;
  Spring 1/12 indicator; Day 1 07:52

Delegation: 3× gdscript-refactor (Sonnet) agents in parallel;
integration recovery + MCP verify on Opus.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 17:19:23 +01:00

185 lines
7.1 KiB
GDScript

extends Node
class_name Designation
## Phase 5 — Designation paint mode.
##
## Captures mouse input to drag-paint ghost tiles on Layer 3 (designation_layer)
## of the world TileMap. Each new cell painted emits EventBus.designation_added;
## removing a ghost emits EventBus.designation_cleared.
##
## Integrates with Selection: raises Selection.designation_active while a non-none
## tool is active so Selection does not also process those clicks.
##
## Opus wires the node into world.tscn and calls bind() + set_active_tool() from
## the build-drawer UI.
# ── tool constants ───────────────────────────────────────────────────────────
const TOOL_NONE: StringName = &"none"
const TOOL_BUILD_WALL: StringName = &"build_wall"
const TOOL_BUILD_FLOOR: StringName = &"build_floor"
const TOOL_BUILD_DOOR: StringName = &"build_door"
# Phase 13 — no-roof designation: painted tiles become courtyards; RoomDetector
# excludes them from auto-roofing. Calls World.toggle_no_roof_at() on apply.
const TOOL_NO_ROOF: StringName = &"no_roof"
# Atlas coords on the shared placeholder tileset (source 0).
# build_wall → stone-grey (2, 0); build_floor → dirt-brown (1, 0).
# build_door → dark stone (3, 0) so the ghost reads visually distinct from walls.
# no_roof → grass (0, 0) with the designation layer modulate tinting it visibly.
const _ATLAS_BY_TOOL: Dictionary = {
&"build_wall": Vector2i(2, 0),
&"build_floor": Vector2i(1, 0),
&"build_door": Vector2i(3, 0),
&"no_roof": Vector2i(0, 0),
}
# Placeholder source ID — mirrors World.PLACEHOLDER_SOURCE_ID.
const _SOURCE_ID: int = 0
# Tile-size in pixels — mirrors World.TILE_SIZE_PX.
const _TILE_SIZE_PX: float = 16.0
# ── signals ──────────────────────────────────────────────────────────────────
signal designation_added(cell: Vector2i, tool: StringName)
signal designation_cleared(cell: Vector2i)
# ── state ────────────────────────────────────────────────────────────────────
var _tool: StringName = TOOL_NONE
var _paint_layer: TileMapLayer = null
var _selection: Selection = null # optional; raised/lowered for input hand-off
# cell → tool that placed the ghost.
var _painted: Dictionary = {} # Dictionary[Vector2i, StringName]
# Stroke deduplication — cells touched in the current mouse-down session.
var _stroke_cells: Dictionary = {} # Dictionary[Vector2i, bool]
var _stroke_active: bool = false
# ── public API ───────────────────────────────────────────────────────────────
## Call once from World._ready() with the TileMapLayer at index 3 (Designation)
## and the sibling Selection node.
func bind(paint_layer: TileMapLayer, selection: Selection = null) -> void:
assert(paint_layer != null, "Designation.bind: paint_layer is null")
_paint_layer = paint_layer
_selection = selection
## Activate a paint tool. Pass TOOL_NONE to deactivate.
func set_active_tool(tool: StringName) -> void:
assert(
tool in [TOOL_NONE, TOOL_BUILD_WALL, TOOL_BUILD_FLOOR, TOOL_BUILD_DOOR, TOOL_NO_ROOF],
"Designation.set_active_tool: unknown tool '%s'" % tool
)
_tool = tool
_stroke_active = false
_stroke_cells.clear()
_sync_selection_flag()
if tool == TOOL_NONE:
Audit.log("designation", "tool deactivated")
else:
Audit.log("designation", "tool set to '%s'" % tool)
func active_tool() -> StringName:
return _tool
## Remove the ghost for a single cell and emit designation_cleared.
func clear_cell(cell: Vector2i) -> void:
if not _painted.has(cell):
return
_painted.erase(cell)
if _paint_layer != null:
_paint_layer.erase_cell(cell)
designation_cleared.emit(cell)
EventBus.designation_cleared.emit(cell)
Audit.log("designation", "cleared cell %s" % cell)
## Returns all cells that currently have an active ghost.
func cells() -> Array[Vector2i]:
var result: Array[Vector2i] = []
for c: Vector2i in _painted.keys():
result.append(c)
return result
# ── input ────────────────────────────────────────────────────────────────────
func _unhandled_input(event: InputEvent) -> void:
if _tool == TOOL_NONE or _paint_layer == null:
return
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
_stroke_active = true
_stroke_cells.clear()
_paint_at_screen(event.position)
else:
_stroke_active = false
_stroke_cells.clear()
get_viewport().set_input_as_handled()
return
if event is InputEventMouseMotion and _stroke_active:
_paint_at_screen(event.position)
get_viewport().set_input_as_handled()
# ── helpers ──────────────────────────────────────────────────────────────────
func _paint_at_screen(screen_pos: Vector2) -> void:
var world_pos: Vector2 = get_viewport().get_canvas_transform().affine_inverse() * screen_pos
var cell := Vector2i(
floori(world_pos.x / _TILE_SIZE_PX),
floori(world_pos.y / _TILE_SIZE_PX),
)
# Deduplication within the current stroke.
if _stroke_cells.has(cell):
return
_stroke_cells[cell] = true
# Don't re-paint the same tool over itself.
if _painted.get(cell) == _tool:
return
_apply_ghost(cell)
func _apply_ghost(cell: Vector2i) -> void:
var atlas_coord: Vector2i = _ATLAS_BY_TOOL.get(_tool, Vector2i(2, 0))
_paint_layer.set_cell(cell, _SOURCE_ID, atlas_coord)
_painted[cell] = _tool
# Modulate the whole paint layer based on whether this cell is placeable.
# Phase 5 simplification: validity applies globally to the layer.
var ok: bool = _cell_is_placeable(cell)
_paint_layer.modulate = Color(0.4, 1.0, 0.4, 0.7) if ok else Color(1.0, 0.4, 0.4, 0.7)
# Phase 13 — no-roof tool: toggle the tile in World.no_roof_cells and
# trigger an immediate room recompute. No build job is queued.
if _tool == TOOL_NO_ROOF:
World.toggle_no_roof_at(cell)
Audit.log("designation", "no_roof toggled at %s" % cell)
return
designation_added.emit(cell, _tool)
EventBus.designation_added.emit(cell, _tool)
Audit.log("designation", "painted %s at %s (placeable=%s)" % [_tool, cell, ok])
func _cell_is_placeable(cell: Vector2i) -> bool:
# For Phase 5: a cell is placeable for build_wall if it is currently walkable
# (no wall present), and for build_floor if it is walkable. Items-on-tile
# check is deferred to Phase 5 BuildJob validation; we only gate on geometry here.
if World.pathfinder == null:
return true
return World.pathfinder.is_walkable(cell)
func _sync_selection_flag() -> void:
if _selection == null:
return
_selection.designation_active = (_tool != TOOL_NONE)