Added filter vehicle by class feature. (#336)

This commit is contained in:
aa15032261
2022-07-15 20:54:23 +08:00
committed by GitHub
parent 320cdbec34
commit 4999c25e93
4 changed files with 104 additions and 10 deletions

View File

@ -14,6 +14,7 @@ namespace big
this->name = "";
this->display_name = "";
this->display_manufacturer = "";
this->clazz = "";
this->hash = 0;
}
@ -22,6 +23,7 @@ namespace big
this->name = item_json["Name"];
this->display_name = item_json["Name"];
this->display_manufacturer = "";
this->clazz = "";
this->hash = item_json["Hash"];
if (!item_json["DisplayName"].is_null())
@ -37,6 +39,16 @@ namespace big
{
this->display_manufacturer = item_json["Manufacturer"];
}
if (!item_json["Class"].is_null())
{
this->clazz = item_json["Class"];
if (this->clazz == "COMPACTS")
{
this->clazz = "COMPACT";
}
}
}
vehicle_preview_service::vehicle_preview_service() :
@ -94,6 +106,11 @@ namespace big
}
}
std::vector<std::string>& vehicle_preview_service::get_vehicle_class_arr()
{
return m_vehicle_class_arr;
}
std::vector<vehicle_preview_item>& vehicle_preview_service::get_vehicle_preview_item_arr()
{
return m_vehicle_preview_item_arr;
@ -189,6 +206,7 @@ namespace big
LOG(WARNING) << "Failed to load vehicles.json:\n" << ex.what();
}
for (auto& item_json : all_vehicles)
{
if (
@ -201,8 +219,18 @@ namespace big
continue;
}
auto item = vehicle_preview_item(item_json);
m_hash_idx_map[item_json["Hash"]] = (int)m_vehicle_preview_item_arr.size();
m_vehicle_preview_item_arr.push_back(vehicle_preview_item(item_json));
m_vehicle_preview_item_arr.push_back(item);
if (std::find(m_vehicle_class_arr.begin(), m_vehicle_class_arr.end(), item.clazz) == m_vehicle_class_arr.end())
{
m_vehicle_class_arr.push_back(item.clazz);
}
std::sort(m_vehicle_class_arr.begin(), m_vehicle_class_arr.end());
}
}
}

View File

@ -12,6 +12,7 @@ namespace big
std::string name;
std::string display_name;
std::string display_manufacturer;
std::string clazz;
Hash hash;
};
@ -24,6 +25,7 @@ namespace big
std::mutex m_mutex;
std::map<Hash, int> m_hash_idx_map;
std::vector<std::string> m_vehicle_class_arr;
std::vector<vehicle_preview_item> m_vehicle_preview_item_arr;
const vehicle_preview_item empty_item = vehicle_preview_item();
@ -37,6 +39,7 @@ namespace big
~vehicle_preview_service();
const vehicle_preview_item& find_vehicle_item_by_hash(Hash hash);
std::vector<std::string>& get_vehicle_class_arr();
std::vector<vehicle_preview_item>& get_vehicle_preview_item_arr();
void set_preview_vehicle(const vehicle_preview_item& item);