mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-10 23:48:04 +02:00
Mod system improvement Part I : Fix content losing after deserialization
This commit is contained in:
parent
bf07cd0ad9
commit
195fb8ff41
@ -698,7 +698,7 @@ void processCommand(const std::string &message)
|
|||||||
|
|
||||||
for(auto contentName : contentNames)
|
for(auto contentName : contentNames)
|
||||||
{
|
{
|
||||||
auto & content = VLC->modh->content[contentName];
|
auto & content = (*VLC->modh->content)[contentName];
|
||||||
|
|
||||||
auto contentOutPath = outPath / contentName;
|
auto contentOutPath = outPath / contentName;
|
||||||
bfs::create_directories(contentOutPath);
|
bfs::create_directories(contentOutPath);
|
||||||
|
@ -610,7 +610,7 @@ void CModInfo::loadLocalData(const JsonNode & data)
|
|||||||
validation = validated ? PASSED : FAILED;
|
validation = validated ? PASSED : FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
CModHandler::CModHandler()
|
CModHandler::CModHandler() : content(std::make_shared<CContentHandler>())
|
||||||
{
|
{
|
||||||
modules.COMMANDERS = false;
|
modules.COMMANDERS = false;
|
||||||
modules.STACK_ARTIFACT = false;
|
modules.STACK_ARTIFACT = false;
|
||||||
@ -955,7 +955,7 @@ void CModHandler::load()
|
|||||||
|
|
||||||
logMod->info("\tInitializing content handler: %d ms", timer.getDiff());
|
logMod->info("\tInitializing content handler: %d ms", timer.getDiff());
|
||||||
|
|
||||||
content.init();
|
content->init();
|
||||||
|
|
||||||
for(const TModID & modName : activeMods)
|
for(const TModID & modName : activeMods)
|
||||||
{
|
{
|
||||||
@ -965,16 +965,16 @@ void CModHandler::load()
|
|||||||
|
|
||||||
// first - load virtual "core" mod that contains all data
|
// first - load virtual "core" mod that contains all data
|
||||||
// TODO? move all data into real mods? RoE, AB, SoD, WoG
|
// TODO? move all data into real mods? RoE, AB, SoD, WoG
|
||||||
content.preloadData(coreMod);
|
content->preloadData(coreMod);
|
||||||
for(const TModID & modName : activeMods)
|
for(const TModID & modName : activeMods)
|
||||||
content.preloadData(allMods[modName]);
|
content->preloadData(allMods[modName]);
|
||||||
logMod->info("\tParsing mod data: %d ms", timer.getDiff());
|
logMod->info("\tParsing mod data: %d ms", timer.getDiff());
|
||||||
|
|
||||||
content.load(coreMod);
|
content->load(coreMod);
|
||||||
for(const TModID & modName : activeMods)
|
for(const TModID & modName : activeMods)
|
||||||
content.load(allMods[modName]);
|
content->load(allMods[modName]);
|
||||||
|
|
||||||
content.loadCustom();
|
content->loadCustom();
|
||||||
|
|
||||||
logMod->info("\tLoading mod data: %d ms", timer.getDiff());
|
logMod->info("\tLoading mod data: %d ms", timer.getDiff());
|
||||||
|
|
||||||
@ -984,7 +984,7 @@ void CModHandler::load()
|
|||||||
identifiers.finalize();
|
identifiers.finalize();
|
||||||
logMod->info("\tResolving identifiers: %d ms", timer.getDiff());
|
logMod->info("\tResolving identifiers: %d ms", timer.getDiff());
|
||||||
|
|
||||||
content.afterLoadFinalization();
|
content->afterLoadFinalization();
|
||||||
logMod->info("\tHandlers post-load finalization: %d ms ", timer.getDiff());
|
logMod->info("\tHandlers post-load finalization: %d ms ", timer.getDiff());
|
||||||
logMod->info("\tAll game content loaded in %d ms", totalTime.getDiff());
|
logMod->info("\tAll game content loaded in %d ms", totalTime.getDiff());
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ public:
|
|||||||
|
|
||||||
CIdentifierStorage identifiers;
|
CIdentifierStorage identifiers;
|
||||||
|
|
||||||
CContentHandler content; //(!)Do not serialize
|
std::shared_ptr<CContentHandler> content; //(!)Do not serialize
|
||||||
|
|
||||||
/// 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();
|
||||||
|
@ -107,7 +107,7 @@ void CBuilding::update792(const BuildingID & bid, BuildingSubID::EBuildingSubID
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const auto & faction = town->faction->identifier;
|
const auto & faction = town->faction->identifier;
|
||||||
auto factionsContent = VLC->modh->content["factions"];
|
auto factionsContent = (*VLC->modh->content)["factions"];
|
||||||
auto & coreData = factionsContent.modData.at("core");
|
auto & coreData = factionsContent.modData.at("core");
|
||||||
auto & coreFactions = coreData.modData;
|
auto & coreFactions = coreData.modData;
|
||||||
auto & currentFaction = coreFactions[faction];
|
auto & currentFaction = coreFactions[faction];
|
||||||
|
@ -186,3 +186,13 @@ LibClasses::~LibClasses()
|
|||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<CContentHandler> LibClasses::getContent() const
|
||||||
|
{
|
||||||
|
return modh->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibClasses::setContent(std::shared_ptr<CContentHandler> content)
|
||||||
|
{
|
||||||
|
modh->content = content;
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@ class CObjectClassesHandler;
|
|||||||
class CTownHandler;
|
class CTownHandler;
|
||||||
class CGeneralTextHandler;
|
class CGeneralTextHandler;
|
||||||
class CModHandler;
|
class CModHandler;
|
||||||
|
class CContentHandler;
|
||||||
class IBonusTypeHandler;
|
class IBonusTypeHandler;
|
||||||
class CBonusTypeHandler;
|
class CBonusTypeHandler;
|
||||||
class CTerrainViewPatternConfig;
|
class CTerrainViewPatternConfig;
|
||||||
@ -33,6 +34,9 @@ class DLL_LINKAGE LibClasses
|
|||||||
|
|
||||||
void callWhenDeserializing(); //should be called only by serialize !!!
|
void callWhenDeserializing(); //should be called only by serialize !!!
|
||||||
void makeNull(); //sets all handler pointers to null
|
void makeNull(); //sets all handler pointers to null
|
||||||
|
std::shared_ptr<CContentHandler> getContent() const;
|
||||||
|
void setContent(std::shared_ptr<CContentHandler> content);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool IS_AI_ENABLED; //unused?
|
bool IS_AI_ENABLED; //unused?
|
||||||
|
|
||||||
@ -73,7 +77,16 @@ public:
|
|||||||
{
|
{
|
||||||
h & skillh;
|
h & skillh;
|
||||||
}
|
}
|
||||||
|
if(!h.saving)
|
||||||
|
{
|
||||||
|
//modh will be changed and modh->content will be empty after deserialization
|
||||||
|
auto content = getContent();
|
||||||
h & modh;
|
h & modh;
|
||||||
|
setContent(content);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
h & modh;
|
||||||
|
|
||||||
h & IS_AI_ENABLED;
|
h & IS_AI_ENABLED;
|
||||||
h & bth;
|
h & bth;
|
||||||
if(!h.saving)
|
if(!h.saving)
|
||||||
|
@ -1038,7 +1038,7 @@ void CSpellHandler::update780()
|
|||||||
{
|
{
|
||||||
static_assert(MINIMAL_SERIALIZATION_VERSION < 780, "No longer needed CSpellHandler::update780");
|
static_assert(MINIMAL_SERIALIZATION_VERSION < 780, "No longer needed CSpellHandler::update780");
|
||||||
|
|
||||||
auto spellsContent = VLC->modh->content["spells"];
|
auto spellsContent = (*VLC->modh->content)["spells"];
|
||||||
|
|
||||||
const ContentTypeHandler::ModInfo & coreData = spellsContent.modData.at("core");
|
const ContentTypeHandler::ModInfo & coreData = spellsContent.modData.at("core");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user