Add scriptstring value callback to weapon loading of t6

This commit is contained in:
Jan
2020-10-23 12:52:44 +02:00
parent 068add0eef
commit 6cca45fc26
6 changed files with 61 additions and 40 deletions

View File

@ -1,11 +1,14 @@
#include "AssetDumperWeapon.h"
#include <cassert>
#include <sstream>
#include "Game/T6/InfoStringT6.h"
using namespace T6;
const std::string AssetDumperWeapon::EMPTY_STRING;
cspField_t AssetDumperWeapon::weapon_fields[]
{
{"displayName", offsetof(WeaponFullDef, weapVariantDef.szDisplayName), CSPFT_STRING},
@ -1445,8 +1448,8 @@ namespace T6
}
public:
InfoStringFromWeaponConverter(const WeaponFullDef* structure, const cspField_t* fields, const size_t fieldCount)
: InfoStringFromStructConverter(structure, fields, fieldCount)
InfoStringFromWeaponConverter(const WeaponFullDef* structure, const cspField_t* fields, const size_t fieldCount, std::function<const std::string&(scr_string_t)> scriptStringValueCallback)
: InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback))
{
}
};
@ -1585,7 +1588,14 @@ void AssetDumperWeapon::DumpAsset(Zone* zone, XAssetInfo<WeaponVariantDef>* asse
memset(fullDef, 0, sizeof WeaponFullDef);
CopyToFullDef(asset->Asset(), fullDef);
InfoStringFromWeaponConverter converter(fullDef, weapon_fields, _countof(weapon_fields));
InfoStringFromWeaponConverter converter(fullDef, weapon_fields, _countof(weapon_fields), [asset](const scr_string_t scrStr) -> const std::string&
{
if (scrStr >= asset->m_script_strings.size())
return EMPTY_STRING;
return asset->m_script_strings[scrStr];
});
const auto infoString = converter.Convert();
const auto stringValue = infoString.ToString("WEAPONFILE");
out->Write(stringValue.c_str(), 1, stringValue.length());

View File

@ -7,6 +7,7 @@ namespace T6
{
class AssetDumperWeapon final : public AbstractAssetDumper<WeaponVariantDef>
{
static const std::string EMPTY_STRING;
static cspField_t weapon_fields[];
void CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef) const;