13#include "api/script_object.hpp"
18#include "table/strings.h"
24 if (
name.has_value()) {
25 this->name =
name.value();
30 this->version = (
info ==
nullptr) ? -1 :
info->GetVersion();
37ScriptConfig::ScriptConfig(
const ScriptConfig &config)
44 for (
const auto &item : config.
settings) {
45 this->
settings[item.first] = item.second;
62 if (this->
info !=
nullptr)
return this->
info->GetConfigList();
64 this->
config_list = std::make_unique<ScriptConfigItemList>();
78 this->
SetSetting(item.name, this->GetSetting(item.name));
86 if (it == this->
settings.end())
return this->
info->GetSettingDefaultValue(
name);
93 if (this->
info ==
nullptr)
return;
96 if (config_item ==
nullptr)
return;
112 for (SettingValueList::iterator it = this->
settings.begin(); it != this->settings.end();) {
114 assert(config_item !=
nullptr);
119 if (editable && visible) {
129 return this->
info !=
nullptr;
144 std::string_view to_process = value;
147 size_t pos = to_process.find_first_of(
'=');
148 if (pos == std::string_view::npos)
return;
150 std::string_view item_name = to_process.substr(0, pos);
152 to_process.remove_prefix(pos + 1);
153 pos = to_process.find_first_of(
',');
155 std::from_chars(to_process.data(), to_process.data() + std::min(pos, to_process.size()), item_value);
159 if (pos == std::string_view::npos)
return;
160 to_process.remove_prefix(pos + 1);
166 if (this->
settings.empty())
return {};
169 for (
const auto &item : this->
settings) {
170 format_append(result,
"{}={},", item.first, item.second);
174 result.resize(result.size() - 1);
180 if (slot == CompanyID::Invalid() || this->
GetInfo() ==
nullptr)
return std::nullopt;
185void ScriptConfig::SetToLoadData(ScriptInstance::ScriptData *data)
190ScriptInstance::ScriptData *ScriptConfig::GetToLoadData()
195static std::pair<StringParameter, StringParameter> GetValueParams(
const ScriptConfigItem &config_item,
int value)
199 auto it = config_item.
labels.find(value);
200 if (it != std::end(config_item.
labels))
return {STR_JUST_RAW_STRING, it->second};
202 return {STR_JUST_INT, value};
212 auto [param1, param2] = GetValueParams(*
this, value);
224 return this->
description.empty() ? TC_ORANGE : TC_LIGHT_BLUE;
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
SettingValueList settings
List with all setting=>value pairs that are configure for this Script.
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
void AnchorUnchangeableSettings()
As long as the default of a setting has not been changed, the value of the setting is not stored.
bool HasScript() const
Is this config attached to an Script?
void SetSetting(std::string_view name, int value)
Set the value of a setting for this config.
void Change(std::optional< std::string_view > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
void StringToSettings(std::string_view value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
virtual ~ScriptConfig()
Delete an Script configuration.
int version
Version of the Script.
virtual ScriptInfo * FindInfo(const std::string &name, int version, bool force_exact_match)=0
This function should call back to the Scanner in charge of this Config, to find the ScriptInfo belong...
const std::string & GetName() const
Get the name of the Script.
class ScriptInfo * info
ScriptInfo object for related to this Script version.
std::unique_ptr< ScriptConfigItemList > config_list
List with all settings defined by this Script.
int GetVersion() const
Get the version of the Script.
void ClearConfigList()
Routine that clears the config list.
std::unique_ptr< ScriptInstance::ScriptData > to_load_data
Data to load after the Script start.
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
void ResetSettings()
Reset all settings to their default value.
std::string name
Name of the Script.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
All static information from an Script like name, version, etc.
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
@ AI_DIR
Subdirectory for all AI files.
@ GAME_DIR
Subdirectory for all game scripts.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
A number of safeguards to prevent using unsafe methods.
std::vector< ScriptConfigItem > ScriptConfigItemList
List of ScriptConfig items.
@ Boolean
This value is a boolean (either 0 (false) or 1 (true) ).
@ Developer
This setting will only be visible when the Script development tools are active.
@ InGame
This setting can be changed while the Script is running.
ScriptInfo keeps track of all information of a script, like Author, Description, ....
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
Info about a single Script setting.
ScriptConfigFlags flags
Flags for the configuration setting.
std::string GetString(int value) const
Get string to display this setting in the configuration interface.
LabelMapping labels
Text labels for the integer values.
int min_value
The minimal value this configuration setting can have.
int max_value
The maximal value this configuration setting can have.
std::string description
The description of the configuration setting.
TextColour GetColour() const
Get text colour to display this setting in the configuration interface.
GUI functions related to textfiles.
TextfileType
Additional text files accompanying Tar archives.