226 lines
7.8 KiB
C#
226 lines
7.8 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.CarryChance);
|
|
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 BraInheritsFromUnderwear_ButOccupiesUpperUnderwear()
|
|
{
|
|
var catalog = _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"colors",
|
|
"white",
|
|
"""{ "defName": "White", "tags": ["neutral"] }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"underwear",
|
|
"""{ "defName": "Underwear", "abstract": true, "layers": ["Underwear"], "portable": true, "mass": 0.05, "colors": ["White"] }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"bra",
|
|
"""{ "defName": "Bra", "parent": "Underwear", "layers": ["UpperUnderwear"], "sex": "female" }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"panties",
|
|
"""{ "defName": "Panties", "parent": "Underwear", "sex": "female" }"""),
|
|
]);
|
|
|
|
Assert.True(catalog.Things["Underwear"].Abstract);
|
|
Assert.False(catalog.Things["Bra"].Abstract);
|
|
Assert.Equal("Underwear", catalog.Things["Bra"].Parent);
|
|
Assert.Equal([ApparelLayers.UpperUnderwear], catalog.Things["Bra"].Layers);
|
|
Assert.True(catalog.Things["Bra"].Portable);
|
|
Assert.Equal(0.05f, catalog.Things["Bra"].Mass);
|
|
Assert.Equal(["White"], catalog.Things["Bra"].Colors);
|
|
Assert.Equal([ApparelLayers.Underwear], catalog.Things["Panties"].Layers);
|
|
Assert.Equal("female", catalog.Things["Panties"].Sex);
|
|
}
|
|
|
|
[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);
|
|
}
|
|
|
|
[Fact]
|
|
public void CarryChanceAboveOne_FailsTheCatalog()
|
|
{
|
|
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"things",
|
|
"phone",
|
|
"""{ "defName": "Phone", "portable": true, "carryChance": 1.2 }"""),
|
|
]));
|
|
|
|
Assert.Contains("carryChance", ex.Message, StringComparison.Ordinal);
|
|
}
|
|
}
|