Trophy Manager: allow to lock/unlock trophies

This commit is contained in:
Megamouse 2023-11-17 21:33:30 +01:00
parent cee6d03033
commit 47fcb9562f
7 changed files with 177 additions and 22 deletions

View file

@ -31,9 +31,9 @@ std::shared_ptr<rXmlNode> trophy_xml_document::GetRoot()
return trophy_base;
}
TROPUSRLoader::load_result TROPUSRLoader::Load(const std::string& filepath, const std::string& configpath)
TROPUSRLoader::load_result TROPUSRLoader::Load(std::string_view filepath, std::string_view configpath)
{
const std::string& path = vfs::get(filepath);
const std::string path = vfs::get(filepath);
load_result res{};
@ -143,7 +143,7 @@ bool TROPUSRLoader::LoadTables()
}
// TODO: TROPUSRLoader::Save deletes the TROPUSR and creates it again. This is probably very slow.
bool TROPUSRLoader::Save(const std::string& filepath)
bool TROPUSRLoader::Save(std::string_view filepath)
{
fs::pending_file temp(vfs::get(filepath));
@ -160,7 +160,7 @@ bool TROPUSRLoader::Save(const std::string& filepath)
return temp.commit();
}
bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& configpath)
bool TROPUSRLoader::Generate(std::string_view filepath, std::string_view configpath)
{
fs::file config(vfs::get(configpath));
@ -377,3 +377,18 @@ bool TROPUSRLoader::UnlockTrophy(u32 id, u64 timestamp1, u64 timestamp2)
return true;
}
bool TROPUSRLoader::LockTrophy(u32 id)
{
if (id >= m_table6.size())
{
trp_log.warning("TROPUSRLoader::LockTrophy: Invalid id=%d", id);
return false;
}
m_table6[id].trophy_state = 0;
m_table6[id].timestamp1 = 0;
m_table6[id].timestamp2 = 0;
return true;
}

View file

@ -81,10 +81,10 @@ class TROPUSRLoader
std::vector<TROPUSREntry4> m_table4;
std::vector<TROPUSREntry6> m_table6;
virtual bool Generate(const std::string& filepath, const std::string& configpath);
virtual bool LoadHeader();
virtual bool LoadTableHeaders();
virtual bool LoadTables();
[[nodiscard]] bool Generate(std::string_view filepath, std::string_view configpath);
[[nodiscard]] bool LoadHeader();
[[nodiscard]] bool LoadTableHeaders();
[[nodiscard]] bool LoadTables();
public:
virtual ~TROPUSRLoader() = default;
@ -95,17 +95,18 @@ public:
bool success;
};
virtual load_result Load(const std::string& filepath, const std::string& configpath);
virtual bool Save(const std::string& filepath);
[[nodiscard]] load_result Load(std::string_view filepath, std::string_view configpath);
[[nodiscard]] bool Save(std::string_view filepath);
virtual u32 GetTrophiesCount() const;
virtual u32 GetUnlockedTrophiesCount() const;
[[nodiscard]] u32 GetTrophiesCount() const;
[[nodiscard]] u32 GetUnlockedTrophiesCount() const;
virtual u32 GetUnlockedPlatinumID(u32 trophy_id, const std::string& config_path);
[[nodiscard]] u32 GetUnlockedPlatinumID(u32 trophy_id, const std::string& config_path);
virtual u32 GetTrophyGrade(u32 id) const;
virtual u32 GetTrophyUnlockState(u32 id) const;
virtual u64 GetTrophyTimestamp(u32 id) const;
[[nodiscard]] u32 GetTrophyGrade(u32 id) const;
[[nodiscard]] u32 GetTrophyUnlockState(u32 id) const;
[[nodiscard]] u64 GetTrophyTimestamp(u32 id) const;
virtual bool UnlockTrophy(u32 id, u64 timestamp1, u64 timestamp2);
[[nodiscard]] bool UnlockTrophy(u32 id, u64 timestamp1, u64 timestamp2);
[[nodiscard]] bool LockTrophy(u32 id);
};