From b134cfddb0b94b69cbb8e48a14f5109d884a73ed Mon Sep 17 00:00:00 2001 From: Jamiras <32680403+Jamiras@users.noreply.github.com> Date: Sat, 13 Jan 2024 16:20:39 -0700 Subject: [PATCH] ensure newly created assets get sync'd to rc_client (#1049) --- rcheevos | 2 +- src/services/AchievementRuntime.cpp | 1 + src/ui/viewmodels/AssetListViewModel.cpp | 15 +++++++++++++++ tests/ui/viewmodels/AssetListViewModel_Tests.cpp | 14 +++++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/rcheevos b/rcheevos index 48942653..6d4f78e9 160000 --- a/rcheevos +++ b/rcheevos @@ -1 +1 @@ -Subproject commit 489426539757de6106a4d0d34d3495f5922f62df +Subproject commit 6d4f78e9287e9165191fe656d4da733b405a3f0f diff --git a/src/services/AchievementRuntime.cpp b/src/services/AchievementRuntime.cpp index 3002ce8d..c3025319 100644 --- a/src/services/AchievementRuntime.cpp +++ b/src/services/AchievementRuntime.cpp @@ -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); } diff --git a/src/ui/viewmodels/AssetListViewModel.cpp b/src/ui/viewmodels/AssetListViewModel.cpp index cbbc34e6..ea19d15f 100644 --- a/src/ui/viewmodels/AssetListViewModel.cpp +++ b/src/ui/viewmodels/AssetListViewModel.cpp @@ -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(); + pRuntime.SyncAssets(); + pAssets.EndUpdate(); // update the local file @@ -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(); + pRuntime.SyncAssets(); + FilteredAssets().EndUpdate(); UpdateTotals(); @@ -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(); + pRuntime.SyncAssets(); + FilteredAssets().EndUpdate(); UpdateTotals(); diff --git a/tests/ui/viewmodels/AssetListViewModel_Tests.cpp b/tests/ui/viewmodels/AssetListViewModel_Tests.cpp index 97912827..82d0174f 100644 --- a/tests/ui/viewmodels/AssetListViewModel_Tests.cpp +++ b/tests/ui/viewmodels/AssetListViewModel_Tests.cpp @@ -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"); @@ -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)