DungeonBuilder UI Attempt
This commit is contained in:
@@ -0,0 +1,208 @@
|
||||
@page "/admin/dungeonbuilder"
|
||||
@model DungeonBuilder.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Dungeon Builder";
|
||||
}
|
||||
|
||||
<div class="mb-6">
|
||||
<h1 class="text-2xl font-bold text-white">Dungeon Builder</h1>
|
||||
<p class="text-gray-400 mt-1">Visual tools for creating dungeon content</p>
|
||||
</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>
|
||||
}
|
||||
|
||||
<!-- Quick Stats -->
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
||||
<div class="card p-4">
|
||||
<div class="text-3xl font-bold text-blue-400">@Model.TileTemplateCount</div>
|
||||
<div class="text-gray-400 text-sm">Tile Templates</div>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<div class="text-3xl font-bold text-purple-400">@Model.ObjectTemplateCount</div>
|
||||
<div class="text-gray-400 text-sm">Object Templates</div>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<div class="text-3xl font-bold text-green-400">@Model.RoomTemplateCount</div>
|
||||
<div class="text-gray-400 text-sm">Room Templates</div>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<div class="text-3xl font-bold text-yellow-400">@Model.PaletteCount</div>
|
||||
<div class="text-gray-400 text-sm">Dungeon Palettes</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Builder Tools Grid -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
|
||||
<!-- Tile Templates -->
|
||||
<a href="/admin/dungeonbuilder/tiles" class="card p-6 hover:border-blue-500 transition-colors group">
|
||||
<div class="flex items-start gap-4">
|
||||
<div class="w-12 h-12 rounded-lg bg-blue-500/20 flex items-center justify-center text-blue-400 text-2xl">
|
||||
🧱
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<h3 class="text-lg font-semibold text-white group-hover:text-blue-400">Tile Templates</h3>
|
||||
<p class="text-gray-400 text-sm mt-1">Create reusable floor, wall, and door patterns</p>
|
||||
<div class="mt-3 text-xs text-gray-500">
|
||||
• Single tiles or multi-tile patterns<br>
|
||||
• Socket configuration for matching<br>
|
||||
• Walkability and blocking settings
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<!-- Object Templates -->
|
||||
<a href="/admin/dungeonbuilder/objects" class="card p-6 hover:border-purple-500 transition-colors group">
|
||||
<div class="flex items-start gap-4">
|
||||
<div class="w-12 h-12 rounded-lg bg-purple-500/20 flex items-center justify-center text-purple-400 text-2xl">
|
||||
🏺
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<h3 class="text-lg font-semibold text-white group-hover:text-purple-400">Object Templates</h3>
|
||||
<p class="text-gray-400 text-sm mt-1">Design furniture, containers, traps, and decorations</p>
|
||||
<div class="mt-3 text-xs text-gray-500">
|
||||
• Animation states<br>
|
||||
• Interaction settings<br>
|
||||
• Loot and rewards
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<!-- Room Templates -->
|
||||
<a href="/admin/dungeonbuilder/rooms" class="card p-6 hover:border-green-500 transition-colors group">
|
||||
<div class="flex items-start gap-4">
|
||||
<div class="w-12 h-12 rounded-lg bg-green-500/20 flex items-center justify-center text-green-400 text-2xl">
|
||||
🗺️
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<h3 class="text-lg font-semibold text-white group-hover:text-green-400">Room Templates</h3>
|
||||
<p class="text-gray-400 text-sm mt-1">Build complete rooms with tiles, objects, and spawns</p>
|
||||
<div class="mt-3 text-xs text-gray-500">
|
||||
• Visual room editor<br>
|
||||
• Connection points<br>
|
||||
• Mob and item spawns
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<!-- Dungeon Palettes -->
|
||||
<a href="/admin/dungeonbuilder/palettes" class="card p-6 hover:border-yellow-500 transition-colors group">
|
||||
<div class="flex items-start gap-4">
|
||||
<div class="w-12 h-12 rounded-lg bg-yellow-500/20 flex items-center justify-center text-yellow-400 text-2xl">
|
||||
🎨
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<h3 class="text-lg font-semibold text-white group-hover:text-yellow-400">Dungeon Palettes</h3>
|
||||
<p class="text-gray-400 text-sm mt-1">Combine templates into themed dungeon sets</p>
|
||||
<div class="mt-3 text-xs text-gray-500">
|
||||
• Template collections<br>
|
||||
• Generation parameters<br>
|
||||
• Biome configuration
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<!-- Sprite Sheet Manager -->
|
||||
<a href="/admin/tilemaps" class="card p-6 hover:border-cyan-500 transition-colors group">
|
||||
<div class="flex items-start gap-4">
|
||||
<div class="w-12 h-12 rounded-lg bg-cyan-500/20 flex items-center justify-center text-cyan-400 text-2xl">
|
||||
🖼️
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<h3 class="text-lg font-semibold text-white group-hover:text-cyan-400">Sprite Sheets</h3>
|
||||
<p class="text-gray-400 text-sm mt-1">Manage tilemap sprite sheets and tile definitions</p>
|
||||
<div class="mt-3 text-xs text-gray-500">
|
||||
• Upload sprite sheets<br>
|
||||
• Tag individual tiles<br>
|
||||
• Define tile properties
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<!-- Test Generator -->
|
||||
<a href="/admin/dungeonbuilder/test" class="card p-6 hover:border-orange-500 transition-colors group">
|
||||
<div class="flex items-start gap-4">
|
||||
<div class="w-12 h-12 rounded-lg bg-orange-500/20 flex items-center justify-center text-orange-400 text-2xl">
|
||||
🧪
|
||||
</div>
|
||||
<div class="flex-1">
|
||||
<h3 class="text-lg font-semibold text-white group-hover:text-orange-400">Test Generator</h3>
|
||||
<p class="text-gray-400 text-sm mt-1">Preview dungeon generation with your templates</p>
|
||||
<div class="mt-3 text-xs text-gray-500">
|
||||
• Generate test dungeons<br>
|
||||
• Visual preview<br>
|
||||
• Adjust parameters
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Recent Activity -->
|
||||
<div class="card p-6 mt-6">
|
||||
<h3 class="text-lg font-semibold text-white mb-4">Recent Templates</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="pb-2 pr-4">Type</th>
|
||||
<th class="pb-2 pr-4">Name</th>
|
||||
<th class="pb-2 pr-4">Biome</th>
|
||||
<th class="pb-2 pr-4">Updated</th>
|
||||
<th class="pb-2">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700/50">
|
||||
@foreach (var item in Model.RecentItems)
|
||||
{
|
||||
<tr class="hover:bg-gray-800/50">
|
||||
<td class="py-2 pr-4">
|
||||
<span class="px-2 py-0.5 rounded text-xs @GetTypeColor(item.Type)">
|
||||
@item.Type
|
||||
</span>
|
||||
</td>
|
||||
<td class="py-2 pr-4 text-white">@item.Name</td>
|
||||
<td class="py-2 pr-4 text-gray-400">@(item.Biome ?? "-")</td>
|
||||
<td class="py-2 pr-4 text-gray-500">@item.UpdatedAt.ToString("MMM d, HH:mm")</td>
|
||||
<td class="py-2">
|
||||
<a href="@item.EditUrl" class="text-blue-400 hover:text-blue-300">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@if (!Model.RecentItems.Any())
|
||||
{
|
||||
<tr>
|
||||
<td colspan="5" class="py-8 text-center text-gray-500">
|
||||
No templates created yet. Start by creating a tile or object template!
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@functions {
|
||||
string GetTypeColor(string type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
"Tile" => "bg-blue-500/20 text-blue-400",
|
||||
"Object" => "bg-purple-500/20 text-purple-400",
|
||||
"Room" => "bg-green-500/20 text-green-400",
|
||||
"Palette" => "bg-yellow-500/20 text-yellow-400",
|
||||
_ => "bg-gray-500/20 text-gray-400"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Server.Services.Admin.Pages.DungeonBuilder;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public IndexModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public int TileTemplateCount { get; set; }
|
||||
public int ObjectTemplateCount { get; set; }
|
||||
public int RoomTemplateCount { get; set; }
|
||||
public int PaletteCount { get; set; }
|
||||
|
||||
public List<RecentItem> RecentItems { get; set; } = new();
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
// Get counts
|
||||
TileTemplateCount = await _db.TileTemplates.CountAsync();
|
||||
ObjectTemplateCount = await _db.ObjectTemplates.CountAsync();
|
||||
RoomTemplateCount = await _db.BuilderRoomTemplates.CountAsync();
|
||||
PaletteCount = await _db.DungeonPalettes.CountAsync();
|
||||
|
||||
// Get recent items (combined from all types)
|
||||
var recentTiles = await _db.TileTemplates
|
||||
.OrderByDescending(t => t.UpdatedAt)
|
||||
.Take(3)
|
||||
.Select(t => new RecentItem
|
||||
{
|
||||
Type = "Tile",
|
||||
Name = t.Name,
|
||||
Biome = t.Biome,
|
||||
UpdatedAt = t.UpdatedAt,
|
||||
EditUrl = $"/admin/dungeonbuilder/tiles/edit?id={t.Id}"
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var recentObjects = await _db.ObjectTemplates
|
||||
.OrderByDescending(t => t.UpdatedAt)
|
||||
.Take(3)
|
||||
.Select(t => new RecentItem
|
||||
{
|
||||
Type = "Object",
|
||||
Name = t.Name,
|
||||
Biome = t.Biome,
|
||||
UpdatedAt = t.UpdatedAt,
|
||||
EditUrl = $"/admin/dungeonbuilder/objects/edit?id={t.Id}"
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var recentRooms = await _db.BuilderRoomTemplates
|
||||
.OrderByDescending(t => t.UpdatedAt)
|
||||
.Take(3)
|
||||
.Select(t => new RecentItem
|
||||
{
|
||||
Type = "Room",
|
||||
Name = t.Name,
|
||||
Biome = t.Biome,
|
||||
UpdatedAt = t.UpdatedAt,
|
||||
EditUrl = $"/admin/dungeonbuilder/rooms/edit?id={t.Id}"
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var recentPalettes = await _db.DungeonPalettes
|
||||
.OrderByDescending(t => t.UpdatedAt)
|
||||
.Take(2)
|
||||
.Select(t => new RecentItem
|
||||
{
|
||||
Type = "Palette",
|
||||
Name = t.Name,
|
||||
Biome = t.Biome,
|
||||
UpdatedAt = t.UpdatedAt,
|
||||
EditUrl = $"/admin/dungeonbuilder/palettes/edit?id={t.Id}"
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
RecentItems = recentTiles
|
||||
.Concat(recentObjects)
|
||||
.Concat(recentRooms)
|
||||
.Concat(recentPalettes)
|
||||
.OrderByDescending(x => x.UpdatedAt)
|
||||
.Take(10)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public class RecentItem
|
||||
{
|
||||
public string Type { get; set; } = "";
|
||||
public string Name { get; set; } = "";
|
||||
public string? Biome { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
public string EditUrl { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
@page "/admin/dungeonbuilder/objects/edit"
|
||||
@model DungeonBuilder.ObjectEditModel
|
||||
@using DataServer.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = Model.Object.Id == 0 ? "New Object Template" : $"Edit: {Model.Object.Name}";
|
||||
var types = Enum.GetValues<ObjectTemplateType>();
|
||||
var interactionTypes = Enum.GetValues<ObjectInteractionType>();
|
||||
var placementTypes = Enum.GetValues<ObjectPlacement>();
|
||||
}
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/admin/dungeonbuilder/objects" class="text-blue-400 hover:text-blue-300 text-sm">← Back to Objects</a>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl font-bold text-white mb-6">@ViewData["Title"]</h1>
|
||||
|
||||
@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>
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Object.Id" />
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
|
||||
<!-- Left Column: Basic Info -->
|
||||
<div class="space-y-6">
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Basic Settings</h2>
|
||||
|
||||
<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="Object.Name" class="input w-full" required />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Description</label>
|
||||
<textarea asp-for="Object.Description" rows="2" class="input w-full"></textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Type</label>
|
||||
<select asp-for="Object.Type" class="input w-full">
|
||||
@foreach (var t in types)
|
||||
{
|
||||
<option value="@t">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Biome</label>
|
||||
<input type="text" asp-for="Object.Biome" class="input w-full" placeholder="dungeon" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Tags</label>
|
||||
<input type="text" asp-for="Object.Tags" class="input w-full" placeholder="stone,dark" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Object.IsEnabled" class="rounded" />
|
||||
<label asp-for="Object.IsEnabled" class="text-gray-300">Enabled</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Size & Blocking</h2>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4 mb-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Width (tiles)</label>
|
||||
<input type="number" asp-for="Object.Width" class="input w-full" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Height (tiles)</label>
|
||||
<input type="number" asp-for="Object.Height" class="input w-full" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Object.BlocksMovement" class="rounded" />
|
||||
<label asp-for="Object.BlocksMovement" class="text-gray-300">Blocks Movement</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Object.BlocksProjectiles" class="rounded" />
|
||||
<label asp-for="Object.BlocksProjectiles" class="text-gray-300">Blocks Projectiles</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Object.BlocksLineOfSight" class="rounded" />
|
||||
<label asp-for="Object.BlocksLineOfSight" class="text-gray-300">Blocks Line of Sight</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Middle Column: Sprite & Animation -->
|
||||
<div class="space-y-6">
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Sprite</h2>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Sprite Sheet</label>
|
||||
<select asp-for="Object.SpriteSheetId" class="input w-full" id="spriteSheetSelect">
|
||||
<option value="">-- Use CDN Path Instead --</option>
|
||||
@foreach (var sheet in Model.SpriteSheets)
|
||||
{
|
||||
<option value="@sheet.Id"
|
||||
data-cdn="@sheet.CdnPath"
|
||||
data-cols="@sheet.Columns"
|
||||
data-tw="@sheet.TileWidth"
|
||||
data-th="@sheet.TileHeight"
|
||||
data-sw="@sheet.SheetWidth"
|
||||
data-sh="@sheet.SheetHeight">
|
||||
@sheet.Name (@sheet.TotalTiles tiles)
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Frame Index</label>
|
||||
<input type="number" asp-for="Object.FrameIndex" class="input w-full" min="0" id="frameIndexInput" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Or CDN Path</label>
|
||||
<input type="text" asp-for="Object.SpritePath" class="input w-full" placeholder="objects/chest.png" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Preview -->
|
||||
<div class="mt-4 bg-gray-900 rounded-lg p-4 min-h-[100px] flex items-center justify-center" id="spritePreview">
|
||||
<span class="text-gray-600">Select a sprite to preview</span>
|
||||
</div>
|
||||
|
||||
<!-- Frame Picker -->
|
||||
<div id="framePicker" class="mt-4 hidden">
|
||||
<label class="block text-sm font-medium text-gray-300 mb-2">Click to select frame:</label>
|
||||
<div class="bg-gray-900 rounded-lg p-2 overflow-auto max-h-[250px]">
|
||||
<div id="frameGrid" class="relative inline-block" style="image-rendering: pixelated;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Animation</h2>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Object.IsAnimated" class="rounded" id="isAnimatedCheck" />
|
||||
<label asp-for="Object.IsAnimated" class="text-gray-300">Is Animated</label>
|
||||
</div>
|
||||
|
||||
<div id="animationSettings" class="space-y-4">
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Frame Count</label>
|
||||
<input type="number" asp-for="Object.AnimationFrameCount" class="input w-full" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">FPS</label>
|
||||
<input type="number" asp-for="Object.AnimationFps" class="input w-full" min="1" step="0.1" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Object.AnimationLoops" class="rounded" />
|
||||
<label asp-for="Object.AnimationLoops" class="text-gray-300">Loops</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Animation States (JSON)</label>
|
||||
<textarea asp-for="Object.AnimationStatesJson" rows="3" class="input w-full font-mono text-xs"
|
||||
placeholder='{"idle":{"startFrame":0,"frameCount":4,"fps":8}}'></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right Column: Interaction & Rewards -->
|
||||
<div class="space-y-6">
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Interaction</h2>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Object.IsInteractable" class="rounded" />
|
||||
<label asp-for="Object.IsInteractable" class="text-gray-300">Is Interactable (Click)</label>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Object.TriggeredByWalk" class="rounded" />
|
||||
<label asp-for="Object.TriggeredByWalk" class="text-gray-300">Triggered by Walking</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Interaction Type</label>
|
||||
<select asp-for="Object.InteractionType" class="input w-full">
|
||||
@foreach (var t in interactionTypes)
|
||||
{
|
||||
<option value="@t">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Interaction State</label>
|
||||
<input type="text" asp-for="Object.InteractionState" class="input w-full" placeholder="open" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Cooldown (seconds)</label>
|
||||
<input type="number" asp-for="Object.InteractionCooldown" class="input w-full" min="0" step="0.1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Loot & Rewards</h2>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Loot Table</label>
|
||||
<select asp-for="Object.LootTableId" class="input w-full">
|
||||
<option value="">-- None --</option>
|
||||
@foreach (var lt in Model.LootTables)
|
||||
{
|
||||
<option value="@lt.Id">@lt.Name</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Gold</label>
|
||||
<input type="number" asp-for="Object.GoldAmount" class="input w-full" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">XP</label>
|
||||
<input type="number" asp-for="Object.XpReward" class="input w-full" min="0" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Trap / Hazard</h2>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Damage</label>
|
||||
<input type="number" asp-for="Object.Damage" class="input w-full" min="0" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Damage Type</label>
|
||||
<select asp-for="Object.DamageTypeKey" class="input w-full">
|
||||
<option value="">-- None --</option>
|
||||
@foreach (var dt in Model.DamageTypes)
|
||||
{
|
||||
<option value="@dt.Key">@dt.Name</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Trigger Delay</label>
|
||||
<input type="number" asp-for="Object.TriggerDelay" class="input w-full" min="0" step="0.1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Reset Time</label>
|
||||
<input type="number" asp-for="Object.ResetTime" class="input w-full" min="0" step="0.1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Generation</h2>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Weight</label>
|
||||
<input type="number" asp-for="Object.Weight" class="input w-full" min="1" />
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Min Tier</label>
|
||||
<input type="number" asp-for="Object.MinTier" class="input w-full" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-300 mb-1">Max Tier</label>
|
||||
<input type="number" asp-for="Object.MaxTier" class="input w-full" min="0" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-4 mt-6">
|
||||
<a href="/admin/dungeonbuilder/objects" class="btn btn-ghost">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
@(Model.Object.Id == 0 ? "Create Object" : "Save Changes")
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
const cdnBaseUrl = '@Model.CdnBaseUrl';
|
||||
const sheetSelect = document.getElementById('spriteSheetSelect');
|
||||
const frameIndexInput = document.getElementById('frameIndexInput');
|
||||
const spritePreview = document.getElementById('spritePreview');
|
||||
const framePicker = document.getElementById('framePicker');
|
||||
const frameGrid = document.getElementById('frameGrid');
|
||||
|
||||
function updateSpritePreview() {
|
||||
const option = sheetSelect.selectedOptions[0];
|
||||
|
||||
if (!option || !option.value) {
|
||||
framePicker.classList.add('hidden');
|
||||
spritePreview.innerHTML = '<span class="text-gray-600">Select a sprite sheet</span>';
|
||||
return;
|
||||
}
|
||||
|
||||
const cdn = option.dataset.cdn;
|
||||
const cols = parseInt(option.dataset.cols);
|
||||
const tw = parseInt(option.dataset.tw);
|
||||
const th = parseInt(option.dataset.th);
|
||||
const sw = parseInt(option.dataset.sw);
|
||||
const sh = parseInt(option.dataset.sh);
|
||||
const frameIndex = parseInt(frameIndexInput.value) || 0;
|
||||
|
||||
const col = frameIndex % cols;
|
||||
const row = Math.floor(frameIndex / cols);
|
||||
const bgX = -col * tw;
|
||||
const bgY = -row * th;
|
||||
const imgUrl = `${cdnBaseUrl}/downloads/${cdn}`;
|
||||
|
||||
spritePreview.innerHTML = `
|
||||
<div style="width: ${tw}px; height: ${th}px;
|
||||
background: url('${imgUrl}') ${bgX}px ${bgY}px no-repeat;
|
||||
background-size: ${sw}px ${sh}px;
|
||||
image-rendering: pixelated;
|
||||
transform: scale(2);"></div>
|
||||
`;
|
||||
|
||||
framePicker.classList.remove('hidden');
|
||||
const rows = Math.ceil((cols * Math.ceil(sh / th)) / cols);
|
||||
frameGrid.innerHTML = `
|
||||
<img src="${imgUrl}" style="display: block;" />
|
||||
<div class="absolute inset-0" style="display: grid; grid-template-columns: repeat(${cols}, ${tw}px);">
|
||||
${Array.from({length: cols * rows}, (_, i) => {
|
||||
const selected = i === frameIndex;
|
||||
return `<div class="border border-white/20 hover:bg-blue-500/30 cursor-pointer ${selected ? 'ring-2 ring-yellow-400' : ''}"
|
||||
style="width: ${tw}px; height: ${th}px;"
|
||||
onclick="selectFrame(${i})"></div>`;
|
||||
}).join('')}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function selectFrame(index) {
|
||||
frameIndexInput.value = index;
|
||||
updateSpritePreview();
|
||||
}
|
||||
|
||||
sheetSelect.addEventListener('change', updateSpritePreview);
|
||||
frameIndexInput.addEventListener('change', updateSpritePreview);
|
||||
updateSpritePreview();
|
||||
</script>
|
||||
@@ -0,0 +1,170 @@
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Server.Services.Admin.Pages.DungeonBuilder;
|
||||
|
||||
public class ObjectEditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public ObjectEditModel(GameDbContext db, IConfiguration config)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public ObjectTemplate Object { get; set; } = new();
|
||||
|
||||
public List<TileMapSheet> SpriteSheets { get; set; } = new();
|
||||
public List<DungeonLootTable> LootTables { get; set; } = new();
|
||||
public List<DamageResistanceType> DamageTypes { get; set; } = new();
|
||||
public List<string> CdnImages { get; set; } = new();
|
||||
|
||||
public string CdnBaseUrl => _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? "";
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync(int? id)
|
||||
{
|
||||
await LoadReferenceData();
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
var obj = await _db.ObjectTemplates
|
||||
.Include(o => o.SpriteSheet)
|
||||
.FirstOrDefaultAsync(o => o.Id == id.Value);
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
Object = obj;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Defaults for new object
|
||||
Object.IsEnabled = true;
|
||||
Object.Weight = 100;
|
||||
Object.Width = 1;
|
||||
Object.Height = 1;
|
||||
Object.AnimationFps = 8.0f;
|
||||
Object.AnimationFrameCount = 1;
|
||||
Object.AnimationLoops = true;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
await LoadReferenceData();
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
IsError = true;
|
||||
Message = "Please fix validation errors.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
Object.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
if (Object.Id == 0)
|
||||
{
|
||||
Object.CreatedAt = DateTime.UtcNow;
|
||||
_db.ObjectTemplates.Add(Object);
|
||||
Message = "Object template created!";
|
||||
}
|
||||
else
|
||||
{
|
||||
var existing = await _db.ObjectTemplates.FindAsync(Object.Id);
|
||||
if (existing == null)
|
||||
{
|
||||
IsError = true;
|
||||
Message = "Object not found.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
// Update properties
|
||||
existing.Name = Object.Name;
|
||||
existing.Description = Object.Description;
|
||||
existing.Type = Object.Type;
|
||||
existing.Tags = Object.Tags;
|
||||
existing.Biome = Object.Biome;
|
||||
existing.SpriteSheetId = Object.SpriteSheetId;
|
||||
existing.FrameIndex = Object.FrameIndex;
|
||||
existing.SpritePath = Object.SpritePath;
|
||||
existing.Width = Object.Width;
|
||||
existing.Height = Object.Height;
|
||||
existing.OffsetX = Object.OffsetX;
|
||||
existing.OffsetY = Object.OffsetY;
|
||||
existing.ZIndex = Object.ZIndex;
|
||||
existing.BlocksMovement = Object.BlocksMovement;
|
||||
existing.BlocksProjectiles = Object.BlocksProjectiles;
|
||||
existing.BlocksLineOfSight = Object.BlocksLineOfSight;
|
||||
existing.BlockedCellsJson = Object.BlockedCellsJson;
|
||||
existing.IsAnimated = Object.IsAnimated;
|
||||
existing.AnimationFrameCount = Object.AnimationFrameCount;
|
||||
existing.AnimationFps = Object.AnimationFps;
|
||||
existing.AnimationLoops = Object.AnimationLoops;
|
||||
existing.AnimationStatesJson = Object.AnimationStatesJson;
|
||||
existing.DefaultState = Object.DefaultState;
|
||||
existing.IsInteractable = Object.IsInteractable;
|
||||
existing.TriggeredByWalk = Object.TriggeredByWalk;
|
||||
existing.InteractionType = Object.InteractionType;
|
||||
existing.InteractionState = Object.InteractionState;
|
||||
existing.InteractionCooldown = Object.InteractionCooldown;
|
||||
existing.RequiredItemId = Object.RequiredItemId;
|
||||
existing.LootTableId = Object.LootTableId;
|
||||
existing.GoldAmount = Object.GoldAmount;
|
||||
existing.XpReward = Object.XpReward;
|
||||
existing.IsDestructible = Object.IsDestructible;
|
||||
existing.Health = Object.Health;
|
||||
existing.DestroyedState = Object.DestroyedState;
|
||||
existing.DestroyedLootTableId = Object.DestroyedLootTableId;
|
||||
existing.Damage = Object.Damage;
|
||||
existing.DamageTypeKey = Object.DamageTypeKey;
|
||||
existing.TriggerDelay = Object.TriggerDelay;
|
||||
existing.ResetTime = Object.ResetTime;
|
||||
existing.Weight = Object.Weight;
|
||||
existing.MinTier = Object.MinTier;
|
||||
existing.MaxTier = Object.MaxTier;
|
||||
existing.MaxPerRoom = Object.MaxPerRoom;
|
||||
existing.Placement = Object.Placement;
|
||||
existing.IsEnabled = Object.IsEnabled;
|
||||
existing.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
Message = "Changes saved!";
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage(new { id = Object.Id });
|
||||
}
|
||||
|
||||
private async Task LoadReferenceData()
|
||||
{
|
||||
SpriteSheets = await _db.TileMapSheets
|
||||
.Where(s => s.IsEnabled)
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync();
|
||||
|
||||
LootTables = await _db.DungeonLootTables
|
||||
.Where(t => t.IsEnabled)
|
||||
.OrderBy(t => t.Name)
|
||||
.ToListAsync();
|
||||
|
||||
DamageTypes = await _db.DamageResistanceTypes
|
||||
.OrderBy(d => d.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public string GetCdnUrl(string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) return "";
|
||||
var baseUrl = CdnBaseUrl;
|
||||
if (!baseUrl.EndsWith("/downloads")) baseUrl += "/downloads";
|
||||
return $"{baseUrl}/{path.TrimStart('/')}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
@page "/admin/dungeonbuilder/objects"
|
||||
@model DungeonBuilder.ObjectsModel
|
||||
@using DataServer.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = "Object Templates";
|
||||
var types = Enum.GetValues<ObjectTemplateType>();
|
||||
}
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/admin/dungeonbuilder" class="text-blue-400 hover:text-blue-300 text-sm">← Back to Dungeon Builder</a>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-6">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-white">Object Templates</h1>
|
||||
<p class="text-gray-400 text-sm mt-1">Furniture, containers, traps, and decorations</p>
|
||||
</div>
|
||||
<a href="/admin/dungeonbuilder/objects/edit" class="btn btn-primary">+ New Object</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>
|
||||
}
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="card p-4 mb-4">
|
||||
<form method="get" class="flex flex-wrap gap-3">
|
||||
<div class="flex-1 min-w-[150px]">
|
||||
<input type="text" name="search" value="@Model.Search"
|
||||
class="input w-full text-sm" placeholder="Search by name..." />
|
||||
</div>
|
||||
<select name="type" class="input text-sm">
|
||||
<option value="">All Types</option>
|
||||
@foreach (var t in types)
|
||||
{
|
||||
<option value="@((int)t)" selected="@(Model.TypeFilter == (int)t)">@t</option>
|
||||
}
|
||||
</select>
|
||||
<select name="biome" class="input text-sm">
|
||||
<option value="">All Biomes</option>
|
||||
@foreach (var b in Model.Biomes)
|
||||
{
|
||||
<option value="@b" selected="@(Model.BiomeFilter == b)">@b</option>
|
||||
}
|
||||
</select>
|
||||
<button type="submit" class="btn btn-secondary text-sm">Filter</button>
|
||||
<a href="/admin/dungeonbuilder/objects" class="btn btn-ghost text-sm">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Objects Grid -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
||||
@foreach (var obj in Model.Objects)
|
||||
{
|
||||
<div class="card p-4 hover:border-purple-500/50 transition-colors">
|
||||
<div class="flex items-start gap-3">
|
||||
<!-- Preview -->
|
||||
<div class="w-16 h-16 bg-gray-900 rounded flex items-center justify-center flex-shrink-0">
|
||||
@if (obj.SpriteSheetId.HasValue && obj.SpriteSheet != null)
|
||||
{
|
||||
var cols = obj.SpriteSheet.TileWidth > 0 ? obj.SpriteSheet.SheetWidth / obj.SpriteSheet.TileWidth : 1;
|
||||
var row = obj.FrameIndex / cols;
|
||||
var col = obj.FrameIndex % cols;
|
||||
var bgX = -col * obj.SpriteSheet.TileWidth;
|
||||
var bgY = -row * obj.SpriteSheet.TileHeight;
|
||||
var imgUrl = Model.GetCdnUrl(obj.SpriteSheet.CdnPath);
|
||||
|
||||
<div style="width: @(obj.SpriteSheet.TileWidth)px; height: @(obj.SpriteSheet.TileHeight)px;
|
||||
background: url('@imgUrl') @(bgX)px @(bgY)px no-repeat;
|
||||
background-size: @(obj.SpriteSheet.SheetWidth)px @(obj.SpriteSheet.SheetHeight)px;
|
||||
image-rendering: pixelated;"></div>
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(obj.SpritePath))
|
||||
{
|
||||
<img src="@Model.GetCdnUrl(obj.SpritePath)" alt="@obj.Name" class="max-w-full max-h-full" style="image-rendering: pixelated;" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-600 text-2xl">📦</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Info -->
|
||||
<div class="flex-1 min-w-0">
|
||||
<h3 class="font-semibold text-white truncate">@obj.Name</h3>
|
||||
<div class="text-xs text-gray-400 mt-1">
|
||||
<span class="@GetTypeColor(obj.Type)">@obj.Type</span>
|
||||
@if (!string.IsNullOrEmpty(obj.Biome))
|
||||
{
|
||||
<span class="ml-2">@obj.Biome</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Flags -->
|
||||
<div class="flex flex-wrap gap-1 mt-2">
|
||||
@if (obj.IsInteractable)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded text-xs">Interactive</span>
|
||||
}
|
||||
@if (obj.TriggeredByWalk)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-yellow-500/20 text-yellow-400 rounded text-xs">Walk Trigger</span>
|
||||
}
|
||||
@if (obj.IsAnimated)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded text-xs">Animated</span>
|
||||
}
|
||||
@if (obj.BlocksMovement)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-red-500/20 text-red-400 rounded text-xs">Solid</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between mt-3 pt-3 border-t border-gray-700">
|
||||
<span class="text-xs text-gray-500">ID: @obj.Id</span>
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/dungeonbuilder/objects/edit?id=@obj.Id" class="text-blue-400 hover:text-blue-300 text-sm">Edit</a>
|
||||
<form method="post" asp-page-handler="Delete" class="inline" onsubmit="return confirm('Delete this object?');">
|
||||
<input type="hidden" name="id" value="@obj.Id" />
|
||||
<button type="submit" class="text-red-400 hover:text-red-300 text-sm">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!Model.Objects.Any())
|
||||
{
|
||||
<div class="col-span-full card p-8 text-center text-gray-500">
|
||||
No object templates found. <a href="/admin/dungeonbuilder/objects/edit" class="text-blue-400 hover:underline">Create one</a>!
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
@if (Model.TotalPages > 1)
|
||||
{
|
||||
<div class="flex justify-center gap-2 mt-6">
|
||||
@for (int i = 1; i <= Model.TotalPages; i++)
|
||||
{
|
||||
<a href="?page=@i&search=@Model.Search&type=@Model.TypeFilter&biome=@Model.BiomeFilter"
|
||||
class="px-3 py-1 rounded @(i == Model.CurrentPage ? "bg-purple-600 text-white" : "bg-gray-700 text-gray-300 hover:bg-gray-600")">
|
||||
@i
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@functions {
|
||||
string GetTypeColor(ObjectTemplateType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
ObjectTemplateType.Decoration => "text-gray-400",
|
||||
ObjectTemplateType.Furniture => "text-blue-400",
|
||||
ObjectTemplateType.Container => "text-yellow-400",
|
||||
ObjectTemplateType.Obstacle => "text-orange-400",
|
||||
ObjectTemplateType.Trap => "text-red-400",
|
||||
ObjectTemplateType.Hazard => "text-red-500",
|
||||
ObjectTemplateType.Door => "text-purple-400",
|
||||
ObjectTemplateType.Switch => "text-cyan-400",
|
||||
ObjectTemplateType.Portal => "text-pink-400",
|
||||
ObjectTemplateType.Shrine => "text-green-400",
|
||||
ObjectTemplateType.Vendor => "text-emerald-400",
|
||||
ObjectTemplateType.Light => "text-yellow-300",
|
||||
ObjectTemplateType.Spawner => "text-orange-500",
|
||||
_ => "text-gray-400"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Server.Services.Admin.Pages.DungeonBuilder;
|
||||
|
||||
public class ObjectsModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public ObjectsModel(GameDbContext db, IConfiguration config)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public List<ObjectTemplate> Objects { get; set; } = new();
|
||||
public List<string> Biomes { get; set; } = new();
|
||||
|
||||
public string? Search { get; set; }
|
||||
public int? TypeFilter { get; set; }
|
||||
public string? BiomeFilter { get; set; }
|
||||
|
||||
public int CurrentPage { get; set; } = 1;
|
||||
public int TotalPages { get; set; }
|
||||
public int PageSize { get; set; } = 20;
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync(string? search, int? type, string? biome, int page = 1)
|
||||
{
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
BiomeFilter = biome;
|
||||
CurrentPage = Math.Max(1, page);
|
||||
|
||||
// Get unique biomes
|
||||
Biomes = await _db.ObjectTemplates
|
||||
.Where(o => o.Biome != null)
|
||||
.Select(o => o.Biome!)
|
||||
.Distinct()
|
||||
.OrderBy(b => b)
|
||||
.ToListAsync();
|
||||
|
||||
// Build query
|
||||
var query = _db.ObjectTemplates
|
||||
.Include(o => o.SpriteSheet)
|
||||
.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(search))
|
||||
{
|
||||
query = query.Where(o => o.Name.Contains(search) || (o.Tags != null && o.Tags.Contains(search)));
|
||||
}
|
||||
|
||||
if (type.HasValue)
|
||||
{
|
||||
query = query.Where(o => o.Type == (ObjectTemplateType)type.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(biome))
|
||||
{
|
||||
query = query.Where(o => o.Biome == biome);
|
||||
}
|
||||
|
||||
var total = await query.CountAsync();
|
||||
TotalPages = (int)Math.Ceiling(total / (double)PageSize);
|
||||
|
||||
Objects = await query
|
||||
.OrderBy(o => o.Name)
|
||||
.Skip((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var obj = await _db.ObjectTemplates.FindAsync(id);
|
||||
if (obj != null)
|
||||
{
|
||||
_db.ObjectTemplates.Remove(obj);
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Deleted object template: {obj.Name}";
|
||||
}
|
||||
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
public string GetCdnUrl(string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) return "";
|
||||
|
||||
var baseUrl = _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? "";
|
||||
if (!baseUrl.EndsWith("/downloads"))
|
||||
{
|
||||
baseUrl += "/downloads";
|
||||
}
|
||||
|
||||
return $"{baseUrl}/{path.TrimStart('/')}";
|
||||
}
|
||||
}
|
||||
@@ -166,6 +166,13 @@
|
||||
Room Templates
|
||||
</a>
|
||||
|
||||
<a href="/admin/dungeonbuilder" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.Contains("DungeonBuilder") == 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="M11 4a2 2 0 114 0v1a1 1 0 001 1h3a1 1 0 011 1v3a1 1 0 01-1 1h-1a2 2 0 100 4h1a1 1 0 011 1v3a1 1 0 01-1 1h-3a1 1 0 01-1-1v-1a2 2 0 10-4 0v1a1 1 0 01-1 1H7a1 1 0 01-1-1v-3a1 1 0 00-1-1H4a2 2 0 110-4h1a1 1 0 001-1V7a1 1 0 011-1h3a1 1 0 001-1V4z"/>
|
||||
</svg>
|
||||
Dungeon Builder
|
||||
</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"/>
|
||||
|
||||
Reference in New Issue
Block a user