Tile changes

This commit is contained in:
dingo
2026-01-01 17:15:07 -05:00
parent 07b599e8d1
commit bcb130cb69
11 changed files with 3657 additions and 604 deletions
File diff suppressed because it is too large Load Diff
+1 -14
View File
@@ -172,17 +172,4 @@ public class DungeonLayoutV2 : DungeonLayout
} }
} }
/// <summary>
/// Tilemap sheet info for client
/// </summary>
public class TileMapSheetInfo
{
public int Id { get; set; }
public string CdnPath { get; set; } = "";
public int TileWidth { get; set; }
public int TileHeight { get; set; }
public int SheetWidth { get; set; }
public int SheetHeight { get; set; }
public int Columns { get; set; }
public int Rows { get; set; }
}
+48
View File
@@ -0,0 +1,48 @@
using DataServer.Data.Entities;
using Server.Game.Dungeon;
namespace Server.Game.Dungeon
{
/// <summary>
/// Extended room with template info
/// </summary>
public class DungeonRoomV2 : DungeonRoom
{
public int? TemplateId { get; set; }
public string? TemplateName { get; set; }
public HashSet<string> TemplateTags { get; set; } = new(StringComparer.OrdinalIgnoreCase);
public new RoomType Type { get; set; } = RoomType.Normal;
/// <summary>Connection points parsed from template</summary>
public List<ConnectionPoint> ConnectionPoints { get; set; } = new();
public DungeonRoomV2(int x, int y, int width, int height) : base(x, y, width, height) { }
/// <summary>Get the best connection point for a given direction</summary>
public ConnectionPoint? GetConnectionPoint(string direction)
{
// First try exact match
var exact = ConnectionPoints.FirstOrDefault(c => c.Direction.Equals(direction, StringComparison.OrdinalIgnoreCase));
if (exact != null) return exact;
// No exact match - create a default one for this direction rather than using wrong direction
// This ensures the connection point is actually on the correct edge
return direction.ToLower() switch
{
"north" => new ConnectionPoint { X = Width / 2, Y = 0, Direction = "north", Width = 3 },
"south" => new ConnectionPoint { X = Width / 2, Y = Height - 1, Direction = "south", Width = 3 },
"east" => new ConnectionPoint { X = Width - 1, Y = Height / 2, Direction = "east", Width = 3 },
"west" => new ConnectionPoint { X = 0, Y = Height / 2, Direction = "west", Width = 3 },
_ => ConnectionPoints.FirstOrDefault() // Last resort fallback
};
}
/// <summary>Get world position of a connection point</summary>
public (int X, int Y) GetConnectionWorldPos(ConnectionPoint cp)
{
return (X + cp.X, Y + cp.Y);
}
}
}
+18
View File
@@ -0,0 +1,18 @@
namespace Server.Game.Dungeon
{
/// <summary>
/// Placed tile with details
/// </summary>
public class PlacedTile
{
public int X { get; set; }
public int Y { get; set; }
public int TileDefinitionId { get; set; }
public int SheetId { get; set; } // For client rendering
public int FrameIndex { get; set; } // Frame in the sheet
public int Layer { get; set; }
public int Rotation { get; set; }
public bool FlipX { get; set; }
public bool FlipY { get; set; }
}
}
+17
View File
@@ -0,0 +1,17 @@
namespace Server.Game.Dungeon
{
/// <summary>
/// Tilemap sheet info for client
/// </summary>
public class TileMapSheetInfo
{
public int Id { get; set; }
public string CdnPath { get; set; } = "";
public int TileWidth { get; set; }
public int TileHeight { get; set; }
public int SheetWidth { get; set; }
public int SheetHeight { get; set; }
public int Columns { get; set; }
public int Rows { get; set; }
}
}
File diff suppressed because it is too large Load Diff
+110
View File
@@ -0,0 +1,110 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SystemRevivalServer.Migrations
{
/// <inheritdoc />
public partial class TileChanges : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "SocketE",
table: "tile_definitions",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "SocketECustom",
table: "tile_definitions",
type: "varchar(32)",
maxLength: 32,
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<int>(
name: "SocketN",
table: "tile_definitions",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "SocketNCustom",
table: "tile_definitions",
type: "varchar(32)",
maxLength: 32,
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<int>(
name: "SocketS",
table: "tile_definitions",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "SocketSCustom",
table: "tile_definitions",
type: "varchar(32)",
maxLength: 32,
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<int>(
name: "SocketW",
table: "tile_definitions",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "SocketWCustom",
table: "tile_definitions",
type: "varchar(32)",
maxLength: 32,
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SocketE",
table: "tile_definitions");
migrationBuilder.DropColumn(
name: "SocketECustom",
table: "tile_definitions");
migrationBuilder.DropColumn(
name: "SocketN",
table: "tile_definitions");
migrationBuilder.DropColumn(
name: "SocketNCustom",
table: "tile_definitions");
migrationBuilder.DropColumn(
name: "SocketS",
table: "tile_definitions");
migrationBuilder.DropColumn(
name: "SocketSCustom",
table: "tile_definitions");
migrationBuilder.DropColumn(
name: "SocketW",
table: "tile_definitions");
migrationBuilder.DropColumn(
name: "SocketWCustom",
table: "tile_definitions");
}
}
}
+28
View File
@@ -1960,6 +1960,34 @@ namespace SystemRevivalServer.Migrations
b.Property<int>("RenderLayer") b.Property<int>("RenderLayer")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("SocketE")
.HasColumnType("int");
b.Property<string>("SocketECustom")
.HasMaxLength(32)
.HasColumnType("varchar(32)");
b.Property<int>("SocketN")
.HasColumnType("int");
b.Property<string>("SocketNCustom")
.HasMaxLength(32)
.HasColumnType("varchar(32)");
b.Property<int>("SocketS")
.HasColumnType("int");
b.Property<string>("SocketSCustom")
.HasMaxLength(32)
.HasColumnType("varchar(32)");
b.Property<int>("SocketW")
.HasColumnType("int");
b.Property<string>("SocketWCustom")
.HasMaxLength(32)
.HasColumnType("varchar(32)");
b.Property<string>("Tags") b.Property<string>("Tags")
.HasMaxLength(256) .HasMaxLength(256)
.HasColumnType("varchar(256)"); .HasColumnType("varchar(256)");
+157 -16
View File
@@ -4,6 +4,7 @@
@{ @{
ViewData["Title"] = Model.Sheet.Id == 0 ? "New TileMap Sheet" : $"Edit: {Model.Sheet.Name}"; ViewData["Title"] = Model.Sheet.Id == 0 ? "New TileMap Sheet" : $"Edit: {Model.Sheet.Name}";
var tileTypes = Enum.GetValues<TileType>(); var tileTypes = Enum.GetValues<TileType>();
var socketTypes = Enum.GetValues<SocketType>();
// Build image URL - handle both with and without /downloads/ path // Build image URL - handle both with and without /downloads/ path
var imageUrl = Model.Sheet.CdnPath; var imageUrl = Model.Sheet.CdnPath;
if (!string.IsNullOrEmpty(imageUrl)) if (!string.IsNullOrEmpty(imageUrl))
@@ -131,7 +132,7 @@
<div class="card p-4 md:p-6 mt-4 md:mt-6"> <div class="card p-4 md:p-6 mt-4 md:mt-6">
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4"> <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4">
<h2 class="text-lg md:text-xl font-semibold text-white">Tile Definitions</h2> <h2 class="text-lg md:text-xl font-semibold text-white">Tile Definitions</h2>
<div class="flex gap-2"> <div class="flex flex-wrap gap-2">
<form method="post" asp-page-handler="AutoGenerate" class="flex gap-2"> <form method="post" asp-page-handler="AutoGenerate" class="flex gap-2">
<input type="hidden" name="sheetId" value="@Model.Sheet.Id" /> <input type="hidden" name="sheetId" value="@Model.Sheet.Id" />
<select name="defaultType" class="input text-sm py-1"> <select name="defaultType" class="input text-sm py-1">
@@ -140,6 +141,12 @@
</select> </select>
<button type="submit" class="btn btn-secondary text-sm py-1">Auto-Generate</button> <button type="submit" class="btn btn-secondary text-sm py-1">Auto-Generate</button>
</form> </form>
<!-- Socket bulk actions -->
<form method="post" asp-page-handler="AutoConfigureSockets" class="inline">
<input type="hidden" name="sheetId" value="@Model.Sheet.Id" />
<button type="submit" class="btn btn-secondary text-sm py-1" title="Set sockets based on tile type">Auto Sockets</button>
</form>
</div> </div>
</div> </div>
@@ -197,14 +204,14 @@
<div class="mt-6"> <div class="mt-6">
<h3 class="text-base md:text-lg font-semibold text-white mb-3">Defined Tiles (@Model.TileDefinitions.Count)</h3> <h3 class="text-base md:text-lg font-semibold text-white mb-3">Defined Tiles (@Model.TileDefinitions.Count)</h3>
<div class="overflow-x-auto -mx-4 md:mx-0"> <div class="overflow-x-auto -mx-4 md:mx-0">
<table class="w-full text-xs md:text-sm min-w-[600px]"> <table class="w-full text-xs md:text-sm min-w-[700px]">
<thead> <thead>
<tr class="text-left text-gray-400 border-b border-gray-700"> <tr class="text-left text-gray-400 border-b border-gray-700">
<th class="p-2">#</th> <th class="p-2">#</th>
<th class="p-2">Preview</th> <th class="p-2">Preview</th>
<th class="p-2">Name</th> <th class="p-2">Name</th>
<th class="p-2">Type</th> <th class="p-2">Type</th>
<th class="p-2">Tags</th> <th class="p-2">Sockets</th>
<th class="p-2">Props</th> <th class="p-2">Props</th>
<th class="p-2">Actions</th> <th class="p-2">Actions</th>
</tr> </tr>
@@ -226,11 +233,16 @@
<td class="p-2"> <td class="p-2">
<span class="px-1.5 py-0.5 text-xs rounded" style="background-color: @GetTileTypeColor(tile.Type);">@tile.Type</span> <span class="px-1.5 py-0.5 text-xs rounded" style="background-color: @GetTileTypeColor(tile.Type);">@tile.Type</span>
</td> </td>
<td class="p-2 text-gray-400 text-xs max-w-[80px] truncate">@(tile.Tags ?? "-")</td>
<td class="p-2 text-xs"> <td class="p-2 text-xs">
@if (tile.IsWalkable) { <span class="text-green-400">W</span> } <span class="@GetSocketBadgeClass(tile.SocketN)" title="North">N</span>
@if (tile.BlocksProjectiles) { <span class="text-red-400">P</span> } <span class="@GetSocketBadgeClass(tile.SocketE)" title="East">E</span>
@if (tile.BlocksLineOfSight) { <span class="text-yellow-400">L</span> } <span class="@GetSocketBadgeClass(tile.SocketS)" title="South">S</span>
<span class="@GetSocketBadgeClass(tile.SocketW)" title="West">W</span>
</td>
<td class="p-2 text-xs">
@if (tile.IsWalkable) { <span class="text-green-400" title="Walkable">W</span> }
@if (tile.BlocksProjectiles) { <span class="text-red-400" title="Blocks Projectiles">P</span> }
@if (tile.BlocksLineOfSight) { <span class="text-yellow-400" title="Blocks LOS">L</span> }
</td> </td>
<td class="p-2"> <td class="p-2">
<button onclick="openTileEditor(@tile.FrameIndex, @tile.Id)" class="text-blue-400 hover:text-blue-300 mr-1">Edit</button> <button onclick="openTileEditor(@tile.FrameIndex, @tile.Id)" class="text-blue-400 hover:text-blue-300 mr-1">Edit</button>
@@ -256,7 +268,7 @@
<!-- Tile Editor Modal --> <!-- Tile Editor Modal -->
<div id="tileEditorModal" class="fixed inset-0 bg-black/50 z-50 hidden items-center justify-center p-4"> <div id="tileEditorModal" class="fixed inset-0 bg-black/50 z-50 hidden items-center justify-center p-4">
<div class="bg-gray-900 rounded-xl shadow-xl p-4 md:p-6 w-full max-w-md border border-gray-700 max-h-[90vh] overflow-y-auto"> <div class="bg-gray-900 rounded-xl shadow-xl p-4 md:p-6 w-full max-w-lg border border-gray-700 max-h-[90vh] overflow-y-auto">
<h3 class="text-lg font-semibold text-white mb-4">Edit Tile <span id="modalFrameIndex"></span></h3> <h3 class="text-lg font-semibold text-white mb-4">Edit Tile <span id="modalFrameIndex"></span></h3>
<form method="post" asp-page-handler="SaveTile"> <form method="post" asp-page-handler="SaveTile">
@@ -275,21 +287,16 @@
<input type="text" name="name" id="editName" class="input w-full text-sm" placeholder="Stone Floor A" /> <input type="text" name="name" id="editName" class="input w-full text-sm" placeholder="Stone Floor A" />
</div> </div>
<div class="grid grid-cols-2 gap-3">
<div> <div>
<label class="block text-sm font-medium text-gray-300 mb-1">Type</label> <label class="block text-sm font-medium text-gray-300 mb-1">Type</label>
<select name="type" id="editType" class="input w-full text-sm"> <select name="type" id="editType" class="input w-full text-sm" onchange="onTypeChange()">
@foreach (var t in tileTypes) @foreach (var t in tileTypes)
{ {
<option value="@((int)t)">@t</option> <option value="@((int)t)">@t</option>
} }
</select> </select>
</div> </div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Tags</label>
<input type="text" name="tags" id="editTags" class="input w-full text-sm" placeholder="stone, cracked" />
</div>
<div> <div>
<label class="block text-sm font-medium text-gray-300 mb-1">Render Layer</label> <label class="block text-sm font-medium text-gray-300 mb-1">Render Layer</label>
<select name="renderLayer" id="editRenderLayer" class="input w-full text-sm"> <select name="renderLayer" id="editRenderLayer" class="input w-full text-sm">
@@ -299,6 +306,77 @@
<option value="3">3 - Ceiling</option> <option value="3">3 - Ceiling</option>
</select> </select>
</div> </div>
</div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Tags</label>
<input type="text" name="tags" id="editTags" class="input w-full text-sm" placeholder="stone, cracked" />
</div>
<!-- Socket Configuration -->
<div class="border border-gray-700 rounded-lg p-3">
<div class="flex items-center justify-between mb-2">
<label class="text-sm font-medium text-gray-300">Sockets</label>
<div class="flex gap-1">
<button type="button" onclick="setAllSockets(1)" class="text-xs px-2 py-0.5 bg-green-900/50 text-green-400 rounded hover:bg-green-900">All Open</button>
<button type="button" onclick="setAllSockets(0)" class="text-xs px-2 py-0.5 bg-red-900/50 text-red-400 rounded hover:bg-red-900">All Closed</button>
</div>
</div>
<div class="grid grid-cols-3 gap-2 text-center">
<!-- North -->
<div></div>
<div>
<label class="text-xs text-gray-400 block">North</label>
<select name="socketN" id="editSocketN" class="input w-full text-xs py-1" onchange="updateSocketCustom('N')">
<option value="0">Closed</option>
<option value="1">Open</option>
<option value="2">Custom</option>
</select>
<input type="text" name="socketNCustom" id="editSocketNCustom" class="input w-full text-xs py-1 mt-1 hidden" placeholder="Custom type" />
</div>
<div></div>
<!-- West / Center / East -->
<div>
<label class="text-xs text-gray-400 block">West</label>
<select name="socketW" id="editSocketW" class="input w-full text-xs py-1" onchange="updateSocketCustom('W')">
<option value="0">Closed</option>
<option value="1">Open</option>
<option value="2">Custom</option>
</select>
<input type="text" name="socketWCustom" id="editSocketWCustom" class="input w-full text-xs py-1 mt-1 hidden" placeholder="Custom type" />
</div>
<div class="flex items-center justify-center">
<div class="w-8 h-8 bg-gray-700 rounded flex items-center justify-center text-gray-500">
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20"><rect x="2" y="2" width="16" height="16" rx="2"/></svg>
</div>
</div>
<div>
<label class="text-xs text-gray-400 block">East</label>
<select name="socketE" id="editSocketE" class="input w-full text-xs py-1" onchange="updateSocketCustom('E')">
<option value="0">Closed</option>
<option value="1">Open</option>
<option value="2">Custom</option>
</select>
<input type="text" name="socketECustom" id="editSocketECustom" class="input w-full text-xs py-1 mt-1 hidden" placeholder="Custom type" />
</div>
<!-- South -->
<div></div>
<div>
<label class="text-xs text-gray-400 block">South</label>
<select name="socketS" id="editSocketS" class="input w-full text-xs py-1" onchange="updateSocketCustom('S')">
<option value="0">Closed</option>
<option value="1">Open</option>
<option value="2">Custom</option>
</select>
<input type="text" name="socketSCustom" id="editSocketSCustom" class="input w-full text-xs py-1 mt-1 hidden" placeholder="Custom type" />
</div>
<div></div>
</div>
<p class="text-xs text-gray-500 mt-2">Open↔Open, Closed↔Closed. Custom must match exactly.</p>
</div>
<div class="grid grid-cols-3 gap-2 text-sm"> <div class="grid grid-cols-3 gap-2 text-sm">
<label class="flex items-center gap-1.5 text-gray-300"> <label class="flex items-center gap-1.5 text-gray-300">
@@ -353,7 +431,11 @@
@section Scripts { @section Scripts {
<script> <script>
const tileDefinitions = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(Model.TileDefinitions.ToDictionary(t => t.FrameIndex, t => new { t.Id, t.FrameIndex, t.Name, t.Type, t.Tags, t.IsWalkable, t.BlocksProjectiles, t.BlocksLineOfSight, t.RenderLayer }))); const tileDefinitions = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(Model.TileDefinitions.ToDictionary(t => t.FrameIndex, t => new {
t.Id, t.FrameIndex, t.Name, t.Type, t.Tags, t.IsWalkable, t.BlocksProjectiles, t.BlocksLineOfSight, t.RenderLayer,
SocketN = (int)t.SocketN, SocketE = (int)t.SocketE, SocketS = (int)t.SocketS, SocketW = (int)t.SocketW,
t.SocketNCustom, t.SocketECustom, t.SocketSCustom, t.SocketWCustom
})));
const sheetWidth = @Model.Sheet.SheetWidth; const sheetWidth = @Model.Sheet.SheetWidth;
const sheetHeight = @Model.Sheet.SheetHeight; const sheetHeight = @Model.Sheet.SheetHeight;
const tileWidth = @Model.Sheet.TileWidth; const tileWidth = @Model.Sheet.TileWidth;
@@ -387,6 +469,15 @@
document.getElementById('editWalkable').checked = existing.IsWalkable; document.getElementById('editWalkable').checked = existing.IsWalkable;
document.getElementById('editBlocksProj').checked = existing.BlocksProjectiles; document.getElementById('editBlocksProj').checked = existing.BlocksProjectiles;
document.getElementById('editBlocksLOS').checked = existing.BlocksLineOfSight; document.getElementById('editBlocksLOS').checked = existing.BlocksLineOfSight;
// Sockets
document.getElementById('editSocketN').value = existing.SocketN;
document.getElementById('editSocketE').value = existing.SocketE;
document.getElementById('editSocketS').value = existing.SocketS;
document.getElementById('editSocketW').value = existing.SocketW;
document.getElementById('editSocketNCustom').value = existing.SocketNCustom || '';
document.getElementById('editSocketECustom').value = existing.SocketECustom || '';
document.getElementById('editSocketSCustom').value = existing.SocketSCustom || '';
document.getElementById('editSocketWCustom').value = existing.SocketWCustom || '';
} else { } else {
document.getElementById('editName').value = ''; document.getElementById('editName').value = '';
document.getElementById('editType').value = '0'; document.getElementById('editType').value = '0';
@@ -395,8 +486,20 @@
document.getElementById('editWalkable').checked = true; document.getElementById('editWalkable').checked = true;
document.getElementById('editBlocksProj').checked = false; document.getElementById('editBlocksProj').checked = false;
document.getElementById('editBlocksLOS').checked = false; document.getElementById('editBlocksLOS').checked = false;
// Default sockets for new tile
document.getElementById('editSocketN').value = '1'; // Open
document.getElementById('editSocketE').value = '1';
document.getElementById('editSocketS').value = '1';
document.getElementById('editSocketW').value = '1';
document.getElementById('editSocketNCustom').value = '';
document.getElementById('editSocketECustom').value = '';
document.getElementById('editSocketSCustom').value = '';
document.getElementById('editSocketWCustom').value = '';
} }
// Update custom field visibility
['N', 'E', 'S', 'W'].forEach(updateSocketCustom);
document.getElementById('tileEditorModal').classList.remove('hidden'); document.getElementById('tileEditorModal').classList.remove('hidden');
document.getElementById('tileEditorModal').classList.add('flex'); document.getElementById('tileEditorModal').classList.add('flex');
} }
@@ -406,6 +509,33 @@
document.getElementById('tileEditorModal').classList.remove('flex'); document.getElementById('tileEditorModal').classList.remove('flex');
} }
function updateSocketCustom(dir) {
const select = document.getElementById('editSocket' + dir);
const custom = document.getElementById('editSocket' + dir + 'Custom');
custom.classList.toggle('hidden', select.value !== '2');
}
function setAllSockets(value) {
['N', 'E', 'S', 'W'].forEach(dir => {
document.getElementById('editSocket' + dir).value = value;
updateSocketCustom(dir);
});
}
function onTypeChange() {
const type = parseInt(document.getElementById('editType').value);
// Auto-set sockets based on type
if (type === 0 || type === 30) { // Floor, FloorDecor
setAllSockets(1); // Open
document.getElementById('editWalkable').checked = true;
} else if (type === 1 || type === 31) { // Wall, WallDecor
setAllSockets(0); // Closed
document.getElementById('editWalkable').checked = false;
document.getElementById('editBlocksProj').checked = true;
document.getElementById('editBlocksLOS').checked = true;
}
}
function showCdnBrowser() { function showCdnBrowser() {
document.getElementById('cdnBrowserModal').classList.remove('hidden'); document.getElementById('cdnBrowserModal').classList.remove('hidden');
document.getElementById('cdnBrowserModal').classList.add('flex'); document.getElementById('cdnBrowserModal').classList.add('flex');
@@ -490,4 +620,15 @@
_ => "transparent" _ => "transparent"
}; };
} }
string GetSocketBadgeClass(SocketType socket)
{
return socket switch
{
SocketType.Open => "text-green-400",
SocketType.Closed => "text-red-400",
SocketType.Custom => "text-yellow-400",
_ => "text-gray-400"
};
}
} }
+85 -6
View File
@@ -28,7 +28,6 @@ public class EditModel : AdminPageModel
public async Task OnGetAsync(int? id) public async Task OnGetAsync(int? id)
{ {
//CdnBaseUrl = _config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com";
CdnBaseUrl = NormalizeCdnBaseUrl(_config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com"); CdnBaseUrl = NormalizeCdnBaseUrl(_config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com");
CdnImages = await _db.ClientAssets CdnImages = await _db.ClientAssets
.Where(a => a.AssetType == ClientAssetType.Texture && a.IsEnabled) .Where(a => a.AssetType == ClientAssetType.Texture && a.IsEnabled)
@@ -70,7 +69,6 @@ public class EditModel : AdminPageModel
public async Task<IActionResult> OnPostAsync() public async Task<IActionResult> OnPostAsync()
{ {
//CdnBaseUrl = _config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com";
CdnBaseUrl = NormalizeCdnBaseUrl(_config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com"); CdnBaseUrl = NormalizeCdnBaseUrl(_config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com");
try try
{ {
@@ -127,7 +125,25 @@ public class EditModel : AdminPageModel
return Page(); return Page();
} }
public async Task<IActionResult> OnPostSaveTileAsync(int sheetId, int frameIndex, string? name, int type, string? tags, bool isWalkable, bool blocksProjectiles, bool blocksLineOfSight, int renderLayer) public async Task<IActionResult> OnPostSaveTileAsync(
int sheetId,
int frameIndex,
string? name,
int type,
string? tags,
bool isWalkable,
bool blocksProjectiles,
bool blocksLineOfSight,
int renderLayer,
// Socket fields
int socketN,
int socketE,
int socketS,
int socketW,
string? socketNCustom,
string? socketECustom,
string? socketSCustom,
string? socketWCustom)
{ {
var existing = await _db.TileDefinitions var existing = await _db.TileDefinitions
.FirstOrDefaultAsync(t => t.TileMapSheetId == sheetId && t.FrameIndex == frameIndex); .FirstOrDefaultAsync(t => t.TileMapSheetId == sheetId && t.FrameIndex == frameIndex);
@@ -141,6 +157,15 @@ public class EditModel : AdminPageModel
existing.BlocksProjectiles = blocksProjectiles; existing.BlocksProjectiles = blocksProjectiles;
existing.BlocksLineOfSight = blocksLineOfSight; existing.BlocksLineOfSight = blocksLineOfSight;
existing.RenderLayer = renderLayer; existing.RenderLayer = renderLayer;
// Socket fields
existing.SocketN = (SocketType)socketN;
existing.SocketE = (SocketType)socketE;
existing.SocketS = (SocketType)socketS;
existing.SocketW = (SocketType)socketW;
existing.SocketNCustom = socketN == 2 ? socketNCustom : null;
existing.SocketECustom = socketE == 2 ? socketECustom : null;
existing.SocketSCustom = socketS == 2 ? socketSCustom : null;
existing.SocketWCustom = socketW == 2 ? socketWCustom : null;
} }
else else
{ {
@@ -155,7 +180,16 @@ public class EditModel : AdminPageModel
BlocksProjectiles = blocksProjectiles, BlocksProjectiles = blocksProjectiles,
BlocksLineOfSight = blocksLineOfSight, BlocksLineOfSight = blocksLineOfSight,
RenderLayer = renderLayer, RenderLayer = renderLayer,
IsEnabled = true IsEnabled = true,
// Socket fields
SocketN = (SocketType)socketN,
SocketE = (SocketType)socketE,
SocketS = (SocketType)socketS,
SocketW = (SocketType)socketW,
SocketNCustom = socketN == 2 ? socketNCustom : null,
SocketECustom = socketE == 2 ? socketECustom : null,
SocketSCustom = socketS == 2 ? socketSCustom : null,
SocketWCustom = socketW == 2 ? socketWCustom : null
}); });
} }
@@ -190,20 +224,65 @@ public class EditModel : AdminPageModel
{ {
if (!existingFrames.Contains(i)) if (!existingFrames.Contains(i))
{ {
_db.TileDefinitions.Add(new TileDefinition var tile = new TileDefinition
{ {
TileMapSheetId = sheetId, TileMapSheetId = sheetId,
FrameIndex = i, FrameIndex = i,
Type = (TileType)defaultType, Type = (TileType)defaultType,
IsWalkable = defaultType == 0, // Floor is walkable IsWalkable = defaultType == 0, // Floor is walkable
IsEnabled = true IsEnabled = true
}); };
// Auto-configure sockets based on type
tile.AutoConfigureSockets();
_db.TileDefinitions.Add(tile);
} }
} }
await _db.SaveChangesAsync(); await _db.SaveChangesAsync();
return RedirectToPage(new { id = sheetId }); return RedirectToPage(new { id = sheetId });
} }
/// <summary>
/// Auto-configure sockets for all tiles based on their type
/// </summary>
public async Task<IActionResult> OnPostAutoConfigureSocketsAsync(int sheetId)
{
var tiles = await _db.TileDefinitions
.Where(t => t.TileMapSheetId == sheetId)
.ToListAsync();
foreach (var tile in tiles)
{
tile.AutoConfigureSockets();
}
await _db.SaveChangesAsync();
Message = $"Auto-configured sockets for {tiles.Count} tiles.";
return RedirectToPage(new { id = sheetId });
}
/// <summary>
/// Bulk set all tile sockets to a specific type
/// </summary>
public async Task<IActionResult> OnPostBulkSetSocketsAsync(int sheetId, int socketType)
{
var tiles = await _db.TileDefinitions
.Where(t => t.TileMapSheetId == sheetId)
.ToListAsync();
var type = (SocketType)socketType;
foreach (var tile in tiles)
{
tile.SetAllSockets(type);
}
await _db.SaveChangesAsync();
Message = $"Set all sockets to {type} for {tiles.Count} tiles.";
return RedirectToPage(new { id = sheetId });
}
private string NormalizeCdnBaseUrl(string? baseUrl) private string NormalizeCdnBaseUrl(string? baseUrl)
{ {
baseUrl = string.IsNullOrWhiteSpace(baseUrl) baseUrl = string.IsNullOrWhiteSpace(baseUrl)
+136 -18
View File
@@ -56,6 +56,21 @@ public class TileMapSheet
public ICollection<TileDefinition>? Tiles { get; set; } public ICollection<TileDefinition>? Tiles { get; set; }
} }
/// <summary>
/// Socket type for tile edge connections
/// </summary>
public enum SocketType
{
/// <summary>Closed edge - only connects to other Closed edges (walls, void borders)</summary>
Closed = 0,
/// <summary>Open edge - only connects to other Open edges (interior floors)</summary>
Open = 1,
/// <summary>Custom type - must match exact custom string in SocketCustom field</summary>
Custom = 2
}
/// <summary> /// <summary>
/// Definition of a single tile within a tilemap sheet /// Definition of a single tile within a tilemap sheet
/// </summary> /// </summary>
@@ -80,7 +95,7 @@ public class TileDefinition
/// <summary>Tile type for game logic</summary> /// <summary>Tile type for game logic</summary>
public TileType Type { get; set; } = TileType.Floor; public TileType Type { get; set; } = TileType.Floor;
/// <summary>Tags for filtering/selection (e.g., "stone,cracked,corner_nw,biome:cave")</summary> /// <summary>Tags for filtering/selection (e.g., "stone,cracked,biome:cave")</summary>
[MaxLength(256)] [MaxLength(256)]
public string? Tags { get; set; } public string? Tags { get; set; }
@@ -112,7 +127,110 @@ public class TileDefinition
[MaxLength(32)] [MaxLength(32)]
public string? Biome { get; set; } public string? Biome { get; set; }
// =========================================================================
// SOCKET SYSTEM - Controls how tiles connect to neighbors
// =========================================================================
/// <summary>North edge socket type</summary>
public SocketType SocketN { get; set; } = SocketType.Closed;
/// <summary>East edge socket type</summary>
public SocketType SocketE { get; set; } = SocketType.Closed;
/// <summary>South edge socket type</summary>
public SocketType SocketS { get; set; } = SocketType.Closed;
/// <summary>West edge socket type</summary>
public SocketType SocketW { get; set; } = SocketType.Closed;
/// <summary>Custom socket type name for North (only used when SocketN = Custom)</summary>
[MaxLength(32)]
public string? SocketNCustom { get; set; }
/// <summary>Custom socket type name for East (only used when SocketE = Custom)</summary>
[MaxLength(32)]
public string? SocketECustom { get; set; }
/// <summary>Custom socket type name for South (only used when SocketS = Custom)</summary>
[MaxLength(32)]
public string? SocketSCustom { get; set; }
/// <summary>Custom socket type name for West (only used when SocketW = Custom)</summary>
[MaxLength(32)]
public string? SocketWCustom { get; set; }
public bool IsEnabled { get; set; } = true; public bool IsEnabled { get; set; } = true;
// =========================================================================
// HELPER METHODS
// =========================================================================
/// <summary>Get the effective socket identifier for a direction</summary>
public string GetSocketId(string direction)
{
return direction.ToUpperInvariant() switch
{
"N" or "NORTH" => SocketN == SocketType.Custom ? $"Custom:{SocketNCustom}" : SocketN.ToString(),
"E" or "EAST" => SocketE == SocketType.Custom ? $"Custom:{SocketECustom}" : SocketE.ToString(),
"S" or "SOUTH" => SocketS == SocketType.Custom ? $"Custom:{SocketSCustom}" : SocketS.ToString(),
"W" or "WEST" => SocketW == SocketType.Custom ? $"Custom:{SocketWCustom}" : SocketW.ToString(),
_ => "Closed"
};
}
/// <summary>Check if this tile's edge is compatible with another tile's edge</summary>
public bool IsEdgeCompatible(string thisEdge, TileDefinition other, string otherEdge)
{
var thisSocket = GetSocketId(thisEdge);
var otherSocket = other.GetSocketId(otherEdge);
// Exact match required
return thisSocket.Equals(otherSocket, StringComparison.OrdinalIgnoreCase);
}
/// <summary>Set all sockets to a given type (useful for bulk operations)</summary>
public void SetAllSockets(SocketType type, string? customName = null)
{
SocketN = SocketE = SocketS = SocketW = type;
if (type == SocketType.Custom)
{
SocketNCustom = SocketECustom = SocketSCustom = SocketWCustom = customName;
}
else
{
SocketNCustom = SocketECustom = SocketSCustom = SocketWCustom = null;
}
}
/// <summary>Auto-configure sockets based on tile type</summary>
public void AutoConfigureSockets()
{
switch (Type)
{
case TileType.Floor:
case TileType.FloorDecor:
SetAllSockets(SocketType.Open);
break;
case TileType.Wall:
case TileType.WallDecor:
SetAllSockets(SocketType.Closed);
break;
case TileType.Door:
// Doors typically open on two sides
// Default to vertical door (open N/S, closed E/W)
SocketN = SocketType.Open;
SocketS = SocketType.Open;
SocketE = SocketType.Closed;
SocketW = SocketType.Closed;
break;
default:
SetAllSockets(SocketType.Closed);
break;
}
}
} }
/// <summary> /// <summary>
@@ -417,15 +535,15 @@ public class DungeonObjectDefinition
/// </summary> /// </summary>
public enum DungeonObjectType public enum DungeonObjectType
{ {
Decoration = 0, // Visual only, no collision Decoration = 0,
Obstacle = 1, // Blocks movement Obstacle = 1,
Container = 2, // Can be opened for loot (chest, barrel, etc.) Container = 2,
Interactable = 3, // Triggers an action (lever, button, etc.) Interactable = 3,
Destructible = 4, // Can be destroyed (crate, pot, etc.) Destructible = 4,
Door = 5, // Openable door Door = 5,
Trap = 6, // Damages player Trap = 6,
Shrine = 7, // Gives buff/heals Shrine = 7,
Vendor = 8 // Shop NPC placeholder Vendor = 8
} }
/// <summary> /// <summary>
@@ -434,12 +552,12 @@ public enum DungeonObjectType
public enum ObjectInteractionType public enum ObjectInteractionType
{ {
None = 0, None = 0,
OpenContainer = 1, // Opens loot UI OpenContainer = 1,
Toggle = 2, // Toggle on/off state Toggle = 2,
Trigger = 3, // Triggers an event Trigger = 3,
Teleport = 4, // Teleports player Teleport = 4,
Heal = 5, // Heals player Heal = 5,
Buff = 6, // Gives buff Buff = 6,
Dialogue = 7, // Shows dialogue Dialogue = 7,
Shop = 8 // Opens shop UI Shop = 8
} }