From 4ba5a1040b1e3c36bebe72385dc6357d4b4dc362 Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 14 Feb 2026 01:31:05 -0500 Subject: [PATCH] Upgrade NPC admin editor selectors and add dialog tree admin UI --- .../Admin/Pages/Npcs/DialogTreeEdit.cshtml | 301 +++++++++++++++++ .../Admin/Pages/Npcs/DialogTreeEdit.cshtml.cs | 236 ++++++++++++++ Services/Admin/Pages/Npcs/DialogTrees.cshtml | 70 ++++ .../Admin/Pages/Npcs/DialogTrees.cshtml.cs | 54 +++ Services/Admin/Pages/Npcs/Edit.cshtml | 308 ++++++++++++++++-- Services/Admin/Pages/Npcs/Edit.cshtml.cs | 198 ++++++++++- Services/Admin/Pages/Npcs/Index.cshtml | 15 +- Services/Admin/Pages/Shared/_Layout.cshtml | 4 + 8 files changed, 1157 insertions(+), 29 deletions(-) create mode 100644 Services/Admin/Pages/Npcs/DialogTreeEdit.cshtml create mode 100644 Services/Admin/Pages/Npcs/DialogTreeEdit.cshtml.cs create mode 100644 Services/Admin/Pages/Npcs/DialogTrees.cshtml create mode 100644 Services/Admin/Pages/Npcs/DialogTrees.cshtml.cs diff --git a/Services/Admin/Pages/Npcs/DialogTreeEdit.cshtml b/Services/Admin/Pages/Npcs/DialogTreeEdit.cshtml new file mode 100644 index 0000000..6b824a3 --- /dev/null +++ b/Services/Admin/Pages/Npcs/DialogTreeEdit.cshtml @@ -0,0 +1,301 @@ +@page "/admin/npcs/dialogtrees/edit" +@model Npcs.DialogTreeEditModel +@using DataServer.Data.Enums +@{ + ViewData["Title"] = Model.IsNew ? "Create Dialog Tree" : $"Edit Dialog Tree: {Model.Tree.Name}"; +} + +
+
+ + + + + +
+

@(Model.IsNew ? "Create Dialog Tree" : "Edit Dialog Tree")

+

@(Model.IsNew ? "Create a conversation flow for NPCs" : $"ID: {Model.Tree.Id}")

+
+
+ + @if (!string.IsNullOrEmpty(Model.Message)) + { +
+ @Model.Message +
+ } + +
+ @Html.AntiForgeryToken() + +
+
+ + +
+
+ +
+
+ + +
+
+
+ + Back +
+
+ + @if (!Model.IsNew) + { +
+
+

Nodes (@Model.Nodes.Count)

+ +
+ + + + + + + + + + + + + @foreach (var n in Model.Nodes) + { + + + + + + + + + } + @if (!Model.Nodes.Any()) + { + + + + } + +
IDNode KeyTextRootEndActions
@n.Id@n.NodeKey@n.Text@(n.IsRoot ? "Yes" : "No")@(n.IsTerminal ? "Yes" : "No") +
+ Options +
+ @Html.AntiForgeryToken() + + + +
+
+
No nodes yet.
+
+ + @if (Model.SelectedNodeId.HasValue) + { +
+
+

Options for Node @Model.SelectedNodeId (@Model.Options.Count)

+ +
+ + + + + + + + + + + + + @foreach (var o in Model.Options) + { + + + + + + + + + } + @if (!Model.Options.Any()) + { + + + + } + +
IDPlayer TextNext NodeConditionSortActions
@o.Id@o.PlayerText@o.NextNodeId@o.ConditionType@o.SortOrder +
+ @Html.AntiForgeryToken() + + + + +
+
No options for this node.
+
+ } + + + + + } +
+ +@section Scripts { + +} diff --git a/Services/Admin/Pages/Npcs/DialogTreeEdit.cshtml.cs b/Services/Admin/Pages/Npcs/DialogTreeEdit.cshtml.cs new file mode 100644 index 0000000..dda7996 --- /dev/null +++ b/Services/Admin/Pages/Npcs/DialogTreeEdit.cshtml.cs @@ -0,0 +1,236 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using DataServer.Data; +using DataServer.Data.Entities; +using DataServer.Data.Enums; + +namespace GameServices.Admin.Pages.Npcs; + +public class DialogTreeEditModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public DialogTreeEditModel(GameDbContext db) + { + _db = db; + } + + [BindProperty] + public DungeonNpcDialogTree Tree { get; set; } = new(); + + public List Nodes { get; set; } = new(); + public List Options { get; set; } = new(); + public List ItemDefinitions { get; set; } = new(); + + [FromQuery(Name = "nodeId")] + public int? SelectedNodeId { get; set; } + + public bool IsNew => Tree.Id == 0; + public string? Message { get; set; } + public bool IsError { get; set; } + + public async Task OnGetAsync(int? id, int? nodeId) + { + await LoadLookupsAsync(); + + if (id.HasValue) + { + var tree = await _db.DungeonNpcDialogTrees.FindAsync(id.Value); + if (tree != null) + { + Tree = tree; + await LoadTreeDataAsync(tree.Id, nodeId); + return; + } + } + + Tree = new DungeonNpcDialogTree + { + Name = "", + Description = "", + IsEnabled = true + }; + } + + public async Task OnPostAsync() + { + await LoadLookupsAsync(); + + Tree.Name = (Tree.Name ?? "").Trim(); + Tree.Description ??= ""; + Tree.IsEnabled = Request.Form.ContainsKey("Tree.IsEnabled"); + + if (string.IsNullOrWhiteSpace(Tree.Name)) + { + IsError = true; + Message = "Name is required."; + return Page(); + } + + try + { + if (Tree.Id == 0) + { + Tree.CreatedAt = DateTime.UtcNow; + Tree.UpdatedAt = DateTime.UtcNow; + _db.DungeonNpcDialogTrees.Add(Tree); + await _db.SaveChangesAsync(); + return RedirectToPage("/Npcs/DialogTreeEdit", new { id = Tree.Id }); + } + + var existing = await _db.DungeonNpcDialogTrees.FindAsync(Tree.Id); + if (existing == null) + { + IsError = true; + Message = "Dialog tree not found."; + return Page(); + } + + existing.Name = Tree.Name; + existing.Description = Tree.Description; + existing.IsEnabled = Tree.IsEnabled; + existing.UpdatedAt = DateTime.UtcNow; + await _db.SaveChangesAsync(); + Tree = existing; + Message = "Dialog tree saved."; + await LoadTreeDataAsync(existing.Id, SelectedNodeId); + } + catch (Exception ex) + { + IsError = true; + Message = $"Error: {ex.Message}"; + if (Tree.Id > 0) await LoadTreeDataAsync(Tree.Id, SelectedNodeId); + } + + return Page(); + } + + public async Task OnPostAddNodeAsync( + int treeId, + string nodeKey, + string text, + bool isRoot, + bool isTerminal, + string? rewardType, + int? rewardItemDefinitionId, + int rewardItemQuantity, + long rewardGold, + long rewardXp, + string? rewardQuestKey) + { + if (isRoot) + { + var roots = await _db.DungeonNpcDialogNodes + .Where(n => n.DialogTreeId == treeId && n.IsRoot) + .ToListAsync(); + foreach (var r in roots) r.IsRoot = false; + } + + var node = new DungeonNpcDialogNode + { + DialogTreeId = treeId, + NodeKey = (nodeKey ?? "").Trim(), + Text = (text ?? "").Trim(), + IsRoot = isRoot, + IsTerminal = isTerminal, + RewardType = string.IsNullOrWhiteSpace(rewardType) ? null : rewardType.Trim(), + RewardItemDefinitionId = rewardItemDefinitionId, + RewardItemQuantity = Math.Max(1, rewardItemQuantity), + RewardGold = Math.Max(0, rewardGold), + RewardXp = Math.Max(0, rewardXp), + RewardQuestKey = string.IsNullOrWhiteSpace(rewardQuestKey) ? null : rewardQuestKey.Trim() + }; + + _db.DungeonNpcDialogNodes.Add(node); + await _db.SaveChangesAsync(); + return RedirectToPage("/Npcs/DialogTreeEdit", new { id = treeId, nodeId = node.Id }); + } + + public async Task OnPostDeleteNodeAsync(int treeId, int nodeId) + { + var node = await _db.DungeonNpcDialogNodes.FindAsync(nodeId); + if (node != null && node.DialogTreeId == treeId) + { + _db.DungeonNpcDialogNodes.Remove(node); + await _db.SaveChangesAsync(); + } + return RedirectToPage("/Npcs/DialogTreeEdit", new { id = treeId }); + } + + public async Task OnPostAddOptionAsync( + int treeId, + int nodeId, + string playerText, + int? nextNodeId, + NpcDialogConditionType conditionType, + string? conditionValue, + int conditionQuantity, + bool consumeConditionItem, + int sortOrder) + { + var node = await _db.DungeonNpcDialogNodes.FirstOrDefaultAsync(n => n.Id == nodeId && n.DialogTreeId == treeId); + if (node == null) + { + return RedirectToPage("/Npcs/DialogTreeEdit", new { id = treeId }); + } + + var option = new DungeonNpcDialogOption + { + NodeId = nodeId, + PlayerText = (playerText ?? "").Trim(), + NextNodeId = nextNodeId, + ConditionType = conditionType, + ConditionValue = string.IsNullOrWhiteSpace(conditionValue) ? null : conditionValue.Trim(), + ConditionQuantity = Math.Max(1, conditionQuantity), + ConsumeConditionItem = consumeConditionItem, + SortOrder = sortOrder + }; + + _db.DungeonNpcDialogOptions.Add(option); + await _db.SaveChangesAsync(); + return RedirectToPage("/Npcs/DialogTreeEdit", new { id = treeId, nodeId }); + } + + public async Task OnPostDeleteOptionAsync(int treeId, int nodeId, int optionId) + { + var option = await _db.DungeonNpcDialogOptions.FindAsync(optionId); + if (option != null && option.NodeId == nodeId) + { + _db.DungeonNpcDialogOptions.Remove(option); + await _db.SaveChangesAsync(); + } + return RedirectToPage("/Npcs/DialogTreeEdit", new { id = treeId, nodeId }); + } + + private async Task LoadLookupsAsync() + { + ItemDefinitions = await _db.DungeonItemDefinitions + .Where(i => i.IsEnabled) + .OrderBy(i => i.Name) + .ToListAsync(); + } + + private async Task LoadTreeDataAsync(int treeId, int? nodeId) + { + Nodes = await _db.DungeonNpcDialogNodes + .Where(n => n.DialogTreeId == treeId) + .OrderByDescending(n => n.IsRoot) + .ThenBy(n => n.Id) + .ToListAsync(); + + SelectedNodeId = nodeId ?? Nodes.FirstOrDefault()?.Id; + + if (SelectedNodeId.HasValue) + { + Options = await _db.DungeonNpcDialogOptions + .Where(o => o.NodeId == SelectedNodeId.Value) + .OrderBy(o => o.SortOrder) + .ThenBy(o => o.Id) + .ToListAsync(); + } + else + { + Options = new List(); + } + } +} diff --git a/Services/Admin/Pages/Npcs/DialogTrees.cshtml b/Services/Admin/Pages/Npcs/DialogTrees.cshtml new file mode 100644 index 0000000..203b72f --- /dev/null +++ b/Services/Admin/Pages/Npcs/DialogTrees.cshtml @@ -0,0 +1,70 @@ +@page "/admin/npcs/dialogtrees" +@model Npcs.DialogTreesModel +@{ + ViewData["Title"] = "Dialog Trees"; +} + +
+
+
+

Dialog Trees

+

Manage NPC conversation trees, nodes, and options

+
+ Create Dialog Tree +
+ +
+
+
+ + +
+ + Clear +
+
+ +
+ + + + + + + + + + + + @foreach (var t in Model.Trees) + { + + + + + + + + } + @if (!Model.Trees.Any()) + { + + + + } + +
IDNameNodesEnabledActions
@t.Id +
@t.Name
+
@t.Description
+
@Model.NodeCountByTreeId.GetValueOrDefault(t.Id)@(t.IsEnabled ? "Yes" : "No") +
+ Edit +
+ @Html.AntiForgeryToken() + + +
+
+
No dialog trees found.
+
+
diff --git a/Services/Admin/Pages/Npcs/DialogTrees.cshtml.cs b/Services/Admin/Pages/Npcs/DialogTrees.cshtml.cs new file mode 100644 index 0000000..2d6f69d --- /dev/null +++ b/Services/Admin/Pages/Npcs/DialogTrees.cshtml.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using DataServer.Data; +using DataServer.Data.Entities; + +namespace GameServices.Admin.Pages.Npcs; + +public class DialogTreesModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public DialogTreesModel(GameDbContext db) + { + _db = db; + } + + [FromQuery(Name = "search")] + public string? Search { get; set; } + + public List Trees { get; set; } = new(); + public Dictionary NodeCountByTreeId { get; set; } = new(); + + public async Task OnGetAsync() + { + var query = _db.DungeonNpcDialogTrees.AsQueryable(); + if (!string.IsNullOrWhiteSpace(Search)) + { + query = query.Where(t => t.Name.Contains(Search) || t.Description.Contains(Search)); + } + + Trees = await query + .OrderBy(t => t.Id) + .ToListAsync(); + + var treeIds = Trees.Select(t => t.Id).ToList(); + NodeCountByTreeId = await _db.DungeonNpcDialogNodes + .Where(n => treeIds.Contains(n.DialogTreeId)) + .GroupBy(n => n.DialogTreeId) + .Select(g => new { TreeId = g.Key, Count = g.Count() }) + .ToDictionaryAsync(x => x.TreeId, x => x.Count); + } + + public async Task OnPostDeleteAsync(int id) + { + var tree = await _db.DungeonNpcDialogTrees.FindAsync(id); + if (tree != null) + { + _db.DungeonNpcDialogTrees.Remove(tree); + await _db.SaveChangesAsync(); + } + + return RedirectToPage(); + } +} diff --git a/Services/Admin/Pages/Npcs/Edit.cshtml b/Services/Admin/Pages/Npcs/Edit.cshtml index 6d62f4a..56c91c9 100644 --- a/Services/Admin/Pages/Npcs/Edit.cshtml +++ b/Services/Admin/Pages/Npcs/Edit.cshtml @@ -1,8 +1,12 @@ @page "/admin/npcs/edit" @model Npcs.EditModel +@using System.Text.Json @using DataServer.Data.Enums @{ ViewData["Title"] = Model.IsNew ? "Create NPC" : $"Edit: {Model.Npc.Name}"; + var selectedAbilitiesJson = JsonSerializer.Serialize(Model.SelectedAbilityIds); + var spriteSheetOptions = JsonSerializer.Serialize(Model.AllSpriteSheets.Select(s => new { id = s.Id, name = s.Name, cdnPath = s.CdnPath })); + var resistanceOptions = string.Join("", Model.ResistanceTypes.Select(rt => $"")); }
@@ -142,21 +146,150 @@
-
-

Visual & Linked Systems

+
+

Damage Resistances

-
-
- -
- - +
+
+ @{ + Dictionary resistances = new(); + try + { + resistances = JsonSerializer.Deserialize>(Model.Npc.ResistancesJson ?? "{}") ?? new(); + } + catch { } + } + @foreach (var resist in resistances) + { + var bgColor = resist.Value < 0 ? "bg-red-900/30 border-red-700" : resist.Value > 0 ? "bg-green-900/30 border-green-700" : "bg-gray-800 border-gray-700"; +
+ +
+ +
+ + % +
+
+ +
+ } +
+ +
+ + + % + +
+
+
+ +
+
+

Abilities

+
+
+
+
+ + +
+
+ +
+ +
- - + +
+
+
+ +
+
+

Sprite Config

+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ +
+ @for (var i = 0; i < Model.SpriteRows.Count; i++) + { + var row = Model.SpriteRows[i]; +
+ + + + + +
+ } +
+ + +
+
+ +
+
+

Linked Systems

+ Manage Dialog Trees +
+
-
+
-
- - +
+ +
+ + +
-
- - -
-
- - +
+ +
@@ -208,3 +340,137 @@
+ +@section Scripts { + +} diff --git a/Services/Admin/Pages/Npcs/Edit.cshtml.cs b/Services/Admin/Pages/Npcs/Edit.cshtml.cs index 2bbdd09..2b3cf0b 100644 --- a/Services/Admin/Pages/Npcs/Edit.cshtml.cs +++ b/Services/Admin/Pages/Npcs/Edit.cshtml.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using DataServer.Data; using DataServer.Data.Entities; using DataServer.Data.Enums; +using System.Text.Json; namespace GameServices.Admin.Pages.Npcs; @@ -21,11 +22,40 @@ public class EditModel : AdminPageModel public List LootTables { get; set; } = new(); public List Shops { get; set; } = new(); public List DialogTrees { get; set; } = new(); + public List ResistanceTypes { get; set; } = new(); + public List AllAbilities { get; set; } = new(); + public List AllSpriteSheets { get; set; } = new(); + public List SelectedAbilityIds { get; set; } = new(); + public List SpriteRows { get; set; } = new(); + public NpcSpriteConfig SpriteConfig { get; set; } = new(); public bool IsNew => Npc.Id == 0; public string? Message { get; set; } public bool IsError { get; set; } + public class NpcSpriteRow + { + public string Key { get; set; } = ""; + public int? SheetId { get; set; } + public int Frames { get; set; } = 8; + public bool Loop { get; set; } = true; + } + + public class NpcSpriteConfig + { + public Dictionary Sprites { get; set; } = new(); + public Dictionary Animations { get; set; } = new(); + public int FrameWidth { get; set; } = 64; + public int FrameHeight { get; set; } = 64; + public int Fps { get; set; } = 8; + + public class SpriteAnimation + { + public int Frames { get; set; } = 8; + public bool Loop { get; set; } = true; + } + } + public async Task OnGetAsync(int? id) { await LoadSelectionsAsync(); @@ -36,6 +66,7 @@ public class EditModel : AdminPageModel if (npc != null) { Npc = npc; + ParseNpcJsonFields(); return; } } @@ -68,6 +99,7 @@ public class EditModel : AdminPageModel WanderRadiusPx = 96f, WanderIntervalSeconds = 2.5f }; + ParseNpcJsonFields(); } public async Task OnPostAsync() @@ -83,14 +115,16 @@ public class EditModel : AdminPageModel Npc.Name = (Npc.Name ?? "").Trim(); Npc.Key = (Npc.Key ?? "").Trim(); Npc.Description ??= ""; - Npc.ResistancesJson ??= "{}"; - Npc.AbilityDefinitionIdsJson ??= "[]"; Npc.TintColor = string.IsNullOrWhiteSpace(Npc.TintColor) ? "#ffffff" : Npc.TintColor.Trim(); + ParseAndSetResistancesFromForm(); + ParseAndSetAbilityIdsFromForm(); + ParseAndSetSpriteConfigFromForm(); if (string.IsNullOrWhiteSpace(Npc.Name)) { IsError = true; Message = "Name is required."; + ParseNpcJsonFields(); return Page(); } @@ -117,6 +151,7 @@ public class EditModel : AdminPageModel { IsError = true; Message = "NPC not found."; + ParseNpcJsonFields(); return Page(); } @@ -153,12 +188,14 @@ public class EditModel : AdminPageModel await _db.SaveChangesAsync(); Npc = existing; + ParseNpcJsonFields(); Message = "Changes saved successfully."; } catch (Exception ex) { IsError = true; Message = $"Error: {ex.Message}"; + ParseNpcJsonFields(); } return Page(); @@ -180,5 +217,162 @@ public class EditModel : AdminPageModel .Where(d => d.IsEnabled) .OrderBy(d => d.Name) .ToListAsync(); + + ResistanceTypes = await _db.DamageResistanceTypes + .Where(r => r.IsEnabled) + .OrderBy(r => r.SortOrder) + .ToListAsync(); + + AllAbilities = await _db.MobAbilityDefinitions + .Where(a => a.IsEnabled) + .OrderBy(a => a.Name) + .ToListAsync(); + + AllSpriteSheets = await _db.MobSpriteSheets + .Where(s => s.IsEnabled) + .OrderBy(s => s.Name) + .ToListAsync(); + } + + private void ParseNpcJsonFields() + { + try + { + var resistanceMap = JsonSerializer.Deserialize>(Npc.ResistancesJson ?? "{}") ?? new(); + Npc.ResistancesJson = JsonSerializer.Serialize(resistanceMap); + } + catch + { + Npc.ResistancesJson = "{}"; + } + + try + { + SelectedAbilityIds = JsonSerializer.Deserialize>(Npc.AbilityDefinitionIdsJson ?? "[]") ?? new(); + } + catch + { + SelectedAbilityIds = new List(); + Npc.AbilityDefinitionIdsJson = "[]"; + } + + try + { + SpriteConfig = string.IsNullOrWhiteSpace(Npc.SpriteConfigJson) + ? new NpcSpriteConfig() + : (JsonSerializer.Deserialize(Npc.SpriteConfigJson!, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }) ?? new NpcSpriteConfig()); + } + catch + { + SpriteConfig = new NpcSpriteConfig(); + } + + SpriteRows = new List(); + foreach (var kv in SpriteConfig.Sprites) + { + var frames = 8; + var loop = true; + if (SpriteConfig.Animations.TryGetValue(kv.Key, out var anim)) + { + frames = anim.Frames; + loop = anim.Loop; + } + + var matchingSheet = AllSpriteSheets.FirstOrDefault(s => + string.Equals(s.CdnPath, kv.Value, StringComparison.OrdinalIgnoreCase)); + + SpriteRows.Add(new NpcSpriteRow + { + Key = kv.Key, + SheetId = matchingSheet?.Id, + Frames = frames, + Loop = loop + }); + } + } + + private void ParseAndSetResistancesFromForm() + { + var map = new Dictionary(StringComparer.OrdinalIgnoreCase); + var keys = Request.Form["resist_name[]"].ToArray(); + var vals = Request.Form["resist_value[]"].ToArray(); + for (var i = 0; i < keys.Length && i < vals.Length; i++) + { + var key = (keys[i] ?? "").Trim().ToLowerInvariant(); + if (string.IsNullOrWhiteSpace(key)) continue; + if (!float.TryParse(vals[i], out var val)) continue; + map[key] = val; + } + Npc.ResistancesJson = JsonSerializer.Serialize(map); + } + + private void ParseAndSetAbilityIdsFromForm() + { + var list = new List(); + foreach (var raw in Request.Form["ability_ids[]"]) + { + if (int.TryParse(raw, out var id) && id > 0 && !list.Contains(id)) + { + list.Add(id); + } + } + SelectedAbilityIds = list; + Npc.AbilityDefinitionIdsJson = JsonSerializer.Serialize(list); + } + + private void ParseAndSetSpriteConfigFromForm() + { + var spriteKeys = Request.Form["sprite_key[]"].ToArray(); + var spriteSheetIds = Request.Form["sprite_sheet_id[]"].ToArray(); + var spriteFrames = Request.Form["sprite_frames[]"].ToArray(); + var spriteLoops = Request.Form["sprite_loop[]"].ToArray(); + + var config = new NpcSpriteConfig(); + if (int.TryParse(Request.Form["sprite_frameWidth"], out var fw)) config.FrameWidth = fw; + if (int.TryParse(Request.Form["sprite_frameHeight"], out var fh)) config.FrameHeight = fh; + if (int.TryParse(Request.Form["sprite_fps"], out var fps)) config.Fps = fps; + + for (var i = 0; i < spriteKeys.Length && i < spriteSheetIds.Length; i++) + { + var key = (spriteKeys[i] ?? "").Trim(); + if (string.IsNullOrWhiteSpace(key)) continue; + if (!int.TryParse(spriteSheetIds[i], out var sheetId)) continue; + var sheet = AllSpriteSheets.FirstOrDefault(s => s.Id == sheetId); + if (sheet == null) continue; + + var frames = 8; + if (i < spriteFrames.Length && int.TryParse(spriteFrames[i], out var rowFrames)) + { + frames = Math.Max(1, rowFrames); + } + + var loop = spriteLoops.Contains(i.ToString()); + config.Sprites[key] = sheet.CdnPath; + config.Animations[key] = new NpcSpriteConfig.SpriteAnimation + { + Frames = frames, + Loop = loop + }; + } + + if (config.Sprites.Count == 0) + { + SpriteConfig = new NpcSpriteConfig(); + SpriteRows = new List(); + Npc.SpriteConfigJson = null; + return; + } + + SpriteConfig = config; + Npc.SpriteConfigJson = JsonSerializer.Serialize(config, new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }); + + // rebuild display rows for round-trip on validation failure + ParseNpcJsonFields(); } } diff --git a/Services/Admin/Pages/Npcs/Index.cshtml b/Services/Admin/Pages/Npcs/Index.cshtml index 7722305..b4763e5 100644 --- a/Services/Admin/Pages/Npcs/Index.cshtml +++ b/Services/Admin/Pages/Npcs/Index.cshtml @@ -10,12 +10,15 @@

NPCs

Manage NPC definitions, stats, behavior, and interactions

- - - - - Create NPC - +
diff --git a/Services/Admin/Pages/Shared/_Layout.cshtml b/Services/Admin/Pages/Shared/_Layout.cshtml index 1890d05..4f26fa0 100644 --- a/Services/Admin/Pages/Shared/_Layout.cshtml +++ b/Services/Admin/Pages/Shared/_Layout.cshtml @@ -117,6 +117,10 @@ NPCs + + + Dialog Trees + Sprite Sheets