summaryrefslogtreecommitdiff
path: root/universe/src
diff options
context:
space:
mode:
Diffstat (limited to 'universe/src')
-rw-r--r--universe/src/JsonRepository.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/universe/src/JsonRepository.cpp b/universe/src/JsonRepository.cpp
index 0100eb6..5d15646 100644
--- a/universe/src/JsonRepository.cpp
+++ b/universe/src/JsonRepository.cpp
@@ -22,6 +22,15 @@ namespace universe
{
+template <typename Type>
+void
+maybe_to(const json& item, const char* member, Type& output)
+{
+ if (item.contains(member))
+ item.at(member).get_to(output);
+}
+
+
void
from_json(const json& item, ShipType& ship)
{
@@ -30,6 +39,9 @@ from_json(const json& item, ShipType& ship)
item.at("base_armour_points").get_to(ship.base_armour_points);
item.at("base_shield_points").get_to(ship.base_shield_points);
item.at("max_speed").get_to(ship.max_speed);
+ maybe_to(item, "base_structure_resists", ship.base_structure_resists);
+ maybe_to(item, "base_armour_resists", ship.base_armour_resists);
+ maybe_to(item, "base_shield_resists", ship.base_shield_resists);
}
@@ -37,20 +49,13 @@ void
from_json(const json& item, TurretType& turret)
{
item.at("name").get_to(turret.name);
- if (item.contains("base_damage"))
- item.at("base_damage").get_to(turret.base_damage);
- if (item.contains("rounds"))
- item.at("rounds").get_to(turret.rounds);
- if (item.contains("rate_of_fire"))
- item.at("rate_of_fire").get_to(turret.rate_of_fire);
- if (item.contains("reload"))
- item.at("reload").get_to(turret.reload);
- if (item.contains("optimal_range"))
- item.at("optimal_range").get_to(turret.optimal_range);
- if (item.contains("falloff_modifier"))
- item.at("falloff_modifier").get_to(turret.falloff_modifier);
- if (item.contains("falloff_intensity"))
- item.at("falloff_intensity").get_to(turret.falloff_intensity);
+ maybe_to(item, "base_damage", turret.base_damage);
+ maybe_to(item, "rounds", turret.rounds);
+ maybe_to(item, "rate_of_fire", turret.rate_of_fire);
+ maybe_to(item, "reload", turret.reload);
+ maybe_to(item, "optimal_range", turret.optimal_range);
+ maybe_to(item, "falloff_modifier", turret.falloff_modifier);
+ maybe_to(item, "falloff_intensity", turret.falloff_intensity);
}