ContentTypeHandler.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. JsonNode conflictList;
  19. public:
  20. struct ModInfo
  21. {
  22. /// mod data from this mod and for this mod
  23. JsonNode modData;
  24. /// mod data for this mod from other mods (patches)
  25. JsonNode patches;
  26. };
  27. /// handler to which all data will be loaded
  28. IHandlerBase * handler;
  29. std::string entityName;
  30. /// contains all loaded H3 data
  31. std::vector<JsonNode> originalData;
  32. std::map<std::string, ModInfo> modData;
  33. ContentTypeHandler(IHandlerBase * handler, const std::string & objectName);
  34. /// local version of methods in ContentHandler
  35. /// returns true if loading was successful
  36. bool preloadModData(const std::string & modName, const std::vector<std::string> & fileList, bool validate);
  37. bool loadMod(const std::string & modName, bool validate);
  38. void loadCustom();
  39. void afterLoadFinalization();
  40. };
  41. /// class used to load all game data into handlers. Used only during loading
  42. class DLL_LINKAGE CContentHandler
  43. {
  44. /// preloads all data from fileList as data from modName.
  45. bool preloadModData(const std::string & modName, JsonNode modConfig, bool validate);
  46. /// actually loads data in mod
  47. bool loadMod(const std::string & modName, bool validate);
  48. std::map<std::string, ContentTypeHandler> handlers;
  49. public:
  50. void init();
  51. /// preloads all data from fileList as data from modName.
  52. void preloadData(CModInfo & mod);
  53. /// actually loads data in mod
  54. void load(CModInfo & mod);
  55. void loadCustom();
  56. /// all data was loaded, time for final validation / integration
  57. void afterLoadFinalization();
  58. const ContentTypeHandler & operator[] (const std::string & name) const;
  59. };
  60. VCMI_LIB_NAMESPACE_END