|
| 1 | +#include "Components/ComponentShared.hpp" |
| 2 | +#include "Components/ComponentTags.hpp" |
| 3 | +#include "Components/FollowingEntity.hpp" |
| 4 | +#include "ECS/World.hpp" |
1 | 5 | #include "Graphics/AssetManager.hpp" |
2 | 6 | #include "UI/UIButton.hpp" |
3 | 7 | #include "UI/UIInput.hpp" |
@@ -52,6 +56,66 @@ Test(ui_input, default_state, .init = setup_ui_tests, .fini = teardown_ui_tests) |
52 | 56 | cr_assert_eq(input.getText(), "Test"); |
53 | 57 | } |
54 | 58 |
|
| 59 | +Test(following_entity, toggle_follow_on) { |
| 60 | + World world; |
| 61 | + Entity player = world.spawn(); |
| 62 | + world.add_component<ServerId>(player, ServerId{42}); |
| 63 | + world.add_component<Position>(player, Position{5, 5}); |
| 64 | + world.add_component<InhabitantTag>(player, InhabitantTag{}); |
| 65 | + |
| 66 | + auto storage = world.get_storage<FollowingEntity>(); |
| 67 | + cr_assert(storage == nullptr || storage->size() == 0, "No entity should be followed initially"); |
| 68 | + |
| 69 | + world.add_component<FollowingEntity>(player, FollowingEntity{.entity = player}); |
| 70 | + |
| 71 | + storage = world.get_storage<FollowingEntity>(); |
| 72 | + cr_assert_not_null(storage.get()); |
| 73 | + cr_assert_eq(storage->size(), 1); |
| 74 | + cr_assert(storage->begin()->first == player); |
| 75 | +} |
| 76 | + |
| 77 | +Test(following_entity, toggle_follow_off) { |
| 78 | + World world; |
| 79 | + Entity player = world.spawn(); |
| 80 | + world.add_component<ServerId>(player, ServerId{7}); |
| 81 | + world.add_component<Position>(player, Position{3, 3}); |
| 82 | + world.add_component<InhabitantTag>(player, InhabitantTag{}); |
| 83 | + |
| 84 | + world.add_component<FollowingEntity>(player, FollowingEntity{.entity = player}); |
| 85 | + |
| 86 | + auto storage = world.get_storage<FollowingEntity>(); |
| 87 | + cr_assert_eq(storage->size(), 1); |
| 88 | + |
| 89 | + storage->clear(); |
| 90 | + cr_assert_eq(storage->size(), 0, "Follow should be cleared after toggle off"); |
| 91 | +} |
| 92 | + |
| 93 | +Test(following_entity, switch_follow_target) { |
| 94 | + World world; |
| 95 | + Entity player1 = world.spawn(); |
| 96 | + world.add_component<ServerId>(player1, ServerId{1}); |
| 97 | + world.add_component<Position>(player1, Position{0, 0}); |
| 98 | + world.add_component<InhabitantTag>(player1, InhabitantTag{}); |
| 99 | + |
| 100 | + Entity player2 = world.spawn(); |
| 101 | + world.add_component<ServerId>(player2, ServerId{2}); |
| 102 | + world.add_component<Position>(player2, Position{1, 1}); |
| 103 | + world.add_component<InhabitantTag>(player2, InhabitantTag{}); |
| 104 | + |
| 105 | + world.add_component<FollowingEntity>(player1, FollowingEntity{.entity = player1}); |
| 106 | + |
| 107 | + auto storage = world.get_storage<FollowingEntity>(); |
| 108 | + cr_assert_eq(storage->size(), 1); |
| 109 | + cr_assert(storage->begin()->first == player1); |
| 110 | + |
| 111 | + storage->clear(); |
| 112 | + world.add_component<FollowingEntity>(player2, FollowingEntity{.entity = player2}); |
| 113 | + |
| 114 | + storage = world.get_storage<FollowingEntity>(); |
| 115 | + cr_assert_eq(storage->size(), 1); |
| 116 | + cr_assert(storage->begin()->first == player2); |
| 117 | +} |
| 118 | + |
55 | 119 | Test(ui_manager, manage_components, .init = setup_ui_tests, .fini = teardown_ui_tests) { |
56 | 120 | UIManager manager; |
57 | 121 |
|
|
0 commit comments