mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-21 00:19:29 +02:00
IdentifierStorage is now separate handler in VLC
This commit is contained in:
@ -23,7 +23,7 @@ std::string IHandlerBase::getScopeBuiltin()
|
|||||||
|
|
||||||
void IHandlerBase::registerObject(const std::string & scope, const std::string & type_name, const std::string & name, si32 index)
|
void IHandlerBase::registerObject(const std::string & scope, const std::string & type_name, const std::string & name, si32 index)
|
||||||
{
|
{
|
||||||
return VLC->modh->getIdentifiers().registerObject(scope, type_name, name, index);
|
return VLC->identifiersHandler->registerObject(scope, type_name, name, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -111,7 +111,7 @@ const IBonusTypeHandler * LibClasses::getBth() const
|
|||||||
|
|
||||||
const CIdentifierStorage * LibClasses::identifiers() const
|
const CIdentifierStorage * LibClasses::identifiers() const
|
||||||
{
|
{
|
||||||
return &modh->getIdentifiers();
|
return identifiersHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
const spells::effects::Registry * LibClasses::spellEffects() const
|
const spells::effects::Registry * LibClasses::spellEffects() const
|
||||||
@ -185,6 +185,7 @@ void LibClasses::loadModFilesystem(bool onlyEssential)
|
|||||||
{
|
{
|
||||||
CStopWatch loadTime;
|
CStopWatch loadTime;
|
||||||
modh = new CModHandler();
|
modh = new CModHandler();
|
||||||
|
identifiersHandler = new CIdentifierStorage();
|
||||||
modh->loadMods(onlyEssential);
|
modh->loadMods(onlyEssential);
|
||||||
logGlobal->info("\tMod handler: %d ms", loadTime.getDiff());
|
logGlobal->info("\tMod handler: %d ms", loadTime.getDiff());
|
||||||
|
|
||||||
@ -212,49 +213,29 @@ void LibClasses::init(bool onlyEssential)
|
|||||||
modh->initializeConfig();
|
modh->initializeConfig();
|
||||||
|
|
||||||
createHandler(generaltexth, "General text", pomtime);
|
createHandler(generaltexth, "General text", pomtime);
|
||||||
|
|
||||||
createHandler(bth, "Bonus type", pomtime);
|
createHandler(bth, "Bonus type", pomtime);
|
||||||
|
|
||||||
createHandler(roadTypeHandler, "Road", pomtime);
|
createHandler(roadTypeHandler, "Road", pomtime);
|
||||||
createHandler(riverTypeHandler, "River", pomtime);
|
createHandler(riverTypeHandler, "River", pomtime);
|
||||||
createHandler(terrainTypeHandler, "Terrain", pomtime);
|
createHandler(terrainTypeHandler, "Terrain", pomtime);
|
||||||
|
|
||||||
createHandler(heroh, "Hero", pomtime);
|
createHandler(heroh, "Hero", pomtime);
|
||||||
|
|
||||||
createHandler(arth, "Artifact", pomtime);
|
createHandler(arth, "Artifact", pomtime);
|
||||||
|
|
||||||
createHandler(creh, "Creature", pomtime);
|
createHandler(creh, "Creature", pomtime);
|
||||||
|
|
||||||
createHandler(townh, "Town", pomtime);
|
createHandler(townh, "Town", pomtime);
|
||||||
|
|
||||||
createHandler(objh, "Object", pomtime);
|
createHandler(objh, "Object", pomtime);
|
||||||
|
|
||||||
createHandler(objtypeh, "Object types information", pomtime);
|
createHandler(objtypeh, "Object types information", pomtime);
|
||||||
|
|
||||||
createHandler(spellh, "Spell", pomtime);
|
createHandler(spellh, "Spell", pomtime);
|
||||||
|
|
||||||
createHandler(skillh, "Skill", pomtime);
|
createHandler(skillh, "Skill", pomtime);
|
||||||
|
|
||||||
createHandler(terviewh, "Terrain view pattern", pomtime);
|
createHandler(terviewh, "Terrain view pattern", pomtime);
|
||||||
|
|
||||||
createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
|
createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
|
||||||
|
|
||||||
#if SCRIPTING_ENABLED
|
#if SCRIPTING_ENABLED
|
||||||
createHandler(scriptHandler, "Script", pomtime);
|
createHandler(scriptHandler, "Script", pomtime);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
createHandler(battlefieldsHandler, "Battlefields", pomtime);
|
createHandler(battlefieldsHandler, "Battlefields", pomtime);
|
||||||
|
|
||||||
createHandler(obstacleHandler, "Obstacles", pomtime);
|
createHandler(obstacleHandler, "Obstacles", pomtime);
|
||||||
|
|
||||||
logGlobal->info("\tInitializing handlers: %d ms", totalTime.getDiff());
|
logGlobal->info("\tInitializing handlers: %d ms", totalTime.getDiff());
|
||||||
|
|
||||||
modh->load();
|
modh->load();
|
||||||
|
|
||||||
modh->afterLoad(onlyEssential);
|
modh->afterLoad(onlyEssential);
|
||||||
|
|
||||||
//FIXME: make sure that everything is ok after game restart
|
|
||||||
//TODO: This should be done every time mod config changes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibClasses::clear()
|
void LibClasses::clear()
|
||||||
@ -276,6 +257,7 @@ void LibClasses::clear()
|
|||||||
#endif
|
#endif
|
||||||
delete battlefieldsHandler;
|
delete battlefieldsHandler;
|
||||||
delete generaltexth;
|
delete generaltexth;
|
||||||
|
delete identifiersHandler;
|
||||||
makeNull();
|
makeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,6 +280,7 @@ void LibClasses::makeNull()
|
|||||||
scriptHandler = nullptr;
|
scriptHandler = nullptr;
|
||||||
#endif
|
#endif
|
||||||
battlefieldsHandler = nullptr;
|
battlefieldsHandler = nullptr;
|
||||||
|
identifiersHandler = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LibClasses::LibClasses()
|
LibClasses::LibClasses()
|
||||||
|
@ -97,6 +97,7 @@ public:
|
|||||||
TerrainTypeHandler * terrainTypeHandler;
|
TerrainTypeHandler * terrainTypeHandler;
|
||||||
RoadTypeHandler * roadTypeHandler;
|
RoadTypeHandler * roadTypeHandler;
|
||||||
RiverTypeHandler * riverTypeHandler;
|
RiverTypeHandler * riverTypeHandler;
|
||||||
|
CIdentifierStorage * identifiersHandler;
|
||||||
|
|
||||||
CTerrainViewPatternConfig * terviewh;
|
CTerrainViewPatternConfig * terviewh;
|
||||||
CRmgTemplateStorage * tplh;
|
CRmgTemplateStorage * tplh;
|
||||||
@ -122,8 +123,9 @@ public:
|
|||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
|
h & identifiersHandler; // must be first - identifiers registry is used for handlers loading
|
||||||
#if SCRIPTING_ENABLED
|
#if SCRIPTING_ENABLED
|
||||||
h & scriptHandler;//must be first (or second after modh), it can modify factories other handlers depends on
|
h & scriptHandler;//must be first (or second after identifiers), it can modify factories other handlers depends on
|
||||||
if(!h.saving)
|
if(!h.saving)
|
||||||
{
|
{
|
||||||
scriptsLoaded();
|
scriptsLoaded();
|
||||||
|
@ -277,7 +277,7 @@ void CObjectClassesHandler::loadObject(std::string scope, std::string name, cons
|
|||||||
{
|
{
|
||||||
auto * object = loadFromJson(scope, data, name, objects.size());
|
auto * object = loadFromJson(scope, data, name, objects.size());
|
||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
VLC->modh->getIdentifiers().registerObject(scope, "object", name, object->id);
|
VLC->identifiersHandler->registerObject(scope, "object", name, object->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||||
@ -285,7 +285,7 @@ void CObjectClassesHandler::loadObject(std::string scope, std::string name, cons
|
|||||||
auto * object = loadFromJson(scope, data, name, index);
|
auto * object = loadFromJson(scope, data, name, index);
|
||||||
assert(objects[(si32)index] == nullptr); // ensure that this id was not loaded before
|
assert(objects[(si32)index] == nullptr); // ensure that this id was not loaded before
|
||||||
objects[static_cast<si32>(index)] = object;
|
objects[static_cast<si32>(index)] = object;
|
||||||
VLC->modh->getIdentifiers().registerObject(scope, "object", name, object->id);
|
VLC->identifiersHandler->registerObject(scope, "object", name, object->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectClassesHandler::loadSubObject(const std::string & identifier, JsonNode config, si32 ID, si32 subID)
|
void CObjectClassesHandler::loadSubObject(const std::string & identifier, JsonNode config, si32 ID, si32 subID)
|
||||||
|
@ -41,25 +41,8 @@ static JsonNode loadModSettings(const std::string & path)
|
|||||||
|
|
||||||
CModHandler::CModHandler()
|
CModHandler::CModHandler()
|
||||||
: content(std::make_shared<CContentHandler>())
|
: content(std::make_shared<CContentHandler>())
|
||||||
, identifiers(std::make_unique<CIdentifierStorage>())
|
|
||||||
, coreMod(std::make_unique<CModInfo>())
|
, coreMod(std::make_unique<CModInfo>())
|
||||||
{
|
{
|
||||||
//TODO: moddable spell schools
|
|
||||||
for (auto i = 0; i < GameConstants::DEFAULT_SCHOOLS; ++i)
|
|
||||||
identifiers->registerObject(ModScope::scopeBuiltin(), "spellSchool", SpellConfig::SCHOOL[i].jsonName, SpellConfig::SCHOOL[i].id);
|
|
||||||
|
|
||||||
identifiers->registerObject(ModScope::scopeBuiltin(), "spellSchool", "any", SpellSchool(ESpellSchool::ANY));
|
|
||||||
|
|
||||||
for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
|
||||||
{
|
|
||||||
identifiers->registerObject(ModScope::scopeBuiltin(), "resource", GameConstants::RESOURCE_NAMES[i], i);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i=0; i<GameConstants::PRIMARY_SKILLS; ++i)
|
|
||||||
{
|
|
||||||
identifiers->registerObject(ModScope::scopeBuiltin(), "primSkill", NPrimarySkill::names[i], i);
|
|
||||||
identifiers->registerObject(ModScope::scopeBuiltin(), "primarySkill", NPrimarySkill::names[i], i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CModHandler::~CModHandler() = default;
|
CModHandler::~CModHandler() = default;
|
||||||
@ -462,7 +445,7 @@ void CModHandler::load()
|
|||||||
|
|
||||||
logMod->info("\tLoading mod data: %d ms", timer.getDiff());
|
logMod->info("\tLoading mod data: %d ms", timer.getDiff());
|
||||||
VLC->creh->loadCrExpMod();
|
VLC->creh->loadCrExpMod();
|
||||||
identifiers->finalize();
|
VLC->identifiersHandler->finalize();
|
||||||
logMod->info("\tResolving identifiers: %d ms", timer.getDiff());
|
logMod->info("\tResolving identifiers: %d ms", timer.getDiff());
|
||||||
|
|
||||||
content->afterLoadFinalization();
|
content->afterLoadFinalization();
|
||||||
@ -534,9 +517,4 @@ void CModHandler::trySetActiveMods(std::vector<TModID> saveActiveMods, const std
|
|||||||
std::swap(activeMods, newActiveMods);
|
std::swap(activeMods, newActiveMods);
|
||||||
}
|
}
|
||||||
|
|
||||||
CIdentifierStorage & CModHandler::getIdentifiers()
|
|
||||||
{
|
|
||||||
return *identifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -54,13 +54,9 @@ class DLL_LINKAGE CModHandler : boost::noncopyable
|
|||||||
/// Attempt to set active mods according to provided list of mods from save, throws on failure
|
/// Attempt to set active mods according to provided list of mods from save, throws on failure
|
||||||
void trySetActiveMods(std::vector<TModID> saveActiveMods, const std::map<TModID, CModVersion> & modList);
|
void trySetActiveMods(std::vector<TModID> saveActiveMods, const std::map<TModID, CModVersion> & modList);
|
||||||
|
|
||||||
std::unique_ptr<CIdentifierStorage> identifiers;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<CContentHandler> content; //(!)Do not serialize FIXME: make private
|
std::shared_ptr<CContentHandler> content; //(!)Do not serialize FIXME: make private
|
||||||
|
|
||||||
CIdentifierStorage & getIdentifiers();
|
|
||||||
|
|
||||||
/// receives list of available mods and trying to load mod.json from all of them
|
/// receives list of available mods and trying to load mod.json from all of them
|
||||||
void initializeConfig();
|
void initializeConfig();
|
||||||
void loadMods(bool onlyEssential = false);
|
void loadMods(bool onlyEssential = false);
|
||||||
@ -109,8 +105,6 @@ public:
|
|||||||
|
|
||||||
trySetActiveMods(saveActiveMods, modVersions);
|
trySetActiveMods(saveActiveMods, modVersions);
|
||||||
}
|
}
|
||||||
|
|
||||||
h & identifiers;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,11 +15,33 @@
|
|||||||
|
|
||||||
#include "../JsonNode.h"
|
#include "../JsonNode.h"
|
||||||
#include "../VCMI_Lib.h"
|
#include "../VCMI_Lib.h"
|
||||||
|
#include "../constants/StringConstants.h"
|
||||||
|
#include "../spells/CSpellHandler.h"
|
||||||
|
|
||||||
#include <vstd/StringUtils.h>
|
#include <vstd/StringUtils.h>
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
CIdentifierStorage::CIdentifierStorage()
|
||||||
|
{
|
||||||
|
//TODO: moddable spell schools
|
||||||
|
for (auto i = 0; i < GameConstants::DEFAULT_SCHOOLS; ++i)
|
||||||
|
registerObject(ModScope::scopeBuiltin(), "spellSchool", SpellConfig::SCHOOL[i].jsonName, SpellConfig::SCHOOL[i].id);
|
||||||
|
|
||||||
|
registerObject(ModScope::scopeBuiltin(), "spellSchool", "any", SpellSchool(ESpellSchool::ANY));
|
||||||
|
|
||||||
|
for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
||||||
|
{
|
||||||
|
registerObject(ModScope::scopeBuiltin(), "resource", GameConstants::RESOURCE_NAMES[i], i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<GameConstants::PRIMARY_SKILLS; ++i)
|
||||||
|
{
|
||||||
|
registerObject(ModScope::scopeBuiltin(), "primSkill", NPrimarySkill::names[i], i);
|
||||||
|
registerObject(ModScope::scopeBuiltin(), "primarySkill", NPrimarySkill::names[i], i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CIdentifierStorage::checkIdentifier(std::string & ID)
|
void CIdentifierStorage::checkIdentifier(std::string & ID)
|
||||||
{
|
{
|
||||||
if (boost::algorithm::ends_with(ID, "."))
|
if (boost::algorithm::ends_with(ID, "."))
|
||||||
|
@ -73,7 +73,7 @@ class DLL_LINKAGE CIdentifierStorage
|
|||||||
std::vector<ObjectData> getPossibleIdentifiers(const ObjectCallback & callback) const;
|
std::vector<ObjectData> getPossibleIdentifiers(const ObjectCallback & callback) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CIdentifierStorage() = default;
|
CIdentifierStorage();
|
||||||
virtual ~CIdentifierStorage() = default;
|
virtual ~CIdentifierStorage() = default;
|
||||||
|
|
||||||
/// request identifier for specific object name.
|
/// request identifier for specific object name.
|
||||||
|
Reference in New Issue
Block a user