diff options
author | Your Name <you@example.com> | 2023-11-29 15:46:24 -0500 |
---|---|---|
committer | Your Name <you@example.com> | 2023-11-29 15:46:24 -0500 |
commit | a454169f8efae6511dfe737c38021e40554f87ea (patch) | |
tree | 3e7c9bb2216968069acd3e482615d78a1c53bf95 /src | |
parent | ae68e84557a7e56fd7210c1009aa1313dcc78adf (diff) | |
download | dmtool-a454169f8efae6511dfe737c38021e40554f87ea.tar.gz dmtool-a454169f8efae6511dfe737c38021e40554f87ea.tar.bz2 dmtool-a454169f8efae6511dfe737c38021e40554f87ea.zip |
Can add spells outside of spells/ dir to creatures
Diffstat (limited to 'src')
-rw-r--r-- | src/spellcasting.cc | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/spellcasting.cc b/src/spellcasting.cc index d969c5e..e1c02b8 100644 --- a/src/spellcasting.cc +++ b/src/spellcasting.cc @@ -10,16 +10,23 @@ using namespace std; namespace entry { // Slot level serialization void to_json(nlohmann::json& j, const SlotLevel& sl) { - std::vector<std::string> s; - for(auto spell : sl.spells) { - s.push_back(spell->getName()); - } - j = {{"slots", sl.numSlots}, {"spells", s}}; + j = {{"slots", sl.numSlots}, {"spells", sl.spells}}; } void from_json(const nlohmann::json& j, SlotLevel& sl) { j.at("slots").get_to(sl.numSlots); - sl.spells = utils::instantiateNames<Spell>("spells", j["spells"]); + std::vector<std::string> names; + for(auto& spell : j["spells"]) { + if(spell.is_string()) { + names.push_back(spell); + } else { + sl.spells.push_back(utils::loadDFromJson<Spell, Spell>(spell)); + } + } + for(auto& spell : utils::instantiateNames<Spell>("spells", names)) { + sl.spells.push_back(spell); + } + } shared_ptr<SlotLevel> SlotLevel::create(const json& data) { |