Implement the following plan: Fix: Player movement broken on Blender levels after…
- User
Implement the following plan:
Fix: Player movement broken on Blender levels after refactor
Context
After the
ro/core-examples-alignmentrefactor, clicking Level 2 (a Blender level) loads all entities visually, but the player doesn't respond to WASD/arrow keys.Root cause: When
BlenderLevelParserSystemwas moved from Examples → core, two game-specific components were dropped from the "Player" collection handler:PlayerState(lives inMonoDreams.Examples.Component— core can't reference it)InputControlled(deleted entirely during the refactor)
MovementSystemqueriesWith<Transform>().With<PlayerState>()but Blender-created player entities no longer havePlayerState, so the system never matches them.Approach: Collection handler registration on BlenderLevelParserSystem
Follow the same pattern as
EntitySpawnSystem(factory registration): let game code register callbacks for specific Blender collection names. The core parser handles universal components (Transform, SpriteInfo, DrawComponent, Visible, BoxCollider, RigidBody, Velocity, CameraFollowTarget), and game code adds game-specific components (PlayerState, etc.).Files to modify
-
MonoDreams/System/Level/BlenderLevelParserSystem.cs— Add collection handler registration- Add
Dictionary<string, Action<Entity>>field for collection handlers - Add
RegisterCollectionHandler(string collectionName, Action<Entity> handler)method - In
ProcessCollections(), after adding core components for a collection, call the registered handler if one exists
- Add
-
MonoDreams.Examples/Screens/LoadLevelExampleGameScreen.cs— Register game-specific handlers- Extract
BlenderLevelParserSysteminto a local variable (currently created inline) - Register a "Player" collection handler that adds
PlayerState:csharpblenderParser.RegisterCollectionHandler("Player", entity => entity.Set(new PlayerState()));
- Extract
Steps
-
In
BlenderLevelParserSystem:
Assistant
I'll start by reading the two files I need to modify.
Assistant
Good, I have both files. Now I'll make the changes.
Step 1: Add collection handler registration to
BlenderLevelParserSystem.Assistant
Now add the handler invocation at the end of
ProcessCollections, after all the core collection blocks:Assistant
Step 2: Update
LoadLevelExampleGameScreento extract the parser into a variable and register the Player handler.Assistant
Step 3: Build to verify.
Assistant
Clean build — 0 errors. Here's a summary of the changes:
MonoDreams/System/Level/BlenderLevelParserSystem.cs:- Added
_collectionHandlersdictionary field - Added
RegisterCollectionHandler(string, Action<Entity>)method for game code to register callbacks per Blender collection name - At the end of
ProcessCollections(), iterates over the entity's collections and invokes any registered handler
MonoDreams.Examples/Screens/LoadLevelExampleGameScreen.cs:- Extracted
BlenderLevelParserSysteminto a local variable - Registered a
"Player"collection handler that setsPlayerStateon the entity
This follows the same extensibility pattern as
EntitySpawnSystem(factory registration): core handles universal components, game code registers handlers for game-specific components. When a Blender level's Player entity is created, the handler will addPlayerState, allowingMovementSystem(which queriesWith<PlayerState>()) to match it.- Added