Skip to content
Snippets Groups Projects
Commit f9eb6bf1 authored by David Bergström's avatar David Bergström
Browse files

Handle situtation where techtree.json is missing

parent 34020a41
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,13 @@ void TechTree::onStart()
solution at the time. Hopefully the JSON-files are still up to date. */
TechTreeImproved tree;
tree.LoadData();
bool success = tree.LoadData();
// If the file was not successfully open/parsed, don't replace the unitTypeData.
if (!success)
{
return;
}
for (std::pair<const UnitType, TypeData> & pair : m_unitTypeData)
{
......
......@@ -112,13 +112,20 @@ void TechTreeImproved::parse_unit(json::iterator it)
producer_to_data[producer_id] = build_descriptions;
}
void TechTreeImproved::LoadData() {
// TODO: Do not hardcode this. Use the latest json available.
// TODO: Check if file exists
bool TechTreeImproved::LoadData() {
std::ifstream i("techtree.json");
if (!i.good())
{
std::wcerr << "File techtree.json cannot be found, information regarding addons and required buildings will not be up to date. Please put techtree.json in working directory." << std::endl;
return false;
}
// Parse the file's content
json j;
i >> j;
// Time to parse content of the JSON file
for (auto & race : j)
{
for (json::iterator it = race.begin(); it != race.end(); ++it)
......@@ -126,6 +133,7 @@ void TechTreeImproved::LoadData() {
parse_unit(it);
}
}
return true;
}
const std::vector<BuildDescription> & TechTreeImproved::HowToBuild(sc2::UnitTypeID unit) const
......
......@@ -31,7 +31,7 @@ class TechTreeImproved
void parse_unit(nlohmann::json::iterator it);
public:
TechTreeImproved();
void LoadData();
bool LoadData();
// Given a unit, how can we build it?
const std::vector<BuildDescription> & HowToBuild(sc2::UnitTypeID unit) const;
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment