- Updated protocol documentation to include new `activity` and `activityLabel` fields in the person card response, reflecting real-time activity status. - Introduced `BehaviorDef` to define behavior rules, including need thresholds and lesson skill gains, enhancing AI decision-making. - Revised the `DefCatalog` to incorporate behavior definitions and updated validation logic to ensure proper behavior handling. - Enhanced the simulation to manage presence and activity states, allowing for more dynamic interactions within the school environment. - Updated tests to validate the new activity tracking and behavior functionalities, ensuring robust performance and reliability. - Improved localization strings to support new activity and behavior features, enhancing user experience.
99 lines
3.8 KiB
C#
99 lines
3.8 KiB
C#
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", "abstract": true }"""),
|
|
PackDocuments.Def(CatalogLoader.CorePackId, "actions", "inspect", """{ "defName": "Inspect", "abstract": true }"""),
|
|
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"],
|
|
"travelMinutes": 1
|
|
}
|
|
"""),
|
|
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);
|
|
}
|
|
}
|