386 lines
19 KiB
Plaintext
386 lines
19 KiB
Plaintext
@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.DisplayName</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}/${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>
|