mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Save string identifiers for all game objects
This commit is contained in:
parent
93c214d7a0
commit
6f203fb7e2
@ -201,28 +201,28 @@ std::vector<JsonNode> CArtHandler::loadLegacyData(size_t dataSize)
|
||||
|
||||
void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||
{
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->id = ArtifactID(artifacts.size());
|
||||
object->iconIndex = object->id + 5;
|
||||
|
||||
artifacts.push_back(object);
|
||||
|
||||
VLC->modh->identifiers.registerObject(scope, "artifact", name, object->id);
|
||||
registerObject(scope, "artifact", object->identifier, object->id);
|
||||
}
|
||||
|
||||
void CArtHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||
{
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->id = ArtifactID(index);
|
||||
object->iconIndex = object->id;
|
||||
|
||||
assert(artifacts[index] == nullptr); // ensure that this id was not loaded before
|
||||
artifacts[index] = object;
|
||||
|
||||
VLC->modh->identifiers.registerObject(scope, "artifact", name, object->id);
|
||||
registerObject(scope, "artifact", object->identifier, object->id);
|
||||
}
|
||||
|
||||
CArtifact * CArtHandler::loadFromJson(const JsonNode & node)
|
||||
CArtifact * CArtHandler::loadFromJson(const JsonNode & node, const std::string & identifier)
|
||||
{
|
||||
CArtifact * art;
|
||||
|
||||
@ -234,7 +234,7 @@ CArtifact * CArtHandler::loadFromJson(const JsonNode & node)
|
||||
loadGrowingArt(growing, node);
|
||||
art = growing;
|
||||
}
|
||||
|
||||
art->identifier = identifier;
|
||||
const JsonNode & text = node["text"];
|
||||
art->name = text["name"].String();
|
||||
art->description = text["description"].String();
|
||||
|
@ -48,7 +48,8 @@ protected:
|
||||
std::string eventText; //short story displayed upon picking
|
||||
public:
|
||||
enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
|
||||
|
||||
|
||||
std::string identifier;
|
||||
std::string image;
|
||||
std::string large; // big image for cutom artifacts, used in drag & drop
|
||||
std::string advMapDef; //used for adventure map object
|
||||
@ -79,6 +80,10 @@ public:
|
||||
h & static_cast<CBonusSystemNode&>(*this);
|
||||
h & name & description & eventText & image & large & advMapDef & iconIndex &
|
||||
price & possibleSlots & constituents & constituentOf & aClass & id;
|
||||
if(version>=755)
|
||||
{
|
||||
h & identifier;
|
||||
}
|
||||
}
|
||||
|
||||
CArtifact();
|
||||
@ -244,7 +249,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
CArtifact * loadFromJson(const JsonNode & node);
|
||||
CArtifact * loadFromJson(const JsonNode & node, const std::string & identifier);
|
||||
|
||||
void addSlot(CArtifact * art, const std::string & slotID);
|
||||
void loadSlots(CArtifact * art, const JsonNode & node);
|
||||
|
@ -357,23 +357,23 @@ std::vector<JsonNode> CCreatureHandler::loadLegacyData(size_t dataSize)
|
||||
|
||||
void CCreatureHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||
{
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->setId(CreatureID(creatures.size()));
|
||||
object->iconIndex = object->idNumber + 2;
|
||||
|
||||
creatures.push_back(object);
|
||||
|
||||
VLC->modh->identifiers.registerObject(scope, "creature", name, object->idNumber);
|
||||
registerObject(scope, "creature", name, object->idNumber);
|
||||
|
||||
for(auto node : data["extraNames"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.registerObject(scope, "creature", node.String(), object->idNumber);
|
||||
registerObject(scope, "creature", node.String(), object->idNumber);
|
||||
}
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||
{
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->setId(CreatureID(index));
|
||||
object->iconIndex = object->idNumber + 2;
|
||||
|
||||
@ -385,10 +385,10 @@ void CCreatureHandler::loadObject(std::string scope, std::string name, const Jso
|
||||
assert(creatures[index] == nullptr); // ensure that this id was not loaded before
|
||||
creatures[index] = object;
|
||||
|
||||
VLC->modh->identifiers.registerObject(scope, "creature", name, object->idNumber);
|
||||
registerObject(scope, "creature", name, object->idNumber);
|
||||
for(auto & node : data["extraNames"].Vector())
|
||||
{
|
||||
VLC->modh->identifiers.registerObject(scope, "creature", node.String(), object->idNumber);
|
||||
registerObject(scope, "creature", node.String(), object->idNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@ -561,11 +561,12 @@ void CCreatureHandler::loadUnitAnimInfo(JsonNode & graphics, CLegacyConfigParser
|
||||
graphics.Struct().erase("missile");
|
||||
}
|
||||
|
||||
CCreature * CCreatureHandler::loadFromJson(const JsonNode & node)
|
||||
CCreature * CCreatureHandler::loadFromJson(const JsonNode & node, const std::string & identifier)
|
||||
{
|
||||
auto cre = new CCreature();
|
||||
|
||||
const JsonNode & name = node["name"];
|
||||
cre->identifier = identifier;
|
||||
cre->nameSing = name["singular"].String();
|
||||
cre->namePl = name["plural"].String();
|
||||
|
||||
|
@ -26,6 +26,8 @@ class CCreature;
|
||||
class DLL_LINKAGE CCreature : public CBonusSystemNode
|
||||
{
|
||||
public:
|
||||
std::string identifier;
|
||||
|
||||
std::string nameRef; // reference name, stringID
|
||||
std::string nameSing;// singular name, e.g. Centaur
|
||||
std::string namePl; // plural name, e.g. Centaurs
|
||||
@ -136,6 +138,10 @@ public:
|
||||
h & idNumber & faction & sounds & animation;
|
||||
|
||||
h & doubleWide & special;
|
||||
if(version>=755)
|
||||
{
|
||||
h & identifier;
|
||||
}
|
||||
}
|
||||
|
||||
CCreature();
|
||||
@ -148,7 +154,7 @@ private:
|
||||
CBonusSystemNode creaturesOfLevel[GameConstants::CREATURES_PER_TOWN + 1];//index 0 is used for creatures of unknown tier or outside <1-7> range
|
||||
|
||||
/// load one creature from json config
|
||||
CCreature * loadFromJson(const JsonNode & node);
|
||||
CCreature * loadFromJson(const JsonNode & node, const std::string & identifier);
|
||||
|
||||
void loadJsonAnimation(CCreature * creature, const JsonNode & graphics);
|
||||
void loadStackExperience(CCreature * creature, const JsonNode &input);
|
||||
|
@ -96,12 +96,12 @@ bool CObstacleInfo::isAppropriate(ETerrainType terrainType, int specialBattlefie
|
||||
return vstd::contains(allowedTerrains, terrainType);
|
||||
}
|
||||
|
||||
CHeroClass *CHeroClassHandler::loadFromJson(const JsonNode & node)
|
||||
CHeroClass * CHeroClassHandler::loadFromJson(const JsonNode & node, const std::string & identifier)
|
||||
{
|
||||
std::string affinityStr[2] = { "might", "magic" };
|
||||
|
||||
auto heroClass = new CHeroClass();
|
||||
|
||||
heroClass->identifier = identifier;
|
||||
heroClass->imageBattleFemale = node["animation"]["battle"]["female"].String();
|
||||
heroClass->imageBattleMale = node["animation"]["battle"]["male"].String();
|
||||
//MODS COMPATIBILITY FOR 0.96
|
||||
@ -192,7 +192,7 @@ std::vector<JsonNode> CHeroClassHandler::loadLegacyData(size_t dataSize)
|
||||
|
||||
void CHeroClassHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||
{
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->id = heroClasses.size();
|
||||
|
||||
heroClasses.push_back(object);
|
||||
@ -210,7 +210,7 @@ void CHeroClassHandler::loadObject(std::string scope, std::string name, const Js
|
||||
|
||||
void CHeroClassHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||
{
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->id = index;
|
||||
|
||||
assert(heroClasses[index] == nullptr); // ensure that this id was not loaded before
|
||||
@ -288,10 +288,10 @@ CHeroHandler::CHeroHandler()
|
||||
loadExperience();
|
||||
}
|
||||
|
||||
CHero * CHeroHandler::loadFromJson(const JsonNode & node)
|
||||
CHero * CHeroHandler::loadFromJson(const JsonNode & node, const std::string & identifier)
|
||||
{
|
||||
auto hero = new CHero;
|
||||
|
||||
hero->identifier = identifier;
|
||||
hero->sex = node["female"].Bool();
|
||||
hero->special = node["special"].Bool();
|
||||
|
||||
@ -536,7 +536,7 @@ std::vector<JsonNode> CHeroHandler::loadLegacyData(size_t dataSize)
|
||||
|
||||
void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
||||
{
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->ID = HeroTypeID(heroes.size());
|
||||
object->imageIndex = heroes.size() + 30; // 2 special frames + some extra portraits
|
||||
|
||||
@ -547,7 +547,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(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->ID = HeroTypeID(index);
|
||||
object->imageIndex = index;
|
||||
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
h & minAmount & maxAmount & creature;
|
||||
}
|
||||
};
|
||||
|
||||
std::string identifier;
|
||||
HeroTypeID ID;
|
||||
si32 imageIndex;
|
||||
|
||||
@ -92,6 +92,10 @@ public:
|
||||
h & ID & imageIndex & initialArmy & heroClass & secSkillsInit & spec & specialty & spells & haveSpellBook & sex & special;
|
||||
h & name & biography & specName & specDescr & specTooltip;
|
||||
h & iconSpecSmall & iconSpecLarge & portraitSmall & portraitLarge;
|
||||
if(version>=755)
|
||||
{
|
||||
h & identifier;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -169,7 +173,7 @@ struct DLL_LINKAGE CObstacleInfo
|
||||
|
||||
class DLL_LINKAGE CHeroClassHandler : public IHandlerBase
|
||||
{
|
||||
CHeroClass *loadFromJson(const JsonNode & node);
|
||||
CHeroClass *loadFromJson(const JsonNode & node, const std::string & identifier);
|
||||
public:
|
||||
std::vector< ConstTransitivePtr<CHeroClass> > heroClasses;
|
||||
|
||||
@ -207,7 +211,7 @@ class DLL_LINKAGE CHeroHandler : public IHandlerBase
|
||||
void loadObstacles();
|
||||
|
||||
/// Load single hero from json
|
||||
CHero * loadFromJson(const JsonNode & node);
|
||||
CHero * loadFromJson(const JsonNode & node, const std::string & identifier);
|
||||
|
||||
public:
|
||||
CHeroClassHandler classes;
|
||||
|
@ -633,7 +633,7 @@ void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source)
|
||||
assert(faction.puzzleMap.size() == GameConstants::PUZZLE_MAP_PIECES);
|
||||
}
|
||||
|
||||
CFaction * CTownHandler::loadFromJson(const JsonNode &source, std::string identifier)
|
||||
CFaction * CTownHandler::loadFromJson(const JsonNode &source, const std::string & identifier)
|
||||
{
|
||||
auto faction = new CFaction();
|
||||
|
||||
|
@ -250,7 +250,7 @@ class DLL_LINKAGE CTownHandler : public IHandlerBase
|
||||
|
||||
void loadPuzzle(CFaction & faction, const JsonNode & source);
|
||||
|
||||
CFaction * loadFromJson(const JsonNode & data, std::string identifier);
|
||||
CFaction * loadFromJson(const JsonNode & data, const std::string & identifier);
|
||||
|
||||
public:
|
||||
std::vector<ConstTransitivePtr<CFaction> > factions;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "mapping/CCampaignHandler.h" //for CCampaignState
|
||||
#include "rmg/CMapGenerator.h" // for CMapGenOptions
|
||||
|
||||
const ui32 version = 754;
|
||||
const ui32 version = 755;
|
||||
const ui32 minSupportedVersion = 753;
|
||||
|
||||
class CISer;
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
void loadObject(std::string scope, std::string name, const JsonNode & data) override
|
||||
{
|
||||
auto type_name = getTypeName();
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->id = _ObjectID(objects.size());
|
||||
|
||||
objects.push_back(object);
|
||||
@ -75,7 +75,7 @@ public:
|
||||
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override
|
||||
{
|
||||
auto type_name = getTypeName();
|
||||
auto object = loadFromJson(data);
|
||||
auto object = loadFromJson(data, name);
|
||||
object->id = _ObjectID(index);
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ public:
|
||||
return objects[raw_id];
|
||||
}
|
||||
protected:
|
||||
virtual _Object * loadFromJson(const JsonNode & json) = 0;
|
||||
virtual _Object * loadFromJson(const JsonNode & json, const std::string & identifier) = 0;
|
||||
virtual const std::string getTypeName() const = 0;
|
||||
public: //todo: make private
|
||||
std::vector<ConstTransitivePtr<_Object>> objects;
|
||||
|
@ -799,7 +799,7 @@ const std::string CSpellHandler::getTypeName() const
|
||||
return "spell";
|
||||
}
|
||||
|
||||
CSpell * CSpellHandler::loadFromJson(const JsonNode & json)
|
||||
CSpell * CSpellHandler::loadFromJson(const JsonNode & json, const std::string & identifier)
|
||||
{
|
||||
using namespace SpellConfig;
|
||||
|
||||
|
@ -172,7 +172,7 @@ public:
|
||||
};
|
||||
|
||||
SpellID id;
|
||||
std::string identifier; //???
|
||||
std::string identifier;
|
||||
std::string name;
|
||||
|
||||
si32 level;
|
||||
@ -366,5 +366,5 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
CSpell * loadFromJson(const JsonNode & json) override;
|
||||
CSpell * loadFromJson(const JsonNode & json, const std::string & identifier) override;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user