From 62a281a66526b33bca36f13cde23ff16158bacb7 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Thu, 13 Dec 2012 14:27:33 +0000 Subject: [PATCH] Complete parsing for new Artifacts. iconIndex needs to be handled. Otherwise, they are ready for test. --- lib/CArtHandler.cpp | 22 +++++++++++++++------- lib/CArtHandler.h | 6 +++++- lib/CModHandler.cpp | 1 + lib/HeroBonus.h | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index 645d1710c..d8a4d2a38 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -215,6 +215,14 @@ std::string CArtifact::nodeName() const // // //boost::algorithm::replace_first(description, "[spell name]", VLC->spellh->spells[spellid].name); // } +void CArtifact::addNewBonus(Bonus *b) +{ + b->source = Bonus::ARTIFACT; + b->duration = Bonus::PERMANENT; + b->description = name; + CBonusSystemNode::addNewBonus(b); +} + void CArtifact::setName (std::string desc) { name = desc; @@ -462,7 +470,12 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node) art->setDescription (text["description"].String()); art->setName (text["event"].String()); - art->image = node["image"].String(); + const JsonNode & graphics = graphics["text"]; + art->iconIndex = graphics["iconIndex"].Float(); + art->image = graphics["image"].String(); + value = &graphics["large"]; + if (!value->isNull()) + art->large = value->String(); art->price = node["value"].Float(); @@ -504,8 +517,7 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node) BOOST_FOREACH (const JsonNode &bonus, node["bonuses"].Vector()) { auto b = JsonUtils::parseBonus(bonus); - b->source = Bonus::ARTIFACT; - b->duration = Bonus::PERMANENT; + //TODO: bonus->sid = art->id; art->addNewBonus(b); } @@ -715,11 +727,7 @@ void CArtHandler::addBonuses() BOOST_FOREACH (auto b, artifact["bonuses"].Vector()) { auto bonus = JsonUtils::parseBonus (b); - //common properties - bonus->source = Bonus::ARTIFACT; bonus->sid = ga->id; - bonus->duration = Bonus::PERMANENT; - bonus->description = ga->Name(); ga->addNewBonus (bonus); } if(artifact["type"].String() == "Creature") diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 4be7232e3..ba25d06e5 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -76,6 +76,8 @@ public: enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes std::string image; + std::string large; // big image for cutom artifacts, used in drag & drop + si32 iconIndex; //TODO: handle automatically const std::string &Name() const; //getter const std::string &Description() const; //getter @@ -87,6 +89,7 @@ public: int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other std::string nodeName() const OVERRIDE; + void addNewBonus(Bonus *b) OVERRIDE; virtual void levelUpArtifact (CArtifactInstance * art){}; @@ -100,7 +103,8 @@ public: template void serialize(Handler &h, const int version) { h & static_cast(*this); - h & name & description & eventText & image & price & possibleSlots & constituents & constituentOf & aClass & id; + h & name & description & eventText & image & large & iconIndex & + price & possibleSlots & constituents & constituentOf & aClass & id; } CArtifact(); diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 4100d03de..b25aae01b 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -141,6 +141,7 @@ void CModHandler::loadActiveMods() VLC->townh->load(JsonUtils::assembleFromFiles(config ["factions"].convertTo >())); VLC->creh->load( JsonUtils::assembleFromFiles(config["creatures"].convertTo >())); + VLC->arth->load( JsonUtils::assembleFromFiles(config["artifacts"].convertTo >())); } VLC->creh->buildBonusTreeForTiers(); //do that after all new creatures are loaded diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 75fb588e0..29a21f839 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -601,7 +601,7 @@ public: void attachTo(CBonusSystemNode *parent); void detachFrom(CBonusSystemNode *parent); void detachFromAll(); - void addNewBonus(Bonus *b); //b will be deleted with destruction of node + virtual void addNewBonus(Bonus *b); //b will be deleted with destruction of node void accumulateBonus(Bonus &b); //add value of bonus with same type/subtype or create new void newChildAttached(CBonusSystemNode *child);