Change: [Script] Extract params info from GS strings

This commit is contained in:
glx22
2023-02-18 00:52:22 +01:00
committed by Loïc Guilloux
parent 6e52ceab96
commit af15dca316
4 changed files with 77 additions and 13 deletions

View File

@@ -19,6 +19,7 @@
#include "game_info.hpp"
#include "table/strings.h"
#include "table/strgen_tables.h"
#include <stdarg.h>
#include <memory>
@@ -273,6 +274,31 @@ GameStrings *LoadTranslations()
}
}
static StringParam::ParamType GetParamType(const CmdStruct *cs)
{
if (cs->value == SCC_RAW_STRING_POINTER) return StringParam::RAW_STRING;
if (cs->value == SCC_STRING || cs != TranslateCmdForCompare(cs)) return StringParam::STRING;
return StringParam::OTHER;
}
static void ExtractStringParams(const StringData &data, StringParamsList &params)
{
for (size_t i = 0; i < data.max_strings; i++) {
const LangString *ls = data.strings[i];
if (ls != nullptr) {
StringParams &param = params.emplace_back();
ParsedCommandStruct pcs;
ExtractCommandString(&pcs, ls->english, false);
for (const CmdStruct *cs : pcs.cmd) {
if (cs == nullptr) break;
param.emplace_back(GetParamType(cs), cs->consumes);
}
}
}
}
/** Compile the language. */
void GameStrings::Compile()
{
@@ -283,6 +309,8 @@ void GameStrings::Compile()
this->version = data.Version();
ExtractStringParams(data, this->string_params);
StringNameWriter id_writer(this->string_names);
id_writer.WriteHeader(data);
@@ -312,6 +340,20 @@ const char *GetGameStringPtr(uint id)
return _current_data->cur_language->lines[id].c_str();
}
/**
* Get the string parameters of a particular game string.
* @param id The ID of the game string.
* @return The string parameters.
*/
const StringParams &GetGameStringParams(uint id)
{
/* An empty result for STR_UNDEFINED. */
static StringParams empty;
if (id >= _current_data->string_params.size()) return empty;
return _current_data->string_params[id];
}
/**
* Register the current translation to the Squirrel engine.
* @param engine The engine to update/