mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-30 18:09:09 +00:00
Codechange: use std::string for getting a script's name
This commit is contained in:
@@ -48,9 +48,9 @@ AIScannerInfo::~AIScannerInfo()
|
||||
delete this->info_dummy;
|
||||
}
|
||||
|
||||
void AIScannerInfo::GetScriptName(ScriptInfo *info, char *name, const char *last)
|
||||
std::string AIScannerInfo::GetScriptName(ScriptInfo *info)
|
||||
{
|
||||
seprintf(name, last, "%s", info->GetName());
|
||||
return info->GetName();
|
||||
}
|
||||
|
||||
void AIScannerInfo::RegisterAPI(class Squirrel *engine)
|
||||
@@ -138,10 +138,10 @@ void AIScannerLibrary::Initialize()
|
||||
ScriptScanner::Initialize("AIScanner");
|
||||
}
|
||||
|
||||
void AIScannerLibrary::GetScriptName(ScriptInfo *info, char *name, const char *last)
|
||||
std::string AIScannerLibrary::GetScriptName(ScriptInfo *info)
|
||||
{
|
||||
AILibrary *library = static_cast<AILibrary *>(info);
|
||||
seprintf(name, last, "%s.%s", library->GetCategory(), library->GetInstanceName());
|
||||
return fmt::format("{}.{}", library->GetCategory(), library->GetInstanceName());
|
||||
}
|
||||
|
||||
void AIScannerLibrary::RegisterAPI(class Squirrel *engine)
|
||||
|
@@ -40,7 +40,7 @@ public:
|
||||
void SetDummyAI(class AIInfo *info);
|
||||
|
||||
protected:
|
||||
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
const char *GetFileName() const override { return PATHSEP "info.nut"; }
|
||||
Subdirectory GetDirectory() const override { return AI_DIR; }
|
||||
const char *GetScannerName() const override { return "AIs"; }
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
class AILibrary *FindLibrary(const char *library, int version);
|
||||
|
||||
protected:
|
||||
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
const char *GetFileName() const override { return PATHSEP "library.nut"; }
|
||||
Subdirectory GetDirectory() const override { return AI_LIBRARY_DIR; }
|
||||
const char *GetScannerName() const override { return "AI Libraries"; }
|
||||
|
@@ -13,6 +13,8 @@
|
||||
#include "game_info.hpp"
|
||||
#include "game_scanner.hpp"
|
||||
|
||||
#include "../3rdparty/fmt/format.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
|
||||
@@ -21,9 +23,9 @@ void GameScannerInfo::Initialize()
|
||||
ScriptScanner::Initialize("GSScanner");
|
||||
}
|
||||
|
||||
void GameScannerInfo::GetScriptName(ScriptInfo *info, char *name, const char *last)
|
||||
std::string GameScannerInfo::GetScriptName(ScriptInfo *info)
|
||||
{
|
||||
seprintf(name, last, "%s", info->GetName());
|
||||
return info->GetName();
|
||||
}
|
||||
|
||||
void GameScannerInfo::RegisterAPI(class Squirrel *engine)
|
||||
@@ -77,10 +79,10 @@ void GameScannerLibrary::Initialize()
|
||||
ScriptScanner::Initialize("GSScanner");
|
||||
}
|
||||
|
||||
void GameScannerLibrary::GetScriptName(ScriptInfo *info, char *name, const char *last)
|
||||
std::string GameScannerLibrary::GetScriptName(ScriptInfo *info)
|
||||
{
|
||||
GameLibrary *library = static_cast<GameLibrary *>(info);
|
||||
seprintf(name, last, "%s.%s", library->GetCategory(), library->GetInstanceName());
|
||||
return fmt::format("{}.{}", library->GetCategory(), library->GetInstanceName());
|
||||
}
|
||||
|
||||
void GameScannerLibrary::RegisterAPI(class Squirrel *engine)
|
||||
|
@@ -26,7 +26,7 @@ public:
|
||||
class GameInfo *FindInfo(const char *nameParam, int versionParam, bool force_exact_match);
|
||||
|
||||
protected:
|
||||
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
const char *GetFileName() const override { return PATHSEP "info.nut"; }
|
||||
Subdirectory GetDirectory() const override { return GAME_DIR; }
|
||||
const char *GetScannerName() const override { return "Game Scripts"; }
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
class GameLibrary *FindLibrary(const char *library, int version);
|
||||
|
||||
protected:
|
||||
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
const char *GetFileName() const override { return PATHSEP "library.nut"; }
|
||||
Subdirectory GetDirectory() const override { return GAME_LIBRARY_DIR; }
|
||||
const char *GetScannerName() const override { return "GS Libraries"; }
|
||||
|
@@ -97,12 +97,8 @@ void ScriptScanner::Reset()
|
||||
|
||||
void ScriptScanner::RegisterScript(ScriptInfo *info)
|
||||
{
|
||||
char script_original_name[1024];
|
||||
this->GetScriptName(info, script_original_name, lastof(script_original_name));
|
||||
strtolower(script_original_name);
|
||||
|
||||
char script_name[1024];
|
||||
seprintf(script_name, lastof(script_name), "%s.%d", script_original_name, info->GetVersion());
|
||||
std::string script_original_name = this->GetScriptName(info);
|
||||
std::string script_name = fmt::format("{}.{}", script_original_name, info->GetVersion());
|
||||
|
||||
/* Check if GetShortName follows the rules */
|
||||
if (strlen(info->GetShortName()) != 4) {
|
||||
|
@@ -99,7 +99,7 @@ protected:
|
||||
/**
|
||||
* Get the script name how to store the script in memory.
|
||||
*/
|
||||
virtual void GetScriptName(ScriptInfo *info, char *name, const char *last) = 0;
|
||||
virtual std::string GetScriptName(ScriptInfo *info) = 0;
|
||||
|
||||
/**
|
||||
* Get the filename to scan for this type of script.
|
||||
|
Reference in New Issue
Block a user