Files
vcmi/lib/VCMI_Lib.h
T

159 lines
4.0 KiB
C++
Raw Normal View History

/*
* VCMI_Lib.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
2009-04-16 11:14:13 +00:00
*/
#pragma once
2009-04-16 11:14:13 +00:00
2018-03-17 17:58:30 +03:00
#include <vcmi/Services.h>
VCMI_LIB_NAMESPACE_BEGIN
2017-08-11 20:03:05 +03:00
class CConsoleHandler;
2009-04-16 11:14:13 +00:00
class CArtHandler;
class CHeroHandler;
class CCreatureHandler;
class CSpellHandler;
class CSkillHandler;
2009-04-16 11:14:13 +00:00
class CBuildingHandler;
class CObjectHandler;
class CObjectClassesHandler;
2009-04-16 11:14:13 +00:00
class CTownHandler;
class CGeneralTextHandler;
class CModHandler;
class CContentHandler;
class BattleFieldHandler;
2013-03-06 18:49:56 +00:00
class IBonusTypeHandler;
class CBonusTypeHandler;
2022-09-21 11:34:23 +02:00
class TerrainTypeHandler;
2022-09-15 12:06:54 +04:00
class ObstacleHandler;
class CTerrainViewPatternConfig;
class CRmgTemplateStorage;
2018-03-17 17:58:30 +03:00
class IHandlerBase;
#if SCRIPTING_ENABLED
2018-03-17 17:58:30 +03:00
namespace scripting
{
class ScriptHandler;
}
#endif
2009-04-16 11:14:13 +00:00
2011-02-22 11:52:36 +00:00
/// Loads and constructs several handlers
2018-03-17 17:58:30 +03:00
class DLL_LINKAGE LibClasses : public Services
2009-04-16 11:14:13 +00:00
{
2013-03-06 18:49:56 +00:00
CBonusTypeHandler * bth;
void callWhenDeserializing(); //should be called only by serialize !!!
void makeNull(); //sets all handler pointers to null
std::shared_ptr<CContentHandler> getContent() const;
void setContent(std::shared_ptr<CContentHandler> content);
2009-04-16 11:14:13 +00:00
public:
2016-11-27 22:07:01 +03:00
bool IS_AI_ENABLED; //unused?
2018-03-17 17:58:30 +03:00
const ArtifactService * artifacts() const override;
const CreatureService * creatures() const override;
const FactionService * factions() const override;
const HeroClassService * heroClasses() const override;
const HeroTypeService * heroTypes() const override;
#if SCRIPTING_ENABLED
2018-03-17 17:58:30 +03:00
const scripting::Service * scripts() const override;
#endif
2018-03-17 17:58:30 +03:00
const spells::Service * spells() const override;
const SkillService * skills() const override;
const BattleFieldService * battlefields() const override;
2022-09-15 12:06:54 +04:00
const ObstacleService * obstacles() const override;
2018-03-17 17:58:30 +03:00
void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
const spells::effects::Registry * spellEffects() const override;
spells::effects::Registry * spellEffects() override;
const IBonusTypeHandler * getBth() const; //deprecated
2009-04-16 11:14:13 +00:00
CArtHandler * arth;
CHeroHandler * heroh;
CCreatureHandler * creh;
CSpellHandler * spellh;
CSkillHandler * skillh;
2009-04-16 11:14:13 +00:00
CObjectHandler * objh;
CObjectClassesHandler * objtypeh;
2009-04-16 11:14:13 +00:00
CTownHandler * townh;
CGeneralTextHandler * generaltexth;
CModHandler * modh;
2022-09-21 11:34:23 +02:00
TerrainTypeHandler * terrainTypeHandler;
CTerrainViewPatternConfig * terviewh;
CRmgTemplateStorage * tplh;
BattleFieldHandler * battlefieldsHandler;
2022-09-15 12:06:54 +04:00
ObstacleHandler * obstacleHandler;
#if SCRIPTING_ENABLED
2018-03-17 17:58:30 +03:00
scripting::ScriptHandler * scriptHandler;
#endif
2009-04-16 11:14:13 +00:00
2009-06-23 08:14:49 +00:00
LibClasses(); //c-tor, loads .lods and NULLs handlers
2012-04-08 01:15:18 +00:00
~LibClasses();
void init(bool onlyEssential); //uses standard config file
2009-04-16 11:14:13 +00:00
void clear(); //deletes all handlers and its data
// basic initialization. should be called before init(). Can also extract original H3 archives
void loadFilesystem(bool onlyEssential, bool extractArchives = false);
2009-04-16 11:14:13 +00:00
#if SCRIPTING_ENABLED
2018-03-17 17:58:30 +03:00
void scriptsLoaded();
#endif
2009-04-16 11:14:13 +00:00
template <typename Handler> void serialize(Handler &h, const int version)
{
#if SCRIPTING_ENABLED
2022-06-20 17:39:50 +03:00
h & scriptHandler;//must be first (or second after modh), it can modify factories other handlers depends on
if(!h.saving)
2018-03-17 17:58:30 +03:00
{
2022-06-20 17:39:50 +03:00
scriptsLoaded();
2018-03-17 17:58:30 +03:00
}
#endif
2018-03-17 17:58:30 +03:00
h & heroh;
h & arth;
h & creh;
h & townh;
h & objh;
h & objtypeh;
h & spellh;
2022-06-20 17:39:50 +03:00
h & skillh;
h & battlefieldsHandler;
2022-09-15 12:06:54 +04:00
h & obstacleHandler;
2022-09-21 11:34:23 +02:00
h & terrainTypeHandler;
if(!h.saving)
{
//modh will be changed and modh->content will be empty after deserialization
auto content = getContent();
h & modh;
setContent(content);
}
else
h & modh;
h & IS_AI_ENABLED;
2013-03-06 18:49:56 +00:00
h & bth;
2018-03-17 17:58:30 +03:00
2009-04-16 11:14:13 +00:00
if(!h.saving)
{
2010-02-12 15:04:01 +00:00
callWhenDeserializing();
2009-04-16 11:14:13 +00:00
}
}
};
extern DLL_LINKAGE LibClasses * VLC;
2009-04-16 11:14:13 +00:00
DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool onlyEssential = false, bool extractArchives = false);
DLL_LINKAGE void loadDLLClasses(bool onlyEssential = false);
VCMI_LIB_NAMESPACE_END