map_settings_manager.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include "settings.h"
  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(const std::string &map_meta_path);
  39. ~MapSettingsManager();
  40. // Finalized map generation parameters
  41. MapgenParams *mapgen_params = nullptr;
  42. bool getMapSetting(const std::string &name, std::string *value_out) const;
  43. bool getMapSettingNoiseParams(const std::string &name,
  44. NoiseParams *value_out) const;
  45. // Note: Map config becomes read-only after makeMapgenParams() gets called
  46. // (i.e. mapgen_params is non-NULL). Attempts to set map config after
  47. // params have been finalized will result in failure.
  48. bool setMapSetting(const std::string &name,
  49. const std::string &value, bool override_meta = false);
  50. bool setMapSettingNoiseParams(const std::string &name,
  51. const NoiseParams *value, bool override_meta = false);
  52. bool loadMapMeta();
  53. bool saveMapMeta();
  54. MapgenParams *makeMapgenParams();
  55. private:
  56. std::string m_map_meta_path;
  57. SettingsHierarchy m_hierarchy;
  58. Settings *m_defaults;
  59. Settings *m_map_settings;
  60. };