From e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 9 May 2021 19:01:59 -0400 Subject: Code refactoring --- src/creature.cc | 44 ++++---------------------------------------- 1 file changed, 4 insertions(+), 40 deletions(-) (limited to 'src/creature.cc') diff --git a/src/creature.cc b/src/creature.cc index d4cf8c4..9366bac 100644 --- a/src/creature.cc +++ b/src/creature.cc @@ -1,5 +1,4 @@ #include "creature.h" -#include "json.hpp" #include "dice.h" #include "rules.h" #include "feature.h" @@ -12,21 +11,13 @@ #include #include -typedef nlohmann::json json; using namespace std; namespace creature { - Creature::Creature(const json& data, const json& base) - : Entry(base), inventory(data["inventory"]), stats(data["stats"]), skills(data["skills"]), prof(data["prof"]), size(data["size"]), alignment(data["alignment"]), hit_die_count(data["hit_die_count"]), hit_die_sides(data["hit_die_sides"]), speed(data["speed"]), saves(data["saves"]), langs(data["langs"]), cr(data["cr"]), observant(data["observant"]), natural_armor(data["natural_armor"]), d_immunities(data["d_immunities"]), d_resistances(data["d_resistances"]), d_vulnerabilities(data["d_vulnerabilities"]), c_immunities(data["c_immunities"]), features(data["features"]) - { - // Initialize names and hp - if(((map) data).contains("givenName")) { - givenName = data["givenName"]; - hpMax = data["hpMax"]; - hp = data["hp"]; - } else { - givenName = "Jerry"; //TODO: Autogenerate - hpMax = this->getBonus(rules::Ability::Con()) * hit_die_count; + void Creature::init() { + if(hpMax == -1) { + // Initialize hp + hpMax = getBonus(rules::Ability::Con()) * hit_die_count; for(int i = 0; i < hit_die_count; i++) { hpMax += dice::roll(hit_die_sides); } @@ -34,33 +25,6 @@ namespace creature { } } - nlohmann::json Creature::toJson() const { - nlohmann::json data = Entry::toJson(); - data["size"] = size; - data["alignment"] = alignment; - data["hit_die_count"] = hit_die_count; - data["hit_die_sides"] = hit_die_sides; - data["speed"] = speed; - data["stats"] = stats; - data["skills"] = skills; - data["saves"] = saves; - data["langs"] = langs; - data["cr"] = cr; - data["observant"] = observant; - data["prof"] = prof; - data["natural_armor"] = natural_armor; - data["d_immunities"] = d_immunities; - data["d_resistances"] = d_resistances; - data["d_vulnerabilities"] = d_vulnerabilities; - data["c_immunities"] = c_immunities; - data["givenName"] = givenName; - data["hpMax"] = hpMax; - data["hp"] = hp; - data["inventory"] = inventory; - data["features"] = features; - return data; - } - // True if type without matching qualifiers is in subdata bool conditionApplies(const string& type, const vector& qualifiers, const vector subdata) { bool applies = false; -- cgit v1.2.3