mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
parent
33719696d8
commit
835bd1fbeb
@ -121,10 +121,12 @@ static void setButton(ButtonInfo &button, const JsonNode &g)
|
||||
button.playerColoured = g["playerColoured"].Float();
|
||||
button.defName = g["graphic"].String();
|
||||
|
||||
const JsonVector &defs_vec = g["additionalDefs"].Vector();
|
||||
if (!g["additionalDefs"].isNull()) {
|
||||
const JsonVector &defs_vec = g["additionalDefs"].Vector();
|
||||
|
||||
BOOST_FOREACH(const JsonNode &def, defs_vec) {
|
||||
button.additionalDefs.push_back(def.String());
|
||||
BOOST_FOREACH(const JsonNode &def, defs_vec) {
|
||||
button.additionalDefs.push_back(def.String());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -479,6 +479,7 @@ 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();
|
||||
@ -494,11 +495,20 @@ void CCreatureHandler::loadCreatures()
|
||||
c->faction = creature["faction"].Float();
|
||||
c->animDefName = creature["defname"].String();
|
||||
|
||||
c->upgrades.insert(creature["upgrade"].Float());
|
||||
idToProjectile[creatureID] = creature["projectile_defname"].String();
|
||||
idToProjectileSpin[creatureID] = creature["projectile_spin"].Bool();
|
||||
value = &creature["upgrade"];
|
||||
if (!value->isNull())
|
||||
c->upgrades.insert(value->Float());
|
||||
|
||||
if (creature["turret_shooter"].Bool(false))
|
||||
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())
|
||||
factionToTurretCreature[c->faction] = creatureID;
|
||||
}
|
||||
|
||||
|
@ -290,24 +290,29 @@ void CHeroHandler::loadHeroes()
|
||||
int hid = hero["id"].Float();
|
||||
const JsonNode *value;
|
||||
|
||||
//sex: 0=male, 1=female
|
||||
heroes[hid]->sex = !hero["female"].Bool(false);
|
||||
heroes[hid]->sex = hero["sex"].Float();
|
||||
|
||||
BOOST_FOREACH(const JsonNode &set, hero["skill_set"].Vector()) {
|
||||
heroes[hid]->secSkillsInit.push_back(std::make_pair(set["skill"].Float(), set["level"].Float(1)));
|
||||
heroes[hid]->secSkillsInit.push_back(std::make_pair(set["skill"].Float(), set["level"].Float()));
|
||||
}
|
||||
|
||||
heroes[hid]->startingSpell = hero["spell"].Float(-1);
|
||||
value = &hero["spell"];
|
||||
if (!value->isNull()) {
|
||||
heroes[hid]->startingSpell = value->Float();
|
||||
}
|
||||
|
||||
BOOST_FOREACH(const JsonNode &specialty, hero["specialties"].Vector()) {
|
||||
SSpecialtyInfo dummy;
|
||||
value = &hero["specialties"];
|
||||
if (!value->isNull()) {
|
||||
BOOST_FOREACH(const JsonNode &specialty, value->Vector()) {
|
||||
SSpecialtyInfo dummy;
|
||||
|
||||
dummy.type = specialty["type"].Float();
|
||||
dummy.val = specialty["val"].Float(0);
|
||||
dummy.subtype = specialty["subtype"].Float(0);
|
||||
dummy.additionalinfo = specialty["info"].Float(0);
|
||||
dummy.type = specialty["type"].Float();
|
||||
dummy.val = specialty["val"].Float();
|
||||
dummy.subtype = specialty["subtype"].Float();
|
||||
dummy.additionalinfo = specialty["info"].Float();
|
||||
|
||||
heroes[hid]->spec.push_back(dummy); //put a copy of dummy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ 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;
|
||||
@ -72,8 +73,13 @@ void CTownHandler::loadStructures()
|
||||
vinya->pos.y = node["y"].Float();
|
||||
vinya->pos.z = 0;
|
||||
|
||||
vinya->borderName = node["border"].String();
|
||||
vinya->areaName = node["area"].String();
|
||||
value = &node["border"];
|
||||
if (!value->isNull())
|
||||
vinya->borderName = value->String();
|
||||
|
||||
value = &node["area"];
|
||||
if (!value->isNull())
|
||||
vinya->areaName = value->String();
|
||||
|
||||
town[vinya->ID] = vinya;
|
||||
}
|
||||
|
@ -125,42 +125,32 @@ JsonMap & JsonNode::Struct()
|
||||
}
|
||||
|
||||
|
||||
const bool & JsonNode::Bool(const bool &value) const
|
||||
const bool & JsonNode::Bool() const
|
||||
{
|
||||
if (isNull())
|
||||
return value;
|
||||
assert(type == DATA_BOOL);
|
||||
return data.Bool;
|
||||
}
|
||||
|
||||
const float & JsonNode::Float(const float &value) const
|
||||
const float & JsonNode::Float() const
|
||||
{
|
||||
if (isNull())
|
||||
return value;
|
||||
assert(type == DATA_FLOAT);
|
||||
return data.Float;
|
||||
}
|
||||
|
||||
const std::string & JsonNode::String(const std::string &value) const
|
||||
const std::string & JsonNode::String() const
|
||||
{
|
||||
if (isNull())
|
||||
return value;
|
||||
assert(type == DATA_STRING);
|
||||
return *data.String;
|
||||
}
|
||||
|
||||
const JsonVector & JsonNode::Vector(const JsonVector &value) const
|
||||
const JsonVector & JsonNode::Vector() const
|
||||
{
|
||||
if (isNull())
|
||||
return value;
|
||||
assert(type == DATA_VECTOR);
|
||||
return *data.Vector;
|
||||
}
|
||||
|
||||
const JsonMap & JsonNode::Struct(const JsonMap &value) const
|
||||
const JsonMap & JsonNode::Struct() const
|
||||
{
|
||||
if (isNull())
|
||||
return value;
|
||||
assert(type == DATA_STRUCT);
|
||||
return *data.Struct;
|
||||
}
|
||||
|
@ -60,18 +60,19 @@ 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
|
||||
//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;
|
||||
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;
|
||||
|
||||
//formatted output of this node in JSON format
|
||||
void write(std::ostream &out, std::string prefix="") const;
|
||||
|
Loading…
Reference in New Issue
Block a user