Codechange: make the name of SettingDesc a std::string

This commit is contained in:
rubidium42 2021-05-30 11:51:21 +02:00 committed by rubidium42
parent e588923bff
commit bf500c39c9
6 changed files with 22 additions and 22 deletions

View File

@ -483,14 +483,14 @@ void GamelogOldver()
* @param oldval old setting value
* @param newval new setting value
*/
void GamelogSetting(const char *name, int32 oldval, int32 newval)
void GamelogSetting(const std::string &name, int32 oldval, int32 newval)
{
assert(_gamelog_action_type == GLAT_SETTING);
LoggedChange *lc = GamelogChange(GLCT_SETTING);
if (lc == nullptr) return;
lc->setting.name = stredup(name);
lc->setting.name = stredup(name.c_str());
lc->setting.oldval = oldval;
lc->setting.newval = newval;
}

View File

@ -48,7 +48,7 @@ bool GamelogTestEmergency();
void GamelogRevision();
void GamelogMode();
void GamelogOldver();
void GamelogSetting(const char *name, int32 oldval, int32 newval);
void GamelogSetting(const std::string &name, int32 oldval, int32 newval);
void GamelogGRFUpdate(const GRFConfig *oldg, const GRFConfig *newg);
void GamelogGRFAddList(const GRFConfig *newg);

View File

