From a454169f8efae6511dfe737c38021e40554f87ea Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Nov 2023 15:46:24 -0500 Subject: Can add spells outside of spells/ dir to creatures --- src/spellcasting.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src') 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 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("spells", j["spells"]); + std::vector names; + for(auto& spell : j["spells"]) { + if(spell.is_string()) { + names.push_back(spell); + } else { + sl.spells.push_back(utils::loadDFromJson(spell)); + } + } + for(auto& spell : utils::instantiateNames("spells", names)) { + sl.spells.push_back(spell); + } + } shared_ptr SlotLevel::create(const json& data) { -- cgit v1.2.3