mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-18 01:42:38 +01:00
Codechange: make the StringIndex (within a StringTab) a strong type
This commit is contained in:
@@ -30,7 +30,7 @@ ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::S
|
||||
|
||||
/* static */ ScriptErrorType ScriptError::StringToError(StringID internal_string_id)
|
||||
{
|
||||
uint index = GetStringIndex(internal_string_id);
|
||||
StringIndexInTab index = GetStringIndex(internal_string_id);
|
||||
switch (GetStringTab(internal_string_id)) {
|
||||
case TEXT_TAB_NEWGRF_START:
|
||||
case TEXT_TAB_GAMESCRIPT_START:
|
||||
|
||||
@@ -33,7 +33,7 @@ ScriptText::ScriptText(HSQUIRRELVM vm)
|
||||
if (SQ_FAILED(sq_getinteger(vm, 2, &sqstring))) {
|
||||
throw sq_throwerror(vm, "First argument must be a valid StringID");
|
||||
}
|
||||
this->string = sqstring;
|
||||
this->string = StringIndexInTab(sqstring);
|
||||
|
||||
/* The rest of the parameters must be arguments. */
|
||||
for (int i = 0; i < nparam - 1; i++) {
|
||||
@@ -185,7 +185,7 @@ void ScriptText::_FillParamList(ParamList ¶ms, ScriptTextList &seen_texts)
|
||||
static Param dummy = 0;
|
||||
int nb_extra = SCRIPT_TEXT_MAX_PARAMETERS - (int)params.size();
|
||||
for (int i = 0; i < nb_extra; i++)
|
||||
params.emplace_back(-1, i, &dummy);
|
||||
params.emplace_back(StringIndexInTab(-1), i, &dummy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,13 +132,13 @@ private:
|
||||
using Param = std::variant<SQInteger, std::string, ScriptTextRef>;
|
||||
|
||||
struct ParamCheck {
|
||||
StringID owner;
|
||||
StringIndexInTab owner;
|
||||
int idx;
|
||||
Param *param;
|
||||
bool used = false;
|
||||
const char *cmd = nullptr;
|
||||
|
||||
ParamCheck(StringID owner, int idx, Param *param) : owner(owner), idx(idx), param(param) {}
|
||||
ParamCheck(StringIndexInTab owner, int idx, Param *param) : owner(owner), idx(idx), param(param) {}
|
||||
|
||||
void Encode(std::back_insert_iterator<std::string> &output, const char *cmd);
|
||||
};
|
||||
@@ -146,7 +146,7 @@ private:
|
||||
using ParamList = std::vector<ParamCheck>;
|
||||
using ParamSpan = std::span<ParamCheck>;
|
||||
|
||||
StringID string;
|
||||
StringIndexInTab string;
|
||||
std::array<Param, SCRIPT_TEXT_MAX_PARAMETERS> param = {};
|
||||
int paramc = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user