Skip to content

Commit

Permalink
Check whether alternate group exists before setting it
Browse files Browse the repository at this point in the history
If user presses an alternate group hotkey check whether the group actually exists in the level before setting it on the level and UI.
Closes #1237
  • Loading branch information
chreden committed May 9, 2024
1 parent cbca87c commit ff7e6d6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
29 changes: 29 additions & 0 deletions trview.app.tests/Windows/ViewerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,3 +1082,32 @@ TEST(Viewer, SectorHighlightForwarded)
auto sector = mock_shared<MockSector>()->with_room(room);
ui.on_sector_hover(sector);
}

TEST(Viewer, AlternateGroupForwarded)
{
auto level = mock_shared<MockLevel>();
EXPECT_CALL(*level, set_alternate_group(6, true)).Times(1);
ON_CALL(*level, alternate_groups).WillByDefault(Return(std::set<uint32_t>{ 6 }));

auto [ui_ptr, ui] = create_mock<MockViewerUI>();
EXPECT_CALL(ui, set_alternate_group(6, true)).Times(1);

auto viewer = register_test_module().with_ui(std::move(ui_ptr)).build();
viewer->open(level, ILevel::OpenMode::Full);

ui.on_alternate_group(6, true);
}

TEST(Viewer, InvalidAlternateGroupNotForwarded)
{
auto level = mock_shared<MockLevel>();
EXPECT_CALL(*level, set_alternate_group).Times(0);

auto [ui_ptr, ui] = create_mock<MockViewerUI>();
EXPECT_CALL(ui, set_alternate_group).Times(0);

auto viewer = register_test_module().with_ui(std::move(ui_ptr)).build();
viewer->open(level, ILevel::OpenMode::Full);

ui.on_alternate_group(6, true);
}
9 changes: 6 additions & 3 deletions trview.app/Windows/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,12 @@ namespace trview
{
if (auto level = _level.lock())
{
_was_alternate_select = true;
level->set_alternate_group(group, enabled);
_ui->set_alternate_group(group, enabled);
if (std::ranges::contains(level->alternate_groups(), group))
{
_was_alternate_select = true;
level->set_alternate_group(group, enabled);
_ui->set_alternate_group(group, enabled);
}
}
}

Expand Down

0 comments on commit ff7e6d6

Please sign in to comment.