aboutsummaryrefslogtreecommitdiff
path: root/frontend/GameData.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 02:45:56 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 02:45:56 +0100
commit991c9aac53fa3562b0fdc03d74b398052b207d2c (patch)
treedaf1d16ecac1de62093d9019e2b9b355f12d81f6 /frontend/GameData.cpp
parentb9e738502260b8f448289c9888203971c7749c76 (diff)
load objects kinda working, going to bed
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r--frontend/GameData.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp
index 0cf6a1d..b036695 100644
--- a/frontend/GameData.cpp
+++ b/frontend/GameData.cpp
@@ -1,4 +1,5 @@
#include <memory>
+#include <unordered_map>
#include "backend/Enemy.h"
#include "backend/EnemyFactory.h"
@@ -23,13 +24,28 @@ Enemy * GameData::create_enemy(const string & name) {
return enemy;
}
+static const unordered_map<string, ObjectType> type_map = {
+ { "teleportatiedrank", ObjectType::CONSUMABLE },
+ { "ervaringsdrank", ObjectType::CONSUMABLE },
+ { "levenselixer", ObjectType::CONSUMABLE },
+ { "wapenrusting", ObjectType::ARMOR },
+ { "wapen", ObjectType::WEAPON },
+ { "goudstukken", ObjectType::GOLD },
+};
+
Object * GameData::create_object(const string & name) {
- DBStatement query = this->db->prepare("select type from Objecten where naam = ?");
+ DBStatement query = this->db->prepare("select type, omschrijving from Objecten where naam = ?");
query.bind(name);
- // TODO: uhhhhhhhhh data ophalen
-
- Object * object = ObjectFactory::create_object();
- return object;
+
+ try {
+ auto row = query.row();
+ string type = row.col<const char *>(0);
+ const char * description = row.col<const char *>(1);
+ if (!type_map.contains(type)) throw std::exception();
+ return ObjectFactory::create_object(type_map.at(type), name.c_str(), description);
+ } catch (...) {
+ return ObjectFactory::create_object(name.c_str());
+ }
}
void GameData::leaderbord_add(const string & name, unsigned int gold) {