Codechange: use std::string for text file name resolution
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user