6.2 KiB
Architectural Plan: Dynamic .prop Loading & Sandbox Integration
This document outlines the architectural plan to transition PropLibrary from a static registry into a dynamic filesystem-backed library (matching StickmanLibrary) and integrate user-created .prop files into the Sandbox Stage.
1. System Architecture Overview
The system bridges custom prop files produced by the Prop Editor into the sandbox physics simulation through four primary layers:
-
Library & File Scanning (
PropLibrary): Scansres://props/for*.propfiles, deserializes them viaPropFile, flattens multi-shape hierarchies into collision payloads, and merges them with built-in templates. -
Thumbnail Pipeline (
ThumbnailCache&PropThumbnail): Computes cache keys using file modification timestamps (mtime), renders visual previews offscreen, and streams textures to the selector grid. -
UI Integration (
AssetSelector&SandboxStage): Presents custom props alongside built-in presets in a unified grid, offering folder scanning, ad-hoc file browsing, and palette live-refresh. -
World Spawning & Physics Lifecycle (
StageSpawner&PropBlock): InstantiatesRigidBody2Dnodes configured with custom collision geometry and material physical properties (mass, friction, bounce), tracking authored positions across sandbox mode transitions.
2. Component Specifications
A. Library Layer (res://scripts/prop_library.gd)
-
Dual-Source Registry: Maintain built-in templates (Crate, Ball, Plank, Triangle) as default presets while scanning
res://props/*.propon demand. -
Entry Model Schema: Standardize entry dictionaries returned to the UI:
-
Identifier (
id): Resource path (res://props/chair.prop) for custom files, or string key (crate) for templates. -
Display Name (
name): Extracted from.propmetadata, with fallback to capitalized file basename. -
Material Preset & Label: Physical properties index (Wood, Metal, Rubber, Cardboard) and human-readable label.
-
Payload (
payload): Flattened shape and collision dictionary generated viaPropFile.flatten_to_payload(). -
Provenance Flags: Boolean flag indicating whether the entry is custom and string path reference for scene serialization.
-
Error Handling: Skip invalid or corrupted
.propfiles gracefully while outputting descriptive warnings.
B. Thumbnail Pipeline (ThumbnailCache & PropThumbnail)
-
Dynamic Keying Strategy:
-
Built-in prop templates compute keys using internal version constants.
-
Custom
.propfiles compute keys combining file basename and filesystem modification timestamp (FileAccess.get_modified_time). -
Renderer Extension (
PropThumbnail): Extend offscreen rendering to support composite shapes and custom vector styling (fill color, outline width, polygons, circles) rather than single primitive shapes. -
Stale Cache Cleanup: Automatically purge superseded PNG thumbnails when custom
.propfiles are edited or deleted.
C. World Spawning Pipeline (StageSpawner)
-
Payload Forwarding: Pass the entry payload directly to
PropUtils.spawn_prop(), which generates the correspondingPropBlocknode withCollisionPolygon2DorCollisionShape2Dnodes. -
Provenance Tagging: Store
spawn_idand source path metadata on spawned instances to support scene serialization and reloading. -
Authored Pose Capture: Save placement positions to instance metadata (
_authored_position,_authored_rotation) during Edit mode.
D. UI & Sandbox Integration (AssetSelector & SandboxStage)
-
Grid Population: Trigger
PropLibrary.scan()when opening the prop selector, populating grid cells with thumbnails and display names. -
Browse & Refresh Integration: Connect the "Browse…" button to a file dialog for arbitrary
*.propselection, and the "Refresh" button to re-scanres://props/. -
Lazy Thumbnail Processing: Process offscreen thumbnail generation non-blockingly during stage frame processing to keep UI interactions responsive.
3. Physics & Sandbox Lifecycle Integration
Custom .prop instances must follow the existing 3-mode sandbox state machine:
| Stage Mode | Prop Physics State | Interaction Capabilities | Reset Behavior |
|---|---|---|---|
| Edit | RigidBody frozen (freeze = true, kinematic mode) |
| Move, rotate, scale, or delete via selection gizmos
| N/A (Authored state recorded on movement)
|
| Direct | RigidBody frozen (freeze = true, kinematic mode)
| Gizmos active for rule/trigger assignment; spawner palette hidden
| N/A
|
| Play | RigidBody unfrozen (freeze = false)
| Full physical simulation, collisions with terrain/stickmen/props
| Mode exit restores initial authored position/rotation and zeroes linear/angular velocity
|
4. Implementation Roadmap
[ Phase 1: Library & Data Layer ]
└─ Extend PropLibrary (res://props/*.prop scanning + PropFile parsing)
└─ Define unified Prop Entry Dictionary schema
[ Phase 2: Thumbnail Pipeline ]
└─ Update PropThumbnail to render multi-shape custom payloads
└─ Implement modification timestamp cache invalidation in ThumbnailCache
[ Phase 3: Spawning & UI Integration ]
└─ Update StageSpawner to tag custom prop provenance
└─ Wire AssetSelector grid refresh and file dialog browsing
[ Phase 4: Stage Lifecycle & Verification ]
└─ Verify Edit -> Play -> Edit position resets for custom props
└─ Validate scene saving/loading persistence
Milestone Checklist for Architect Agent
-
Directory Scanning:
PropLibraryreadsres://props/and extracts payloads viaPropFile. -
Visual Previews:
PropThumbnailrenders multi-polygon custom vector props to textures. -
Palette Display:
AssetSelectordisplays merged built-in templates and.propfiles. -
Physics Interaction: Custom props unfreeze during Play mode, participating in physics simulation and collision events.
-
State Reset: Props return to their original authored transforms when switching from Play back to Edit mode.