summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-12 23:11:18 +0100
committerAki <please@ignore.pl>2023-01-12 23:11:18 +0100
commitc583337927c3dff61d7a3cf19aa4fda96c4d0e96 (patch)
tree41b4697fd830b6ca0655e62c932c1ee61c5a214e
parente9187a92220a62337d83a18aa973a8e86d3014a4 (diff)
downloadkurator-c583337927c3dff61d7a3cf19aa4fda96c4d0e96.zip
kurator-c583337927c3dff61d7a3cf19aa4fda96c4d0e96.tar.gz
kurator-c583337927c3dff61d7a3cf19aa4fda96c4d0e96.tar.bz2
Added method to retrieve default/first item from repository
-rw-r--r--kurator/src/ScenarioEditor.cpp4
-rw-r--r--universe/include/kurator/universe/Repository.h2
-rw-r--r--universe/src/JsonRepository.cpp20
-rw-r--r--universe/src/JsonRepository.h2
4 files changed, 26 insertions, 2 deletions
diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp
index b79dc14..76f384e 100644
--- a/kurator/src/ScenarioEditor.cpp
+++ b/kurator/src/ScenarioEditor.cpp
@@ -105,7 +105,7 @@ groups_editor(std::shared_ptr<universe::Repository> repo, std::vector<Group>& gr
ImGui::PopID();
}
if (ImGui::Button("Add Group")) {
- groups.push_back(Group{{repo->ship_type("Anvil")}}); // access to default/first?
+ groups.push_back(Group{{repo->ship_type()}});
changed = true;
}
return changed;
@@ -145,7 +145,7 @@ loadout_editor(std::shared_ptr<universe::Repository> repo, campaign::Loadout& lo
ImGui::PopID();
}
if (ImGui::Button("Add Turret")) {
- loadout.turrets.push_back(repo->turret_type("ChargeLaser")); // access to default or first?
+ loadout.turrets.push_back(repo->turret_type());
changed = true;
}
ImGui::Unindent();
diff --git a/universe/include/kurator/universe/Repository.h b/universe/include/kurator/universe/Repository.h
index 3758421..e3f97a2 100644
--- a/universe/include/kurator/universe/Repository.h
+++ b/universe/include/kurator/universe/Repository.h
@@ -17,7 +17,9 @@ class Repository
{
public:
virtual ~Repository() = default;
+ virtual ShipType ship_type() const = 0;
virtual ShipType ship_type(const std::string& id) const = 0;
+ virtual TurretType turret_type() const = 0;
virtual TurretType turret_type(const std::string& id) const = 0;
virtual void for_ship_types(std::function<void(const ShipType&)> func) const = 0;
virtual void for_turret_types(std::function<void(const TurretType&)> func) const = 0;
diff --git a/universe/src/JsonRepository.cpp b/universe/src/JsonRepository.cpp
index e8c8ed3..0100eb6 100644
--- a/universe/src/JsonRepository.cpp
+++ b/universe/src/JsonRepository.cpp
@@ -82,6 +82,16 @@ JsonRepository::JsonRepository(const std::string& path)
ShipType
+JsonRepository::ship_type() const
+{
+ const auto it = ships.begin();
+ if (it == ships.end())
+ throw NotFound("any/default");
+ return it->second;
+}
+
+
+ShipType
JsonRepository::ship_type(const std::string& id) const
try {
return ships.at(id);
@@ -92,6 +102,16 @@ catch (const std::out_of_range&) {
TurretType
+JsonRepository::turret_type() const
+{
+ const auto it = turrets.begin();
+ if (it == turrets.end())
+ throw NotFound("any/default");
+ return it->second;
+}
+
+
+TurretType
JsonRepository::turret_type(const std::string& id) const
try {
return turrets.at(id);
diff --git a/universe/src/JsonRepository.h b/universe/src/JsonRepository.h
index ea6bf46..13df7e4 100644
--- a/universe/src/JsonRepository.h
+++ b/universe/src/JsonRepository.h
@@ -19,7 +19,9 @@ class JsonRepository : public Repository
{
public:
explicit JsonRepository(const std::string& path);
+ ShipType ship_type() const override;
ShipType ship_type(const std::string& id) const override;
+ TurretType turret_type() const override;
TurretType turret_type(const std::string& id) const override;
void for_ship_types(std::function<void(const ShipType&)> func) const;
void for_turret_types(std::function<void(const TurretType&)> func) const;