tilemap
This commit is contained in:
+2384
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SystemRevivalServer.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class RecreateMissingTables : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1309,6 +1309,67 @@ namespace SystemRevivalServer.Migrations
|
||||
b.ToTable("dungeon_stash_items");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.DungeonTemplate", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<int?>("DefaultTileMapSheetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("varchar(512)");
|
||||
|
||||
b.Property<string>("GenerationParamsJson")
|
||||
.HasColumnType("json");
|
||||
|
||||
b.Property<int>("Height")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<bool>("IsHandCrafted")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("varchar(64)");
|
||||
|
||||
b.Property<string>("RoomPlacementsJson")
|
||||
.HasColumnType("json");
|
||||
|
||||
b.Property<string>("Tags")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)");
|
||||
|
||||
b.Property<int>("Tier")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("TileDataJson")
|
||||
.HasColumnType("json");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<int>("Width")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DefaultTileMapSheetId");
|
||||
|
||||
b.ToTable("dungeon_templates");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.MobAbilityAnimationMapping", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -1639,6 +1700,166 @@ namespace SystemRevivalServer.Migrations
|
||||
b.ToTable("mob_sprite_sheets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.RoomTemplate", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ConnectionPointsJson")
|
||||
.HasColumnType("json");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(512)
|
||||
.HasColumnType("varchar(512)");
|
||||
|
||||
b.Property<int>("Height")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<int>("MaxTier")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MinTier")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("varchar(64)");
|
||||
|
||||
b.Property<string>("SpawnPointsJson")
|
||||
.HasColumnType("json");
|
||||
|
||||
b.Property<string>("Tags")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)");
|
||||
|
||||
b.Property<string>("TileDataJson")
|
||||
.HasColumnType("json");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<int>("Weight")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Width")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("room_templates");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.TileDefinition", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("BlocksLineOfSight")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<bool>("BlocksProjectiles")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<int>("FrameIndex")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<bool>("IsWalkable")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("varchar(64)");
|
||||
|
||||
b.Property<int>("RenderLayer")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Tags")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)");
|
||||
|
||||
b.Property<int>("TileMapSheetId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ZIndex")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TileMapSheetId");
|
||||
|
||||
b.ToTable("tile_definitions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.TileMapSheet", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("CdnPath")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("varchar(64)");
|
||||
|
||||
b.Property<int>("SheetHeight")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("SheetWidth")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Tags")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("varchar(256)");
|
||||
|
||||
b.Property<int>("TileHeight")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("TileWidth")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("tilemap_sheets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Session", b =>
|
||||
{
|
||||
b.Property<ulong>("Id")
|
||||
@@ -2014,6 +2235,15 @@ namespace SystemRevivalServer.Migrations
|
||||
b.Navigation("Definition");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.DungeonTemplate", b =>
|
||||
{
|
||||
b.HasOne("DataServer.Data.Entities.TileMapSheet", "DefaultTileMapSheet")
|
||||
.WithMany()
|
||||
.HasForeignKey("DefaultTileMapSheetId");
|
||||
|
||||
b.Navigation("DefaultTileMapSheet");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.MobAbilityAnimationMapping", b =>
|
||||
{
|
||||
b.HasOne("DataServer.Data.Entities.MobAbilityAssignment", "AbilityAssignment")
|
||||
@@ -2074,6 +2304,17 @@ namespace SystemRevivalServer.Migrations
|
||||
b.Navigation("SpriteSheet");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.TileDefinition", b =>
|
||||
{
|
||||
b.HasOne("DataServer.Data.Entities.TileMapSheet", "TileMapSheet")
|
||||
.WithMany("Tiles")
|
||||
.HasForeignKey("TileMapSheetId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("TileMapSheet");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Session", b =>
|
||||
{
|
||||
b.HasOne("DataServer.Data.Account", "Account")
|
||||
@@ -2129,6 +2370,11 @@ namespace SystemRevivalServer.Migrations
|
||||
{
|
||||
b.Navigation("Animations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataServer.Data.Entities.TileMapSheet", b =>
|
||||
{
|
||||
b.Navigation("Tiles");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +152,13 @@
|
||||
Sprite Sheets
|
||||
</a>
|
||||
|
||||
<a href="/admin/tilemaps" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/TileMaps") == true ? "active" : "")" onclick="closeMobileMenu()">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 5a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1H5a1 1 0 01-1-1V5zm10 0a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1V5zM4 15a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1H5a1 1 0 01-1-1v-4zm10 0a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1v-4z"/>
|
||||
</svg>
|
||||
TileMaps
|
||||
</a>
|
||||
|
||||
<a href="/admin/assets" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Assets") == true ? "active" : "")" onclick="closeMobileMenu()">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
|
||||
@@ -0,0 +1,473 @@
|
||||
@page "/admin/tilemaps/edit"
|
||||
@model TileMaps.EditModel
|
||||
@using DataServer.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = Model.Sheet.Id == 0 ? "New TileMap Sheet" : $"Edit: {Model.Sheet.Name}";
|
||||
var tileTypes = Enum.GetValues<TileType>();
|
||||
}
|
||||
|
||||
<div class="mb-6">
|
||||
<a href="/admin/tilemaps" class="text-blue-400 hover:text-blue-300">← Back to TileMap Sheets</a>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="mb-4 p-3 rounded @(Model.IsError ? "bg-red-900/50 text-red-300" : "bg-green-900/50 text-green-300")">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="grid grid-cols-1 xl:grid-cols-2 gap-6">
|
||||
<!-- Sheet Settings -->
|
||||
<div class="card">
|
||||
<h2 class="text-xl font-semibold text-white mb-4">TileMap Sheet Settings</h2>
|
||||
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Sheet.Id" />
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Name</label>
|
||||
<input type="text" asp-for="Sheet.Name" class="input w-full" placeholder="Dungeon Stone Tiles" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">CDN Path</label>
|
||||
<div class="flex gap-2">
|
||||
<input type="text" asp-for="Sheet.CdnPath" class="input flex-1" placeholder="textures/tilemaps/dungeon.png" />
|
||||
<button type="button" onclick="showCdnBrowser()" class="btn btn-secondary">Browse</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Tags (comma-separated)</label>
|
||||
<input type="text" asp-for="Sheet.Tags" class="input w-full" placeholder="dungeon, stone, dark" />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Sheet Width (px)</label>
|
||||
<input type="number" asp-for="Sheet.SheetWidth" class="input w-full" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Sheet Height (px)</label>
|
||||
<input type="number" asp-for="Sheet.SheetHeight" class="input w-full" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Tile Width (px)</label>
|
||||
<input type="number" asp-for="Sheet.TileWidth" class="input w-full" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Tile Height (px)</label>
|
||||
<input type="number" asp-for="Sheet.TileHeight" class="input w-full" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Sheet.IsEnabled" class="rounded" />
|
||||
<label asp-for="Sheet.IsEnabled" class="text-gray-300">Enabled</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-full">
|
||||
@(Model.Sheet.Id == 0 ? "Create TileMap Sheet" : "Save Changes")
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Preview -->
|
||||
<div class="card">
|
||||
<h2 class="text-xl font-semibold text-white mb-4">Preview</h2>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Sheet.CdnPath))
|
||||
{
|
||||
<div class="bg-gray-900 rounded-lg p-4 overflow-auto max-h-96">
|
||||
<div class="relative inline-block" style="image-rendering: pixelated;">
|
||||
<img src="@Model.CdnBaseUrl/@Model.Sheet.CdnPath"
|
||||
alt="@Model.Sheet.Name"
|
||||
id="sheetPreview"
|
||||
class="max-w-none" />
|
||||
<!-- Grid overlay will be drawn by JavaScript -->
|
||||
<canvas id="gridOverlay" class="absolute top-0 left-0 pointer-events-none"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-sm text-gray-400 mt-2">
|
||||
Grid: @Model.Sheet.Columns columns × @Model.Sheet.Rows rows = @Model.Sheet.TotalTiles tiles
|
||||
</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="bg-gray-900 rounded-lg p-8 text-center text-gray-500">
|
||||
Select a CDN path to preview the tilemap
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (Model.Sheet.Id > 0)
|
||||
{
|
||||
<!-- Tile Editor Section -->
|
||||
<div class="card mt-6">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h2 class="text-xl font-semibold text-white">Tile Definitions</h2>
|
||||
<div class="flex gap-2">
|
||||
<form method="post" asp-page-handler="AutoGenerate" class="inline">
|
||||
<input type="hidden" name="sheetId" value="@Model.Sheet.Id" />
|
||||
<select name="defaultType" class="input">
|
||||
<option value="0">Floor (walkable)</option>
|
||||
<option value="1">Wall (blocked)</option>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-secondary">Auto-Generate All</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-gray-400 mb-4">Click on a tile to define its properties. Defined tiles: @Model.TileDefinitions.Count / @Model.Sheet.TotalTiles</p>
|
||||
|
||||
<!-- Interactive Tile Grid -->
|
||||
<div class="bg-gray-900 rounded-lg p-4 overflow-auto">
|
||||
<div class="relative inline-block" id="tileGridContainer" style="image-rendering: pixelated;">
|
||||
@if (!string.IsNullOrEmpty(Model.Sheet.CdnPath))
|
||||
{
|
||||
<img src="@Model.CdnBaseUrl/@Model.Sheet.CdnPath"
|
||||
alt="@Model.Sheet.Name"
|
||||
id="tileGridImage"
|
||||
class="max-w-none" />
|
||||
|
||||
<!-- Clickable tile overlay -->
|
||||
<div id="tileClickOverlay" class="absolute top-0 left-0"
|
||||
style="width: @(Model.Sheet.SheetWidth)px; height: @(Model.Sheet.SheetHeight)px;">
|
||||
@for (int row = 0; row < Model.Sheet.Rows; row++)
|
||||
{
|
||||
@for (int col = 0; col < Model.Sheet.Columns; col++)
|
||||
{
|
||||
var frameIndex = row * Model.Sheet.Columns + col;
|
||||
var tileDef = Model.TileDefinitions.FirstOrDefault(t => t.FrameIndex == frameIndex);
|
||||
var hasDefinition = tileDef != null;
|
||||
var tileColor = hasDefinition ? GetTileTypeColor(tileDef!.Type) : "transparent";
|
||||
|
||||
<div class="absolute cursor-pointer border border-gray-700/50 hover:border-yellow-400 hover:bg-yellow-400/20 transition-all"
|
||||
style="left: @(col * Model.Sheet.TileWidth)px; top: @(row * Model.Sheet.TileHeight)px; width: @(Model.Sheet.TileWidth)px; height: @(Model.Sheet.TileHeight)px; background-color: @tileColor;"
|
||||
onclick="openTileEditor(@frameIndex, @(tileDef?.Id ?? 0))"
|
||||
title="Frame @frameIndex @(hasDefinition ? $"({tileDef!.Type})" : "(undefined)")">
|
||||
@if (hasDefinition)
|
||||
{
|
||||
<span class="absolute bottom-0 right-0 text-[8px] text-white bg-black/50 px-0.5">@frameIndex</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tile Type Legend -->
|
||||
<div class="mt-4 flex flex-wrap gap-2">
|
||||
<span class="text-sm text-gray-400">Legend:</span>
|
||||
<span class="px-2 py-0.5 text-xs rounded" style="background-color: rgba(34, 197, 94, 0.3);">Floor</span>
|
||||
<span class="px-2 py-0.5 text-xs rounded" style="background-color: rgba(239, 68, 68, 0.3);">Wall</span>
|
||||
<span class="px-2 py-0.5 text-xs rounded" style="background-color: rgba(168, 85, 247, 0.3);">Door</span>
|
||||
<span class="px-2 py-0.5 text-xs rounded" style="background-color: rgba(59, 130, 246, 0.3);">Water</span>
|
||||
<span class="px-2 py-0.5 text-xs rounded" style="background-color: rgba(249, 115, 22, 0.3);">Lava</span>
|
||||
<span class="px-2 py-0.5 text-xs rounded" style="background-color: rgba(234, 179, 8, 0.3);">Spawn</span>
|
||||
</div>
|
||||
|
||||
<!-- Defined Tiles Table -->
|
||||
@if (Model.TileDefinitions.Count > 0)
|
||||
{
|
||||
<div class="mt-6">
|
||||
<h3 class="text-lg font-semibold text-white mb-3">Defined Tiles</h3>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="text-left text-gray-400 border-b border-gray-700">
|
||||
<th class="p-2">Frame</th>
|
||||
<th class="p-2">Preview</th>
|
||||
<th class="p-2">Name</th>
|
||||
<th class="p-2">Type</th>
|
||||
<th class="p-2">Tags</th>
|
||||
<th class="p-2">Properties</th>
|
||||
<th class="p-2">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var tile in Model.TileDefinitions)
|
||||
{
|
||||
var col = tile.FrameIndex % Model.Sheet.Columns;
|
||||
var row = tile.FrameIndex / Model.Sheet.Columns;
|
||||
|
||||
<tr class="border-b border-gray-800 hover:bg-gray-800/50">
|
||||
<td class="p-2 text-gray-300">@tile.FrameIndex</td>
|
||||
<td class="p-2">
|
||||
<div class="w-8 h-8 bg-gray-900 overflow-hidden" style="image-rendering: pixelated;">
|
||||
<div style="width: @(Model.Sheet.TileWidth)px; height: @(Model.Sheet.TileHeight)px; background-image: url('@Model.CdnBaseUrl/@Model.Sheet.CdnPath'); background-position: -@(col * Model.Sheet.TileWidth)px -@(row * Model.Sheet.TileHeight)px; transform: scale(@(32.0 / Model.Sheet.TileWidth));"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-2 text-gray-300">@(tile.Name ?? "-")</td>
|
||||
<td class="p-2">
|
||||
<span class="px-2 py-0.5 text-xs rounded" style="background-color: @GetTileTypeColor(tile.Type);">@tile.Type</span>
|
||||
</td>
|
||||
<td class="p-2 text-gray-400 text-xs">@(tile.Tags ?? "-")</td>
|
||||
<td class="p-2 text-xs">
|
||||
@if (tile.IsWalkable) { <span class="text-green-400">Walk</span> }
|
||||
@if (tile.BlocksProjectiles) { <span class="text-red-400 ml-1">NoProj</span> }
|
||||
@if (tile.BlocksLineOfSight) { <span class="text-yellow-400 ml-1">NoLOS</span> }
|
||||
</td>
|
||||
<td class="p-2">
|
||||
<button onclick="openTileEditor(@tile.FrameIndex, @tile.Id)" class="text-blue-400 hover:text-blue-300 mr-2">Edit</button>
|
||||
<form method="post" asp-page-handler="DeleteTile" class="inline">
|
||||
<input type="hidden" name="tileId" value="@tile.Id" />
|
||||
<input type="hidden" name="sheetId" value="@Model.Sheet.Id" />
|
||||
<button type="submit" class="text-red-400 hover:text-red-300" onclick="return confirm('Delete?')">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Tile Editor Modal -->
|
||||
<div id="tileEditorModal" class="fixed inset-0 bg-black/50 z-50 hidden items-center justify-center">
|
||||
<div class="bg-gray-900 rounded-xl shadow-xl p-6 w-full max-w-md mx-4 border border-gray-700">
|
||||
<h3 class="text-lg font-semibold text-white mb-4">Edit Tile <span id="modalFrameIndex"></span></h3>
|
||||
|
||||
<form method="post" asp-page-handler="SaveTile">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="sheetId" value="@Model.Sheet.Id" />
|
||||
<input type="hidden" name="frameIndex" id="editFrameIndex" />
|
||||
|
||||
<div class="space-y-4">
|
||||
<!-- Tile Preview -->
|
||||
<div class="flex justify-center">
|
||||
<div id="modalTilePreview" class="bg-gray-800 border border-gray-600" style="image-rendering: pixelated;"></div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Name (optional)</label>
|
||||
<input type="text" name="name" id="editName" class="input w-full" placeholder="Stone Floor A" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Type</label>
|
||||
<select name="type" id="editType" class="input w-full">
|
||||
@foreach (var t in tileTypes)
|
||||
{
|
||||
<option value="@((int)t)">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Tags (comma-separated)</label>
|
||||
<input type="text" name="tags" id="editTags" class="input w-full" placeholder="stone, cracked, floor" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Render Layer</label>
|
||||
<select name="renderLayer" id="editRenderLayer" class="input w-full">
|
||||
<option value="0">0 - Ground</option>
|
||||
<option value="1">1 - Floor Decor</option>
|
||||
<option value="2">2 - Walls</option>
|
||||
<option value="3">3 - Ceiling/Overlay</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<label class="flex items-center gap-2 text-gray-300">
|
||||
<input type="checkbox" name="isWalkable" id="editWalkable" value="true" class="rounded" />
|
||||
Walkable
|
||||
</label>
|
||||
<label class="flex items-center gap-2 text-gray-300">
|
||||
<input type="checkbox" name="blocksProjectiles" id="editBlocksProj" value="true" class="rounded" />
|
||||
Blocks Proj
|
||||
</label>
|
||||
<label class="flex items-center gap-2 text-gray-300">
|
||||
<input type="checkbox" name="blocksLineOfSight" id="editBlocksLOS" value="true" class="rounded" />
|
||||
Blocks LOS
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 mt-6">
|
||||
<button type="submit" class="btn btn-primary flex-1">Save Tile</button>
|
||||
<button type="button" onclick="closeTileEditor()" class="btn btn-secondary flex-1">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CDN Browser Modal -->
|
||||
<div id="cdnBrowserModal" class="fixed inset-0 bg-black/50 z-50 hidden items-center justify-center">
|
||||
<div class="bg-gray-900 rounded-xl shadow-xl p-6 w-full max-w-2xl mx-4 border border-gray-700 max-h-[80vh] overflow-hidden flex flex-col">
|
||||
<h3 class="text-lg font-semibold text-white mb-4">Select TileMap from CDN</h3>
|
||||
<div class="flex-1 overflow-y-auto grid grid-cols-2 md:grid-cols-3 gap-3">
|
||||
@foreach (var asset in Model.CdnImages)
|
||||
{
|
||||
<button type="button" onclick="selectCdnImage('@asset.DownloadPath')" class="p-2 bg-gray-800 rounded-lg hover:bg-gray-700 text-left">
|
||||
<img src="@Model.CdnBaseUrl/@asset.DownloadPath" alt="@asset.FilePath" class="w-full h-20 object-contain mb-1" style="image-rendering: pixelated;" />
|
||||
<p class="text-xs text-gray-400 truncate">@asset.FilePath</p>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<div class="flex justify-end pt-4">
|
||||
<button type="button" onclick="closeCdnBrowser()" class="btn btn-secondary">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
// Tile definitions data from server
|
||||
const tileDefinitions = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(Model.TileDefinitions.ToDictionary(t => t.FrameIndex)));
|
||||
const sheetWidth = @Model.Sheet.SheetWidth;
|
||||
const sheetHeight = @Model.Sheet.SheetHeight;
|
||||
const tileWidth = @Model.Sheet.TileWidth;
|
||||
const tileHeight = @Model.Sheet.TileHeight;
|
||||
const columns = @Model.Sheet.Columns;
|
||||
const cdnBaseUrl = '@Model.CdnBaseUrl';
|
||||
const cdnPath = '@Model.Sheet.CdnPath';
|
||||
|
||||
function openTileEditor(frameIndex, existingId) {
|
||||
document.getElementById('editFrameIndex').value = frameIndex;
|
||||
document.getElementById('modalFrameIndex').textContent = '#' + frameIndex;
|
||||
|
||||
// Calculate tile position for preview
|
||||
const col = frameIndex % columns;
|
||||
const row = Math.floor(frameIndex / columns);
|
||||
|
||||
// Set preview
|
||||
const preview = document.getElementById('modalTilePreview');
|
||||
preview.style.width = (tileWidth * 2) + 'px';
|
||||
preview.style.height = (tileHeight * 2) + 'px';
|
||||
preview.style.backgroundImage = `url('${cdnBaseUrl}/${cdnPath}')`;
|
||||
preview.style.backgroundPosition = `-${col * tileWidth * 2}px -${row * tileHeight * 2}px`;
|
||||
preview.style.backgroundSize = `${sheetWidth * 2}px ${sheetHeight * 2}px`;
|
||||
|
||||
// Load existing data if available
|
||||
const existing = tileDefinitions[frameIndex];
|
||||
if (existing) {
|
||||
document.getElementById('editName').value = existing.Name || '';
|
||||
document.getElementById('editType').value = existing.Type;
|
||||
document.getElementById('editTags').value = existing.Tags || '';
|
||||
document.getElementById('editRenderLayer').value = existing.RenderLayer;
|
||||
document.getElementById('editWalkable').checked = existing.IsWalkable;
|
||||
document.getElementById('editBlocksProj').checked = existing.BlocksProjectiles;
|
||||
document.getElementById('editBlocksLOS').checked = existing.BlocksLineOfSight;
|
||||
} else {
|
||||
// Defaults for new tile
|
||||
document.getElementById('editName').value = '';
|
||||
document.getElementById('editType').value = '0';
|
||||
document.getElementById('editTags').value = '';
|
||||
document.getElementById('editRenderLayer').value = '0';
|
||||
document.getElementById('editWalkable').checked = true;
|
||||
document.getElementById('editBlocksProj').checked = false;
|
||||
document.getElementById('editBlocksLOS').checked = false;
|
||||
}
|
||||
|
||||
document.getElementById('tileEditorModal').classList.remove('hidden');
|
||||
document.getElementById('tileEditorModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeTileEditor() {
|
||||
document.getElementById('tileEditorModal').classList.add('hidden');
|
||||
document.getElementById('tileEditorModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
function showCdnBrowser() {
|
||||
document.getElementById('cdnBrowserModal').classList.remove('hidden');
|
||||
document.getElementById('cdnBrowserModal').classList.add('flex');
|
||||
}
|
||||
|
||||
function closeCdnBrowser() {
|
||||
document.getElementById('cdnBrowserModal').classList.add('hidden');
|
||||
document.getElementById('cdnBrowserModal').classList.remove('flex');
|
||||
}
|
||||
|
||||
function selectCdnImage(path) {
|
||||
document.getElementById('Sheet_CdnPath').value = path;
|
||||
closeCdnBrowser();
|
||||
}
|
||||
|
||||
// Draw grid overlay on preview
|
||||
function drawGridOverlay() {
|
||||
const img = document.getElementById('sheetPreview');
|
||||
const canvas = document.getElementById('gridOverlay');
|
||||
if (!img || !canvas) return;
|
||||
|
||||
canvas.width = img.naturalWidth;
|
||||
canvas.height = img.naturalHeight;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
// Vertical lines
|
||||
for (let x = tileWidth; x < canvas.width; x += tileWidth) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x, 0);
|
||||
ctx.lineTo(x, canvas.height);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// Horizontal lines
|
||||
for (let y = tileHeight; y < canvas.height; y += tileHeight) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, y);
|
||||
ctx.lineTo(canvas.width, y);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize when image loads
|
||||
const previewImg = document.getElementById('sheetPreview');
|
||||
if (previewImg) {
|
||||
previewImg.onload = drawGridOverlay;
|
||||
if (previewImg.complete) drawGridOverlay();
|
||||
}
|
||||
|
||||
// Close modals on escape
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape') {
|
||||
closeTileEditor();
|
||||
closeCdnBrowser();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
@functions {
|
||||
string GetTileTypeColor(TileType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
TileType.Floor => "rgba(34, 197, 94, 0.3)",
|
||||
TileType.Wall => "rgba(239, 68, 68, 0.3)",
|
||||
TileType.Door => "rgba(168, 85, 247, 0.3)",
|
||||
TileType.Water => "rgba(59, 130, 246, 0.3)",
|
||||
TileType.Lava => "rgba(249, 115, 22, 0.3)",
|
||||
TileType.Pit => "rgba(31, 41, 55, 0.5)",
|
||||
TileType.Stairs => "rgba(236, 72, 153, 0.3)",
|
||||
TileType.PlayerSpawn => "rgba(234, 179, 8, 0.4)",
|
||||
TileType.MobSpawn => "rgba(234, 179, 8, 0.3)",
|
||||
TileType.BossSpawn => "rgba(220, 38, 38, 0.4)",
|
||||
TileType.ChestSpawn => "rgba(251, 191, 36, 0.4)",
|
||||
TileType.Trigger => "rgba(139, 92, 246, 0.3)",
|
||||
TileType.Transition => "rgba(14, 165, 233, 0.3)",
|
||||
TileType.Secret => "rgba(163, 163, 163, 0.3)",
|
||||
TileType.Trap => "rgba(239, 68, 68, 0.4)",
|
||||
TileType.FloorDecor => "rgba(34, 197, 94, 0.2)",
|
||||
TileType.WallDecor => "rgba(239, 68, 68, 0.2)",
|
||||
_ => "transparent"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
|
||||
namespace Server.Services.Admin.Pages.TileMaps;
|
||||
|
||||
public class EditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public EditModel(GameDbContext db, IConfiguration config)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public TileMapSheet Sheet { get; set; } = new();
|
||||
|
||||
public List<TileDefinition> TileDefinitions { get; set; } = new();
|
||||
public List<ClientAsset> CdnImages { get; set; } = new();
|
||||
public string CdnBaseUrl { get; set; } = "";
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync(int? id)
|
||||
{
|
||||
CdnBaseUrl = _config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com";
|
||||
CdnImages = await _db.ClientAssets
|
||||
.Where(a => a.AssetType == ClientAssetType.Texture && a.IsEnabled)
|
||||
.Where(a => a.FilePath.StartsWith("textures/tilemaps/") || a.FilePath.Contains("tilemap"))
|
||||
.OrderBy(a => a.FilePath)
|
||||
.ToListAsync();
|
||||
|
||||
// Also get all textures as fallback
|
||||
if (CdnImages.Count == 0)
|
||||
{
|
||||
CdnImages = await _db.ClientAssets
|
||||
.Where(a => a.AssetType == ClientAssetType.Texture && a.IsEnabled)
|
||||
.OrderBy(a => a.FilePath)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
var sheet = await _db.TileMapSheets
|
||||
.Include(s => s.Tiles)
|
||||
.FirstOrDefaultAsync(s => s.Id == id.Value);
|
||||
|
||||
if (sheet != null)
|
||||
{
|
||||
Sheet = sheet;
|
||||
TileDefinitions = sheet.Tiles?.OrderBy(t => t.FrameIndex).ToList() ?? new();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Sheet = new TileMapSheet
|
||||
{
|
||||
IsEnabled = true,
|
||||
TileWidth = 32,
|
||||
TileHeight = 32
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
CdnBaseUrl = _config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com";
|
||||
|
||||
try
|
||||
{
|
||||
if (Sheet.Id == 0)
|
||||
{
|
||||
Sheet.CreatedAt = DateTime.UtcNow;
|
||||
Sheet.UpdatedAt = DateTime.UtcNow;
|
||||
_db.TileMapSheets.Add(Sheet);
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"TileMap sheet '{Sheet.Name}' created.";
|
||||
return RedirectToPage(new { id = Sheet.Id });
|
||||
}
|
||||
else
|
||||
{
|
||||
var existing = await _db.TileMapSheets.FindAsync(Sheet.Id);
|
||||
if (existing == null)
|
||||
{
|
||||
Message = "TileMap sheet not found.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
existing.Name = Sheet.Name;
|
||||
existing.CdnPath = Sheet.CdnPath;
|
||||
existing.Tags = Sheet.Tags;
|
||||
existing.SheetWidth = Sheet.SheetWidth;
|
||||
existing.SheetHeight = Sheet.SheetHeight;
|
||||
existing.TileWidth = Sheet.TileWidth;
|
||||
existing.TileHeight = Sheet.TileHeight;
|
||||
existing.IsEnabled = Sheet.IsEnabled;
|
||||
existing.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
Sheet = existing;
|
||||
Message = "TileMap sheet updated.";
|
||||
|
||||
TileDefinitions = await _db.TileDefinitions
|
||||
.Where(t => t.TileMapSheetId == Sheet.Id)
|
||||
.OrderBy(t => t.FrameIndex)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Message = $"Error: {ex.Message}";
|
||||
IsError = true;
|
||||
}
|
||||
|
||||
CdnImages = await _db.ClientAssets
|
||||
.Where(a => a.AssetType == ClientAssetType.Texture && a.IsEnabled)
|
||||
.OrderBy(a => a.FilePath)
|
||||
.ToListAsync();
|
||||
|
||||
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)
|
||||
{
|
||||
var existing = await _db.TileDefinitions
|
||||
.FirstOrDefaultAsync(t => t.TileMapSheetId == sheetId && t.FrameIndex == frameIndex);
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
existing.Name = name;
|
||||
existing.Type = (TileType)type;
|
||||
existing.Tags = tags;
|
||||
existing.IsWalkable = isWalkable;
|
||||
existing.BlocksProjectiles = blocksProjectiles;
|
||||
existing.BlocksLineOfSight = blocksLineOfSight;
|
||||
existing.RenderLayer = renderLayer;
|
||||
}
|
||||
else
|
||||
{
|
||||
_db.TileDefinitions.Add(new TileDefinition
|
||||
{
|
||||
TileMapSheetId = sheetId,
|
||||
FrameIndex = frameIndex,
|
||||
Name = name,
|
||||
Type = (TileType)type,
|
||||
Tags = tags,
|
||||
IsWalkable = isWalkable,
|
||||
BlocksProjectiles = blocksProjectiles,
|
||||
BlocksLineOfSight = blocksLineOfSight,
|
||||
RenderLayer = renderLayer,
|
||||
IsEnabled = true
|
||||
});
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
return RedirectToPage(new { id = sheetId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteTileAsync(int tileId, int sheetId)
|
||||
{
|
||||
var tile = await _db.TileDefinitions.FindAsync(tileId);
|
||||
if (tile != null)
|
||||
{
|
||||
_db.TileDefinitions.Remove(tile);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
return RedirectToPage(new { id = sheetId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAutoGenerateAsync(int sheetId, int defaultType)
|
||||
{
|
||||
var sheet = await _db.TileMapSheets.FindAsync(sheetId);
|
||||
if (sheet == null) return RedirectToPage();
|
||||
|
||||
// Generate tile definitions for all frames that don't have one
|
||||
var existingFrames = await _db.TileDefinitions
|
||||
.Where(t => t.TileMapSheetId == sheetId)
|
||||
.Select(t => t.FrameIndex)
|
||||
.ToListAsync();
|
||||
|
||||
var totalTiles = sheet.TotalTiles;
|
||||
for (int i = 0; i < totalTiles; i++)
|
||||
{
|
||||
if (!existingFrames.Contains(i))
|
||||
{
|
||||
_db.TileDefinitions.Add(new TileDefinition
|
||||
{
|
||||
TileMapSheetId = sheetId,
|
||||
FrameIndex = i,
|
||||
Type = (TileType)defaultType,
|
||||
IsWalkable = defaultType == 0, // Floor is walkable
|
||||
IsEnabled = true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
return RedirectToPage(new { id = sheetId });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
@page "/admin/tilemaps"
|
||||
@model TileMaps.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "TileMap Sheets";
|
||||
}
|
||||
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-white">TileMap Sheets</h1>
|
||||
<p class="text-gray-400">Manage tilemap sprite sheets for dungeon generation</p>
|
||||
</div>
|
||||
<a href="/admin/tilemaps/edit" class="btn btn-primary">+ New TileMap Sheet</a>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
@foreach (var sheet in Model.Sheets)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="flex justify-between items-start mb-3">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-white">@sheet.Name</h3>
|
||||
<p class="text-sm text-gray-400">@sheet.CdnPath</p>
|
||||
</div>
|
||||
<span class="px-2 py-1 text-xs rounded @(sheet.IsEnabled ? "bg-green-900 text-green-300" : "bg-red-900 text-red-300")">
|
||||
@(sheet.IsEnabled ? "Enabled" : "Disabled")
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Preview -->
|
||||
<div class="mb-3 bg-gray-900 rounded-lg p-2 flex justify-center">
|
||||
<img src="@Model.CdnBaseUrl/@sheet.CdnPath"
|
||||
alt="@sheet.Name"
|
||||
class="max-h-32 object-contain"
|
||||
style="image-rendering: pixelated;" />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-2 text-sm mb-3">
|
||||
<div>
|
||||
<span class="text-gray-500">Sheet Size:</span>
|
||||
<span class="text-gray-300">@sheet.SheetWidth x @sheet.SheetHeight</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">Tile Size:</span>
|
||||
<span class="text-gray-300">@sheet.TileWidth x @sheet.TileHeight</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">Grid:</span>
|
||||
<span class="text-gray-300">@sheet.Columns x @sheet.Rows (@sheet.TotalTiles tiles)</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">Defined:</span>
|
||||
<span class="text-gray-300">@(sheet.Tiles?.Count ?? 0) tiles</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(sheet.Tags))
|
||||
{
|
||||
<div class="flex flex-wrap gap-1 mb-3">
|
||||
@foreach (var tag in sheet.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
<span class="px-2 py-0.5 bg-blue-900/50 text-blue-300 text-xs rounded">@tag.Trim()</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/tilemaps/edit?id=@sheet.Id" class="btn btn-secondary flex-1 text-center">Edit</a>
|
||||
<form method="post" asp-page-handler="Delete" class="flex-1">
|
||||
<input type="hidden" name="id" value="@sheet.Id" />
|
||||
<button type="submit" class="btn bg-red-600 hover:bg-red-700 w-full"
|
||||
onclick="return confirm('Delete this tilemap sheet?')">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (Model.Sheets.Count == 0)
|
||||
{
|
||||
<div class="card text-center py-12">
|
||||
<p class="text-gray-400 mb-4">No tilemap sheets yet.</p>
|
||||
<a href="/admin/tilemaps/edit" class="btn btn-primary">Create Your First TileMap Sheet</a>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
|
||||
namespace Server.Services.Admin.Pages.TileMaps;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public IndexModel(GameDbContext db, IConfiguration config)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public List<TileMapSheet> Sheets { get; set; } = new();
|
||||
public string CdnBaseUrl { get; set; } = "";
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
CdnBaseUrl = _config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com";
|
||||
Sheets = await _db.TileMapSheets
|
||||
.Include(s => s.Tiles)
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var sheet = await _db.TileMapSheets.FindAsync(id);
|
||||
if (sheet != null)
|
||||
{
|
||||
// Check if used in any room templates
|
||||
// For now just delete - add check later
|
||||
_db.TileMapSheets.Remove(sheet);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,12 @@ public sealed class GameDbContext : DbContext
|
||||
public DbSet<MobAnimationAssignment> MobAnimationAssignments => Set<MobAnimationAssignment>();
|
||||
public DbSet<MobAbilityAnimationMapping> MobAbilityAnimationMappings => Set<MobAbilityAnimationMapping>();
|
||||
|
||||
// TileMap system
|
||||
public DbSet<TileMapSheet> TileMapSheets => Set<TileMapSheet>();
|
||||
public DbSet<TileDefinition> TileDefinitions => Set<TileDefinition>();
|
||||
public DbSet<RoomTemplate> RoomTemplates => Set<RoomTemplate>();
|
||||
public DbSet<DungeonTemplate> DungeonTemplates => Set<DungeonTemplate>();
|
||||
|
||||
public DbSet<DungeonBeltItem> DungeonBeltItems => Set<DungeonBeltItem>();
|
||||
public DbSet<DeathChest> DeathChests => Set<DeathChest>();
|
||||
public DbSet<DeathChestItem> DeathChestItems => Set<DeathChestItem>();
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DataServer.Data.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// A tilemap sprite sheet uploaded to CDN
|
||||
/// </summary>
|
||||
[Table("tilemap_sheets")]
|
||||
public class TileMapSheet
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>Friendly name (e.g., "Dungeon Stone Set", "Cave Tiles")</summary>
|
||||
[Required, MaxLength(64)]
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>CDN path (e.g., "textures/tilemaps/dungeon_stone.png")</summary>
|
||||
[Required, MaxLength(256)]
|
||||
public string CdnPath { get; set; } = "";
|
||||
|
||||
/// <summary>Tags for categorization (e.g., "dungeon,stone,dark")</summary>
|
||||
[MaxLength(256)]
|
||||
public string? Tags { get; set; }
|
||||
|
||||
/// <summary>Total width of sprite sheet in pixels</summary>
|
||||
public int SheetWidth { get; set; } = 512;
|
||||
|
||||
/// <summary>Total height of sprite sheet in pixels</summary>
|
||||
public int SheetHeight { get; set; } = 512;
|
||||
|
||||
/// <summary>Width of each tile in pixels</summary>
|
||||
public int TileWidth { get; set; } = 32;
|
||||
|
||||
/// <summary>Height of each tile in pixels (for isometric, often 16 or TileWidth/2)</summary>
|
||||
public int TileHeight { get; set; } = 32;
|
||||
|
||||
/// <summary>Number of columns in sheet</summary>
|
||||
[NotMapped]
|
||||
public int Columns => TileWidth > 0 ? SheetWidth / TileWidth : 1;
|
||||
|
||||
/// <summary>Number of rows in sheet</summary>
|
||||
[NotMapped]
|
||||
public int Rows => TileHeight > 0 ? SheetHeight / TileHeight : 1;
|
||||
|
||||
/// <summary>Total tile count</summary>
|
||||
[NotMapped]
|
||||
public int TotalTiles => Columns * Rows;
|
||||
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
// Navigation
|
||||
public ICollection<TileDefinition>? Tiles { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Definition of a single tile within a tilemap sheet
|
||||
/// </summary>
|
||||
[Table("tile_definitions")]
|
||||
public class TileDefinition
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int TileMapSheetId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(TileMapSheetId))]
|
||||
public TileMapSheet? TileMapSheet { get; set; }
|
||||
|
||||
/// <summary>Frame index in the sheet (0-based, left-to-right, top-to-bottom)</summary>
|
||||
public int FrameIndex { get; set; }
|
||||
|
||||
/// <summary>Optional name for this specific tile</summary>
|
||||
[MaxLength(64)]
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>Tile type for game logic</summary>
|
||||
public TileType Type { get; set; } = TileType.Floor;
|
||||
|
||||
/// <summary>Tags for filtering/selection (e.g., "stone,cracked,corner_nw")</summary>
|
||||
[MaxLength(256)]
|
||||
public string? Tags { get; set; }
|
||||
|
||||
/// <summary>Whether entities can walk on this tile</summary>
|
||||
public bool IsWalkable { get; set; } = true;
|
||||
|
||||
/// <summary>Whether projectiles can pass through</summary>
|
||||
public bool BlocksProjectiles { get; set; } = false;
|
||||
|
||||
/// <summary>Whether this blocks line of sight</summary>
|
||||
public bool BlocksLineOfSight { get; set; } = false;
|
||||
|
||||
/// <summary>Layer for rendering order (0=ground, 1=floor decor, 2=walls, 3=ceiling)</summary>
|
||||
public int RenderLayer { get; set; } = 0;
|
||||
|
||||
/// <summary>Z-index within the layer</summary>
|
||||
public int ZIndex { get; set; } = 0;
|
||||
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Types of tiles for game logic
|
||||
/// </summary>
|
||||
public enum TileType
|
||||
{
|
||||
Floor = 0,
|
||||
Wall = 1,
|
||||
Door = 2,
|
||||
Water = 3,
|
||||
Lava = 4,
|
||||
Pit = 5,
|
||||
Stairs = 6,
|
||||
|
||||
// Spawn points
|
||||
PlayerSpawn = 10,
|
||||
MobSpawn = 11,
|
||||
BossSpawn = 12,
|
||||
ChestSpawn = 13,
|
||||
|
||||
// Special
|
||||
Trigger = 20,
|
||||
Transition = 21,
|
||||
Secret = 22,
|
||||
Trap = 23,
|
||||
|
||||
// Decorative (walkable but with visual interest)
|
||||
FloorDecor = 30,
|
||||
WallDecor = 31
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A room template that can be placed in dungeons
|
||||
/// </summary>
|
||||
[Table("room_templates")]
|
||||
public class RoomTemplate
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>Name of this room template</summary>
|
||||
[Required, MaxLength(64)]
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>Description of the room</summary>
|
||||
[MaxLength(512)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>Tags for categorization (e.g., "entrance,large,treasure")</summary>
|
||||
[MaxLength(256)]
|
||||
public string? Tags { get; set; }
|
||||
|
||||
/// <summary>Room type for generation logic</summary>
|
||||
public RoomType Type { get; set; } = RoomType.Normal;
|
||||
|
||||
/// <summary>Width in tiles</summary>
|
||||
public int Width { get; set; } = 10;
|
||||
|
||||
/// <summary>Height in tiles</summary>
|
||||
public int Height { get; set; } = 10;
|
||||
|
||||
/// <summary>Minimum dungeon tier this room can appear in</summary>
|
||||
public int MinTier { get; set; } = 1;
|
||||
|
||||
/// <summary>Maximum dungeon tier (0 = no max)</summary>
|
||||
public int MaxTier { get; set; } = 0;
|
||||
|
||||
/// <summary>Spawn weight for random selection (higher = more common)</summary>
|
||||
public int Weight { get; set; } = 100;
|
||||
|
||||
/// <summary>JSON data containing tile placements</summary>
|
||||
[Column(TypeName = "json")]
|
||||
public string? TileDataJson { get; set; }
|
||||
|
||||
/// <summary>JSON data containing spawn points</summary>
|
||||
[Column(TypeName = "json")]
|
||||
public string? SpawnPointsJson { get; set; }
|
||||
|
||||
/// <summary>JSON data for connection points (where hallways can attach)</summary>
|
||||
[Column(TypeName = "json")]
|
||||
public string? ConnectionPointsJson { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Types of rooms for generation logic
|
||||
/// </summary>
|
||||
public enum RoomType
|
||||
{
|
||||
Normal = 0,
|
||||
Entrance = 1,
|
||||
Exit = 2,
|
||||
Boss = 3,
|
||||
Treasure = 4,
|
||||
Secret = 5,
|
||||
Shop = 6,
|
||||
Shrine = 7,
|
||||
Challenge = 8,
|
||||
Hallway = 9,
|
||||
Junction = 10
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A complete dungeon template (optional - for hand-crafted dungeons)
|
||||
/// </summary>
|
||||
[Table("dungeon_templates")]
|
||||
public class DungeonTemplate
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>Name of this dungeon</summary>
|
||||
[Required, MaxLength(64)]
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
/// <summary>Description</summary>
|
||||
[MaxLength(512)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>Tags for categorization</summary>
|
||||
[MaxLength(256)]
|
||||
public string? Tags { get; set; }
|
||||
|
||||
/// <summary>Dungeon tier (difficulty)</summary>
|
||||
public int Tier { get; set; } = 1;
|
||||
|
||||
/// <summary>Total width in tiles</summary>
|
||||
public int Width { get; set; } = 100;
|
||||
|
||||
/// <summary>Total height in tiles</summary>
|
||||
public int Height { get; set; } = 100;
|
||||
|
||||
/// <summary>If true, this is a complete hand-crafted dungeon. If false, it's generation parameters.</summary>
|
||||
public bool IsHandCrafted { get; set; } = false;
|
||||
|
||||
/// <summary>JSON containing full tile data (for hand-crafted)</summary>
|
||||
[Column(TypeName = "json")]
|
||||
public string? TileDataJson { get; set; }
|
||||
|
||||
/// <summary>JSON containing room placements (for hand-crafted or as hints for generation)</summary>
|
||||
[Column(TypeName = "json")]
|
||||
public string? RoomPlacementsJson { get; set; }
|
||||
|
||||
/// <summary>JSON containing generation parameters (room counts, weights, etc.)</summary>
|
||||
[Column(TypeName = "json")]
|
||||
public string? GenerationParamsJson { get; set; }
|
||||
|
||||
/// <summary>Default tilemap sheet to use</summary>
|
||||
public int? DefaultTileMapSheetId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(DefaultTileMapSheetId))]
|
||||
public TileMapSheet? DefaultTileMapSheet { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for tile placement data (serialized to JSON)
|
||||
/// </summary>
|
||||
public class TilePlacement
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public int TileDefinitionId { get; set; }
|
||||
public int Layer { get; set; } = 0;
|
||||
|
||||
/// <summary>Optional rotation (0, 90, 180, 270)</summary>
|
||||
public int Rotation { get; set; } = 0;
|
||||
|
||||
/// <summary>Optional flip X</summary>
|
||||
public bool FlipX { get; set; } = false;
|
||||
|
||||
/// <summary>Optional flip Y</summary>
|
||||
public bool FlipY { get; set; } = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for spawn point data (serialized to JSON)
|
||||
/// </summary>
|
||||
public class SpawnPoint
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public TileType Type { get; set; }
|
||||
|
||||
/// <summary>Optional specific mob/item ID to spawn</summary>
|
||||
public int? EntityId { get; set; }
|
||||
|
||||
/// <summary>Tags for filtering what can spawn here</summary>
|
||||
public string? Tags { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for room connection points (where hallways attach)
|
||||
/// </summary>
|
||||
public class ConnectionPoint
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
|
||||
/// <summary>Direction this connection faces (north, south, east, west)</summary>
|
||||
public string Direction { get; set; } = "north";
|
||||
|
||||
/// <summary>Width of the connection (for wider hallways)</summary>
|
||||
public int Width { get; set; } = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user