Files
Cinderwild/scripts/building/piece.gd
Paul Bailey 4640f5e577 M1a: survival core, pause menu, title screen and save/load
Design: docs/SURVIVAL_DESIGN.md (core loop, systems, architecture, phases).

Survival core (M1a):
- Items/recipes as data (data/*.json) in the addon SDK's define_item /
  define_recipe shape; procedural item meshes and offscreen-rendered icons
- Inventory class (40 slots, hotbar = row 1) shared by player and chests;
  click / right-click split / shift-click quick-move
- Actions autoload: the intent layer (craft, pickup, harvest_hit, place,
  transfer) that validates every change; becomes the RPC surface in M2
- Gathering: ground pickups (sticks, stones, flint); trees chopped with an
  axe fall and leave stumps; boulders mined with a pickaxe shrink per hit
- Crafting screen with station checks (workbench); placement mode with
  green/red ghost, rotation and overlap/slope validation
- Pieces: campfire (light, flames, embers), workbench, chest (16 slots)
- HUD: hotbar, held tool view model with swing, prompts, toasts

Menus and saving:
- ESC pause menu: resume, controls, fullscreen, mouse sensitivity, quit
- Title screen over a flyover of the island: Continue / New World (name +
  seed) / Load World (with delete) / Quit
- Saves autoload: one folder per world under user://worlds, atomic writes
  with a .bak; stores only player changes (player, pieces, chest contents,
  harvested resources, taken pickups) and regenerates the rest from the seed
- Autosave every 2 min, Save & Quit to title/desktop, save on window close

Fixes: UI screens now fill the viewport (were pinned top-left); title
backdrop no longer captures the mouse.

Tests: test_survival_core (31 checks), test_save_load (round trip + slots),
test_terrain_edges now checks 8 seeds for deep pits / unbanked water.
2026-11-04 00:34:46 +00:00

37 lines
929 B
GDScript

extends StaticBody3D
## Base for placed pieces (campfire, workbench, chest, later walls/floors).
## Builds the visual from the item's procedural mesh and a box collider from
## the item's footprint. Subclasses add behaviour.
var item_id := ""
var def: Dictionary = {}
func setup(d: Dictionary) -> void:
def = d
item_id = d.id
var mi := MeshInstance3D.new()
mi.name = "Mesh"
mi.mesh = ItemDB.mesh_for(item_id)
mi.material_override = ItemDB.item_material()
add_child(mi)
var aabb := mi.mesh.get_aabb()
var cs := CollisionShape3D.new()
var box := BoxShape3D.new()
box.size = Vector3(aabb.size.x, maxf(aabb.size.y, 0.3), aabb.size.z)
cs.shape = box
cs.position = aabb.get_center()
add_child(cs)
_build()
func _build() -> void:
pass
func display_name() -> String:
return ItemDB.item_name(item_id)
func interact_prompt(_player: Node) -> String:
return display_name()
func interact(_player: Node) -> void:
pass