ContentTypeHandler.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. bool validateMod(const CModInfo & mod) const;
  50. public:
  51. void init();
  52. /// preloads all data from fileList as data from modName.
  53. void preloadData(CModInfo & mod);
  54. /// actually loads data in mod
  55. void load(CModInfo & mod);
  56. void loadCustom();
  57. /// all data was loaded, time for final validation / integration
  58. void afterLoadFinalization();
  59. const ContentTypeHandler & operator[] (const std::string & name) const;
  60. };
  61. VCMI_LIB_NAMESPACE_END