aboutsummaryrefslogtreecommitdiff
path: root/src/test/InputTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/InputTest.cpp')
-rw-r--r--src/test/InputTest.cpp57
1 files changed, 37 insertions, 20 deletions
diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp
index 0243bd8..a1fe59a 100644
--- a/src/test/InputTest.cpp
+++ b/src/test/InputTest.cpp
@@ -28,22 +28,23 @@ using namespace crepe;
class InputTest : public ::testing::Test {
public:
Mediator mediator;
- ComponentManager mgr{mediator};
- SDLContext sdl_context{mediator};
+ ComponentManager mgr {mediator};
+ SDLContext sdl_context {mediator};
- InputSystem input_system{mediator};
- ResourceManager resman{mediator};
- RenderSystem render{mediator};
- EventManager event_manager{mediator};
+ InputSystem input_system {mediator};
+ ResourceManager resman {mediator};
+ RenderSystem render {mediator};
+ EventManager event_manager {mediator};
//GameObject camera;
vec2 offset = {100, 200};
protected:
void SetUp() override {
GameObject obj = mgr.new_object("camera", "camera", offset, 0, 1);
- auto & camera
- = obj.add_component<Camera>(ivec2{500, 500}, vec2{500, 500},
- Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
+ auto & camera = obj.add_component<Camera>(
+ ivec2 {500, 500}, vec2 {500, 500},
+ Camera::Data {.bg_color = Color::WHITE, .zoom = 1.0f}
+ );
render.frame_update();
//mediator.event_manager = event_manager;
//mediator.component_manager = mgr;
@@ -208,14 +209,15 @@ TEST_F(InputTest, MouseClick) {
}
TEST_F(InputTest, testButtonClick) {
- GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
+ GameObject button_obj = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1);
bool button_clicked = false;
event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) {
button_clicked = true;
EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
return false;
});
- auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0});
+ auto & button
+ = button_obj.add_component<Button>(vec2 {100, 100}, Button::Data {}, vec2 {0, 0});
bool hover = false;
button.active = true;
@@ -230,16 +232,21 @@ TEST_F(InputTest, testButtonClick) {
EXPECT_TRUE(button_clicked);
}
TEST_F(InputTest, buttonPositionCamera) {
- GameObject button_obj = mgr.new_object("body", "person", vec2{50, 50}, 0, 1);
+ GameObject button_obj = mgr.new_object("body", "person", vec2 {50, 50}, 0, 1);
bool button_clicked = false;
event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) {
button_clicked = true;
EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
return false;
});
- auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0});
+ auto & button = button_obj.add_component<Button>(
+ vec2 {10, 10},
+ Button::Data {
+ .world_space = false,
+ },
+ vec2 {0, 0}
+ );
- button.world_space = false;
bool hover = false;
button.active = true;
this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
@@ -253,15 +260,20 @@ TEST_F(InputTest, buttonPositionCamera) {
EXPECT_TRUE(button_clicked);
}
TEST_F(InputTest, buttonPositionWorld) {
- GameObject button_obj = mgr.new_object("body", "person", vec2{50, 50}, 0, 1);
+ GameObject button_obj = mgr.new_object("body", "person", vec2 {50, 50}, 0, 1);
bool button_clicked = false;
event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) {
button_clicked = true;
EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
return false;
});
- auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0});
- button.world_space = true;
+ auto & button = button_obj.add_component<Button>(
+ vec2 {10, 10},
+ Button::Data {
+ .world_space = true,
+ },
+ vec2 {0, 0}
+ );
bool hover = false;
button.active = true;
this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
@@ -275,7 +287,7 @@ TEST_F(InputTest, buttonPositionWorld) {
EXPECT_FALSE(button_clicked);
}
TEST_F(InputTest, testButtonHover) {
- GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
+ GameObject button_obj = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1);
bool button_hover = false;
event_manager.subscribe<ButtonEnterEvent>([&](const ButtonEnterEvent & event) {
button_hover = true;
@@ -287,8 +299,13 @@ TEST_F(InputTest, testButtonHover) {
EXPECT_EQ(event.metadata.game_object_id, button_obj.id);
return false;
});
- auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0});
- button.active = true;
+ auto & button = button_obj.add_component<Button>(
+ vec2 {100, 100},
+ Button::Data {
+ .world_space = true,
+ },
+ vec2 {0, 0}
+ );
// Mouse on button
SDL_Event hover_event;
SDL_zero(hover_event);