TSing sockets
This commit is contained in:
@@ -69,6 +69,12 @@ public class DungeonGeneratorV3
|
||||
/// </summary>
|
||||
private Dictionary<string, int> _placedTemplates = new();
|
||||
|
||||
/// <summary>
|
||||
/// Lookup TileTemplate by (sheetId, frameIndex) for room stamping.
|
||||
/// Key = "sheetId:frameIndex", Value = TileTemplate
|
||||
/// </summary>
|
||||
private Dictionary<string, TileTemplate> _tileTemplatesBySprite = new();
|
||||
|
||||
// ============================================================
|
||||
// PALETTE & TEMPLATES
|
||||
// ============================================================
|
||||
@@ -391,6 +397,7 @@ public class DungeonGeneratorV3
|
||||
CategorizeRoomTemplates();
|
||||
LogTemplateStats();
|
||||
ParseSocketConfigurations();
|
||||
BuildSpriteToTemplateLookup();
|
||||
}
|
||||
|
||||
private async Task LoadAllTemplatesAsync()
|
||||
@@ -433,6 +440,7 @@ public class DungeonGeneratorV3
|
||||
CategorizeRoomTemplates();
|
||||
LogTemplateStats();
|
||||
ParseSocketConfigurations();
|
||||
BuildSpriteToTemplateLookup();
|
||||
}
|
||||
|
||||
private void CategorizeRoomTemplates()
|
||||
@@ -941,10 +949,21 @@ public class DungeonGeneratorV3
|
||||
// Ensure the sheet is loaded for client rendering
|
||||
EnsureSheetLoaded(t.SheetId);
|
||||
|
||||
// Room template tiles are assumed walkable (they define the room interior)
|
||||
// Walls will be placed around them by PlaceWallTiles
|
||||
layout.Tiles[worldX, worldY] = 1; // Non-zero to indicate tile is placed
|
||||
layout.Walkable[worldX, worldY] = true;
|
||||
// Try to find a matching TileTemplate for this sprite
|
||||
var tileTemplate = FindTemplateBySprite(t.SheetId, t.FrameIndex);
|
||||
|
||||
// Use template properties if found, otherwise default to walkable floor
|
||||
bool isWalkable = tileTemplate?.IsWalkable ?? true;
|
||||
int templateId = tileTemplate?.Id ?? 0;
|
||||
|
||||
layout.Tiles[worldX, worldY] = templateId > 0 ? templateId : 1; // Non-zero to indicate tile is placed
|
||||
layout.Walkable[worldX, worldY] = isWalkable;
|
||||
|
||||
// Track placement for socket matching if we found a template
|
||||
if (templateId > 0)
|
||||
{
|
||||
_placedTemplates[$"{worldX},{worldY}"] = templateId;
|
||||
}
|
||||
|
||||
layout.TileDetails.Add(new PlacedTile
|
||||
{
|
||||
@@ -1529,6 +1548,53 @@ public class DungeonGeneratorV3
|
||||
Log($"Parsed socket configurations for {parsed} templates");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a lookup of TileTemplates by their sprite (sheetId:frameIndex).
|
||||
/// Used when stamping room templates to get tile properties.
|
||||
/// </summary>
|
||||
private void BuildSpriteToTemplateLookup()
|
||||
{
|
||||
_tileTemplatesBySprite.Clear();
|
||||
|
||||
var allTemplates = _floorTemplates
|
||||
.Concat(_wallTemplates)
|
||||
.Concat(_doorTemplates);
|
||||
|
||||
foreach (var template in allTemplates)
|
||||
{
|
||||
if (string.IsNullOrEmpty(template.TilesJson)) continue;
|
||||
|
||||
try
|
||||
{
|
||||
var tiles = JsonSerializer.Deserialize<List<TemplateTilePlacement>>(template.TilesJson, _jsonOptions);
|
||||
if (tiles?.Count > 0)
|
||||
{
|
||||
var first = tiles[0];
|
||||
var key = $"{first.SheetId}:{first.FrameIndex}";
|
||||
|
||||
// Only store if not already present (first template wins)
|
||||
if (!_tileTemplatesBySprite.ContainsKey(key))
|
||||
{
|
||||
_tileTemplatesBySprite[key] = template;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { /* ignore parse errors */ }
|
||||
}
|
||||
|
||||
Log($"Built sprite->template lookup with {_tileTemplatesBySprite.Count} entries");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a TileTemplate by sheetId and frameIndex.
|
||||
/// Returns null if no matching template exists.
|
||||
/// </summary>
|
||||
private TileTemplate? FindTemplateBySprite(int sheetId, int frameIndex)
|
||||
{
|
||||
var key = $"{sheetId}:{frameIndex}";
|
||||
return _tileTemplatesBySprite.TryGetValue(key, out var template) ? template : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a template's socket configuration from JSON or legacy fields.
|
||||
/// </summary>
|
||||
|
||||
@@ -145,6 +145,10 @@ public class SocketConfiguration
|
||||
}
|
||||
|
||||
// Open↔Open or Closed↔Closed
|
||||
if (a.Type == SocketType.Closed && b.Type == SocketType.Closed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user