1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- added default values to JsonNode

- small cleanup to heroes.json
This commit is contained in:
Ivan Savenko 2011-08-27 21:17:45 +00:00
parent f3b6ecf9a3
commit 33719696d8
7 changed files with 487 additions and 501 deletions

View File

@ -121,13 +121,11 @@ static void setButton(ButtonInfo &button, const JsonNode &g)
button.playerColoured = g["playerColoured"].Float();
button.defName = g["graphic"].String();
if (!g["additionalDefs"].isNull()) {
const JsonVector &defs_vec = g["additionalDefs"].Vector();
BOOST_FOREACH(const JsonNode &def, defs_vec) {
button.additionalDefs.push_back(def.String());
}
}
}
static void setGem(AdventureMapConfig &ac, const int gem, const JsonNode &g)

File diff suppressed because it is too large Load Diff

View File

@ -479,7 +479,6 @@ void CCreatureHandler::loadCreatures()
for (JsonVector::const_iterator it = creatures_vec.begin(); it!=creatures_vec.end(); ++it) {
const JsonNode &creature = *it;
int creatureID = creature["id"].Float();
const JsonNode *value;
/* A creature can have several names. */
const JsonVector &names_vec = creature["name"].Vector();
@ -495,20 +494,11 @@ void CCreatureHandler::loadCreatures()
c->faction = creature["faction"].Float();
c->animDefName = creature["defname"].String();
value = &creature["upgrade"];
if (!value->isNull())
c->upgrades.insert(value->Float());
c->upgrades.insert(creature["upgrade"].Float());
idToProjectile[creatureID] = creature["projectile_defname"].String();
idToProjectileSpin[creatureID] = creature["projectile_spin"].Bool();
value = &creature["projectile_defname"];
if (!value->isNull()) {
idToProjectile[creatureID] = value->String();
value = &creature["projectile_spin"];
idToProjectileSpin[creatureID] = value->Bool();
}
value = &creature["turret_shooter"];
if (!value->isNull() && value->Bool())
if (creature["turret_shooter"].Bool(false))
factionToTurretCreature[c->faction] = creatureID;
}

View File

@ -290,31 +290,26 @@ void CHeroHandler::loadHeroes()
int hid = hero["id"].Float();
const JsonNode *value;
heroes[hid]->sex = hero["sex"].Float();
//sex: 0=male, 1=female
heroes[hid]->sex = !hero["female"].Bool(false);
BOOST_FOREACH(const JsonNode &set, hero["skill_set"].Vector()) {
heroes[hid]->secSkillsInit.push_back(std::make_pair(set["skill"].Float(), set["level"].Float()));
heroes[hid]->secSkillsInit.push_back(std::make_pair(set["skill"].Float(), set["level"].Float(1)));
}
value = &hero["spell"];
if (!value->isNull()) {
heroes[hid]->startingSpell = value->Float();
}
heroes[hid]->startingSpell = hero["spell"].Float(-1);
value = &hero["specialties"];
if (!value->isNull()) {
BOOST_FOREACH(const JsonNode &specialty, value->Vector()) {
BOOST_FOREACH(const JsonNode &specialty, hero["specialties"].Vector()) {
SSpecialtyInfo dummy;
dummy.type = specialty["type"].Float();
dummy.val = specialty["val"].Float();
dummy.subtype = specialty["subtype"].Float();
dummy.additionalinfo = specialty["info"].Float();
dummy.val = specialty["val"].Float(0);
dummy.subtype = specialty["subtype"].Float(0);
dummy.additionalinfo = specialty["info"].Float(0);
heroes[hid]->spec.push_back(dummy); //put a copy of dummy
}
}
}
loadHeroClasses();
initHeroClasses();

View File

@ -62,7 +62,6 @@ void CTownHandler::loadStructures()
// Read buildings coordinates for that city
BOOST_FOREACH(const JsonNode &node, town_node["defnames"].Vector()) {
Structure *vinya = new Structure;
const JsonNode *value;
vinya->group = -1;
vinya->townID = townID;
@ -73,13 +72,8 @@ void CTownHandler::loadStructures()
vinya->pos.y = node["y"].Float();
vinya->pos.z = 0;
value = &node["border"];
if (!value->isNull())
vinya->borderName = value->String();
value = &node["area"];
if (!value->isNull())
vinya->areaName = value->String();
vinya->borderName = node["border"].String();
vinya->areaName = node["area"].String();
town[vinya->ID] = vinya;
}

View File

@ -125,32 +125,42 @@ JsonMap & JsonNode::Struct()
}
const bool & JsonNode::Bool() const
const bool & JsonNode::Bool(const bool &value) const
{
if (isNull())
return value;
assert(type == DATA_BOOL);
return data.Bool;
}
const float & JsonNode::Float() const
const float & JsonNode::Float(const float &value) const
{
if (isNull())
return value;
assert(type == DATA_FLOAT);
return data.Float;
}
const std::string & JsonNode::String() const
const std::string & JsonNode::String(const std::string &value) const
{
if (isNull())
return value;
assert(type == DATA_STRING);
return *data.String;
}
const JsonVector & JsonNode::Vector() const
const JsonVector & JsonNode::Vector(const JsonVector &value) const
{
if (isNull())
return value;
assert(type == DATA_VECTOR);
return *data.Vector;
}
const JsonMap & JsonNode::Struct() const
const JsonMap & JsonNode::Struct(const JsonMap &value) const
{
if (isNull())
return value;
assert(type == DATA_STRUCT);
return *data.Struct;
}

View File

@ -60,19 +60,18 @@ public:
//non-const accessors, node will change type on type mismatch
bool & Bool();
int & Int();
float & Float();
std::string & String();
JsonVector & Vector();
JsonMap & Struct();
//const accessors, will cause assertion failure on type mismatch
const bool & Bool() const;
const int & Int() const;
const float & Float() const;
const std::string & String() const;
const JsonVector & Vector() const;
const JsonMap & Struct() const;
//if node is null then default value will be returned instead
const bool & Bool(const bool &value = false) const;
const float & Float(const float &value = 0) const;
const std::string & String(const std::string &value = "") const;
const JsonVector & Vector(const JsonVector &value = JsonVector()) const;
const JsonMap & Struct(const JsonMap &value = JsonMap()) const;
//formatted output of this node in JSON format
void write(std::ostream &out, std::string prefix="") const;