diff --git a/AI/VCAI/Goals/AdventureSpellCast.cpp b/AI/VCAI/Goals/AdventureSpellCast.cpp index d64c39c40..b0c49ff81 100644 --- a/AI/VCAI/Goals/AdventureSpellCast.cpp +++ b/AI/VCAI/Goals/AdventureSpellCast.cpp @@ -33,16 +33,16 @@ TSubgoal AdventureSpellCast::whatToDoToAchieve() auto spell = getSpell(); - logAi->trace("Decomposing adventure spell cast of %s for hero %s", spell->getName(), hero->getNameTranslated()); + logAi->trace("Decomposing adventure spell cast of %s for hero %s", spell->getNameTranslated(), hero->getNameTranslated()); if(!spell->isAdventure()) - throw cannotFulfillGoalException(spell->getName() + " is not an adventure spell."); + throw cannotFulfillGoalException(spell->getNameTranslated() + " is not an adventure spell."); if(!hero->canCastThisSpell(spell)) - throw cannotFulfillGoalException("Hero can not cast " + spell->getName()); + throw cannotFulfillGoalException("Hero can not cast " + spell->getNameTranslated()); if(hero->mana < hero->getSpellCost(spell)) - throw cannotFulfillGoalException("Hero has not enough mana to cast " + spell->getName()); + throw cannotFulfillGoalException("Hero has not enough mana to cast " + spell->getNameTranslated()); if(spellID == SpellID::TOWN_PORTAL && town && town->visitingHero) throw cannotFulfillGoalException("The town is already occupied by " + town->visitingHero->getNameTranslated()); @@ -75,10 +75,10 @@ void AdventureSpellCast::accept(VCAI * ai) std::string AdventureSpellCast::name() const { - return "AdventureSpellCast " + getSpell()->getName(); + return "AdventureSpellCast " + getSpell()->getNameTranslated(); } std::string AdventureSpellCast::completeMessage() const { - return "Spell cast successfully " + getSpell()->getName(); + return "Spell cast successfully " + getSpell()->getNameTranslated(); } diff --git a/client/ClientCommandManager.cpp b/client/ClientCommandManager.cpp index 3113b4342..1e8c9f30f 100644 --- a/client/ClientCommandManager.cpp +++ b/client/ClientCommandManager.cpp @@ -195,7 +195,7 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle { const JsonNode & object = nameAndObject.second; - std::string name = CModHandler::normalizeIdentifier(object.meta, CModHandler::scopeBuiltin(), nameAndObject.first); + std::string name = CModHandler::makeFullIdentifier(object.meta, contentName, nameAndObject.first); boost::algorithm::replace_all(name,":","_"); diff --git a/include/vcmi/Artifact.h b/include/vcmi/Artifact.h index fda53de1a..e675bb487 100644 --- a/include/vcmi/Artifact.h +++ b/include/vcmi/Artifact.h @@ -19,8 +19,8 @@ class CreatureID; class DLL_LINKAGE Artifact : public EntityWithBonuses { - using EntityWithBonuses::getName; public: + virtual bool isBig() const = 0; virtual bool isTradable() const = 0; virtual uint32_t getPrice() const = 0; @@ -28,11 +28,9 @@ public: virtual std::string getDescriptionTranslated() const = 0; virtual std::string getEventTranslated() const = 0; - virtual std::string getNameTranslated() const = 0; virtual std::string getDescriptionTextID() const = 0; virtual std::string getEventTextID() const = 0; - virtual std::string getNameTextID() const = 0; }; VCMI_LIB_NAMESPACE_END diff --git a/include/vcmi/Creature.h b/include/vcmi/Creature.h index 91996e39d..d29fa4480 100644 --- a/include/vcmi/Creature.h +++ b/include/vcmi/Creature.h @@ -19,10 +19,10 @@ class CreatureID; class DLL_LINKAGE Creature : public EntityWithBonuses { protected: - using EntityWithBonuses::getName; + // use getNamePlural/Singular instead + std::string getNameTranslated() const override = 0; + std::string getNameTextID() const override = 0; - virtual std::string getNameTranslated() const = 0; - virtual std::string getNameTextID() const = 0; public: virtual std::string getNamePluralTranslated() const = 0; virtual std::string getNameSingularTranslated() const = 0; diff --git a/include/vcmi/Entity.h b/include/vcmi/Entity.h index 280d852cf..ec64feaad 100644 --- a/include/vcmi/Entity.h +++ b/include/vcmi/Entity.h @@ -23,8 +23,9 @@ public: virtual int32_t getIndex() const = 0; virtual int32_t getIconIndex() const = 0; - virtual const std::string & getJsonKey() const = 0; - virtual const std::string & getName() const = 0; + virtual std::string getJsonKey() const = 0; + virtual std::string getNameTranslated() const = 0; + virtual std::string getNameTextID() const = 0; virtual void registerIcons(const IconRegistar & cb) const = 0; }; diff --git a/include/vcmi/Faction.h b/include/vcmi/Faction.h index 7833bc1f8..0939c154c 100644 --- a/include/vcmi/Faction.h +++ b/include/vcmi/Faction.h @@ -18,12 +18,9 @@ class FactionID; class DLL_LINKAGE Faction : public EntityT { - using EntityT::getName; public: virtual bool hasTown() const = 0; - virtual std::string getNameTranslated() const = 0; - virtual std::string getNameTextID() const = 0; }; VCMI_LIB_NAMESPACE_END diff --git a/include/vcmi/HeroClass.h b/include/vcmi/HeroClass.h index 3f6c47c53..3cbed38eb 100644 --- a/include/vcmi/HeroClass.h +++ b/include/vcmi/HeroClass.h @@ -18,12 +18,6 @@ class HeroClassID; class DLL_LINKAGE HeroClass : public EntityT { - using EntityT::getName; -public: - virtual std::string getNameTranslated() const = 0; - virtual std::string getNameTextID() const = 0; - - }; diff --git a/include/vcmi/HeroType.h b/include/vcmi/HeroType.h index 3df57b24b..94d0b2ccf 100644 --- a/include/vcmi/HeroType.h +++ b/include/vcmi/HeroType.h @@ -18,15 +18,11 @@ class HeroTypeID; class DLL_LINKAGE HeroType : public EntityT { - using EntityT::getName; -public: - virtual std::string getNameTranslated() const = 0; virtual std::string getBiographyTranslated() const = 0; virtual std::string getSpecialtyNameTranslated() const = 0; virtual std::string getSpecialtyDescriptionTranslated() const = 0; virtual std::string getSpecialtyTooltipTranslated() const = 0; - virtual std::string getNameTextID() const = 0; virtual std::string getBiographyTextID() const = 0; virtual std::string getSpecialtyNameTextID() const = 0; virtual std::string getSpecialtyDescriptionTextID() const = 0; diff --git a/include/vcmi/spells/Spell.h b/include/vcmi/spells/Spell.h index b260cf9a2..453187e00 100644 --- a/include/vcmi/spells/Spell.h +++ b/include/vcmi/spells/Spell.h @@ -23,8 +23,6 @@ class Caster; class DLL_LINKAGE Spell: public EntityT { - using EntityT::getName; - public: using SchoolCallback = std::function; diff --git a/lib/BattleFieldHandler.cpp b/lib/BattleFieldHandler.cpp index 18fc7664c..3e1c3f34d 100644 --- a/lib/BattleFieldHandler.cpp +++ b/lib/BattleFieldHandler.cpp @@ -16,48 +16,27 @@ VCMI_LIB_NAMESPACE_BEGIN BattleFieldInfo * BattleFieldHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + BattleFieldInfo * info = new BattleFieldInfo(BattleField(index), identifier); - if(json["graphics"].getType() == JsonNode::JsonType::DATA_STRING) + info->graphics = json["graphics"].String(); + info->icon = json["icon"].String(); + info->name = json["name"].String(); + for(auto b : json["bonuses"].Vector()) { - info->graphics = json["graphics"].String(); - } - - if(json["icon"].getType() == JsonNode::JsonType::DATA_STRING) - { - info->icon = json["icon"].String(); - } - - if(json["name"].getType() == JsonNode::JsonType::DATA_STRING) - { - info->name = json["name"].String(); - } - - if(json["bonuses"].getType() == JsonNode::JsonType::DATA_VECTOR) - { - for(auto b : json["bonuses"].Vector()) - { - auto bonus = JsonUtils::parseBonus(b); - - bonus->source = Bonus::TERRAIN_OVERLAY; - bonus->sid = info->getIndex(); - bonus->duration = Bonus::ONE_BATTLE; - - info->bonuses.push_back(bonus); - } - } - - if(json["isSpecial"].getType() == JsonNode::JsonType::DATA_BOOL) - { - info->isSpecial = json["isSpecial"].Bool(); - } - - if(json["impassableHexes"].getType() == JsonNode::JsonType::DATA_VECTOR) - { - for(auto node : json["impassableHexes"].Vector()) - info->impassableHexes.push_back(BattleHex(node.Integer())); + auto bonus = JsonUtils::parseBonus(b); + + bonus->source = Bonus::TERRAIN_OVERLAY; + bonus->sid = info->getIndex(); + bonus->duration = Bonus::ONE_BATTLE; + + info->bonuses.push_back(bonus); } + info->isSpecial = json["isSpecial"].Bool(); + for(auto node : json["impassableHexes"].Vector()) + info->impassableHexes.push_back(BattleHex(node.Integer())); return info; } @@ -89,14 +68,19 @@ int32_t BattleFieldInfo::getIconIndex() const return iconIndex; } -const std::string & BattleFieldInfo::getName() const +std::string BattleFieldInfo::getJsonKey() const +{ + return identifier; +} + +std::string BattleFieldInfo::getNameTextID() const { return name; } -const std::string & BattleFieldInfo::getJsonKey() const +std::string BattleFieldInfo::getNameTranslated() const { - return identifier; + return name; // TODO? } void BattleFieldInfo::registerIcons(const IconRegistar & cb) const diff --git a/lib/BattleFieldHandler.h b/lib/BattleFieldHandler.h index 3bfd2440e..34d60d8be 100644 --- a/lib/BattleFieldHandler.h +++ b/lib/BattleFieldHandler.h @@ -43,8 +43,9 @@ public: int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getName() const override; - const std::string & getJsonKey() const override; + std::string getJsonKey() const override; + std::string getNameTextID() const override; + std::string getNameTranslated() const override; void registerIcons(const IconRegistar & cb) const override; BattleField getId() const override; diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index 2ca86712f..0536a2c76 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -60,14 +60,9 @@ int32_t CArtifact::getIconIndex() const return iconIndex; } -const std::string & CArtifact::getName() const +std::string CArtifact::getJsonKey() const { - return identifier; -} - -const std::string & CArtifact::getJsonKey() const -{ - return identifier; + return modScope + ':' + identifier; } void CArtifact::registerIcons(const IconRegistar & cb) const @@ -103,17 +98,17 @@ std::string CArtifact::getNameTranslated() const std::string CArtifact::getDescriptionTextID() const { - return TextIdentifier("object", modScope, identifier, "description").get(); + return TextIdentifier("artifact", modScope, identifier, "description").get(); } std::string CArtifact::getEventTextID() const { - return TextIdentifier("object", modScope, identifier, "event").get(); + return TextIdentifier("artifact", modScope, identifier, "event").get(); } std::string CArtifact::getNameTextID() const { - return TextIdentifier("object", modScope, identifier, "name").get(); + return TextIdentifier("artifact", modScope, identifier, "name").get(); } uint32_t CArtifact::getPrice() const @@ -181,7 +176,7 @@ int CArtifact::getArtClassSerial() const std::string CArtifact::nodeName() const { - return "Artifact: " + getName(); + return "Artifact: " + getNameTranslated(); } void CArtifact::addNewBonus(const std::shared_ptr& b) @@ -301,7 +296,7 @@ std::vector CArtHandler::loadLegacyData(size_t dataSize) void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name), objects.size()); + auto object = loadFromJson(scope, data, name, objects.size()); object->iconIndex = object->getIndex() + 5; @@ -312,7 +307,7 @@ void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name), index); + auto object = loadFromJson(scope, data, name, index); object->iconIndex = object->getIndex(); @@ -330,6 +325,9 @@ const std::vector & CArtHandler::getTypeNames() const CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + assert(!scope.empty()); + CArtifact * art; if(!VLC->modh->modules.COMMANDERS || node["growing"].isNull()) @@ -690,11 +688,11 @@ void CArtHandler::erasePickedArt(ArtifactID id) artifactList->erase(itr); } else - logMod->warn("Problem: cannot erase artifact %s from list, it was not present", art->getName()); + logMod->warn("Problem: cannot erase artifact %s from list, it was not present", art->getNameTranslated()); } else - logMod->warn("Problem: cannot find list for artifact %s, strange class. (special?)", art->getName()); + logMod->warn("Problem: cannot find list for artifact %s, strange class. (special?)", art->getNameTranslated()); } boost::optional&> CArtHandler::listFromClass( CArtifact::EartClass artifactClass ) diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index 0ef065344..115702b38 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -50,8 +50,6 @@ class DLL_LINKAGE CArtifact : public Artifact, public CBonusSystemNode //contain std::string modScope; std::string identifier; - const std::string & getName() const override; - public: enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes @@ -68,7 +66,7 @@ public: int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getJsonKey() const override; + std::string getJsonKey() const override; void registerIcons(const IconRegistar & cb) const override; ArtifactID getId() const override; virtual const IBonusBearer * accessBonuses() const override; diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index b1712c213..590999476 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -33,14 +33,9 @@ int32_t CCreature::getIconIndex() const return iconIndex; } -const std::string & CCreature::getName() const +std::string CCreature::getJsonKey() const { - return identifier; -} - -const std::string & CCreature::getJsonKey() const -{ - return identifier; + return modScope + ':' + identifier;; } void CCreature::registerIcons(const IconRegistar & cb) const @@ -598,6 +593,9 @@ std::vector CCreatureHandler::loadLegacyData(size_t dataSize) CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + assert(!scope.empty()); + auto cre = new CCreature(); if(node["hasDoubleWeek"].Bool()) @@ -607,6 +605,7 @@ CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const Json cre->idNumber = CreatureID(index); cre->iconIndex = cre->getIndex() + 2; cre->identifier = identifier; + cre->modScope = scope; JsonDeserializer handler(nullptr, node); cre->serializeJson(handler); diff --git a/lib/CCreatureHandler.h b/lib/CCreatureHandler.h index ae96b590e..01b0d6693 100644 --- a/lib/CCreatureHandler.h +++ b/lib/CCreatureHandler.h @@ -37,7 +37,6 @@ class DLL_LINKAGE CCreature : public Creature, public CBonusSystemNode // std::string nameSing;// singular name, e.g. Centaur // std::string namePl; // plural name, e.g. Centaurs - const std::string & getName() const override; std::string getNameTranslated() const override; std::string getNameTextID() const override; @@ -153,7 +152,7 @@ public: TerrainId getNativeTerrain() const; int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getJsonKey() const override; + std::string getJsonKey() const override; void registerIcons(const IconRegistar & cb) const override; CreatureID getId() const override; virtual const IBonusBearer * accessBonuses() const override; diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 4f00b6411..a63a5a5f2 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1713,7 +1713,7 @@ void CGameState::initTowns() } if(vti->getNameTranslated().empty()) { - size_t nameID = getRandomGenerator().nextInt(vti->town->getRandomNamesCount()); + size_t nameID = getRandomGenerator().nextInt(vti->town->getRandomNamesCount() - 1); vti->setNameTranslated(vti->town->getRandomNameTranslated(nameID)); } diff --git a/lib/CGeneralTextHandler.cpp b/lib/CGeneralTextHandler.cpp index d7ed33199..59d0d5aa8 100644 --- a/lib/CGeneralTextHandler.cpp +++ b/lib/CGeneralTextHandler.cpp @@ -405,6 +405,8 @@ const std::string & CGeneralTextHandler::deserialize(const TextIdentifier & iden void CGeneralTextHandler::registerString(const TextIdentifier & UID, const std::string & localized) { + assert(UID.get().find("..") == std::string::npos); + stringsIdentifiers[localized] = UID.get(); stringsLocalizations[UID.get()] = localized; } diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index 574048b7b..30007a2d1 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -41,14 +41,9 @@ int32_t CHero::getIconIndex() const return imageIndex; } -const std::string & CHero::getName() const +std::string CHero::getJsonKey() const { - return identifier; -} - -const std::string & CHero::getJsonKey() const -{ - return identifier; + return modScope + ':' + identifier;; } HeroTypeID CHero::getId() const @@ -168,14 +163,9 @@ int32_t CHeroClass::getIconIndex() const return getIndex(); } -const std::string & CHeroClass::getName() const +std::string CHeroClass::getJsonKey() const { - return identifier; -} - -const std::string & CHeroClass::getJsonKey() const -{ - return identifier; + return modScope + ':' + identifier;; } HeroClassID CHeroClass::getId() const @@ -224,7 +214,7 @@ void CHeroClassHandler::fillPrimarySkillData(const JsonNode & node, CHeroClass * if(currentPrimarySkillValue < primarySkillLegalMinimum) { logMod->error("Hero class '%s' has incorrect initial value '%d' for skill '%s'. Value '%d' will be used instead.", - heroClass->getName(), currentPrimarySkillValue, skillName, primarySkillLegalMinimum); + heroClass->getNameTranslated(), currentPrimarySkillValue, skillName, primarySkillLegalMinimum); currentPrimarySkillValue = primarySkillLegalMinimum; } heroClass->primarySkillInitial.push_back(currentPrimarySkillValue); @@ -240,12 +230,16 @@ const std::vector & CHeroClassHandler::getTypeNames() const CHeroClass * CHeroClassHandler::loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + assert(!scope.empty()); + std::string affinityStr[2] = { "might", "magic" }; auto heroClass = new CHeroClass(); heroClass->id = HeroClassID(index); heroClass->identifier = identifier; + heroClass->modScope = scope; heroClass->imageBattleFemale = node["animation"]["battle"]["female"].String(); heroClass->imageBattleMale = node["animation"]["battle"]["male"].String(); //MODS COMPATIBILITY FOR 0.96 @@ -417,9 +411,13 @@ const std::vector & CHeroHandler::getTypeNames() const CHero * CHeroHandler::loadFromJson(const std::string & scope, const JsonNode & node, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + assert(!scope.empty()); + auto hero = new CHero(); hero->ID = HeroTypeID(index); hero->identifier = identifier; + hero->modScope = scope; hero->sex = node["female"].Bool(); hero->special = node["special"].Bool(); @@ -923,7 +921,7 @@ std::vector CHeroHandler::loadLegacyData(size_t dataSize) void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { size_t index = objects.size(); - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name), index); + auto object = loadFromJson(scope, data, name, index); object->imageIndex = (si32)index + GameConstants::HERO_PORTRAIT_SHIFT; // 2 special frames + some extra portraits objects.push_back(object); @@ -933,7 +931,7 @@ void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNod void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name), index); + auto object = loadFromJson(scope, data, name, index); object->imageIndex = static_cast(index); assert(objects[index] == nullptr); // ensure that this id was not loaded before diff --git a/lib/CHeroHandler.h b/lib/CHeroHandler.h index 546439eac..5e49545c5 100644 --- a/lib/CHeroHandler.h +++ b/lib/CHeroHandler.h @@ -66,8 +66,6 @@ class DLL_LINKAGE CHero : public HeroType std::string nameTextID; //name of hero std::string biographyTextID; - const std::string & getName() const override; - public: struct InitialArmyStack { @@ -108,7 +106,7 @@ public: int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getJsonKey() const override; + std::string getJsonKey() const override; HeroTypeID getId() const override; void registerIcons(const IconRegistar & cb) const override; @@ -146,6 +144,7 @@ public: h & portraitSmall; h & portraitLarge; h & identifier; + h & modScope; h & battleImage; } }; @@ -162,7 +161,6 @@ class DLL_LINKAGE CHeroClass : public HeroClass std::string identifier; // use getJsonKey instead std::string nameTextID; - const std::string & getName() const override; public: enum EClassAffinity { @@ -197,7 +195,7 @@ public: int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getJsonKey() const override; + std::string getJsonKey() const override; HeroClassID getId() const override; void registerIcons(const IconRegistar & cb) const override; diff --git a/lib/CSkillHandler.cpp b/lib/CSkillHandler.cpp index d8a630c24..6e6b03563 100644 --- a/lib/CSkillHandler.cpp +++ b/lib/CSkillHandler.cpp @@ -54,11 +54,6 @@ int32_t CSkill::getIconIndex() const return getIndex(); //TODO: actual value with skill level } -const std::string & CSkill::getName() const -{ - return identifier; -} - std::string CSkill::getNameTextID() const { TextIdentifier id("skill", modScope, identifier, "name"); @@ -70,9 +65,9 @@ std::string CSkill::getNameTranslated() const return VLC->generaltexth->translate(getNameTextID()); } -const std::string & CSkill::getJsonKey() const +std::string CSkill::getJsonKey() const { - return identifier; + return modScope + ':' + identifier;; } std::string CSkill::getDescriptionTextID(int level) const @@ -210,7 +205,11 @@ const std::vector & CSkillHandler::getTypeNames() const CSkill * CSkillHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + assert(!scope.empty()); + CSkill * skill = new CSkill(SecondarySkill((si32)index), identifier); + skill->modScope = scope; VLC->generaltexth->registerString(skill->getNameTextID(), json["name"].String()); switch(json["gainChance"].getType()) diff --git a/lib/CSkillHandler.h b/lib/CSkillHandler.h index e771a25ca..bf48b18f4 100644 --- a/lib/CSkillHandler.h +++ b/lib/CSkillHandler.h @@ -50,20 +50,18 @@ private: std::string modScope; std::string identifier; - const std::string & getName() const override; - public: CSkill(SecondarySkill id = SecondarySkill::DEFAULT, std::string identifier = "default"); ~CSkill(); int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getJsonKey() const override; + std::string getJsonKey() const override; void registerIcons(const IconRegistar & cb) const override; SecondarySkill getId() const override; - std::string getNameTextID() const; - std::string getNameTranslated() const; + std::string getNameTextID() const override; + std::string getNameTranslated() const override; std::string getDescriptionTextID(int level) const; std::string getDescriptionTranslated(int level) const; diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 3b7170515..4e312c948 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -46,7 +46,7 @@ const std::map CBuilding::TOWER_TYPES = std::string CBuilding::getJsonKey() const { - return identifier; + return modScope + ':' + identifier;; } std::string CBuilding::getNameTranslated() const @@ -61,12 +61,12 @@ std::string CBuilding::getDescriptionTranslated() const std::string CBuilding::getNameTextID() const { - return TextIdentifier("building", town->faction->getJsonKey(), modScope, identifier, "name").get(); + return TextIdentifier("building", modScope, town->faction->identifier, identifier, "name").get(); } std::string CBuilding::getDescriptionTextID() const { - return TextIdentifier("building", town->faction->getJsonKey(), modScope, identifier, "description").get(); + return TextIdentifier("building", modScope, town->faction->identifier, identifier, "description").get(); } BuildingID CBuilding::getBase() const @@ -122,14 +122,9 @@ int32_t CFaction::getIconIndex() const return index; //??? } -const std::string & CFaction::getName() const +std::string CFaction::getJsonKey() const { - return identifier; -} - -const std::string & CFaction::getJsonKey() const -{ - return identifier; + return modScope + ':' + identifier;; } void CFaction::registerIcons(const IconRegistar & cb) const @@ -205,7 +200,7 @@ std::string CTown::getRandomNameTranslated(size_t index) const std::string CTown::getRandomNameTextID(size_t index) const { - return TextIdentifier("faction", faction->getJsonKey(), "randomName", index).get(); + return TextIdentifier("faction", faction->modScope, faction->identifier, "randomName", index).get(); } size_t CTown::getRandomNamesCount() const @@ -582,6 +577,9 @@ void CTownHandler::loadSpecialBuildingBonuses(const JsonNode & source, BonusList void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, const JsonNode & source) { + assert(stringID.find(':') == std::string::npos); + assert(!source.meta.empty()); + auto ret = new CBuilding(); ret->bid = getMappedValue(stringID, BuildingID::NONE, MappedKeys::BUILDING_NAMES_TO_TYPES, false); @@ -603,6 +601,7 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons ret->height = getMappedValue(source["height"], CBuilding::HEIGHT_NO_TOWER, CBuilding::TOWER_TYPES); ret->identifier = stringID; + ret->modScope = source.meta; ret->town = town; VLC->generaltexth->registerString(ret->getNameTextID(), source["name"].String()); @@ -983,6 +982,8 @@ void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source) CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode & source, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + auto faction = new CFaction(); faction->index = static_cast(index); @@ -1032,7 +1033,7 @@ CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name), objects.size()); + auto object = loadFromJson(scope, data, name, objects.size()); objects.push_back(object); @@ -1071,7 +1072,7 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name), index); + auto object = loadFromJson(scope, data, name, index); if (objects.size() > index) assert(objects[index] == nullptr); // ensure that this id was not loaded before diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 389dc7a85..ec1fd5158 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -183,13 +183,14 @@ struct DLL_LINKAGE SPuzzleInfo class DLL_LINKAGE CFaction : public Faction { friend class CTownHandler; + friend class CBuilding; + friend class CTown; + std::string modScope; //town name, by default - from TownName.txt std::string identifier; TFaction index; - const std::string & getName() const override; - public: TerrainId nativeTerrain; EAlignment::EAlignment alignment; @@ -207,7 +208,7 @@ public: int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getJsonKey() const override; + std::string getJsonKey() const override; void registerIcons(const IconRegistar & cb) const override; FactionID getId() const override; diff --git a/lib/IHandlerBase.cpp b/lib/IHandlerBase.cpp index a91e5430f..93634e8f7 100644 --- a/lib/IHandlerBase.cpp +++ b/lib/IHandlerBase.cpp @@ -24,9 +24,4 @@ void IHandlerBase::registerObject(std::string scope, std::string type_name, std: return VLC->modh->identifiers.registerObject(scope, type_name, name, index); } -std::string IHandlerBase::normalizeIdentifier(const std::string& scope, const std::string& remoteScope, const std::string& identifier) const -{ - return VLC->modh->normalizeIdentifier(scope, remoteScope, identifier); -} - VCMI_LIB_NAMESPACE_END diff --git a/lib/IHandlerBase.h b/lib/IHandlerBase.h index d47bbd820..813e18ae0 100644 --- a/lib/IHandlerBase.h +++ b/lib/IHandlerBase.h @@ -25,8 +25,6 @@ protected: /// Calls modhandler. Mostly needed to avoid large number of includes in headers void registerObject(std::string scope, std::string type_name, std::string name, si32 index); - std::string normalizeIdentifier(const std::string & scope, const std::string & remoteScope, const std::string & identifier) const; - public: /// loads all original game data in vector of json nodes /// dataSize - is number of items that must be loaded (normally - constant from GameConstants) @@ -94,7 +92,7 @@ public: void loadObject(std::string scope, std::string name, const JsonNode & data) override { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, getScopeBuiltin(), name), objects.size()); + auto object = loadFromJson(scope, data, name, objects.size()); objects.push_back(object); @@ -104,7 +102,7 @@ public: void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, getScopeBuiltin(), name), index); + auto object = loadFromJson(scope, data, name, index); assert(objects[index] == nullptr); // ensure that this id was not loaded before objects[index] = object; diff --git a/lib/ObstacleHandler.cpp b/lib/ObstacleHandler.cpp index c427d4640..4ae68caae 100644 --- a/lib/ObstacleHandler.cpp +++ b/lib/ObstacleHandler.cpp @@ -24,16 +24,21 @@ int32_t ObstacleInfo::getIconIndex() const return iconIndex; } -const std::string & ObstacleInfo::getName() const +std::string ObstacleInfo::getJsonKey() const { return identifier; } -const std::string & ObstacleInfo::getJsonKey() const +std::string ObstacleInfo::getNameTranslated() const { return identifier; } +std::string ObstacleInfo::getNameTextID() const +{ + return identifier; // TODO? +} + void ObstacleInfo::registerIcons(const IconRegistar & cb) const { } @@ -43,7 +48,6 @@ Obstacle ObstacleInfo::getId() const return obstacle; } - std::vector ObstacleInfo::getBlocked(BattleHex hex) const { std::vector ret; @@ -81,6 +85,8 @@ bool ObstacleInfo::isAppropriate(const TerrainId terrainType, const BattleField ObstacleInfo * ObstacleHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + auto * info = new ObstacleInfo(Obstacle(index), identifier); info->animation = json["animation"].String(); diff --git a/lib/ObstacleHandler.h b/lib/ObstacleHandler.h index 40fef6366..a7f38249f 100644 --- a/lib/ObstacleHandler.h +++ b/lib/ObstacleHandler.h @@ -44,8 +44,9 @@ public: int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getJsonKey() const override; - const std::string & getName() const override; + std::string getJsonKey() const override; + std::string getNameTranslated() const override; + std::string getNameTextID() const override; void registerIcons(const IconRegistar & cb) const override; Obstacle getId() const override; diff --git a/lib/RiverHandler.cpp b/lib/RiverHandler.cpp index 4236d6ce4..850f738fb 100644 --- a/lib/RiverHandler.cpp +++ b/lib/RiverHandler.cpp @@ -26,6 +26,8 @@ RiverType * RiverTypeHandler::loadFromJson( const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + RiverType * info = new RiverType; info->id = RiverId(index); diff --git a/lib/RiverHandler.h b/lib/RiverHandler.h index 0dc57225a..627dde1de 100644 --- a/lib/RiverHandler.h +++ b/lib/RiverHandler.h @@ -23,17 +23,16 @@ class DLL_LINKAGE RiverType : public EntityT std::string identifier; RiverId id; - const std::string & getName() const override { return identifier;} public: int32_t getIndex() const override { return id.getNum(); } int32_t getIconIndex() const override { return 0; } - const std::string & getJsonKey() const override { return identifier;} + std::string getJsonKey() const override { return identifier;} void registerIcons(const IconRegistar & cb) const override {} RiverId getId() const override { return id;} void updateFrom(const JsonNode & data) {}; - std::string getNameTextID() const; - std::string getNameTranslated() const; + std::string getNameTextID() const override; + std::string getNameTranslated() const override; std::string tilesFilename; std::string shortIdentifier; diff --git a/lib/RoadHandler.cpp b/lib/RoadHandler.cpp index d7f94eecd..8c55c55e8 100644 --- a/lib/RoadHandler.cpp +++ b/lib/RoadHandler.cpp @@ -26,6 +26,8 @@ RoadType * RoadTypeHandler::loadFromJson( const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + RoadType * info = new RoadType; info->id = RoadId(index); diff --git a/lib/RoadHandler.h b/lib/RoadHandler.h index 2b74cdec2..0b84535b6 100644 --- a/lib/RoadHandler.h +++ b/lib/RoadHandler.h @@ -23,17 +23,16 @@ class DLL_LINKAGE RoadType : public EntityT std::string identifier; RoadId id; - const std::string & getName() const override { return identifier;} public: int32_t getIndex() const override { return id.getNum(); } int32_t getIconIndex() const override { return 0; } - const std::string & getJsonKey() const override { return identifier;} + std::string getJsonKey() const override { return identifier;} void registerIcons(const IconRegistar & cb) const override {} RoadId getId() const override { return id;} void updateFrom(const JsonNode & data) {}; - std::string getNameTextID() const; - std::string getNameTranslated() const; + std::string getNameTextID() const override; + std::string getNameTranslated() const override; std::string tilesFilename; std::string shortIdentifier; diff --git a/lib/ScriptHandler.cpp b/lib/ScriptHandler.cpp index ed58f4b92..403fb34af 100644 --- a/lib/ScriptHandler.cpp +++ b/lib/ScriptHandler.cpp @@ -243,7 +243,7 @@ ScriptPtr ScriptHandler::loadFromJson(vstd::CLoggerBase * logger, const std::str void ScriptHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { - auto object = loadFromJson(logMod, scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name)); + auto object = loadFromJson(logMod, scope, data, name); objects[object->identifier] = object; } diff --git a/lib/TerrainHandler.cpp b/lib/TerrainHandler.cpp index c9e3fac67..73bf2c271 100644 --- a/lib/TerrainHandler.cpp +++ b/lib/TerrainHandler.cpp @@ -17,6 +17,8 @@ VCMI_LIB_NAMESPACE_BEGIN TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + TerrainType * info = new TerrainType; info->id = TerrainId(index); diff --git a/lib/TerrainHandler.h b/lib/TerrainHandler.h index 983e06cc3..648775b42 100644 --- a/lib/TerrainHandler.h +++ b/lib/TerrainHandler.h @@ -24,17 +24,16 @@ class DLL_LINKAGE TerrainType : public EntityT TerrainId id; ui8 passabilityType; - const std::string & getName() const override { return identifier;} public: int32_t getIndex() const override { return id.getNum(); } int32_t getIconIndex() const override { return 0; } - const std::string & getJsonKey() const override { return identifier;} + std::string getJsonKey() const override { return identifier;} void registerIcons(const IconRegistar & cb) const override {} TerrainId getId() const override { return id;} void updateFrom(const JsonNode & data) {}; - std::string getNameTextID() const; - std::string getNameTranslated() const; + std::string getNameTextID() const override; + std::string getNameTranslated() const override; enum PassabilityType : ui8 { diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index e8580e6b9..10024f3d8 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -259,14 +259,14 @@ CObjectClassesHandler::ObjectContainter * CObjectClassesHandler::loadFromJson(co void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data) { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name)); + auto object = loadFromJson(scope, data, VLC->modh->normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name)); objects[object->id] = object; VLC->modh->identifiers.registerObject(scope, "object", name, object->id); } void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) { - auto object = loadFromJson(scope, data, normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name)); + auto object = loadFromJson(scope, data, VLC->modh->normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name)); assert(objects[(si32)index] == nullptr); // ensure that this id was not loaded before objects[(si32)index] = object; VLC->modh->identifiers.registerObject(scope, "object", name, object->id); diff --git a/lib/rmg/CRmgTemplateStorage.cpp b/lib/rmg/CRmgTemplateStorage.cpp index 813fb785e..4904ece2d 100644 --- a/lib/rmg/CRmgTemplateStorage.cpp +++ b/lib/rmg/CRmgTemplateStorage.cpp @@ -31,7 +31,7 @@ void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const try { JsonDeserializer handler(nullptr, data); - auto fullKey = normalizeIdentifier(scope, CModHandler::scopeBuiltin(), name); //actually it's not used + auto fullKey = scope + ":" + name; //actually it's not used templates[fullKey].setId(fullKey); templates[fullKey].serializeJson(handler); templates[fullKey].setName(name); diff --git a/lib/spells/CSpellHandler.cpp b/lib/spells/CSpellHandler.cpp index b1b1a9c0d..132d504f1 100644 --- a/lib/spells/CSpellHandler.cpp +++ b/lib/spells/CSpellHandler.cpp @@ -201,11 +201,6 @@ SpellID CSpell::getId() const return id; } -const std::string & CSpell::getName() const -{ - return identifier; -} - std::string CSpell::getNameTextID() const { TextIdentifier id("spell", modScope, identifier, "name"); @@ -228,9 +223,9 @@ std::string CSpell::getDescriptionTranslated(int32_t level) const return VLC->generaltexth->translate(getDescriptionTextID(level)); } -const std::string & CSpell::getJsonKey() const +std::string CSpell::getJsonKey() const { - return identifier; + return modScope + ':' + identifier;; } int32_t CSpell::getIndex() const @@ -711,6 +706,9 @@ const std::vector & CSpellHandler::getTypeNames() const CSpell * CSpellHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index) { + assert(identifier.find(':') == std::string::npos); + assert(!scope.empty()); + using namespace SpellConfig; SpellID id(static_cast(index)); @@ -947,7 +945,8 @@ CSpell * CSpellHandler::loadFromJson(const std::string & scope, const JsonNode & const si32 levelPower = levelObject.power = static_cast(levelNode["power"].Integer()); - VLC->generaltexth->registerString(spell->getDescriptionTranslated(levelIndex), levelNode["description"].String()); + if (!spell->isCreatureAbility()) + VLC->generaltexth->registerString(spell->getDescriptionTextID(levelIndex), levelNode["description"].String()); levelObject.cost = static_cast(levelNode["cost"].Integer()); levelObject.AIValue = static_cast(levelNode["aiValue"].Integer()); diff --git a/lib/spells/CSpellHandler.h b/lib/spells/CSpellHandler.h index 718779962..c7c59a819 100644 --- a/lib/spells/CSpellHandler.h +++ b/lib/spells/CSpellHandler.h @@ -170,7 +170,6 @@ public: SpellID id; std::string identifier; std::string modScope; - const std::string & getName() const override; public: enum ESpellPositiveness { @@ -236,7 +235,7 @@ public: int32_t getIndex() const override; int32_t getIconIndex() const override; - const std::string & getJsonKey() const override; + std::string getJsonKey() const override; SpellID getId() const override; std::string getNameTextID() const override; diff --git a/lib/spells/ISpellMechanics.cpp b/lib/spells/ISpellMechanics.cpp index 5e8f39287..59704af3f 100644 --- a/lib/spells/ISpellMechanics.cpp +++ b/lib/spells/ISpellMechanics.cpp @@ -571,7 +571,7 @@ SpellID BaseMechanics::getSpellId() const std::string BaseMechanics::getSpellName() const { - return owner->getName(); + return owner->getNameTranslated(); } int32_t BaseMechanics::getSpellLevel() const diff --git a/mapeditor/inspector/rewardswidget.cpp b/mapeditor/inspector/rewardswidget.cpp index 1210e7ce9..eab3481db 100644 --- a/mapeditor/inspector/rewardswidget.cpp +++ b/mapeditor/inspector/rewardswidget.cpp @@ -90,7 +90,7 @@ QList RewardsWidget::getListForType(RewardType typeId) for(int i = 0; i < map.allowedSpell.size(); ++i) { if(map.allowedSpell[i]) - result.append(QString::fromStdString(VLC->spellh->objects.at(i)->getName())); + result.append(QString::fromStdString(VLC->spellh->objects.at(i)->getNameTranslated())); } break; diff --git a/mapeditor/mapsettings.cpp b/mapeditor/mapsettings.cpp index 498f4c33a..c9b021e6d 100644 --- a/mapeditor/mapsettings.cpp +++ b/mapeditor/mapsettings.cpp @@ -42,7 +42,7 @@ MapSettings::MapSettings(MapController & ctrl, QWidget *parent) : } for(int i = 0; i < controller.map()->allowedSpell.size(); ++i) { - auto * item = new QListWidgetItem(QString::fromStdString(VLC->spellh->objects[i]->getName())); + auto * item = new QListWidgetItem(QString::fromStdString(VLC->spellh->objects[i]->getNameTranslated())); item->setData(Qt::UserRole, QVariant::fromValue(i)); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setCheckState(controller.map()->allowedSpell[i] ? Qt::Checked : Qt::Unchecked);