Codechange: use std::optional<std::string> for changing the script over char *

This commit is contained in:
Rubidium
2023-05-05 21:59:50 +02:00
committed by rubidium42
parent 0fd9eb0faa
commit 9f2fc860ad
9 changed files with 25 additions and 21 deletions

View File

@@ -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();

View File

@@ -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.

View File

@@ -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);