Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
map_settings_manager.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4
5#pragma once
6
7#include <memory>
8#include <string>
9#include "settings.h" // SettingsHierarchy
10
11struct NoiseParams;
12struct MapgenParams;
13
14/*
15 MapSettingsManager is a centralized object for management (creating,
16 loading, storing, saving, etc.) of config settings related to the Map.
17
18 It has two phases: the initial r/w "gather and modify settings" state, and
19 the final r/o "read and save settings" state.
20
21 The typical use case is, in order, as follows:
22 - Create a MapSettingsManager object
23 - Try to load map metadata into it from the metadata file
24 - Manually view and modify the current configuration as desired through a
25 Settings-like interface
26 - When all modifications are finished, create a 'Parameters' object
27 containing the finalized, active parameters. This could be passed along
28 to whichever Map-related objects that may require it.
29 - Save these active settings to the metadata file when requested
30*/
32public:
33 MapSettingsManager(const std::string &map_meta_path);
35
36 // Finalized map generation parameters
38
39 bool getMapSetting(const std::string &name, std::string *value_out) const;
40
41 bool getNoiseParams(const std::string &name,
42 NoiseParams *value_out) const;
43
44 // Note: Map config becomes read-only after makeMapgenParams() gets called
45 // (i.e. mapgen_params is non-NULL). Attempts to set map config after
46 // params have been finalized will result in failure.
47 bool setMapSetting(const std::string &name,
48 const std::string &value, bool override_meta = false);
49
50 bool setMapSettingNoiseParams(const std::string &name,
51 const NoiseParams *value, bool override_meta = false);
52
53 bool loadMapMeta();
54 bool saveMapMeta();
55
60
61private:
62 std::string m_map_meta_path;
63
65 std::unique_ptr<Settings> m_defaults;
66 std::unique_ptr<Settings> m_map_settings;
67};
Definition map_settings_manager.h:31
MapSettingsManager(const std::string &map_meta_path)
Definition map_settings_manager.cpp:12
bool loadMapMeta()
Definition map_settings_manager.cpp:78
bool setMapSetting(const std::string &name, const std::string &value, bool override_meta=false)
Definition map_settings_manager.cpp:48
bool setMapSettingNoiseParams(const std::string &name, const NoiseParams *value, bool override_meta=false)
Definition map_settings_manager.cpp:63
~MapSettingsManager()
Definition map_settings_manager.cpp:28
bool getNoiseParams(const std::string &name, NoiseParams *value_out) const
Definition map_settings_manager.cpp:41
MapgenParams * makeMapgenParams()
Finalizes and creates the mapgen params.
Definition map_settings_manager.cpp:122
MapgenParams * mapgen_params
Definition map_settings_manager.h:37
std::unique_ptr< Settings > m_map_settings
Definition map_settings_manager.h:66
std::string m_map_meta_path
Definition map_settings_manager.h:62
bool getMapSetting(const std::string &name, std::string *value_out) const
Definition map_settings_manager.cpp:34
SettingsHierarchy m_hierarchy
Definition map_settings_manager.h:64
std::unique_ptr< Settings > m_defaults
Definition map_settings_manager.h:65
bool saveMapMeta()
Definition map_settings_manager.cpp:93
MapgenParams * makeMapgenParamsCopy() const
Creates a copy of the mapgen params without making the manager immutable.
Definition map_settings_manager.cpp:134
Definition settings.h:59
Definition mapgen.h:111
Definition noise.h:119