ContentTypeHandler.h 1.9 KB

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