ContentTypeHandler.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * ContentTypeHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../json/JsonNode.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class IHandlerBase;
  14. class CModInfo;
  15. /// internal type to handle loading of one data type (e.g. artifacts, creatures)
  16. class DLL_LINKAGE ContentTypeHandler
  17. {
  18. public:
  19. struct ModInfo
  20. {
  21. /// mod data from this mod and for this mod
  22. JsonNode modData;
  23. /// mod data for this mod from other mods (patches)
  24. JsonNode patches;
  25. };
  26. /// handler to which all data will be loaded
  27. IHandlerBase * handler;
  28. std::string objectName;
  29. /// contains all loaded H3 data
  30. std::vector<JsonNode> originalData;
  31. std::map<std::string, ModInfo> modData;
  32. ContentTypeHandler(IHandlerBase * handler, const std::string & objectName);
  33. /// local version of methods in ContentHandler
  34. /// returns true if loading was successful
  35. bool preloadModData(const std::string & modName, const JsonNode & fileList, bool validate);
  36. bool loadMod(const std::string & modName, bool validate);
  37. void loadCustom();
  38. void afterLoadFinalization();
  39. };
  40. /// class used to load all game data into handlers. Used only during loading
  41. class DLL_LINKAGE CContentHandler
  42. {
  43. /// preloads all data from fileList as data from modName.
  44. bool preloadModData(const std::string & modName, JsonNode modConfig, bool validate);
  45. /// actually loads data in mod
  46. bool loadMod(const std::string & modName, bool validate);
  47. std::map<std::string, ContentTypeHandler> handlers;
  48. public:
  49. void init();
  50. /// preloads all data from fileList as data from modName.
  51. void preloadData(CModInfo & mod);
  52. /// actually loads data in mod
  53. void load(CModInfo & mod);
  54. void loadCustom();
  55. /// all data was loaded, time for final validation / integration
  56. void afterLoadFinalization();
  57. const ContentTypeHandler & operator[] (const std::string & name) const;
  58. };
  59. VCMI_LIB_NAMESPACE_END