ModernUO/Projects/UOContent/Commands/GenObjects.cs
Kamron Batman 0ac505d7b6
feat(objects): ObjectCacheGenerator core + GenObjects command
Wraps introspection, categorization sync, and cache-building into a
single file-I/O-free Generate() so the full pipeline is testable
without a shard; GenObjects is a thin command that adds file I/O and
operator messaging on top.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 12:38:04 -07:00

56 lines
2.1 KiB
C#

using System.Collections.Generic;
using System.IO;
using Server.Json;
using Server.Logging;
namespace Server.Commands;
public static class GenObjects
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(GenObjects));
public static void Configure()
{
CommandSystem.Register("GenObjects", AccessLevel.Developer, GenObjects_OnCommand);
}
[Usage("GenObjects")]
[Aliases("GenObjWeb")]
[Description("Generates the objects cache (index + detail chunks) and syncs categorization.json.")]
private static void GenObjects_OnCommand(CommandEventArgs e)
{
var baseDir = Core.BaseDirectory;
var categorizationPath = Path.Combine(baseDir, "Data", "categorization.json");
var categorization = JsonConfig.Deserialize<List<CAGJson>>(categorizationPath) ?? [];
var discovered = ObjectIntrospection.DiscoverConstructibleTypes();
var result = ObjectCacheGenerator.Generate(categorization, discovered);
var objectsDir = Path.Combine(baseDir, "Data", "objects");
var detailDir = Path.Combine(objectsDir, "detail");
Directory.CreateDirectory(detailDir);
JsonConfig.Serialize(Path.Combine(objectsDir, "index.json"), result.Index);
foreach (var (chunkKey, map) in result.Chunks)
{
JsonConfig.Serialize(Path.Combine(detailDir, $"{chunkKey}.json"), map);
}
JsonConfig.Serialize(categorizationPath, result.UpdatedCategorization);
e.Mobile.SendMessage(
$"Objects cache written: {result.Index.Objects.Count} objects, {result.Chunks.Count} chunks. " +
$"Appended {result.Report.Appended.Count} to Uncategorized, {result.Report.Orphaned.Count} orphaned."
);
if (result.Report.Appended.Count > 0)
{
logger.Information("Appended to Uncategorized: {Types}", string.Join(", ", result.Report.Appended));
}
if (result.Report.Orphaned.Count > 0)
{
logger.Warning("Orphaned categorization entries: {Types}", string.Join(", ", result.Report.Orphaned));
}
}
}