Codechange: use std::optional<std::string> for changing the script over char *
This commit is contained in:
@@ -17,10 +17,14 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
void ScriptConfig::Change(const char *name, int version, bool force_exact_match, bool is_random)
|
||||
void ScriptConfig::Change(std::optional<const std::string> name, int version, bool force_exact_match, bool is_random)
|
||||
{
|
||||
this->name = (name == nullptr) ? "" : name;
|
||||
this->info = (name == nullptr) ? nullptr : this->FindInfo(this->name, version, force_exact_match);
|
||||
if (name.has_value()) {
|
||||
this->name = std::move(name.value());
|
||||
this->info = this->FindInfo(this->name, version, force_exact_match);
|
||||
} else {
|
||||
this->info = nullptr;
|
||||
}
|
||||
this->version = (info == nullptr) ? -1 : info->GetVersion();
|
||||
this->is_random = is_random;
|
||||
this->config_list.reset();
|
||||
|
@@ -83,7 +83,7 @@ public:
|
||||
* as specified. If false any compatible version is ok.
|
||||
* @param is_random Is the Script chosen randomly?
|
||||
*/
|
||||
void Change(const char *name, int version = -1, bool force_exact_match = false, bool is_random = false);
|
||||
void Change(std::optional<const std::string> name, int version = -1, bool force_exact_match = false, bool is_random = false);
|
||||
|
||||
/**
|
||||
* Get the ScriptInfo linked to this ScriptConfig.
|
||||
|
@@ -172,7 +172,7 @@ struct ScriptListWindow : public Window {
|
||||
void ChangeScript()
|
||||
{
|
||||
if (this->selected == -1) {
|
||||
GetConfig(slot)->Change(nullptr);
|
||||
GetConfig(slot)->Change(std::nullopt);
|
||||
} else {
|
||||
ScriptInfoList::const_iterator it = this->info_list->cbegin();
|
||||
std::advance(it, this->selected);
|
||||
|
Reference in New Issue
Block a user