Skip to content

Commit 14e8946

Browse files
committed
move GameAssets to devkit
1 parent 8160b28 commit 14e8946

59 files changed

Lines changed: 832 additions & 502 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/RA_Integration.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
</Link>
7373
</ItemDefinitionGroup>
7474
<ItemGroup>
75-
<ClCompile Include="data\context\GameAssets.cpp" />
7675
<ClCompile Include="api\ApiCall.cpp" />
7776
<ClCompile Include="api\impl\ConnectedServer.cpp" />
7877
<ClCompile Include="api\impl\DisconnectedServer.cpp" />
@@ -206,7 +205,6 @@
206205
<ClInclude Include="api\UpdateRichPresence.hh" />
207206
<ClInclude Include="api\UploadBadge.hh" />
208207
<ClInclude Include="data\context\EmulatorContext.hh" />
209-
<ClInclude Include="data\context\GameAssets.hh" />
210208
<ClInclude Include="data\context\GameContext.hh" />
211209
<ClInclude Include="data\context\SessionTracker.hh" />
212210
<ClInclude Include="data\Types.hh" />

src/RA_Integration.vcxproj.filters

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,6 @@
312312
<ClCompile Include="data\context\SessionTracker.cpp">
313313
<Filter>Data\Context</Filter>
314314
</ClCompile>
315-
<ClCompile Include="data\context\GameAssets.cpp">
316-
<Filter>Data\Context</Filter>
317-
</ClCompile>
318315
<ClCompile Include="ui\viewmodels\ProgressViewModel.cpp">
319316
<Filter>UI\ViewModels</Filter>
320317
</ClCompile>
@@ -791,9 +788,6 @@
791788
<ClInclude Include="data\context\SessionTracker.hh">
792789
<Filter>Data\Context</Filter>
793790
</ClInclude>
794-
<ClInclude Include="data\context\GameAssets.hh">
795-
<Filter>Data\Context</Filter>
796-
</ClInclude>
797791
<ClInclude Include="ui\viewmodels\ProgressViewModel.hh">
798792
<Filter>UI\ViewModels</Filter>
799793
</ClInclude>

src/data/context/GameContext.cpp

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool GameContext::BeginLoadGame(unsigned int nGameId, Mode nMode, bool& bWasPaus
116116
// reset the GameContext
117117
m_nMode = nMode;
118118
m_sGameTitle.clear();
119-
m_vSubsets.clear();
119+
m_vAssets.ClearAchievementSets();
120120
m_vAssets.ResetLocalId();
121121

122122
m_vAssets.BeginUpdate();
@@ -293,7 +293,7 @@ void GameContext::EndLoadGame(int nResult, bool bWasPaused, bool bShowSoftcoreWa
293293
// activate rich presence (or remove if not defined)
294294
if (pRichPresence && nResult == RC_OK)
295295
{
296-
pRichPresence->SetSubsetID(m_vSubsets.front().AchievementSetID());
296+
pRichPresence->SetSubsetID(Assets().AchievementSets().GetItemAt(0)->GetID());
297297

298298
// if the server value differs from the local value, the model will appear as Unpublished
299299
if (pRichPresence->GetChanges() != ra::data::models::AssetChanges::None)
@@ -501,11 +501,6 @@ void GameContext::InitializeFromAchievementRuntime(const std::map<uint32_t, std:
501501

502502
void GameContext::InitializeSubsets(const rc_api_fetch_game_sets_response_t* game_data_response)
503503
{
504-
Expects(game_data_response != nullptr);
505-
506-
std::lock_guard<std::mutex> lock(m_mLoadMutex);
507-
m_vSubsets.clear();
508-
509504
// GameID dictates which game is loaded for purposes of local achievement storage and memory notes
510505
m_nGameId = GetRealGameId(game_data_response->id);
511506
// ActiveGameID dictates which game is running for purposes of rich presence and pings
@@ -516,69 +511,34 @@ void GameContext::InitializeSubsets(const rc_api_fetch_game_sets_response_t* gam
516511
ra::services::ServiceLocator::GetMutable<ra::data::context::SessionTracker>().BeginSession(nActiveGameId);
517512
}
518513

519-
for (uint32_t i = 0; i < game_data_response->num_sets; ++i)
520-
{
521-
const auto* pSet = &game_data_response->sets[i];
522-
if (pSet->type == RC_ACHIEVEMENT_SET_TYPE_CORE)
523-
{
524-
// core subset should always be first
525-
m_vSubsets.insert(m_vSubsets.begin(),
526-
Subset(pSet->id, GetRealGameId(pSet->game_id),
527-
ra::util::String::Widen(pSet->title), SubsetType::Core));
528-
}
529-
else
530-
{
531-
SubsetType nType = SubsetType::Bonus;
532-
switch (pSet->type)
533-
{
534-
case RC_ACHIEVEMENT_SET_TYPE_EXCLUSIVE:
535-
nType = SubsetType::Exclusive;
536-
break;
537-
case RC_ACHIEVEMENT_SET_TYPE_SPECIALTY:
538-
nType = SubsetType::Specialty;
539-
break;
540-
default:
541-
nType = SubsetType::Bonus;
542-
break;
543-
}
544-
m_vSubsets.emplace_back(pSet->id, GetRealGameId(pSet->game_id),
545-
ra::util::String::Widen(pSet->title), nType);
546-
}
547-
}
514+
Assets().InitializeSubsets(game_data_response, m_nActiveGameId != m_nGameId);
548515

549516
// if subsets were found, migrate any SUBSET-User.txt files into the the GAME-User.txt file
550-
if (m_vSubsets.size() > 1)
551-
{
517+
if (Assets().AchievementSets().Count() > 1)
552518
MigrateSubsetUserFiles();
553-
}
554-
else if (m_nActiveGameId != m_nGameId)
555-
{
556-
m_vSubsets.front().SetTitle(ra::util::String::Printf(L"%s (%s)",
557-
m_vSubsets.front().Title(), game_data_response->title));
558-
}
559519
}
560520

561521
void GameContext::MigrateSubsetUserFiles()
562522
{
563523
auto& pLocalStorage = ra::services::ServiceLocator::GetMutable<ra::services::ILocalStorage>();
564524
std::unique_ptr<ra::services::TextWriter> pGameData;
565525

566-
for (size_t i = 1; i < m_vSubsets.size(); ++i)
526+
for (const auto& pSubset : Assets().AchievementSets())
567527
{
568-
const auto& pSubset = m_vSubsets.at(i);
569-
Expects(pSubset.GameID() != m_nGameId);
528+
if (pSubset.GetBackingGameID() == m_nGameId)
529+
continue;
570530

571531
auto pSubsetData = pLocalStorage.ReadText(ra::services::StorageItemType::UserAchievements,
572-
std::to_wstring(pSubset.GameID()));
532+
std::to_wstring(pSubset.GetBackingGameID()));
573533
if (pSubsetData)
574534
{
575535
// replace ID with "0|SUBSETID" so new IDs will be generated
576-
std::string sSubsetReplace = "0|" + std::to_string(pSubset.AchievementSetID());
536+
std::string sSubsetReplace = "0|" + std::to_string(pSubset.GetID());
577537

578538
if (!pGameData)
579539
{
580540
pGameData = pLocalStorage.AppendText(ra::services::StorageItemType::UserAchievements,
581-
std::to_wstring(m_nGameId));
541+
std::to_wstring(m_nGameId));
582542
if (!pGameData)
583543
{
584544
RA_LOG_ERR("Could not append to %u-User.txt", m_nGameId);
@@ -622,17 +582,17 @@ void GameContext::MigrateSubsetUserFiles()
622582
// release the file so it can be deleted, then delete it.
623583
pSubsetData.reset();
624584
pLocalStorage.Delete(ra::services::StorageItemType::UserAchievements,
625-
std::to_wstring(pSubset.GameID()));
585+
std::to_wstring(pSubset.GetBackingGameID()));
626586
}
627587
}
628588
}
629589

630590
uint32_t GameContext::GetGameId(uint32_t nSubsetId) const noexcept
631591
{
632-
for (const auto& pSubset : m_vSubsets)
592+
for (const auto& pSubset : Assets().AchievementSets())
633593
{
634-
if (pSubset.ID() == nSubsetId)
635-
return pSubset.GameID();
594+
if (pSubset.GetID() == nSubsetId)
595+
return pSubset.GetBackingGameID();
636596
}
637597

638598
return GameId();

src/data/context/GameContext.hh

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
#include "context/IGameContext.hh"
66

7+
#include "data/models/GameAssets.hh"
78
#include "data/models/LocalBadgesModel.hh"
89

910
#include "services/ServiceLocator.hh"
1011

11-
#include "GameAssets.hh"
12-
1312
#include <string>
1413
#include <atomic>
1514

@@ -56,11 +55,6 @@ public:
5655
/// </summary>
5756
bool IsGameLoading() const noexcept { return m_nLoadCount != 0; }
5857

59-
/// <summary>
60-
/// Gets the title of the currently loaded game.
61-
/// </summary>
62-
const std::wstring& GameTitle() const noexcept { return m_sGameTitle; }
63-
6458
/// <summary>
6559
/// Sets the game title.
6660
/// </summary>
@@ -95,20 +89,6 @@ public:
9589
}
9690
}
9791

98-
/// <summary>
99-
/// Determines if the provided game identifier is virtual
100-
/// </summary>
101-
/// <remarks>
102-
/// IDs above 1 billion are incompatible. The 100 millions place indicates how.
103-
/// Mask off the part above 100 million to get the actual game id.
104-
/// </remarks>
105-
static constexpr bool IsVirtualGameId(uint32_t nGameId) noexcept { return nGameId > 1000000000; }
106-
107-
/// <summary>
108-
/// Gets the real game identifier from a virtual one
109-
/// </summary>
110-
static constexpr uint32_t GetRealGameId(uint32_t nGameId) noexcept { return nGameId % 100000000; }
111-
11292
enum HashCompatibility
11393
{
11494
Compatible = 0,
@@ -128,44 +108,11 @@ public:
128108
/// <summary>
129109
/// Gets the assets for the current game.
130110
/// </summary>
131-
GameAssets& Assets() noexcept { return m_vAssets; }
132-
const GameAssets& Assets() const noexcept { return m_vAssets; }
111+
ra::data::models::GameAssets& Assets() noexcept { return m_vAssets; }
112+
const ra::data::models::GameAssets& Assets() const noexcept { return m_vAssets; }
133113

134114
void DoFrame();
135115

136-
enum SubsetType
137-
{
138-
Core,
139-
Bonus,
140-
Specialty,
141-
Exclusive,
142-
};
143-
144-
class Subset
145-
{
146-
public:
147-
Subset(uint32_t nAchievementSetId, uint32_t nGameId, const std::wstring& sTitle, SubsetType nType) :
148-
m_sTitle(sTitle), m_nType(nType), m_nAchievementSetId(nAchievementSetId), m_nGameId(nGameId)
149-
{
150-
}
151-
152-
const std::wstring& Title() const noexcept { return m_sTitle; }
153-
SubsetType Type() const noexcept { return m_nType; }
154-
uint32_t AchievementSetID() const noexcept { return m_nAchievementSetId; }
155-
uint32_t GameID() const noexcept { return m_nGameId; }
156-
157-
// Core assets have SubsetId of 0
158-
uint32_t ID() const noexcept { return (m_nType == SubsetType::Core) ? 0 : m_nAchievementSetId; }
159-
160-
void SetTitle(const std::wstring& sTitle) { m_sTitle = sTitle; }
161-
162-
private:
163-
std::wstring m_sTitle;
164-
SubsetType m_nType;
165-
uint32_t m_nAchievementSetId;
166-
uint32_t m_nGameId;
167-
};
168-
const std::vector<Subset>& Subsets() const noexcept { return m_vSubsets; }
169116
void InitializeSubsets(const rc_api_fetch_game_sets_response_t* game_data_response);
170117
uint32_t GetGameId(uint32_t nSubsetId) const noexcept;
171118

@@ -207,14 +154,11 @@ protected:
207154
void BeginLoad();
208155
void EndLoad();
209156

210-
std::wstring m_sGameTitle;
211157
std::string m_sGameHash;
212158
Mode m_nMode{};
213159

214-
std::vector<Subset> m_vSubsets;
215-
216160
private:
217-
GameAssets m_vAssets;
161+
ra::data::models::GameAssets m_vAssets;
218162

219163
std::atomic<int> m_nLoadCount = 0;
220164
int m_nMasteryPopupId = 0;

src/devkit/RADevKit.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
</ItemDefinitionGroup>
5858
<ItemGroup>
5959
<ClCompile Include="context\impl\ConsoleContext.cpp" />
60+
<ClCompile Include="context\impl\DevKitContext.cpp" />
6061
<ClCompile Include="context\impl\EmulatorMemoryContext.cpp" />
6162
<ClCompile Include="context\impl\RcClient.cpp" />
6263
<ClCompile Include="data\CapturedMemoryBlock.cpp" />
@@ -68,7 +69,9 @@
6869
<ClCompile Include="data\ModelProperty.cpp" />
6970
<ClCompile Include="data\ModelPropertyContainer.cpp" />
7071
<ClCompile Include="data\models\AchievementModel.cpp" />
72+
<ClCompile Include="data\models\AchievementSetModel.cpp" />
7173
<ClCompile Include="data\models\AssetModelBase.cpp" />
74+
<ClCompile Include="data\models\GameAssets.cpp" />
7275
<ClCompile Include="data\models\LeaderboardModel.cpp" />
7376
<ClCompile Include="data\models\LocalBadgesModel.cpp" />
7477
<ClCompile Include="data\models\MemoryNoteModel.cpp" />
@@ -85,9 +88,11 @@
8588
<ClCompile Include="util\Strings.cpp" />
8689
<ClCompile Include="util\Tokenizer.cpp" />
8790
<ClInclude Include="context\IConsoleContext.hh" />
91+
<ClInclude Include="context\IDevKitContext.hh" />
8892
<ClInclude Include="context\IEmulatorMemoryContext.hh" />
8993
<ClInclude Include="context\IGameContext.hh" />
9094
<ClInclude Include="context\impl\ConsoleContext.hh" />
95+
<ClInclude Include="context\impl\DevKitContext.hh" />
9196
<ClInclude Include="context\impl\EmulatorMemoryContext.hh" />
9297
<ClInclude Include="context\impl\RcClient.hh" />
9398
<ClInclude Include="context\IRcClient.hh" />
@@ -103,7 +108,9 @@
103108
<ClInclude Include="data\ModelProperty.hh" />
104109
<ClInclude Include="data\ModelPropertyContainer.hh" />
105110
<ClInclude Include="data\models\AchievementModel.hh" />
111+
<ClInclude Include="data\models\AchievementSetModel.hh" />
106112
<ClInclude Include="data\models\AssetModelBase.hh" />
113+
<ClInclude Include="data\models\GameAssets.hh" />
107114
<ClInclude Include="data\models\LeaderboardModel.hh" />
108115
<ClInclude Include="data\models\LocalBadgesModel.hh" />
109116
<ClInclude Include="data\models\MemoryNoteModel.hh" />

src/devkit/RADevKit.vcxproj.filters

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,18 @@
207207
<ClInclude Include="data\util\TriggerValidation.hh">
208208
<Filter>data\util</Filter>
209209
</ClInclude>
210+
<ClInclude Include="context\impl\DevKitContext.hh">
211+
<Filter>context\impl</Filter>
212+
</ClInclude>
213+
<ClInclude Include="context\IDevKitContext.hh">
214+
<Filter>context</Filter>
215+
</ClInclude>
216+
<ClInclude Include="data\models\GameAssets.hh">
217+
<Filter>data\models</Filter>
218+
</ClInclude>
219+
<ClInclude Include="data\models\AchievementSetModel.hh">
220+
<Filter>data\models</Filter>
221+
</ClInclude>
210222
</ItemGroup>
211223
<ItemGroup>
212224
<ClCompile Include="util\GSL.cpp">
@@ -293,5 +305,14 @@
293305
<ClCompile Include="data\util\TriggerValidation.cpp">
294306
<Filter>data\util</Filter>
295307
</ClCompile>
308+
<ClCompile Include="context\impl\DevKitContext.cpp">
309+
<Filter>context\impl</Filter>
310+
</ClCompile>
311+
<ClCompile Include="data\models\GameAssets.cpp">
312+
<Filter>data\models</Filter>
313+
</ClCompile>
314+
<ClCompile Include="data\models\AchievementSetModel.cpp">
315+
<Filter>data\models</Filter>
316+
</ClCompile>
296317
</ItemGroup>
297318
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef RA_CONTEXT_IDEVKITCONTEXT_HH
2+
#define RA_CONTEXT_IDEVKITCONTEXT_HH
3+
#pragma once
4+
5+
#include <string>
6+
7+
namespace ra {
8+
namespace context {
9+
10+
class IDevKitContext
11+
{
12+
public:
13+
IDevKitContext() noexcept = default;
14+
virtual ~IDevKitContext() noexcept = default;
15+
IDevKitContext(const IDevKitContext&) noexcept = delete;
16+
IDevKitContext& operator=(const IDevKitContext&) noexcept = delete;
17+
IDevKitContext(IDevKitContext&&) noexcept = delete;
18+
IDevKitContext& operator=(IDevKitContext&&) noexcept = delete;
19+
20+
/// <summary>
21+
/// Gets the version of the devkit library.
22+
/// </summary>
23+
virtual const std::string& Version() const noexcept = 0;
24+
};
25+
26+
} // namespace context
27+
} // namespace ra
28+
29+
#endif // !RA_CONTEXT_USERCONTEXT_HH

0 commit comments

Comments
 (0)