Empty layers keep furniture on the map; a known layer set and ColorDef palette reject unknown ids at load. Co-authored-by: Cursor <cursoragent@cursor.com>
170 lines
5.5 KiB
C#
170 lines
5.5 KiB
C#
namespace HSchool.Content.Tests;
|
|
|
|
public class ApparelDefTests
|
|
{
|
|
private readonly CatalogLoader _loader = new();
|
|
|
|
[Fact]
|
|
public void ChairWithoutApparelFields_LoadsAsFurniture()
|
|
{
|
|
var catalog = _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"actions",
|
|
"sit",
|
|
"""{ "defName": "Sit", "abstract": true }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"chair",
|
|
"""{ "defName": "Chair", "actions": ["Sit"] }"""),
|
|
]);
|
|
|
|
var chair = catalog.Things["Chair"];
|
|
Assert.Equal(["Sit"], chair.Actions);
|
|
Assert.Empty(chair.Layers);
|
|
Assert.False(chair.Portable);
|
|
Assert.Equal(0, chair.Mass);
|
|
Assert.Equal(0, chair.Insulation);
|
|
Assert.Equal(0, chair.Formality);
|
|
Assert.Null(chair.Age);
|
|
Assert.Null(chair.Sex);
|
|
Assert.Empty(chair.Colors);
|
|
Assert.Null(chair.SkirtLength);
|
|
Assert.False(chair.Pe);
|
|
Assert.Equal(0, chair.PupilSlots);
|
|
}
|
|
|
|
[Fact]
|
|
public void DressOccupyingTwoLayers_Loads()
|
|
{
|
|
var catalog = _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"dress",
|
|
"""{ "defName": "Dress", "layers": ["Bottom", "Top"], "portable": true }"""),
|
|
]);
|
|
|
|
Assert.Equal([ApparelLayers.Bottom, ApparelLayers.Top], catalog.Things["Dress"].Layers);
|
|
Assert.True(catalog.Things["Dress"].Portable);
|
|
}
|
|
|
|
[Fact]
|
|
public void UnknownLayer_FailsTheCatalog()
|
|
{
|
|
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"cape",
|
|
"""{ "defName": "Cape", "layers": ["Cloak"] }"""),
|
|
]));
|
|
|
|
Assert.Contains("Cloak", ex.Message, StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public void TwoTopsInTheCatalog_DoNotFailLoad()
|
|
{
|
|
var catalog = _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"shirt",
|
|
"""{ "defName": "Shirt", "layers": ["Top"] }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"tshirt",
|
|
"""{ "defName": "TShirt", "layers": ["Top"] }"""),
|
|
]);
|
|
|
|
Assert.Equal([ApparelLayers.Top], catalog.Things["Shirt"].Layers);
|
|
Assert.Equal([ApparelLayers.Top], catalog.Things["TShirt"].Layers);
|
|
}
|
|
|
|
[Fact]
|
|
public void TShirtReferencingRed_LoadsWhenThePaletteHasRed()
|
|
{
|
|
var catalog = _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"colors",
|
|
"red",
|
|
"""{ "defName": "Red", "tags": ["bright"] }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"tshirt",
|
|
"""{ "defName": "TShirt", "layers": ["Top"], "colors": ["Red"] }"""),
|
|
]);
|
|
|
|
Assert.Equal(["Red"], catalog.Things["TShirt"].Colors);
|
|
Assert.Equal([ColorTags.Bright], catalog.Colors["Red"].Tags);
|
|
}
|
|
|
|
[Fact]
|
|
public void TShirtReferencingMissingRed_FailsTheCatalog()
|
|
{
|
|
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"tshirt",
|
|
"""{ "defName": "TShirt", "layers": ["Top"], "colors": ["Red"] }"""),
|
|
]));
|
|
|
|
Assert.Contains("Red", ex.Message, StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public void UnknownColorTag_FailsTheCatalog()
|
|
{
|
|
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"colors",
|
|
"neon",
|
|
"""{ "defName": "Neon", "tags": ["glow"] }"""),
|
|
]));
|
|
|
|
Assert.Contains("glow", ex.Message, StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public void RoomSlotWithApparel_FailsTheCatalog()
|
|
{
|
|
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"tshirt",
|
|
"""{ "defName": "TShirt", "layers": ["Top"] }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"rooms",
|
|
"office",
|
|
"""{ "defName": "Office", "slots": [{ "key": "seat", "thing": "TShirt" }], "travelMinutes": 1 }"""),
|
|
]));
|
|
|
|
Assert.Contains("TShirt", ex.Message, StringComparison.Ordinal);
|
|
}
|
|
}
|