TileBuildChanges
This commit is contained in:
@@ -77,22 +77,35 @@ public class TileTemplate
|
||||
public bool BlocksMovement { get; set; } = false;
|
||||
|
||||
// --- Socket Configuration (for WFC-style matching) ---
|
||||
// NOTE: Legacy socket fields kept for backward compatibility during migration
|
||||
// New code should use SocketConfigJson instead
|
||||
|
||||
/// <summary>North edge socket type</summary>
|
||||
/// <summary>North edge socket type (LEGACY - use SocketConfigJson)</summary>
|
||||
public SocketType SocketN { get; set; } = SocketType.Open;
|
||||
|
||||
/// <summary>East edge socket type</summary>
|
||||
/// <summary>East edge socket type (LEGACY - use SocketConfigJson)</summary>
|
||||
public SocketType SocketE { get; set; } = SocketType.Open;
|
||||
|
||||
/// <summary>South edge socket type</summary>
|
||||
/// <summary>South edge socket type (LEGACY - use SocketConfigJson)</summary>
|
||||
public SocketType SocketS { get; set; } = SocketType.Open;
|
||||
|
||||
/// <summary>West edge socket type</summary>
|
||||
/// <summary>West edge socket type (LEGACY - use SocketConfigJson)</summary>
|
||||
public SocketType SocketW { get; set; } = SocketType.Open;
|
||||
|
||||
/// <summary>Custom socket names (comma-separated for each direction)</summary>
|
||||
/// <summary>Custom socket names (LEGACY - use SocketConfigJson)</summary>
|
||||
[MaxLength(128)]
|
||||
public string? SocketCustom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// New socket configuration supporting:
|
||||
/// - Per-direction custom socket names
|
||||
/// - Multiple sockets per edge for multi-tile templates
|
||||
///
|
||||
/// JSON format: { "north": [...], "east": [...], "south": [...], "west": [...] }
|
||||
/// See SocketConfiguration class for full structure.
|
||||
/// </summary>
|
||||
[Column(TypeName = "json")]
|
||||
public string? SocketConfigJson { get; set; }
|
||||
|
||||
// --- Generation Weight ---
|
||||
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DataServer.Data.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Stores unique custom socket names for autocomplete in the tile editor.
|
||||
/// All names are stored lowercase for consistency.
|
||||
/// Examples: "field-wall", "cave-entrance", "water-edge"
|
||||
/// </summary>
|
||||
[Table("socket_names")]
|
||||
public class SocketName
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The socket name (lowercase, unique).
|
||||
/// Used for Custom socket type matching: Custom:field-wall matches Custom:field-wall
|
||||
/// </summary>
|
||||
[Required, MaxLength(64)]
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>Optional description of what this socket represents</summary>
|
||||
[MaxLength(256)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>Usage count (for sorting by popularity)</summary>
|
||||
public int UsageCount { get; set; } = 0;
|
||||
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Socket configuration for a single edge.
|
||||
/// </summary>
|
||||
public class EdgeSocket
|
||||
{
|
||||
/// <summary>Socket type: Open, Closed, or Custom</summary>
|
||||
public SocketType Type { get; set; } = SocketType.Open;
|
||||
|
||||
/// <summary>Custom socket name (only used when Type == Custom)</summary>
|
||||
public string? CustomName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Complete socket configuration for a tile template.
|
||||
/// For 1x1 tiles: 4 sockets (N, E, S, W)
|
||||
/// For larger tiles: multiple sockets per edge based on dimensions
|
||||
///
|
||||
/// Example 3x2 template:
|
||||
/// - North edge: 3 sockets (one per column)
|
||||
/// - South edge: 3 sockets (one per column)
|
||||
/// - East edge: 2 sockets (one per row)
|
||||
/// - West edge: 2 sockets (one per row)
|
||||
///
|
||||
/// JSON format:
|
||||
/// {
|
||||
/// "north": [
|
||||
/// { "type": "Open", "customName": null },
|
||||
/// { "type": "Custom", "customName": "field-wall" },
|
||||
/// { "type": "Open", "customName": null }
|
||||
/// ],
|
||||
/// "east": [
|
||||
/// { "type": "Closed", "customName": null },
|
||||
/// { "type": "Closed", "customName": null }
|
||||
/// ],
|
||||
/// "south": [...],
|
||||
/// "west": [...]
|
||||
/// }
|
||||
/// </summary>
|
||||
public class SocketConfiguration
|
||||
{
|
||||
/// <summary>North edge sockets (left to right)</summary>
|
||||
public List<EdgeSocket> North { get; set; } = new();
|
||||
|
||||
/// <summary>East edge sockets (top to bottom)</summary>
|
||||
public List<EdgeSocket> East { get; set; } = new();
|
||||
|
||||
/// <summary>South edge sockets (left to right)</summary>
|
||||
public List<EdgeSocket> South { get; set; } = new();
|
||||
|
||||
/// <summary>West edge sockets (top to bottom)</summary>
|
||||
public List<EdgeSocket> West { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Create a default configuration for a template of given dimensions.
|
||||
/// All sockets default to Open.
|
||||
/// </summary>
|
||||
public static SocketConfiguration CreateDefault(int width, int height, SocketType defaultType = SocketType.Open)
|
||||
{
|
||||
var config = new SocketConfiguration();
|
||||
|
||||
// North and South have 'width' sockets
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
config.North.Add(new EdgeSocket { Type = defaultType });
|
||||
config.South.Add(new EdgeSocket { Type = defaultType });
|
||||
}
|
||||
|
||||
// East and West have 'height' sockets
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
config.East.Add(new EdgeSocket { Type = defaultType });
|
||||
config.West.Add(new EdgeSocket { Type = defaultType });
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resize the socket configuration when template dimensions change.
|
||||
/// Preserves existing sockets where possible.
|
||||
/// </summary>
|
||||
public void Resize(int newWidth, int newHeight, SocketType defaultType = SocketType.Open)
|
||||
{
|
||||
// Adjust North/South (horizontal edges)
|
||||
while (North.Count < newWidth) North.Add(new EdgeSocket { Type = defaultType });
|
||||
while (North.Count > newWidth) North.RemoveAt(North.Count - 1);
|
||||
|
||||
while (South.Count < newWidth) South.Add(new EdgeSocket { Type = defaultType });
|
||||
while (South.Count > newWidth) South.RemoveAt(South.Count - 1);
|
||||
|
||||
// Adjust East/West (vertical edges)
|
||||
while (East.Count < newHeight) East.Add(new EdgeSocket { Type = defaultType });
|
||||
while (East.Count > newHeight) East.RemoveAt(East.Count - 1);
|
||||
|
||||
while (West.Count < newHeight) West.Add(new EdgeSocket { Type = defaultType });
|
||||
while (West.Count > newHeight) West.RemoveAt(West.Count - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a specific socket on this template can connect to another socket.
|
||||
/// Rules: Open↔Open, Closed↔Closed, Custom:name↔Custom:name (same name)
|
||||
/// </summary>
|
||||
public static bool CanConnect(EdgeSocket a, EdgeSocket b)
|
||||
{
|
||||
if (a.Type != b.Type) return false;
|
||||
|
||||
if (a.Type == SocketType.Custom)
|
||||
{
|
||||
// Custom sockets must have matching names (case-insensitive)
|
||||
return string.Equals(a.CustomName, b.CustomName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
// Open↔Open or Closed↔Closed
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user