commit c2374d88
Spells for a lot of items
Changed files
| M | data/saland/spells/base_spells.json before |
| M | extra/scripts/python/process_food_items.py before |
| M | src/saland/model/spells.cpp before |
| M | src/saland/model/spells.hpp before |
diff --git a/data/saland/spells/base_spells.json b/data/saland/spells/base_spells.json
index 002212f..997512e 100644
--- a/data/saland/spells/base_spells.json
+++ b/data/saland/spells/base_spells.json
@@ -1,5 +1,5 @@
{
- "items": [
+ "spells": [
{
"name": "spell_fireball",
"icon": "effect_fireball",
diff --git a/extra/scripts/python/process_food_items.py b/extra/scripts/python/process_food_items.py
index 5c2ead1..3abc8b9 100644
--- a/extra/scripts/python/process_food_items.py
+++ b/extra/scripts/python/process_food_items.py
@@ -61,7 +61,7 @@ def produce_spell_file():
item = {
"icon": name,
"name": "spell_spawn_item",
- "item_name": row["food_name"]
+ "item_name": "food_"+row["food_name"]
}
items_arrays.append(item)
items["spells"] = items_arrays
@@ -79,4 +79,4 @@ def main():
print(row)
-main()
\ No newline at end of file
+main()
diff --git a/src/saland/model/spells.cpp b/src/saland/model/spells.cpp
index 2341914..d04b57a 100644
--- a/src/saland/model/spells.cpp
+++ b/src/saland/model/spells.cpp
@@ -25,6 +25,7 @@ https://github.com/sago007/saland
#include "../../sago/SagoMisc.hpp"
#include "rapidjson/document.h"
#include <iostream>
+#include "fmt/core.h"
void SpellHolder::add_spell(const Spell& spell) {
spells.push_back(spell);
@@ -49,15 +50,15 @@ void SpellHolder::ReadSpellFile(const std::string& filename) {
}
for (auto& m : document.GetObject()) {
const std::string& itemHeader = m.name.GetString();
- if (itemHeader == "items") {
- const auto& items = m.value;
- if (!items.IsArray()) {
+ if (itemHeader == "spells") {
+ const auto& spells = m.value;
+ if (!spells.IsArray()) {
std::cerr << "Failure reading " << filename << ": 'items' must be an array" << "\n";
}
- for (const auto& item : items.GetArray()) {
- if (item.IsObject()) {
+ for (const auto& spell_data : spells.GetArray()) {
+ if (spell_data.IsObject()) {
Spell spell = blankSpell;
- for (const auto& member : item.GetObject()) {
+ for (const auto& member : spell_data.GetObject()) {
if (member.name == "name") {
spell.name = member.value.GetString();
}
@@ -100,7 +101,13 @@ void SpellHolder::init() {
clearTileSpell.icon = "icon_trash_can";
clearTileSpell.name = "spell_clear_block";
clearTileSpell.type = SpellCursorType::tile;
- ReadSpellFile("saland/spells/base_spells.json");
+ const char* spellDir = "saland/spells/";
+ std::vector<std::string> file_list = sago::GetFileList(spellDir);
+ for(const std::string& file : file_list) {
+ std::string filename = fmt::format("{}{}", spellDir, file);
+ printf("Spells: file: %s\n",filename.c_str());
+ ReadSpellFile(filename);
+ }
}
size_t SpellHolder::get_spell_count() const {
@@ -124,4 +131,4 @@ const Spell& SpellHolder::get_spell_by_name(const std::string& spell_name) const
const Spell& SpellHolder::get_spell_clear_tile() const {
return clearTileSpell;
-}
\ No newline at end of file
+}
diff --git a/src/saland/model/spells.hpp b/src/saland/model/spells.hpp
index 2764525..c112d2b 100644
--- a/src/saland/model/spells.hpp
+++ b/src/saland/model/spells.hpp
@@ -58,4 +58,4 @@ public:
void ReadSpellFile(const std::string& filename);
};
-#endif //MODEL_SPELLS_HPP
\ No newline at end of file
+#endif //MODEL_SPELLS_HPP