feat(objects): ObjectCacheBuilder — assemble index + per-category detail chunks
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8f20106aec
commit
a55d83fc21
2 changed files with 95 additions and 0 deletions
|
|
@ -0,0 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
using Server.Commands;
|
||||
using Server.Items;
|
||||
using Xunit;
|
||||
|
||||
namespace UOContent.Tests.Commands.Objects;
|
||||
|
||||
public class ObjectCacheBuilderTests
|
||||
{
|
||||
[Fact]
|
||||
public void Build_produces_index_row_and_detail_chunk()
|
||||
{
|
||||
var extracted = new ExtractedObject(
|
||||
typeof(Runebook),
|
||||
"item",
|
||||
"Items.Skill Items.Magical",
|
||||
new LeanMetadata(8901, 0x461, "runebook", 1041267),
|
||||
[new CtorDoc()],
|
||||
[new PropertyDoc { Name = "Hue", Type = "int" }],
|
||||
[new OplLine { Cliloc = 1041267 }],
|
||||
"Item"
|
||||
);
|
||||
|
||||
var (index, chunks) = ObjectCacheBuilder.Build([extracted], "2026-07-19T00:00:00Z");
|
||||
|
||||
var row = Assert.Single(index.Objects);
|
||||
Assert.Equal("Runebook", row.Type);
|
||||
Assert.Equal("items.skill-items.magical", row.Chunk);
|
||||
Assert.Equal(8901, row.ItemID);
|
||||
|
||||
var chunk = Assert.Contains("items.skill-items.magical", chunks);
|
||||
Assert.Contains("Runebook", chunk.Keys);
|
||||
Assert.Equal("Item", chunk["Runebook"].BaseType);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Commands;
|
||||
|
||||
public sealed record ExtractedObject(
|
||||
Type Type,
|
||||
string Entity,
|
||||
string Category,
|
||||
LeanMetadata Lean,
|
||||
List<CtorDoc> Ctors,
|
||||
List<PropertyDoc> Properties,
|
||||
List<OplLine> Opl,
|
||||
string BaseType
|
||||
);
|
||||
|
||||
public static class ObjectCacheBuilder
|
||||
{
|
||||
public static (ObjectIndexFile index, Dictionary<string, Dictionary<string, ObjectDetail>> chunks) Build(
|
||||
IReadOnlyList<ExtractedObject> objects, string generatedUtc
|
||||
)
|
||||
{
|
||||
var index = new ObjectIndexFile { GeneratedUtc = generatedUtc };
|
||||
var chunks = new Dictionary<string, Dictionary<string, ObjectDetail>>();
|
||||
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
var chunkKey = ObjectNaming.ChunkKey(obj.Category);
|
||||
|
||||
index.Objects.Add(
|
||||
new ObjectIndexEntry
|
||||
{
|
||||
Type = obj.Type.Name,
|
||||
Entity = obj.Entity,
|
||||
Category = obj.Category,
|
||||
Chunk = chunkKey,
|
||||
ItemID = obj.Lean.ItemID,
|
||||
Hue = obj.Lean.Hue,
|
||||
Name = obj.Lean.Name,
|
||||
Cliloc = obj.Lean.Cliloc
|
||||
}
|
||||
);
|
||||
|
||||
if (!chunks.TryGetValue(chunkKey, out var chunk))
|
||||
{
|
||||
chunks[chunkKey] = chunk = new Dictionary<string, ObjectDetail>();
|
||||
}
|
||||
|
||||
chunk[obj.Type.Name] = new ObjectDetail
|
||||
{
|
||||
BaseType = obj.BaseType,
|
||||
Ctors = obj.Ctors,
|
||||
Properties = obj.Properties,
|
||||
Opl = obj.Opl
|
||||
};
|
||||
}
|
||||
|
||||
return (index, chunks);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue