map_settings_manager.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include <string>
  18. class Settings;
  19. struct NoiseParams;
  20. struct MapgenParams;
  21. /*
  22. MapSettingsManager is a centralized object for management (creating,
  23. loading, storing, saving, etc.) of config settings related to the Map.
  24. It has two phases: the initial r/w "gather and modify settings" state, and
  25. the final r/o "read and save settings" state.
  26. The typical use case is, in order, as follows:
  27. - Create a MapSettingsManager object
  28. - Try to load map metadata into it from the metadata file
  29. - Manually view and modify the current configuration as desired through a
  30. Settings-like interface
  31. - When all modifications are finished, create a 'Parameters' object
  32. containing the finalized, active parameters. This could be passed along
  33. to whichever Map-related objects that may require it.
  34. - Save these active settings to the metadata file when requested
  35. */
  36. class MapSettingsManager {
  37. public:
  38. MapSettingsManager(Settings *user_settings,
  39. const std::string &map_meta_path);
  40. ~MapSettingsManager();
  41. // Finalized map generation parameters
  42. MapgenParams *mapgen_params = nullptr;
  43. bool getMapSetting(const std::string &name, std::string *value_out);
  44. bool getMapSettingNoiseParams(
  45. const std::string &name, NoiseParams *value_out);
  46. // Note: Map config becomes read-only after makeMapgenParams() gets called
  47. // (i.e. mapgen_params is non-NULL). Attempts to set map config after
  48. // params have been finalized will result in failure.
  49. bool setMapSetting(const std::string &name,
  50. const std::string &value, bool override_meta = false);
  51. bool setMapSettingNoiseParams(const std::string &name,
  52. const NoiseParams *value, bool override_meta = false);
  53. bool loadMapMeta();
  54. bool saveMapMeta();
  55. MapgenParams *makeMapgenParams();
  56. private:
  57. std::string m_map_meta_path;
  58. Settings *m_map_settings;
  59. Settings *m_user_settings;
  60. };