Codechange: use std::string for text file name resolution

This commit is contained in:
Rubidium
2023-05-05 00:04:52 +02:00
committed by rubidium42
parent 0b72297d57
commit 877349c13d
15 changed files with 56 additions and 58 deletions

View File

@@ -234,9 +234,9 @@ std::string ScriptConfig::SettingsToString() const
return string;
}
const char *ScriptConfig::GetTextfile(TextfileType type, CompanyID slot) const
std::optional<std::string> ScriptConfig::GetTextfile(TextfileType type, CompanyID slot) const
{
if (slot == INVALID_COMPANY || this->GetInfo() == nullptr) return nullptr;
if (slot == INVALID_COMPANY || this->GetInfo() == nullptr) return std::nullopt;
return ::GetTextfile(type, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR, this->GetInfo()->GetMainScript());
}

View File

@@ -184,9 +184,9 @@ public:
* Search a textfile file next to this script.
* @param type The type of the textfile to search for.
* @param slot #CompanyID to check status of.
* @return The filename for the textfile, \c nullptr otherwise.
* @return The filename for the textfile.
*/
const char *GetTextfile(TextfileType type, CompanyID slot) const;
std::optional<std::string> GetTextfile(TextfileType type, CompanyID slot) const;
void SetToLoadData(ScriptInstance::ScriptData *data);
ScriptInstance::ScriptData *GetToLoadData();

View File

@@ -643,11 +643,11 @@ struct ScriptTextfileWindow : public TextfileWindow {
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
const char *textfile = GetConfig(slot)->GetTextfile(file_type, slot);
if (textfile == nullptr) {
auto textfile = GetConfig(slot)->GetTextfile(file_type, slot);
if (!textfile.has_value()) {
this->Close();
} else {
this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
this->LoadTextfile(textfile.value(), (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
}
}
};