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