SpriteSheets

This commit is contained in:
dingo
2025-12-27 20:24:49 -05:00
parent c16dc1259d
commit 326110ada8
5 changed files with 2395 additions and 12 deletions
+19 -10
View File
@@ -39,6 +39,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
// Mob definitions cache
private Dictionary<int, DungeonMobDefinition> _mobDefinitions = new();
private Dictionary<int, string?> _mobSpriteConfigs = new(); // MobDefinitionId -> SpriteConfig JSON
private bool _initialized = false;
// Tick management
@@ -238,20 +239,28 @@ public sealed partial class DungeonHandler : IClientMessageHandler
_log.LogCritical("Dungeon Mobs Table EMPTY");
}
// Debug: Log which mobs have SpriteConfigJson
_mobDefinitions = mobs.ToDictionary(m => m.Id);
// Build sprite configs from animation assignments
var spriteConfigBuilder = new MobSpriteConfigBuilder(db);
_mobSpriteConfigs = await spriteConfigBuilder.BuildSpriteConfigsAsync(mobs.Select(m => m.Id));
// Log sprite config status
foreach (var mob in mobs)
{
if (!string.IsNullOrEmpty(mob.SpriteConfigJson))
if (_mobSpriteConfigs.TryGetValue(mob.Id, out var config) && !string.IsNullOrEmpty(config))
{
_log.LogInformation("Mob {Name} has SpriteConfigJson: {Json}", mob.Name, mob.SpriteConfigJson.Substring(0, Math.Min(100, mob.SpriteConfigJson.Length)));
_log.LogInformation("Mob {Name} has new-format SpriteConfig ({Length} chars)", mob.Name, config.Length);
}
else if (!string.IsNullOrEmpty(mob.SpriteConfigJson))
{
_log.LogInformation("Mob {Name} has legacy SpriteConfigJson: {Json}", mob.Name, mob.SpriteConfigJson.Substring(0, Math.Min(100, mob.SpriteConfigJson.Length)));
}
else
{
_log.LogInformation("Mob {Name} has NO SpriteConfigJson", mob.Name);
_log.LogInformation("Mob {Name} has NO sprite config", mob.Name);
}
}
_mobDefinitions = mobs.ToDictionary(m => m.Id);
}
public async Task HandleAsync(int opCode, IConnection connection, ReadOnlyMemory<byte> payload, CancellationToken ct)
@@ -658,7 +667,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
int seed = Random.Shared.Next();
var layout = DungeonGenerator.Generate(seed, tier);
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin);
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, null, _mobSpriteConfigs);
instance = new DungeonInstance
{
@@ -2077,7 +2086,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
int seed = Random.Shared.Next();
var layout = DungeonGenerator.Generate(seed, tier);
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin);
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, null, _mobSpriteConfigs);
var instance = new DungeonInstance
{
@@ -2293,7 +2302,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
try
{
var layout = DungeonGenerator.Generate(persisted.Seed, persisted.Tier);
var simulation = new DungeonSimulation(layout, persisted.Tier, _mobDefinitions, persisted.LevelBracketMin);
var simulation = new DungeonSimulation(layout, persisted.Tier, _mobDefinitions, persisted.LevelBracketMin, null, _mobSpriteConfigs);
// NOTE: We intentionally do NOT restore mob state here.
// When a dungeon is restored (all players left), ALL mobs respawn fresh.
@@ -2365,7 +2374,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
// Create a fresh simulation with the same parameters
var layout = DungeonGenerator.Generate(instance.Seed, instance.Tier);
var freshSimulation = new DungeonSimulation(layout, instance.Tier, _mobDefinitions, instance.LevelBracketMin);
var freshSimulation = new DungeonSimulation(layout, instance.Tier, _mobDefinitions, instance.LevelBracketMin, null, _mobSpriteConfigs);
// Clear and rebuild mobs, keeping those with loot
instance.Simulation.Mobs.Clear();