git repos / saland

commit 5d3d5c8f

Poul Sander · 2026-01-17 20:33
5d3d5c8f2c3d3939513da3a8cb2107aa862f0c14 patch · browse files
parent 8269a20a7e86e43cd00189498544a98af38a9377

Do now spawn the item if it doees not exist

Changed files

M src/saland/Game.cpp before
M src/saland/GameItems.cpp before
M src/saland/GameItems.hpp before
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index b3ecab9..5ba50d7 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -889,8 +889,13 @@ void Game::Update() {
globalData.pendingSpawnLake = false;
}
if (!globalData.pendingSpawnItem.empty()) {
- ItemDef itemDef = getItem(globalData.pendingSpawnItem);
- data->gameRegion.SpawnItem(itemDef, static_cast<float>(data->world_mouse_x), static_cast<float>(data->world_mouse_y));
+ if (itemExists(globalData.pendingSpawnItem)) {
+ ItemDef itemDef = getItem(globalData.pendingSpawnItem);
+ data->gameRegion.SpawnItem(itemDef, static_cast<float>(data->world_mouse_x), static_cast<float>(data->world_mouse_y));
+ }
+ else {
+ std::cerr << "Item '" << globalData.pendingSpawnItem << "' does not exist\n";
+ }
globalData.pendingSpawnItem.clear();
}
if (data->consoleActive && data->console && !data->console->IsActive()) {
diff --git a/src/saland/GameItems.cpp b/src/saland/GameItems.cpp index 656a7d3..015781d 100644 --- a/src/saland/GameItems.cpp +++ b/src/saland/GameItems.cpp
@@ -108,3 +108,10 @@ const ItemDef& getItem(const std::string& itemName) {
}
return all_items[itemName];
}
+
+bool itemExists(const std::string& itemName) {
+ if (all_items.size() == 0) {
+ initItems();
+ }
+ return all_items.find(itemName) != all_items.end();
+}
diff --git a/src/saland/GameItems.hpp b/src/saland/GameItems.hpp index a1d87cb..8e5dd88 100644 --- a/src/saland/GameItems.hpp +++ b/src/saland/GameItems.hpp
@@ -38,5 +38,6 @@ struct ItemDef {
};
const ItemDef& getItem(const std::string& itemName);
+bool itemExists(const std::string& itemName);
#endif /* GAMEITEMS_HPP */
\ No newline at end of file