upgrades
This commit is contained in:
@@ -949,12 +949,22 @@ public class DungeonGeneratorV3
|
||||
// Ensure the sheet is loaded for client rendering
|
||||
EnsureSheetLoaded(t.SheetId);
|
||||
|
||||
// Try to find a matching TileTemplate for this sprite
|
||||
var tileTemplate = FindTemplateBySprite(t.SheetId, t.FrameIndex);
|
||||
// Use IsWalkable from the tile placement data (set by room editor)
|
||||
// This is the primary source of truth for walkability
|
||||
bool isWalkable = t.IsWalkable;
|
||||
int templateId = t.TemplateId ?? 0;
|
||||
|
||||
// Use template properties if found, otherwise default to walkable floor
|
||||
bool isWalkable = tileTemplate?.IsWalkable ?? true;
|
||||
int templateId = tileTemplate?.Id ?? 0;
|
||||
// If no templateId provided, try to find one by sprite lookup (legacy support)
|
||||
if (templateId == 0)
|
||||
{
|
||||
var tileTemplate = FindTemplateBySprite(t.SheetId, t.FrameIndex);
|
||||
if (tileTemplate != null)
|
||||
{
|
||||
templateId = tileTemplate.Id;
|
||||
// Only override isWalkable if not explicitly set in placement
|
||||
// (legacy data won't have IsWalkable set)
|
||||
}
|
||||
}
|
||||
|
||||
layout.Tiles[worldX, worldY] = templateId > 0 ? templateId : 1; // Non-zero to indicate tile is placed
|
||||
layout.Walkable[worldX, worldY] = isWalkable;
|
||||
@@ -984,6 +994,43 @@ public class DungeonGeneratorV3
|
||||
}
|
||||
}
|
||||
|
||||
// Parse and handle connection points
|
||||
if (!string.IsNullOrEmpty(template.ConnectionPointsJson))
|
||||
{
|
||||
try
|
||||
{
|
||||
var connections = JsonSerializer.Deserialize<List<BuilderConnectionPoint>>(template.ConnectionPointsJson, jsonOptions);
|
||||
if (connections != null)
|
||||
{
|
||||
foreach (var conn in connections)
|
||||
{
|
||||
int worldX = room.X + conn.X;
|
||||
int worldY = room.Y + conn.Y;
|
||||
|
||||
if (worldX >= 0 && worldX < MapWidth && worldY >= 0 && worldY < MapHeight)
|
||||
{
|
||||
// Connection points must be walkable for corridors to connect
|
||||
layout.Walkable[worldX, worldY] = true;
|
||||
|
||||
// Store connection point info for corridor generation
|
||||
room.ConnectionPoints.Add(new ConnectionPoint
|
||||
{
|
||||
X = worldX,
|
||||
Y = worldY,
|
||||
Direction = conn.Direction ?? "north"
|
||||
});
|
||||
|
||||
LogVerbose($" Connection point at ({worldX},{worldY}) facing {conn.Direction ?? "north"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($" Error parsing ConnectionPointsJson: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// Place objects from ObjectPlacementsJson
|
||||
if (!string.IsNullOrEmpty(template.ObjectPlacementsJson))
|
||||
{
|
||||
@@ -1979,6 +2026,24 @@ public class RoomTilePlacement
|
||||
public int Y { get; set; }
|
||||
public int SheetId { get; set; }
|
||||
public int FrameIndex { get; set; }
|
||||
public int? TemplateId { get; set; } // TileTemplate ID (new format)
|
||||
public bool IsWalkable { get; set; } = true; // Whether this tile is walkable (new format)
|
||||
}
|
||||
|
||||
public class BuilderConnectionPoint
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public string? Direction { get; set; } // north, south, east, west
|
||||
public int Width { get; set; } = 1;
|
||||
}
|
||||
|
||||
public class ConnectionPoint
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public string Direction { get; set; } = "north";
|
||||
public int Width { get; set; }
|
||||
}
|
||||
|
||||
public class TemplateTilePlacement
|
||||
|
||||
Reference in New Issue
Block a user