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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user