diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 15:27:59 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 15:27:59 +0100 |
commit | a3c1ba7b49e4c5901d7c9dd917049744ad20fc96 (patch) | |
tree | 66750c2c740aca751f47c2896985d2b79f6f7806 /frontend/GameData.cpp | |
parent | 6dfa3fb34fb0a2ea028fd46e77296e26b092fb99 (diff) |
enemy loading kinda works
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r-- | frontend/GameData.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp index edcd854..739ad1e 100644 --- a/frontend/GameData.cpp +++ b/frontend/GameData.cpp @@ -21,9 +21,31 @@ GameData::GameData() { } Enemy * GameData::create_enemy(const string & name) { - Enemy * enemy = EnemyFactory::create_enemy(); - // TODO: fill fields - return enemy; + static DBStatement query = this->db->prepare(R"( + select + naam, + omschrijving, + minimumobjecten, + maximumobjecten, + levenspunten, + aanvalskans, + minimumschade, + maximumschade + from Vijanden + where lower(naam) = lower(?) + limit 1 + )"); + query.reset() + .bind(name) + ; + + try { + auto row = query.row(); + return EnemyFactory::create_enemy(row.col<const char *>(0), row.col<const char *>(1)); + // TODO: set all other properties + } catch (...) { + return EnemyFactory::create_enemy(name.c_str()); + } } static const unordered_map<string, ObjectType> type_map = { @@ -85,7 +107,7 @@ Location * GameData::create_location(const string & name) { auto row = query.row(); return LocationFactory::create_location(row.col<const char *>(0), row.col<const char *>(1)); } catch (...) { - return LocationFactory::create_location(name.c_str(), ""); + return LocationFactory::create_location(name.c_str()); } } |