Repository: RetroAchievements/RAIntegration
Pull request #1049 (2024-01-13 21:06:20)

ensure newly created assets get sync'd to rc_client
fixes asset remaining in "Waiting" state until game is reloaded

https://discord.com/channels/310192285306454017/1149693430306447380/1195824998150049953


Patch:
diff --git a/rcheevos b/rcheevos
index 48942653..6d4f78e9 160000
--- a/rcheevos
+++ b/rcheevos
@@ -1,1 +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<ra::services::AchievementRuntime>();
+    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<ra::services::AchievementRuntime>();
+    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<ra::services::AchievementRuntime>();
+    pRuntime.SyncAssets();
+
     FilteredAssets().EndUpdate();
 
     UpdateTotals();


Test patch:
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 @@ public:
         Assert::AreEqual(AssetState::Active, pAchievement->GetState());
     }
 
-    TEST_METHOD(TestCreateNew)
+    TEST_METHOD(TestCreateNewAchievement)
     {
         AssetListViewModelHarness vmAssetList;
         vmAssetList.mockUserContext.Initialize("User1", "FOO");
@@ -3189,6 +3189,18 @@ public:
         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)