Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarTechDatabase.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/game/StarTechDatabase.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/game/StarTechDatabase.cpp')
-rw-r--r--source/game/StarTechDatabase.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/game/StarTechDatabase.cpp b/source/game/StarTechDatabase.cpp
new file mode 100644
index 0000000..ae8defa
--- /dev/null
+++ b/source/game/StarTechDatabase.cpp
@@ -0,0 +1,62 @@
+#include "StarTechDatabase.hpp"
+#include "StarJsonExtra.hpp"
+#include "StarRoot.hpp"
+#include "StarAssets.hpp"
+
+namespace Star {
+
+EnumMap<TechType> const TechTypeNames{
+ {TechType::Head, "Head"},
+ {TechType::Body, "Body"},
+ {TechType::Legs, "Legs"}
+};
+
+TechDatabase::TechDatabase() {
+ auto assets = Root::singleton().assets();
+ auto files = assets->scanExtension("tech");
+ assets->queueJsons(files);
+ for (auto file : files) {
+ auto tech = parseTech(assets->json(file), file);
+
+ if (m_tech.contains(tech.name))
+ throw TechDatabaseException::format("Duplicate tech named '%s', config file '%s'", tech.name, file);
+ m_tech[tech.name] = tech;
+ }
+}
+
+bool TechDatabase::contains(String const& techName) const {
+ return m_tech.contains(techName);
+}
+
+TechConfig TechDatabase::tech(String const& techName) const {
+ if (auto p = m_tech.ptr(techName))
+ return *p;
+ throw TechDatabaseException::format("No such tech '%s'", techName);
+}
+
+TechConfig TechDatabase::parseTech(Json const& config, String const& path) const {
+ try {
+ auto assets = Root::singleton().assets();
+
+ TechConfig tech;
+ tech.name = config.getString("name");
+ tech.path = path;
+ tech.parameters = config;
+
+ tech.type = TechTypeNames.getLeft(config.getString("type"));
+
+ tech.scripts = jsonToStringList(config.get("scripts")).transformed(bind(AssetPath::relativeTo, path, _1));
+ tech.animationConfig = config.optString("animator").apply(bind(&AssetPath::relativeTo, path, _1));
+
+ tech.description = config.getString("description");
+ tech.shortDescription = config.getString("shortDescription");
+ tech.rarity = RarityNames.getLeft(config.getString("rarity"));
+ tech.icon = AssetPath::relativeTo(path, config.getString("icon"));
+
+ return tech;
+ } catch (std::exception const& e) {
+ throw TechDatabaseException(strf("Error reading tech config %s", path), e);
+ }
+}
+
+}