diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 12:24:43 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 12:24:43 +0100 |
commit | b1d5d7936bed17a684daff15b0294ef70754e8b9 (patch) | |
tree | 85ee543a15b42c7f854e4ce403bcff3dff5a3bd4 /frontend/GameData.cpp | |
parent | 991c9aac53fa3562b0fdc03d74b398052b207d2c (diff) |
more more WIP
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r-- | frontend/GameData.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp index b036695..c8f47e3 100644 --- a/frontend/GameData.cpp +++ b/frontend/GameData.cpp @@ -34,24 +34,47 @@ static const unordered_map<string, ObjectType> type_map = { }; Object * GameData::create_object(const string & name) { - DBStatement query = this->db->prepare("select type, omschrijving from Objecten where naam = ?"); - query.bind(name); + static DBStatement query = this->db->prepare(R"( + select + type, + omschrijving, + minimumwaarde, + maximumwaarde, + bescherming + from Objecten + where lower(naam) = lower(?) + limit 1 + )"); + query.reset() + .bind(name) + ; 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); + return ObjectFactory::create_object({ + .name = name.c_str(), + .description = row.col<const char *>(1), + .type = type_map.at(type), + .min_value = row.col<int>(2), + .max_value = row.col<int>(3), + .protection = row.col<int>(4), + }); } catch (...) { return ObjectFactory::create_object(name.c_str()); } } void GameData::leaderbord_add(const string & name, unsigned int gold) { - this->db->prepare("insert into Leaderboard (naam, goudstukken) values (?, ?)") + static DBStatement stmt = this->db->prepare(R"( + insert into Leaderboard (naam, goudstukken) + values (?, ?) + )"); + stmt.reset() .bind(name) .bind(gold) - .execute(); + ; + stmt.execute(); } |