Phase 5 — Designation, BuildJob, Wall/Floor/Door, Crate; 3/4 perspective pivot
Three gdscript-refactor agents in parallel + Opus integration.
Architectural pivot (memory.md Decisions table updated):
- View: top-down grid for gameplay + 3/4-perspective rendering for vertical
structures (Stardew/Going Medieval style). Walls/doors/crates are Y-sorted
entity sprites, not TileMap cells.
- Wall TileMap layer (Layer 2) becomes data-only — used for room detection,
roof BFS, save serialization. Visual rendering happens at entity level.
- Asset reality check baked into the decision: the entire asset library is
RPG-style perspective art; pivoting the renderer is cheaper than authoring
or commissioning top-down 47-tile autotile sets.
Designation paint (scenes/world/, Agent A — ~170 lines):
- class_name Designation extends Node, lives as DesignationCtl child of World
- TOOL_NONE / TOOL_BUILD_WALL / TOOL_BUILD_FLOOR
- _unhandled_input captures left-mouse press/drag/release
- Drag-paints ghost tiles on Layer 3 via paint_layer.set_cell
- Green/red modulate based on World.pathfinder.is_walkable + cell occupancy
- Emits EventBus.designation_added/cleared per cell
- Selection.designation_active guard prevents double-handling clicks
EventBus signals added:
- designation_added(cell: Vector2i, tool: StringName)
- designation_cleared(cell: Vector2i)
BuildJob + Wall/Floor/Door entities (scenes/ai/ + scenes/entities/, Agent B — ~530 lines):
- Toil.KIND_BUILD + Toil.build_at(target_path) factory
- JobRunner._tick_build: resolves NodePath target, calls on_build_tick() per
sim tick, marks toil done when is_buildable() returns false
- ConstructionProvider (priority=6, highest): nearest is_buildable() site in
World.build_queue → Job=[walk_to(site.tile), build_at(site.get_path())]
- Wall entity: BUILD_TICKS=100, 40% alpha ghost; _complete() calls
pathfinder.set_cell_walkable(false) + World.mark_wall_tile + Audit.log
- Floor entity: BUILD_TICKS=30, ground-level (no y_sort), does NOT block
pathfinding, calls mark_floor_tile on complete
- Door entity: BUILD_TICKS=80, bottom-anchored, walkable when built (no
pathfinder block); registers with World.doors for Phase 7 open/close logic
- ALL wall/door scenes have y_sort_enabled=true on root; floors don't (always
on ground plane)
Crate furniture (scenes/world/, Agent C — ~270 lines):
- class_name Crate extends StorageDestination (Phase 4's abstract base)
- CAPACITY=4 stacks; accepts() gates on _completed + _filter_accepts + room
- find_drop_position returns tile when room exists, (-1,-1) otherwise
- BUILD_TICKS=60; on_build_tick mirrors Wall's pattern
- _draw procedural brown crate body + slat lines + fill-level dots
World autoload extensions (Opus):
- build_queue: Array — Wall/Floor/Door/Crate ghost entities awaiting
construction. ConstructionProvider iterates by .priority desc; Phase 6+
prepends material-haul toils.
- doors: Array — completed doors for future open/close (Phase 7+)
- wall_layer / floor_layer / designation_layer refs exposed for entity code
- mark_wall_tile(tile, material) / mark_floor_tile(tile, material) —
stamps data-only TileMap layer with material-encoded atlas coord
- stockpile_at_tile(tile) — finds StockpileZone OR Crate covering a tile;
used by JobRunner._tick_deposit to route Crate deposits
JobRunner._tick_deposit refactor (Opus):
- After clearing the haul-dirty flag, looks up stockpile_at_tile(pawn.tile)
- If destination is a Crate (has_method('register_item')), calls
dest.register_item(item) so the crate's _contents tracks the stack
World scene integration (Opus):
- y_sort_enabled=true on World root so all entity sprites sort correctly
- DesignationCtl, ConstructionProvider, Wall TileMap (data-only, visible=false)
- World._ready wires:
* World.wall_layer / floor_layer / designation_layer
* designation.bind(designation_layer, selection)
* Register 5 work providers (construction=6 > chop=5 > mine=4 > haul=3 > rest=0)
* EventBus.designation_added → _on_designation_added (spawns Wall/Floor entity)
- _seed_phase5_demo_buildings: pre-queues 14 wall designations forming a
5×4 cabin outline at (45, 25) so pawns visibly construct walls without
player-paint UI (deferred to Phase 17). Spawns 2 fully-built crates at
(17-18, 60) for hauling routing.
Acceptance — MCP-verified end-to-end:
- 14 wall designations seeded at boot, 2 crates pre-built
- All 3 pawns picked construction (highest priority work) and walked to
build sites (paths 37/32/27 from spawn). Walls built one by one.
- Wall layer post-construction has 42 cells: 28 (Phase 1 stone ring) +
14 (Phase 5 cabin) — both rendering paths (placeholder TileMap from
Phase 1, plus new entity sprites from Phase 5) coexist correctly.
- Pathfinder set_cell_walkable(false) fired on each wall completion.
- Pawns transitioned from construction to hauling once all walls done.
- Final visual: 5×4 stone-walled cabin with mortar lines, Y-sorted entity
rendering, wood items scattered east of the cabin awaiting haul.
Phase 5 gotchas (logged):
- 'material' as a member var shadows CanvasItem.material (Node2D inherits
it). Renamed to wall_material / floor_material via quick-edit agent.
Save-format dict KEYS stay as 'material' for stability.
- Class-name registration cache lag bit again (Tree/Pawn pattern from
earlier phases). Workflow stays: agent writes class_name file → MCP
reload_project → godot --headless --editor --quit → headless validate.
- ConstructionProvider scans build_queue every tick including completed
walls; is_buildable() filters them out but the queue keeps growing.
Phase 16+ should add an unregister_build_site call from _complete or
a periodic queue compaction.
Delegation report this phase:
- Agent A (Sonnet, gdscript-refactor): Designation paint mode + EventBus
signals + Selection guard. ~180 lines.
- Agent B (Sonnet, gdscript-refactor): Toil.KIND_BUILD + JobRunner._tick_build
+ ConstructionProvider + Wall/Floor/Door entities + scenes. ~530 lines.
- Agent C (Sonnet, gdscript-refactor): Crate furniture extending
StorageDestination. ~270 lines.
- quick-edit (Haiku): material → wall_material/floor_material rename. ~14
occurrences across 2 files.
- Opus: World autoload extensions + JobRunner _tick_deposit refactor +
World scene integration (DesignationCtl + ConstructionProvider + new
scene preloads + _seed_phase5_demo_buildings) + MCP runtime verification
+ the material-shadow + class-cache-lag debugging.
Pivot decision worth flagging: the asset library audit revealed that no
pack we own ships top-down 47-tile autotile walls. After multiple
researcher-overpromise cycles, the pragmatic call was to pivot the
rendering model itself. Walls now render as bottom-anchored tall sprites
with Y-sort; the entire asset library becomes usable as-is. Phase 17
polish will swap procedural _draw() with AtlasTexture regions from
Pixel Crawler / FG_Houses / Ventilatore Castle_Building.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
91bceeebe8
commit
f82807ff3d
26 changed files with 1273 additions and 6 deletions
169
scenes/entities/floor.gd
Normal file
169
scenes/entities/floor.gd
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
class_name Floor extends Node2D
|
||||
## Floor entity — built by a pawn with a Build job. Stamps the Floor TileMap
|
||||
## layer once complete. Floors do NOT block pathfinding.
|
||||
##
|
||||
## Floor is ground-level: its render origin sits at the tile centre (not
|
||||
## bottom-anchored like Wall/Door). Y-sort is not needed because floor sprites
|
||||
## always sort below any tall entity at the same tile.
|
||||
##
|
||||
## Build model (docs/implementation.md Phase 5):
|
||||
## A ConstructionProvider creates a Job whose BUILD toil calls on_build_tick()
|
||||
## once per sim tick via JobRunner. After BUILD_TICKS ticks the floor is
|
||||
## complete: it stamps the data-layer TileMap (World.mark_floor_tile) and
|
||||
## transitions from ghost (40% alpha) to solid.
|
||||
##
|
||||
## World registration: World.register_build_site / World.unregister_build_site
|
||||
## are called from _ready / _exit_tree. Methods land in the Opus integration pass.
|
||||
|
||||
const TILE_SIZE_PX: int = 16
|
||||
|
||||
## Sim ticks to lay a floor at 1× speed (30 ticks = 1.5 sim seconds).
|
||||
const BUILD_TICKS: int = 30
|
||||
|
||||
const MATERIAL_WOOD: StringName = &"wood"
|
||||
const MATERIAL_STONE: StringName = &"stone"
|
||||
const MATERIAL_DIRT: StringName = &"dirt"
|
||||
|
||||
# ── state ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
@export var floor_material: StringName = MATERIAL_WOOD
|
||||
@export var tile: Vector2i = Vector2i.ZERO
|
||||
|
||||
## 0..BUILD_TICKS.
|
||||
var build_progress: int = 0
|
||||
var _completed: bool = false
|
||||
|
||||
|
||||
# ── lifecycle ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
World.register_build_site(self)
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
World.unregister_build_site(self)
|
||||
|
||||
|
||||
# ── public API ─────────────────────────────────────────────────────────────────
|
||||
|
||||
## One-shot initialiser. Call after add_child() so _ready() has already fired.
|
||||
func setup(p_tile: Vector2i, p_material: StringName) -> void:
|
||||
tile = p_tile
|
||||
floor_material = p_material
|
||||
# Floor renders at tile centre (not bottom-anchored).
|
||||
position = Vector2(
|
||||
tile.x * TILE_SIZE_PX + TILE_SIZE_PX / 2.0,
|
||||
tile.y * TILE_SIZE_PX + TILE_SIZE_PX / 2.0
|
||||
)
|
||||
queue_redraw()
|
||||
Audit.log("floor", "%s floor ghost placed at %s" % [floor_material, tile])
|
||||
|
||||
|
||||
## True while the floor still needs construction work.
|
||||
func is_buildable() -> bool:
|
||||
return not _completed
|
||||
|
||||
|
||||
## Human-readable label for job descriptions and Audit logs.
|
||||
func label() -> String:
|
||||
return "%s floor" % floor_material
|
||||
|
||||
|
||||
## Called by the BUILD toil in JobRunner once per sim tick.
|
||||
func on_build_tick() -> void:
|
||||
if _completed:
|
||||
return
|
||||
build_progress += 1
|
||||
queue_redraw()
|
||||
if build_progress >= BUILD_TICKS:
|
||||
_complete()
|
||||
|
||||
|
||||
## True once the floor has been fully laid.
|
||||
func is_completed() -> bool:
|
||||
return _completed
|
||||
|
||||
|
||||
# ── save / load ────────────────────────────────────────────────────────────────
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"material": str(floor_material),
|
||||
"build_progress": build_progress,
|
||||
"completed": _completed,
|
||||
}
|
||||
|
||||
|
||||
static func from_dict(d: Dictionary) -> Dictionary:
|
||||
return {
|
||||
"tile_x": int(d.get("tile_x", 0)),
|
||||
"tile_y": int(d.get("tile_y", 0)),
|
||||
"material": str(d.get("material", "wood")),
|
||||
"build_progress": int(d.get("build_progress", 0)),
|
||||
"completed": bool(d.get("completed", false)),
|
||||
}
|
||||
|
||||
|
||||
# ── render ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _draw() -> void:
|
||||
# 16×16 tile centred on origin.
|
||||
var alpha: float = 1.0 if _completed else 0.4
|
||||
var half: float = TILE_SIZE_PX / 2.0
|
||||
|
||||
match floor_material:
|
||||
MATERIAL_WOOD:
|
||||
_draw_wood_floor(alpha, half)
|
||||
MATERIAL_STONE:
|
||||
_draw_stone_floor(alpha, half)
|
||||
_: # MATERIAL_DIRT and any future materials
|
||||
_draw_dirt_floor(alpha, half)
|
||||
|
||||
|
||||
func _draw_wood_floor(alpha: float, half: float) -> void:
|
||||
var base := Color(0.58, 0.40, 0.20, alpha)
|
||||
var plank := Color(0.50, 0.34, 0.16, alpha)
|
||||
|
||||
draw_rect(Rect2(Vector2(-half, -half), Vector2(TILE_SIZE_PX, TILE_SIZE_PX)), base)
|
||||
|
||||
# Horizontal plank lines.
|
||||
for y_offset in [-3.0, 2.0]:
|
||||
draw_line(
|
||||
Vector2(-half, y_offset),
|
||||
Vector2(half, y_offset),
|
||||
plank, 1.0
|
||||
)
|
||||
|
||||
draw_rect(Rect2(Vector2(-half, -half), Vector2(TILE_SIZE_PX, TILE_SIZE_PX)), Color(0.0, 0.0, 0.0, 0.3 * alpha), false, 1.0)
|
||||
|
||||
|
||||
func _draw_stone_floor(alpha: float, half: float) -> void:
|
||||
var base := Color(0.60, 0.60, 0.57, alpha)
|
||||
var joint := Color(0.45, 0.45, 0.43, alpha)
|
||||
|
||||
draw_rect(Rect2(Vector2(-half, -half), Vector2(TILE_SIZE_PX, TILE_SIZE_PX)), base)
|
||||
|
||||
# Stone tile grid lines.
|
||||
draw_line(Vector2(0.0, -half), Vector2(0.0, half), joint, 1.0)
|
||||
draw_line(Vector2(-half, 0.0), Vector2(half, 0.0), joint, 1.0)
|
||||
|
||||
draw_rect(Rect2(Vector2(-half, -half), Vector2(TILE_SIZE_PX, TILE_SIZE_PX)), Color(0.0, 0.0, 0.0, 0.3 * alpha), false, 1.0)
|
||||
|
||||
|
||||
func _draw_dirt_floor(alpha: float, half: float) -> void:
|
||||
var base := Color(0.42, 0.30, 0.18, alpha)
|
||||
|
||||
draw_rect(Rect2(Vector2(-half, -half), Vector2(TILE_SIZE_PX, TILE_SIZE_PX)), base)
|
||||
draw_rect(Rect2(Vector2(-half, -half), Vector2(TILE_SIZE_PX, TILE_SIZE_PX)), Color(0.0, 0.0, 0.0, 0.25 * alpha), false, 1.0)
|
||||
|
||||
|
||||
# ── internal ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func _complete() -> void:
|
||||
_completed = true
|
||||
# Floors do NOT block pathfinding — no pathfinder call here.
|
||||
World.mark_floor_tile(tile, floor_material)
|
||||
queue_redraw()
|
||||
Audit.log("floor", "%s floor completed at %s" % [floor_material, tile])
|
||||
Loading…
Add table
Add a link
Reference in a new issue