ContentTypeHandler.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 ModDescription;
  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 JsonNode & 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. std::map<std::string, ContentTypeHandler> handlers;
  45. public:
  46. void init();
  47. /// preloads all data from fileList as data from modName.
  48. bool preloadData(const ModDescription & mod, bool validateMod);
  49. /// actually loads data in mod
  50. bool load(const ModDescription & mod, bool validateMod);
  51. void loadCustom();
  52. /// all data was loaded, time for final validation / integration
  53. void afterLoadFinalization();
  54. const ContentTypeHandler & operator[] (const std::string & name) const;
  55. };
  56. VCMI_LIB_NAMESPACE_END