Implement the following plan: Fix: Player and NPC not Y-sorted in Blender Level Context…
- User
Implement the following plan:
Fix: Player and NPC not Y-sorted in Blender Level
Context
When loading Level 2 (Blender level), Player ("Pete") and NPC ("Boldo") are not Y-sorted with each other. The root cause is a name mismatch:
BlenderLevelParserSystem.ResolveLayerDepth()tries to match Blender collection names againstDrawLayerMap, but "Player" and "NPC" don't match anyGameDrawLayerenum value — the correct one is "Characters". Both entities fall through toDEFAULT_LAYER_DEPTH = 0.5f, whichYSortSystemdoesn't recognize as a Y-sorted layer.Approach: Add alias support to DrawLayerMap
Add a
WithAlias<TEnum>(string alias, TEnum layer)method toDrawLayerMap. Aliases are stored directly in the existing_layersdictionary, so all string-based lookups (TryGetDepth,GetDepth) work transparently with zero changes to any other system.This is the cleanest fix because:
- Solves the problem at the right abstraction —
DrawLayerMapis the single source of truth for name-to-depth mapping - General-purpose — works for any system using string lookup, not just Blender
- Zero changes to
BlenderLevelParserSystem,YSortSystem, or any other core system - Follows the framework philosophy of extending existing mechanisms
Changes
1.
MonoDreams/Draw/DrawLayerMap.cs— AddWithAliasmethodAdd a fluent method that inserts an alias key into
_layerspointing to the same depth as the given enum layer:csharppublic DrawLayerMap WithAlias<TEnum>(string alias, TEnum layer) where TEnum : struct, Enum { var layerName = layer.ToString(); if (!_layers.TryGetValue(layerName, out var depth)) throw new ArgumentException($"Layer '{layerName}' not found in map.", nameof(layer)); _layers[alias] = depth; return this; }2.
MonoDreams.Examples/Screens/LoadLevelExampleGameScreen.cs— Wire up aliasescsharp - Solves the problem at the right abstraction —
Assistant
Let me read both files first.
Assistant
Now I'll make both changes in parallel.
Assistant
The IDE diagnostic about
WithAliasis likely stale — the method was just added. Let me build to verify.Assistant
Build succeeded — 0 errors.
Summary of changes:
-
MonoDreams/Draw/DrawLayerMap.cs— AddedWithAlias<TEnum>(string alias, TEnum layer)fluent method that stores an alias key in the existing_layersdictionary pointing to the same depth as the given enum layer. All string-based lookups (TryGetDepth,GetDepth) work transparently with aliases. -
MonoDreams.Examples/Screens/LoadLevelExampleGameScreen.cs— Wired up"Player"and"NPC"as aliases forGameDrawLayer.Characters, so whenBlenderLevelParserSystem.ResolveLayerDepth()looks up those Blender collection names, they resolve to the Characters layer depth — whichYSortSystemrecognizes as Y-sorted.
-
- User
commit this
Assistant
Committed as
7e5d104. Now let me open the PR.Assistant
PR created: https://github.com/roo-oliv/monodreams/pull/19