mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: [Script] Merge the 3 ScriptText param arrays
This commit is contained in:
parent
af15dca316
commit
a1fc4d5c0e
|
@ -56,8 +56,7 @@ ScriptText::ScriptText(HSQUIRRELVM vm) :
|
|||
ScriptText::~ScriptText()
|
||||
{
|
||||
for (int i = 0; i < SCRIPT_TEXT_MAX_PARAMETERS; i++) {
|
||||
free(this->params[i]);
|
||||
if (this->paramt[i] != nullptr) this->paramt[i]->Release();
|
||||
if (std::holds_alternative<ScriptText *>(this->param[i])) std::get<ScriptText *>(this->param[i])->Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,20 +64,14 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
|||
{
|
||||
if (parameter >= SCRIPT_TEXT_MAX_PARAMETERS) return SQ_ERROR;
|
||||
|
||||
free(this->params[parameter]);
|
||||
if (this->paramt[parameter] != nullptr) this->paramt[parameter]->Release();
|
||||
|
||||
this->parami[parameter] = 0;
|
||||
this->params[parameter] = nullptr;
|
||||
this->paramt[parameter] = nullptr;
|
||||
if (std::holds_alternative<ScriptText *>(this->param[parameter])) std::get<ScriptText *>(this->param[parameter])->Release();
|
||||
|
||||
switch (sq_gettype(vm, -1)) {
|
||||
case OT_STRING: {
|
||||
const SQChar *value;
|
||||
sq_getstring(vm, -1, &value);
|
||||
|
||||
this->params[parameter] = stredup(value);
|
||||
StrMakeValidInPlace(this->params[parameter]);
|
||||
this->param[parameter] = StrMakeValid(value);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -86,7 +79,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
|||
SQInteger value;
|
||||
sq_getinteger(vm, -1, &value);
|
||||
|
||||
this->parami[parameter] = value;
|
||||
this->param[parameter] = value;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -110,7 +103,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
|
|||
|
||||
ScriptText *value = static_cast<ScriptText *>(real_instance);
|
||||
value->AddRef();
|
||||
this->paramt[parameter] = value;
|
||||
this->param[parameter] = value;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -186,17 +179,17 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
|||
p += Utf8Encode(p, SCC_ENCODED);
|
||||
p += seprintf(p, lastofp, "%X", this->string);
|
||||
for (int i = 0; i < this->paramc; i++) {
|
||||
if (this->params[i] != nullptr) {
|
||||
p += seprintf(p, lastofp, ":\"%s\"", this->params[i]);
|
||||
if (std::holds_alternative<std::string>(this->param[i])) {
|
||||
p += seprintf(p, lastofp, ":\"%s\"", std::get<std::string>(this->param[i]).c_str());
|
||||
param_count++;
|
||||
continue;
|
||||
}
|
||||
if (this->paramt[i] != nullptr) {
|
||||
if (std::holds_alternative<ScriptText *>(this->param[i])) {
|
||||
p += seprintf(p, lastofp, ":");
|
||||
p = this->paramt[i]->_GetEncodedText(p, lastofp, param_count);
|
||||
p = std::get<ScriptText *>(this->param[i])->_GetEncodedText(p, lastofp, param_count);
|
||||
continue;
|
||||
}
|
||||
p += seprintf(p, lastofp,":" OTTD_PRINTFHEX64, this->parami[i]);
|
||||
p += seprintf(p, lastofp, ":" OTTD_PRINTFHEX64, std::get<SQInteger>(this->param[i]));
|
||||
param_count++;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include "script_object.hpp"
|
||||
#include "../../core/alloc_type.hpp"
|
||||
|
||||
#include <variant>
|
||||
|
||||
/**
|
||||
* Internal parent object of all Text-like objects.
|
||||
* @api -all
|
||||
|
@ -128,9 +130,7 @@ public:
|
|||
|
||||
private:
|
||||
StringID string;
|
||||
char *params[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||
int64 parami[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||
ScriptText *paramt[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||
std::variant<SQInteger, std::string, ScriptText *> param[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||
int paramc;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue