Pageing on CDN Assets Page, and Player management

This commit is contained in:
dingo
2025-12-25 21:32:36 -05:00
parent 1f34b985f0
commit 958fc01056
9 changed files with 755 additions and 16 deletions
+27
View File
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Server.Data;
using Server.Data.Entities;
using System.Text.Json;
namespace VoidScavengers.Services.Admin.Pages.Mobs;
@@ -23,6 +24,19 @@ public class EditModel : AdminPageModel
public bool IsNew => Mob.Id == 0;
public string? Message { get; set; }
public bool IsError { get; set; }
// Helper to get resistance value for a damage type
public float GetResistance(string damageType)
{
try
{
var resistances = JsonSerializer.Deserialize<Dictionary<string, float>>(Mob.ResistancesJson ?? "{}");
if (resistances != null && resistances.TryGetValue(damageType, out var value))
return value;
}
catch { }
return 0f;
}
public async Task OnGetAsync(int? id)
{
@@ -79,6 +93,18 @@ public class EditModel : AdminPageModel
// Ensure nullable strings are never null
Mob.Description ??= "";
Mob.TintColor ??= "#ffffff";
// Parse resistances from form
var resistances = new Dictionary<string, float>();
foreach (var key in Request.Form.Keys.Where(k => k.StartsWith("resistance_")))
{
var damageType = key.Replace("resistance_", "");
if (float.TryParse(Request.Form[key], out var value) && value != 0)
{
resistances[damageType] = value;
}
}
Mob.ResistancesJson = JsonSerializer.Serialize(resistances);
if (string.IsNullOrWhiteSpace(Mob.Name))
{
@@ -171,6 +197,7 @@ public class EditModel : AdminPageModel
existing.Scale = Mob.Scale;
existing.AnimationSpeed = Mob.AnimationSpeed;
existing.SpriteConfigJson = Mob.SpriteConfigJson;
existing.ResistancesJson = Mob.ResistancesJson;
existing.IsEnabled = Mob.IsEnabled;
await _db.SaveChangesAsync();