Script: Move old-style/lenient text param encode to separate function
This commit is contained in:
@@ -182,16 +182,8 @@ void ScriptText::_TextParamError(std::string msg)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output, int ¶m_count, StringIDList &seen_ids)
|
||||
void ScriptText::_GetEncodedTextParamsTraditional(std::back_insert_iterator<std::string> &output, int ¶m_count, StringIDList &seen_ids, const std::string &name)
|
||||
{
|
||||
const std::string &name = GetGameStringName(this->string);
|
||||
|
||||
if (std::find(seen_ids.begin(), seen_ids.end(), this->string) != seen_ids.end()) throw Script_FatalError(fmt::format("{}: Circular reference detected", name));
|
||||
seen_ids.push_back(this->string);
|
||||
|
||||
Utf8Encode(output, SCC_ENCODED);
|
||||
fmt::format_to(output, "{:X}", this->string);
|
||||
|
||||
auto write_param_fallback = [&](int idx) {
|
||||
if (std::holds_alternative<ScriptTextRef>(this->param[idx])) {
|
||||
int count = 1; // 1 because the string id is included in consumed parameters
|
||||
@@ -210,9 +202,6 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
|
||||
|
||||
const StringParams ¶ms = GetGameStringParams(this->string);
|
||||
int cur_idx = 0;
|
||||
int prev_string = -1;
|
||||
int prev_idx = -1;
|
||||
int prev_count = -1;
|
||||
|
||||
for (const StringParam &cur_param : params) {
|
||||
if (cur_idx >= this->paramc) {
|
||||
@@ -220,7 +209,6 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
|
||||
break;
|
||||
}
|
||||
|
||||
if (this->GetActiveInstance()->IsTextParamMismatchAllowed()) {
|
||||
switch (cur_param.type) {
|
||||
case StringParam::RAW_STRING:
|
||||
if (!std::holds_alternative<std::string>(this->param[cur_idx])) {
|
||||
@@ -263,7 +251,38 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
for (int i = cur_idx; i < this->paramc; i++) {
|
||||
write_param_fallback(i);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output, int ¶m_count, StringIDList &seen_ids)
|
||||
{
|
||||
const std::string &name = GetGameStringName(this->string);
|
||||
|
||||
if (std::find(seen_ids.begin(), seen_ids.end(), this->string) != seen_ids.end()) throw Script_FatalError(fmt::format("{}: Circular reference detected", name));
|
||||
seen_ids.push_back(this->string);
|
||||
|
||||
Utf8Encode(output, SCC_ENCODED);
|
||||
fmt::format_to(output, "{:X}", this->string);
|
||||
|
||||
if (this->GetActiveInstance()->IsTextParamMismatchAllowed()) {
|
||||
this->_GetEncodedTextParamsTraditional(output, param_count, seen_ids, name);
|
||||
seen_ids.pop_back();
|
||||
return;
|
||||
}
|
||||
|
||||
const StringParams ¶ms = GetGameStringParams(this->string);
|
||||
int cur_idx = 0;
|
||||
int prev_string = -1;
|
||||
int prev_idx = -1;
|
||||
int prev_count = -1;
|
||||
|
||||
for (const StringParam &cur_param : params) {
|
||||
if (cur_idx >= this->paramc) throw Script_FatalError(fmt::format("{}: Not enough parameters", name));
|
||||
|
||||
if (prev_string != -1) {
|
||||
/* The previous substring added more parameters than expected, means we will consume them but can't properly validate them. */
|
||||
for (int i = 0; i < cur_param.consumes; i++) {
|
||||
@@ -314,13 +333,8 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this->GetActiveInstance()->IsTextParamMismatchAllowed()) {
|
||||
for (int i = cur_idx; i < this->paramc; i++) {
|
||||
write_param_fallback(i);
|
||||
}
|
||||
param_count += cur_param.consumes;
|
||||
}
|
||||
|
||||
seen_ids.pop_back();
|
||||
|
@@ -136,6 +136,7 @@ private:
|
||||
int paramc;
|
||||
|
||||
void _TextParamError(std::string msg);
|
||||
void _GetEncodedTextParamsTraditional(std::back_insert_iterator<std::string> &output, int ¶m_count, StringIDList &seen_ids, const std::string &name);
|
||||
|
||||
/**
|
||||
* Internal function for recursive calling this function over multiple
|
||||
|
Reference in New Issue
Block a user