Register new PhysicalProperties type in ComponentStore.

Update stale references in PlayerBehavior unit test.
Update PlayerBehavior unit tests so that they check for proper behavior.
This commit is contained in:
S David 2023-06-15 15:15:32 -04:00
parent 2950f23b4d
commit 75ddfcad71
2 changed files with 32 additions and 3 deletions

View File

@ -11,6 +11,7 @@
#include "framework/core/components/EntityManager.hpp"
#include "framework/core/components/PhysicalProperties.hpp"
#include "framework/core/components/PlayerBehavior.hpp"
#include "framework/core/components/PositionAttribute.hpp"
#include "framework/core/components/RenderedCircle.hpp"
@ -35,15 +36,18 @@ class ComponentStore : public EntityManager
ComponentDictionary<PositionAttribute> positions;
ComponentDictionary<PlayerBehavior> players;
ComponentDictionary<RenderedCircle> views;
ComponentDictionary<PhysicalProperties> properties;
protected:
ComponentStore() : EntityManager(), positions(), players(), views()
ComponentStore()
: EntityManager(), positions(), players(), views(), properties()
{
using base = EntityManager;
base::RegisterPool(positions);
base::RegisterPool(players);
base::RegisterPool(views);
base::RegisterPool(properties);
}
};
}

View File

@ -25,6 +25,7 @@ namespace {
using Catch::Approx;
using namespace QW;
using namespace QW::Core::Types;
using Core::Components::PlayerBehavior;
using Core::Components::PositionAttribute;
@ -83,8 +84,13 @@ TEST_CASE_METHOD(PlayerBehaviorTestFixture,
{
using keydir_t = Sdl2Testing::SdlEventSimulator::KEY_DIR;
auto& velocityX = playerBehavior.getVelocity().first;
auto& velocityY = playerBehavior.getVelocity().second;
QW::Core::Components::PhysicalProperties* prop =
playerBehavior.getProperties();
velocity_t velocity = prop->GetValueAs<velocity_t>("velocity");
auto& velocityX = velocity.first;
auto& velocityY = velocity.second;
REQUIRE(velocityX == Approx(0.0f));
REQUIRE(velocityY == Approx(0.0f));
@ -92,6 +98,11 @@ TEST_CASE_METHOD(PlayerBehaviorTestFixture,
// Case 1: keydir_t::DOWN #region
// eventSource.Notify(keydir_t::DOWN);
eventSource.Notify(keydir_t::DOWN);
velocity = prop->GetValueAs<velocity_t>("velocity");
velocityX = velocity.first;
velocityY = velocity.second;
REQUIRE(velocityX == Approx(0.0f));
REQUIRE(velocityY > 0.0f);
velocityY = 0.0f;
@ -99,6 +110,11 @@ TEST_CASE_METHOD(PlayerBehaviorTestFixture,
// Case 2: keydir_t::UP #region
eventSource.Notify(keydir_t::UP);
velocity = prop->GetValueAs<velocity_t>("velocity");
velocityX = velocity.first;
velocityY = velocity.second;
REQUIRE(velocityX == Approx(0.0f));
REQUIRE(velocityY < 0.0f);
velocityY = 0.0f;
@ -106,6 +122,11 @@ TEST_CASE_METHOD(PlayerBehaviorTestFixture,
// Case 3: keydir_t::RIGHT #region
eventSource.Notify(keydir_t::RIGHT);
velocity = prop->GetValueAs<velocity_t>("velocity");
velocityX = velocity.first;
velocityY = velocity.second;
REQUIRE(velocityX > 0.0f);
REQUIRE(velocityY == Approx(0.0f));
velocityX = 0.0f;
@ -114,6 +135,10 @@ TEST_CASE_METHOD(PlayerBehaviorTestFixture,
// Case 4: keydir_t::LEFT #region
eventSource.Notify(keydir_t::LEFT);
velocity = prop->GetValueAs<velocity_t>("velocity");
velocityX = velocity.first;
velocityY = velocity.second;
REQUIRE(velocityX < 0.0f);
REQUIRE(velocityY == Approx(0.0f));
velocityX = 0.0f;