Skip to content

Commit

Permalink
ensure newly created assets get sync'd to rc_client (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Jan 13, 2024
1 parent a2ad077 commit b134cfd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rcheevos
1 change: 1 addition & 0 deletions src/services/AchievementRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ AchievementRuntime::AchievementRuntime()
#endif

rc_client_set_event_handler(m_pClient.get(), EventHandler);
m_pClient->state.allow_leaderboards_in_softcore = true;

rc_client_set_unofficial_enabled(m_pClient.get(), 1);
}
Expand Down
15 changes: 15 additions & 0 deletions src/ui/viewmodels/AssetListViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,11 @@ void AssetListViewModel::RevertSelected()
}
}

// sync assets before calling EndUpdate to ensure anything watching for TriggerProperty to change
// can find the new definition (i.e. asset editor)
auto& pRuntime = ra::services::ServiceLocator::GetMutable<ra::services::AchievementRuntime>();
pRuntime.SyncAssets();

pAssets.EndUpdate();

// update the local file
Expand Down Expand Up @@ -1748,6 +1753,11 @@ void AssetListViewModel::CreateNew()
}
}

// sync assets before calling EndUpdate to ensure anything watching for TriggerProperty to change
// can find the new definition (i.e. asset editor)
auto& pRuntime = ra::services::ServiceLocator::GetMutable<ra::services::AchievementRuntime>();
pRuntime.SyncAssets();

FilteredAssets().EndUpdate();

UpdateTotals();
Expand Down Expand Up @@ -1865,6 +1875,11 @@ void AssetListViewModel::CloneSelected()
}
}

// sync assets before calling EndUpdate to ensure anything watching for TriggerProperty to change
// can find the new definition (i.e. asset editor)
auto& pRuntime = ra::services::ServiceLocator::GetMutable<ra::services::AchievementRuntime>();
pRuntime.SyncAssets();

FilteredAssets().EndUpdate();

UpdateTotals();
Expand Down
14 changes: 13 additions & 1 deletion tests/ui/viewmodels/AssetListViewModel_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3132,7 +3132,7 @@ TEST_CLASS(AssetListViewModel_Tests)
Assert::AreEqual(AssetState::Active, pAchievement->GetState());
}

TEST_METHOD(TestCreateNew)
TEST_METHOD(TestCreateNewAchievement)
{
AssetListViewModelHarness vmAssetList;
vmAssetList.mockUserContext.Initialize("User1", "FOO");
Expand Down Expand Up @@ -3189,6 +3189,18 @@ TEST_CLASS(AssetListViewModel_Tests)
pAsset = vmAssetList.FilteredAssets().GetItemAt(1);
Expects(pAsset != nullptr);
Assert::IsTrue(pAsset->IsSelected());

// both achievements should be loaded in the runtime
auto* pClient = vmAssetList.mockRuntime.GetClient();
auto* pAch1 = (rc_client_achievement_info_t*)rc_client_get_achievement_info(pClient, 111000001U);
Expects(pAch1 != nullptr);
Assert::IsNull(pAch1->trigger); // trigger not set until activated
Assert::AreEqual({0}, pAch1->public_.points);

auto* pAch2 = (rc_client_achievement_info_t*)rc_client_get_achievement_info(pClient, 111000002U);
Expects(pAch2 != nullptr);
Assert::IsNull(pAch2->trigger);
Assert::AreEqual({0}, pAch2->public_.points);
}

TEST_METHOD(TestCreateNewHardcore)
Expand Down

0 comments on commit b134cfd

Please sign in to comment.