@ -37,7 +37,7 @@
if ((sd->flags & SF_NO_NETWORK_SYNC) != 0) return false;
return ScriptObject::DoCommand(0, 0, value, CMD_CHANGE_SETTING, sd->name);
return ScriptObject::DoCommand(0, 0, value, CMD_CHANGE_SETTING, sd->name.c_str());
}
/* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type)

View File

@ -1980,13 +1980,13 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
if (sd->IsStringSetting()) {
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, sd->AsStringSetting()->Read(object).c_str());
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", sd->name.c_str(), sd->AsStringSetting()->Read(object).c_str());
} else if (sd->IsIntSetting()) {
char value[20];
sd->FormatValue(value, lastof(value), object);
const IntSettingDesc *int_setting = sd->AsIntSetting();
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)",
name, value, (sd->flags & SF_GUI_0_IS_SPECIAL) ? "(0) " : "", int_setting->min, int_setting->max);
sd->name.c_str(), value, (sd->flags & SF_GUI_0_IS_SPECIAL) ? "(0) " : "", int_setting->min, int_setting->max);
}
}
@ -2001,10 +2001,10 @@ void IConsoleListSettings(const char *prefilter)
for (auto &sd : _settings) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (prefilter != nullptr && strstr(sd->name, prefilter) == nullptr) continue;
if (prefilter != nullptr && sd->name.find(prefilter) == std::string::npos) continue;
char value[80];
sd->FormatValue(value, lastof(value), &GetGameSettings());
IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name, value);
IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name.c_str(), value);
}
IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");

View File

@ -69,11 +69,11 @@ struct IniItem;
/** Properties of config file settings. */
struct SettingDesc {
SettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup) :
SettingDesc(SaveLoad save, const std::string &name, SettingFlag flags, bool startup) :
name(name), flags(flags), startup(startup), save(save) {}
virtual ~SettingDesc() {}
const char *name; ///< Name of the setting. Used in configuration file and for console.
std::string name; ///< Name of the setting. Used in configuration file and for console.
SettingFlag flags; ///< Handles how a setting would show up in the GUI (text/currency, etc.).
bool startup; ///< Setting has to be loaded directly at startup?.
SaveLoad save; ///< Internal structure (going to savegame, parts to config).
@ -140,7 +140,7 @@ struct IntSettingDesc : SettingDesc {
*/
typedef void PostChangeCallback(int32 value);
IntSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def,
IntSettingDesc(SaveLoad save, const std::string &name, SettingFlag flags, bool startup, int32 def,
int32 min, uint32 max, int32 interval, StringID str, StringID str_help, StringID str_val,
SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback) :
SettingDesc(save, name, flags, startup), def(def), min(min), max(max), interval(interval),
@ -182,7 +182,7 @@ private:
/** Boolean setting. */
struct BoolSettingDesc : IntSettingDesc {
BoolSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, bool def,
BoolSettingDesc(SaveLoad save, const std::string &name, SettingFlag flags, bool startup, bool def,
StringID str, StringID str_help, StringID str_val, SettingCategory cat,
PreChangeCheck pre_check, PostChangeCallback post_callback) :
IntSettingDesc(save, name, flags, startup, def, 0, 1, 0, str, str_help, str_val, cat,
@ -198,7 +198,7 @@ struct BoolSettingDesc : IntSettingDesc {
struct OneOfManySettingDesc : IntSettingDesc {
typedef size_t OnConvert(const char *value); ///< callback prototype for conversion error
OneOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def,
OneOfManySettingDesc(SaveLoad save, const std::string &name, SettingFlag flags, bool startup, int32 def,
int32 max, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
PreChangeCheck pre_check, PostChangeCallback post_callback,
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
@ -222,7 +222,7 @@ struct OneOfManySettingDesc : IntSettingDesc {
/** Many of many setting. */
struct ManyOfManySettingDesc : OneOfManySettingDesc {
ManyOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup,
ManyOfManySettingDesc(SaveLoad save, const std::string &name, SettingFlag flags, bool startup,
int32 def, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
PreChangeCheck pre_check, PostChangeCallback post_callback,
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
@ -251,7 +251,7 @@ struct StringSettingDesc : SettingDesc {
*/
typedef void PostChangeCallback(const std::string &value);
StringSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def,
StringSettingDesc(SaveLoad save, const std::string &name, SettingFlag flags, bool startup, const char *def,
uint32 max_length, PreChangeCheck pre_check, PostChangeCallback post_callback) :
SettingDesc(save, name, flags, startup), def(def == nullptr ? "" : def), max_length(max_length),
pre_check(pre_check), post_callback(post_callback) {}
@ -277,7 +277,7 @@ private:
/** List/array settings. */
struct ListSettingDesc : SettingDesc {
ListSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def) :
ListSettingDesc(SaveLoad save, const std::string &name, SettingFlag flags, bool startup, const char *def) :
SettingDesc(save, name, flags, startup), def(def) {}
virtual ~ListSettingDesc() {}
@ -291,7 +291,7 @@ struct ListSettingDesc : SettingDesc {
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
struct NullSettingDesc : SettingDesc {
NullSettingDesc(SaveLoad save) :
SettingDesc(save, "", SF_NOT_IN_CONFIG, false) {}
SettingDesc(save, {}, SF_NOT_IN_CONFIG, false) {}
virtual ~NullSettingDesc() {}
void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }

View File

@ -1002,14 +1002,14 @@ post_cb = MaxVehiclesChanged
cat = SC_BASIC
[SDTG_BOOL]
name = nullptr
name = {}
flags = SF_NO_NETWORK
var = _old_vds.servint_ispercent
def = false
to = SLV_120
[SDTG_VAR]
name = nullptr
name = {}
type = SLE_UINT16
flags = SF_GUI_0_IS_SPECIAL
var = _old_vds.servint_trains
@ -1019,7 +1019,7 @@ max = 800
to = SLV_120
[SDTG_VAR]
name = nullptr
name = {}
type = SLE_UINT16
flags = SF_GUI_0_IS_SPECIAL
var = _old_vds.servint_roadveh
@ -1029,7 +1029,7 @@ max = 800
to = SLV_120
[SDTG_VAR]
name = nullptr
name = {}
type = SLE_UINT16
flags = SF_GUI_0_IS_SPECIAL
var = _old_vds.servint_ships
@ -1039,7 +1039,7 @@ max = 800
to = SLV_120
[SDTG_VAR]
name = nullptr
name = {}
type = SLE_UINT16
flags = SF_GUI_0_IS_SPECIAL
var = _old_vds.servint_aircraft