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
+97
View File
@@ -0,0 +1,97 @@
namespace HSchool.Content.Tests;
public class PatchTests
{
private readonly CatalogLoader _loader = new();
[Fact]
public void Add_AppendsToActions()
{
var catalog = _loader.Load(
[CatalogLoader.CorePackId, "addon"],
[
PackDocuments.Def(CatalogLoader.CorePackId, "actions", "sit", """{ "defName": "Sit" }"""),
PackDocuments.Def(CatalogLoader.CorePackId, "actions", "inspect", """{ "defName": "Inspect" }"""),
PackDocuments.Def(CatalogLoader.CorePackId, "things", "chair", """{ "defName": "Chair", "actions": ["Sit"] }"""),
PackDocuments.Patch(
"addon",
"chair-inspect",
"""
{ "target": "Chair", "ops": [ { "op": "add", "path": "/actions/-", "value": "Inspect" } ] }
"""),
]);
Assert.Equal(["Sit", "Inspect"], catalog.Things["Chair"].Actions);
}
[Fact]
public void UnknownOp_FailsTheCatalog()
{
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
[CatalogLoader.CorePackId],
[
PackDocuments.Def(CatalogLoader.CorePackId, "things", "chair", """{ "defName": "Chair" }"""),
PackDocuments.Patch(
CatalogLoader.CorePackId,
"bad",
"""{ "target": "Chair", "ops": [ { "op": "move", "path": "/actions" } ] }"""),
]));
Assert.Contains("Unknown patch op", ex.Message);
}
[Fact]
public void MissingTarget_FailsTheCatalog()
{
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
[CatalogLoader.CorePackId],
[
PackDocuments.Def(CatalogLoader.CorePackId, "things", "chair", """{ "defName": "Chair" }"""),
PackDocuments.Patch(
CatalogLoader.CorePackId,
"ghost",
"""{ "target": "Missing", "ops": [ { "op": "remove", "path": "/actions" } ] }"""),
]));
Assert.Contains("was not found", ex.Message);
}
[Fact]
public void ReplaceAndRemove_EditRoomDef()
{
var catalog = _loader.Load(
[CatalogLoader.CorePackId, "addon"],
[
PackDocuments.Def(CatalogLoader.CorePackId, "things", "chair", """{ "defName": "Chair" }"""),
PackDocuments.Def(CatalogLoader.CorePackId, "things", "desk", """{ "defName": "Desk" }"""),
PackDocuments.Def(CatalogLoader.CorePackId, "works", "teach", """{ "defName": "TeachLesson" }"""),
PackDocuments.Def(CatalogLoader.CorePackId, "works", "walk", """{ "defName": "WalkSchool" }"""),
PackDocuments.Def(
CatalogLoader.CorePackId,
"rooms",
"office",
"""
{
"defName": "Office",
"slots": [ { "key": "seat", "thing": "Chair" } ],
"works": ["TeachLesson", "WalkSchool"]
}
"""),
PackDocuments.Patch(
"addon",
"office",
"""
{
"target": "Office",
"ops": [
{ "op": "replace", "path": "/slots/0/thing", "value": "Desk" },
{ "op": "remove", "path": "/works/1" }
]
}
"""),
]);
Assert.Equal("Desk", catalog.Rooms["Office"].Slots[0].Thing);
Assert.Equal(["TeachLesson"], catalog.Rooms["Office"].Works);
}
}