feat(VehicleService): Keep track of active profile

This commit is contained in:
Yimura 2021-09-16 22:03:38 +02:00
parent 6f5e12168b
commit be66188f7c
3 changed files with 32 additions and 6 deletions

View File

@ -64,6 +64,9 @@ namespace big
{ {
auto& profile = it->second; auto& profile = it->second;
if (profile.share_code == g_vehicle_service->get_active_profile(profile.handling_hash))
ImGui::TextColored({ 0.1254f,0.8039f,0.3137f,1.f }, "Active");
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::Text("Name:"); ImGui::Text("Name:");
@ -82,9 +85,7 @@ namespace big
ImGui::Text("Share Code: %s", profile.share_code.c_str()); ImGui::Text("Share Code: %s", profile.share_code.c_str());
if (ImGui::Button("Load Profile")) if (ImGui::Button("Load Profile"))
{ g_vehicle_service->set_handling_profile(profile);
*g_local_player->m_vehicle->m_handling = profile.data;
}
ImGui::EndGroup(); ImGui::EndGroup();
@ -139,9 +140,7 @@ namespace big
ImGui::Text("Share Code: %s", profile.share_code.c_str()); ImGui::Text("Share Code: %s", profile.share_code.c_str());
if (ImGui::Button("Load Profile")) if (ImGui::Button("Load Profile"))
{ g_vehicle_service->set_handling_profile(profile);
*g_local_player->m_vehicle->m_handling = profile.data;
}
ImGui::EndGroup(); ImGui::EndGroup();
} }

View File

@ -39,6 +39,13 @@ namespace big
return 1; return 1;
} }
std::string vehicle_service::get_active_profile(std::uint32_t hash)
{
if (auto it = this->m_active_profiles.find(hash); it != this->m_active_profiles.end())
return it->second;
return std::string("");
}
bool vehicle_service::get_by_share_code(const char* share_code) bool vehicle_service::get_by_share_code(const char* share_code)
{ {
static std::string up_to_date = ""; static std::string up_to_date = "";
@ -172,6 +179,7 @@ namespace big
if (auto it = m_handling_backup.find(g_local_player->m_vehicle->m_handling->m_model_hash); it != m_handling_backup.end()) if (auto it = m_handling_backup.find(g_local_player->m_vehicle->m_handling->m_model_hash); it != m_handling_backup.end())
{ {
*g_local_player->m_vehicle->m_handling = it->second; *g_local_player->m_vehicle->m_handling = it->second;
this->m_active_profiles.erase(g_local_player->m_vehicle->m_handling->m_model_hash);
return true; return true;
} }
@ -179,6 +187,21 @@ namespace big
return false; return false;
} }
void vehicle_service::set_active_profile(std::uint32_t hash, std::string share_code)
{
if (auto& it = this->m_active_profiles.find(hash); it != this->m_active_profiles.end())
it->second = share_code;
else
this->m_active_profiles.emplace(hash, share_code);
}
void vehicle_service::set_handling_profile(HandlingProfile& profile)
{
*g_local_player->m_vehicle->m_handling = profile.data;
this->set_active_profile(profile.handling_hash, profile.share_code);
}
bool vehicle_service::update_mine(bool force_update) bool vehicle_service::update_mine(bool force_update)
{ {
static bool busy = false; static bool busy = false;

View File

@ -120,13 +120,17 @@ namespace big
bool apply_from_cache(std::string id); bool apply_from_cache(std::string id);
int attempt_save(); int attempt_save();
std::string get_active_profile(std::uint32_t hash);
bool get_by_share_code(const char* share_code); bool get_by_share_code(const char* share_code);
bool publish_profile(const char* name, const char* description); bool publish_profile(const char* name, const char* description);
PublishStatus publish_status(PublishStatus new_status = PublishStatus::NONE); PublishStatus publish_status(PublishStatus new_status = PublishStatus::NONE);
bool restore_vehicle(); bool restore_vehicle();
void set_active_profile(std::uint32_t hash, std::string share_code);
void set_handling_profile(HandlingProfile& profile);
bool update_mine(bool force_update = false); bool update_mine(bool force_update = false);
inline static std::unordered_map<std::uint32_t, std::string> m_active_profiles;
inline static std::vector<std::string> m_my_profiles; inline static std::vector<std::string> m_my_profiles;
inline static std::unordered_map<std::string, HandlingProfile> m_handling_profiles; inline static std::unordered_map<std::string, HandlingProfile> m_handling_profiles;