forked from FWGS/hlsdk-portable
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make followers and objecthint classes derive from JSONConfig. Add tests
- Loading branch information
Showing
7 changed files
with
200 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <gtest/gtest.h> | ||
#include <algorithm> | ||
#include "followers.h" | ||
|
||
const char followers[] = R"( | ||
{ | ||
"fast_recruit_monsters": ["monster_scientist", "monster_barney"], | ||
"fast_recruit_range": 666 | ||
} | ||
)"; | ||
|
||
TEST(Followers, Parse) { | ||
FollowersDescription f; | ||
ASSERT_TRUE(f.ReadFromContents(followers, "")); | ||
|
||
EXPECT_EQ(f.FastRecruitRange(), 666); | ||
|
||
std::array<std::string, 2> a = {"monster_scientist", "monster_barney"}; | ||
EXPECT_TRUE(std::equal(f.RecruitsBegin(), f.RecruitsEnd(), a.cbegin())); | ||
} | ||
|
||
const char followersNonunique[] = R"( | ||
{ | ||
"fast_recruit_monsters": ["monster_barney", "monster_scientist", "monster_barney"], | ||
} | ||
)"; | ||
|
||
TEST(Followers, NonUniqueFollowers) { | ||
FollowersDescription f; | ||
ASSERT_FALSE(f.ReadFromContents(followersNonunique, "")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#include <gtest/gtest.h> | ||
#include "objecthint_spec.h" | ||
|
||
const char objecthints[] = R"( | ||
{ | ||
"visuals": { | ||
"base": { | ||
"sprite": "sprites/hud_brackets.spr" | ||
}, | ||
"interactable": { | ||
"color": [255, 200, 50], | ||
"sprite": "sprites/hud_brackets.spr" | ||
}, | ||
"charged": { | ||
"color": [0, 255, 0], | ||
"sprite": "sprites/hud_charged.spr", | ||
"scale": 1.2 | ||
}, | ||
"depleted": { | ||
"color": [255, 0, 0], | ||
"sprite": "sprites/hud_depleted.spr" | ||
}, | ||
"lock": { | ||
"color": [255, 50, 0], | ||
"sprite": "sprites/hud_brackets.spr" | ||
} | ||
}, | ||
"templates": { | ||
"button": { | ||
"interaction": { | ||
"default": "interactable", | ||
"unusable": null, | ||
"locked": "lock" | ||
} | ||
}, | ||
"charger": { | ||
"interaction": { | ||
"default": "charged", | ||
"unusable": "depleted" | ||
} | ||
}, | ||
"pickup": { | ||
"scan": { | ||
"default": "base", | ||
"unusable": null | ||
}, | ||
"interaction": { | ||
"default": "interactable", | ||
"unusable": null | ||
}, | ||
"distance": 256 | ||
}, | ||
"hidden": {} | ||
}, | ||
"entity_mapping": { | ||
"func_button": "button", | ||
"func_rot_button": "button", | ||
"func_healthcharger": "charger", | ||
"func_recharge": "charger", | ||
"item_pickup": "pickup" | ||
}, | ||
"pickup_mapping": { | ||
"charger_item": "charger", | ||
"button_item": "button" | ||
} | ||
} | ||
)"; | ||
|
||
TEST(ObjectHint, Parse) { | ||
ObjectHintCatalog c; | ||
ASSERT_TRUE(c.ReadFromContents(objecthints, "")); | ||
|
||
{ | ||
const ObjectHintSpec* buttonSpec = c.GetSpec("button"); | ||
ASSERT_TRUE(buttonSpec != nullptr); | ||
ASSERT_TRUE(buttonSpec->interactionVisualSet.defaultVisual != nullptr); | ||
ASSERT_TRUE(buttonSpec->interactionVisualSet.unusableVisual == nullptr); | ||
ASSERT_TRUE(buttonSpec->interactionVisualSet.lockedVisual != nullptr); | ||
EXPECT_FALSE(buttonSpec->scanVisualSet.HasAnySpriteDefined()); | ||
|
||
EXPECT_EQ(buttonSpec->interactionVisualSet.defaultVisual->color, Color(255, 200, 50)); | ||
EXPECT_EQ(buttonSpec->interactionVisualSet.defaultVisual->sprite, "sprites/hud_brackets.spr"); | ||
EXPECT_EQ(buttonSpec->interactionVisualSet.defaultVisual->scale, 1.0f); | ||
|
||
EXPECT_EQ(buttonSpec->interactionVisualSet.lockedVisual->color, Color(255, 50, 0)); | ||
|
||
EXPECT_EQ(buttonSpec, c.GetSpecByEntityName("func_button")); | ||
EXPECT_EQ(buttonSpec, c.GetSpecByEntityName("func_rot_button")); | ||
} | ||
|
||
{ | ||
const ObjectHintSpec* chargerSpec = c.GetSpec("charger"); | ||
ASSERT_TRUE(chargerSpec != nullptr); | ||
ASSERT_TRUE(chargerSpec->interactionVisualSet.defaultVisual != nullptr); | ||
ASSERT_TRUE(chargerSpec->interactionVisualSet.unusableVisual != nullptr); | ||
EXPECT_EQ(chargerSpec->interactionVisualSet.lockedVisual, chargerSpec->interactionVisualSet.defaultVisual); | ||
|
||
EXPECT_EQ(chargerSpec->interactionVisualSet.defaultVisual->color, Color(0, 255, 0)); | ||
EXPECT_EQ(chargerSpec->interactionVisualSet.defaultVisual->sprite, "sprites/hud_charged.spr"); | ||
EXPECT_EQ(chargerSpec->interactionVisualSet.defaultVisual->scale, 1.2f); | ||
|
||
EXPECT_EQ(chargerSpec->interactionVisualSet.unusableVisual->color, Color(255, 0, 0)); | ||
EXPECT_EQ(chargerSpec->interactionVisualSet.unusableVisual->sprite, "sprites/hud_depleted.spr"); | ||
|
||
EXPECT_EQ(chargerSpec, c.GetSpecByEntityName("func_healthcharger")); | ||
EXPECT_EQ(chargerSpec, c.GetSpecByEntityName("func_recharge")); | ||
} | ||
|
||
{ | ||
const ObjectHintSpec* pickupSpec = c.GetSpec("pickup"); | ||
ASSERT_TRUE(pickupSpec != nullptr); | ||
ASSERT_TRUE(pickupSpec->interactionVisualSet.defaultVisual != nullptr); | ||
ASSERT_TRUE(pickupSpec->interactionVisualSet.unusableVisual == nullptr); | ||
EXPECT_EQ(pickupSpec->interactionVisualSet.lockedVisual, pickupSpec->interactionVisualSet.defaultVisual); | ||
|
||
ASSERT_TRUE(pickupSpec->scanVisualSet.defaultVisual != nullptr); | ||
ASSERT_TRUE(pickupSpec->scanVisualSet.unusableVisual == nullptr); | ||
EXPECT_EQ(pickupSpec->scanVisualSet.lockedVisual, pickupSpec->scanVisualSet.defaultVisual); | ||
|
||
EXPECT_EQ(pickupSpec->interactionVisualSet.defaultVisual->color, Color(255, 200, 50)); | ||
|
||
EXPECT_EQ(pickupSpec, c.GetSpecByEntityName("item_pickup")); | ||
|
||
const ObjectHintSpec* item1Spec = c.GetSpecByPickupName("charger_item"); | ||
ASSERT_TRUE(item1Spec != nullptr); | ||
EXPECT_EQ(item1Spec, c.GetSpec("charger")); | ||
|
||
const ObjectHintSpec* item2Spec = c.GetSpecByPickupName("button_item"); | ||
ASSERT_TRUE(item2Spec != nullptr); | ||
EXPECT_EQ(item2Spec, c.GetSpec("button")); | ||
} | ||
|
||
{ | ||
const ObjectHintSpec* hiddenSpec = c.GetSpec("hidden"); | ||
ASSERT_TRUE(hiddenSpec != nullptr); | ||
EXPECT_FALSE(hiddenSpec->interactionVisualSet.HasAnySpriteDefined()); | ||
EXPECT_FALSE(hiddenSpec->scanVisualSet.HasAnySpriteDefined()); | ||
} | ||
} |