Add HSchool.Content project for JSONC definitions, catalog, and map validation. Update solution structure to include new content and tests projects. Enhance school management to support mod packs and map instances, ensuring proper loading and validation. Revise documentation to reflect these changes and update tests for new functionality.
ci / server (push) Failing after 3m36s
ci / client (push) Successful in 13s

This commit is contained in:
Leonid Pershin
2026-08-18 14:35:09 +03:00
parent 37c39a3beb
commit 1bc75244e8
55 changed files with 2289 additions and 59 deletions
@@ -0,0 +1,115 @@
namespace HSchool.Content.Tests;
public class CatalogLoaderTests
{
private readonly CatalogLoader _loader = new();
[Fact]
public void Jsonc_AllowsCommentsAndTrailingCommas()
{
var catalog = _loader.Load(
[CatalogLoader.CorePackId],
[
PackDocuments.Def(
CatalogLoader.CorePackId,
"actions",
"sit",
"""
// a verb the Sit system already knows
{ "defName": "Sit", }
"""),
]);
Assert.True(catalog.Actions.ContainsKey("Sit"));
}
[Fact]
public void DuplicateDefName_LastPackWinsAndWarns()
{
var log = new RecordingLog();
var catalog = _loader.Load(
[CatalogLoader.CorePackId, "addon"],
[
PackDocuments.Def(CatalogLoader.CorePackId, "things", "chair", """{ "defName": "Chair", "actions": [] }"""),
PackDocuments.Def("addon", "things", "chair", """{ "defName": "Chair", "actions": ["Sit"] }"""),
PackDocuments.Def(CatalogLoader.CorePackId, "actions", "sit", """{ "defName": "Sit" }"""),
],
log);
Assert.Equal(["Sit"], catalog.Things["Chair"].Actions);
Assert.Contains(log.Warnings, warning => warning.Contains("Chair") && warning.Contains("addon"));
}
[Fact]
public void DuplicateLocaleKey_LastPackWinsAndWarns()
{
var log = new RecordingLog();
var catalog = _loader.Load(
[CatalogLoader.CorePackId, "addon"],
[
PackDocuments.Def(CatalogLoader.CorePackId, "actions", "sit", """{ "defName": "Sit" }"""),
PackDocuments.Locale(CatalogLoader.CorePackId, "ru", """{ "Sit": "Сесть" }"""),
PackDocuments.Locale("addon", "ru", """{ "Sit": "Присесть" }"""),
],
log);
Assert.Equal("Присесть", catalog.Label("ru", catalog.Actions["Sit"]));
Assert.Contains(log.Warnings, warning => warning.Contains("Sit") && warning.Contains("addon"));
}
[Fact]
public void CoreIsAlwaysFirst_EvenIfOmittedFromThePackList()
{
var catalog = _loader.Load(
["addon"],
[
PackDocuments.Def(CatalogLoader.CorePackId, "actions", "sit", """{ "defName": "Sit" }"""),
PackDocuments.Def("addon", "actions", "wave", """{ "defName": "Wave" }"""),
]);
Assert.Equal([CatalogLoader.CorePackId, "addon"], catalog.PackIds);
Assert.True(catalog.Actions.ContainsKey("Sit"));
Assert.True(catalog.Actions.ContainsKey("Wave"));
}
[Fact]
public void ThingActions_MustExist()
{
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
[CatalogLoader.CorePackId],
[PackDocuments.Def(CatalogLoader.CorePackId, "things", "chair", """{ "defName": "Chair", "actions": ["Sit"] }""")]));
Assert.Contains("Sit", ex.Message);
}
[Fact]
public void RoomSlotsAndPositions_MustExist()
{
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
[CatalogLoader.CorePackId],
[
PackDocuments.Def(
CatalogLoader.CorePackId,
"rooms",
"office",
"""{ "defName": "Office", "slots": [{ "key": "chair", "thing": "Chair" }], "positions": ["Principal"] }"""),
]));
Assert.Contains("Chair", ex.Message);
}
[Fact]
public void Label_FallsBackToParentThenDefName()
{
var catalog = _loader.Load(
[CatalogLoader.CorePackId],
[
PackDocuments.Def(CatalogLoader.CorePackId, "things", "base", """{ "defName": "FurnitureBase", "abstract": true }"""),
PackDocuments.Def(CatalogLoader.CorePackId, "things", "chair", """{ "defName": "Chair", "parent": "FurnitureBase" }"""),
PackDocuments.Locale(CatalogLoader.CorePackId, "ru", """{ "FurnitureBase": "Мебель" }"""),
]);
Assert.Equal("Мебель", catalog.Label("ru", catalog.Things["Chair"]));
Assert.Equal("Chair", catalog.Label("en", catalog.Things["Chair"]));
}
}