aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/spellcasting.cc19
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) {