1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

IdentifierStorage is now separate handler in VLC

This commit is contained in:
Ivan Savenko 2023-08-25 22:36:00 +03:00
parent c8a6cd74cc
commit 7e27ac7073
8 changed files with 34 additions and 55 deletions

View File

@ -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)
{
return VLC->modh->getIdentifiers().registerObject(scope, type_name, name, index);
return VLC->identifiersHandler->registerObject(scope, type_name, name, index);
}
VCMI_LIB_NAMESPACE_END

View File

@ -111,7 +111,7 @@ const IBonusTypeHandler * LibClasses::getBth() const
const CIdentifierStorage * LibClasses::identifiers() const
{
return &modh->getIdentifiers();
return identifiersHandler;
}
const spells::effects::Registry * LibClasses::spellEffects() const
@ -185,6 +185,7 @@ void LibClasses::loadModFilesystem(bool onlyEssential)
{
CStopWatch loadTime;
modh = new CModHandler();
identifiersHandler = new CIdentifierStorage();
modh->loadMods(onlyEssential);
logGlobal->info("\tMod handler: %d ms", loadTime.getDiff());
@ -212,49 +213,29 @@ void LibClasses::init(bool onlyEssential)
modh->initializeConfig();
createHandler(generaltexth, "General text", pomtime);
createHandler(bth, "Bonus type", pomtime);
createHandler(roadTypeHandler, "Road", pomtime);
createHandler(riverTypeHandler, "River", pomtime);
createHandler(terrainTypeHandler, "Terrain", pomtime);
createHandler(heroh, "Hero", pomtime);
createHandler(arth, "Artifact", pomtime);
createHandler(creh, "Creature", pomtime);
createHandler(townh, "Town", pomtime);
createHandler(objh, "Object", pomtime);
createHandler(objtypeh, "Object types information", pomtime);
createHandler(spellh, "Spell", pomtime);
createHandler(skillh, "Skill", pomtime);
createHandler(terviewh, "Terrain view pattern", pomtime);
createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
#if SCRIPTING_ENABLED
createHandler(scriptHandler, "Script", pomtime);
#endif
createHandler(battlefieldsHandler, "Battlefields", pomtime);
createHandler(obstacleHandler, "Obstacles", pomtime);
logGlobal->info("\tInitializing handlers: %d ms", totalTime.getDiff());
modh->load();
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()
@ -276,6 +257,7 @@ void LibClasses::clear()
#endif
delete battlefieldsHandler;
delete generaltexth;
delete identifiersHandler;
makeNull();
}
@ -298,6 +280,7 @@ void LibClasses::makeNull()
scriptHandler = nullptr;
#endif
battlefieldsHandler = nullptr;
identifiersHandler = nullptr;
}
LibClasses::LibClasses()

View File

@ -97,6 +97,7 @@ public:
TerrainTypeHandler * terrainTypeHandler;
RoadTypeHandler * roadTypeHandler;
RiverTypeHandler * riverTypeHandler;
CIdentifierStorage * identifiersHandler;
CTerrainViewPatternConfig * terviewh;
CRmgTemplateStorage * tplh;
@ -122,8 +123,9 @@ public:
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
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)
{
scriptsLoaded();

View File

@ -277,7 +277,7 @@ void CObjectClassesHandler::loadObject(std::string scope, std::string name, cons
{
auto * object = loadFromJson(scope, data, name, objects.size());
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)
@ -285,7 +285,7 @@ void CObjectClassesHandler::loadObject(std::string scope, std::string name, cons
auto * object = loadFromJson(scope, data, name, index);
assert(objects[(si32)index] == nullptr); // ensure that this id was not loaded before
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)

View File

@ -41,25 +41,8 @@ static JsonNode loadModSettings(const std::string & path)
CModHandler::CModHandler()
: content(std::make_shared<CContentHandler>())
, identifiers(std::make_unique<CIdentifierStorage>())
, 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;
@ -462,7 +445,7 @@ void CModHandler::load()
logMod->info("\tLoading mod data: %d ms", timer.getDiff());
VLC->creh->loadCrExpMod();
identifiers->finalize();
VLC->identifiersHandler->finalize();
logMod->info("\tResolving identifiers: %d ms", timer.getDiff());
content->afterLoadFinalization();
@ -534,9 +517,4 @@ void CModHandler::trySetActiveMods(std::vector<TModID> saveActiveMods, const std
std::swap(activeMods, newActiveMods);
}
CIdentifierStorage & CModHandler::getIdentifiers()
{
return *identifiers;
}
VCMI_LIB_NAMESPACE_END

View File

@ -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
void trySetActiveMods(std::vector<TModID> saveActiveMods, const std::map<TModID, CModVersion> & modList);
std::unique_ptr<CIdentifierStorage> identifiers;
public:
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
void initializeConfig();
void loadMods(bool onlyEssential = false);
@ -109,8 +105,6 @@ public:
trySetActiveMods(saveActiveMods, modVersions);
}
h & identifiers;
}
};

View File

@ -15,11 +15,33 @@
#include "../JsonNode.h"
#include "../VCMI_Lib.h"
#include "../constants/StringConstants.h"
#include "../spells/CSpellHandler.h"
#include <vstd/StringUtils.h>
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)
{
if (boost::algorithm::ends_with(ID, "."))

View File

@ -73,7 +73,7 @@ class DLL_LINKAGE CIdentifierStorage
std::vector<ObjectData> getPossibleIdentifiers(const ObjectCallback & callback) const;
public:
CIdentifierStorage() = default;
CIdentifierStorage();
virtual ~CIdentifierStorage() = default;
/// request identifier for specific object name.