feat: automatically load anims of weapons in t6

This commit is contained in:
Jan
2024-02-06 23:56:31 +01:00
parent 0a13281295
commit 2dd4eaf54f
6 changed files with 171 additions and 134 deletions

View File

@ -227,7 +227,7 @@ namespace T6
{
std::cout << "Cannot have more than "
<< (std::extent_v<decltype(WeaponFullDef::attachmentUniques)> - std::extent_v<decltype(WeaponFullDef::attachments)>)
<< " combined attachment attachment unique entries!" << std::endl;
<< " combined attachment attachment unique entries!\n";
return false;
}
@ -239,15 +239,14 @@ namespace T6
if (static_cast<unsigned>(attachmentUniqueAsset->attachmentType) >= ATTACHMENT_TYPE_COUNT)
{
std::cout << "Invalid attachment type " << attachmentUniqueAsset->attachmentType << " for attachment unique asset \""
<< attachmentUniqueName << "\"" << std::endl;
<< attachmentUniqueName << "\"\n";
return false;
}
if (attachmentUniques[attachmentUniqueAsset->attachmentType] != nullptr)
{
std::cout << "Already loaded attachment unique with same type " << attachmentUniqueAsset->attachmentType << ": \""
<< attachmentUniques[attachmentUniqueAsset->attachmentType]->szInternalName << "\", \"" << attachmentUniqueName << "\""
<< std::endl;
<< attachmentUniques[attachmentUniqueAsset->attachmentType]->szInternalName << "\", \"" << attachmentUniqueName << "\"\n";
return false;
}
@ -259,6 +258,18 @@ namespace T6
return true;
}
bool ConvertAnimName(const cspField_t& field, const std::string& value)
{
if (ConvertString(value, field.iOffset))
{
if (!value.empty())
m_indirect_asset_references.emplace(m_loading_manager->LoadIndirectAssetReference(ASSET_TYPE_XANIMPARTS, value));
return true;
}
return false;
}
protected:
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
{
@ -352,7 +363,9 @@ namespace T6
case WFT_ATTACHMENT_UNIQUES:
return ConvertAttachmentUniques(field, value);
case WFT_NUM_FIELD_TYPES:
case WFT_ANIM_NAME:
return ConvertAnimName(field, value);
default:
assert(false);
return false;
@ -553,7 +566,12 @@ bool AssetLoaderWeapon::LoadFromInfoString(
CalculateWeaponFields(weaponFullDef);
CalculateAttachmentFields(weaponFullDef);
manager->AddAsset(ASSET_TYPE_WEAPON, assetName, &weaponFullDef->weapVariantDef, converter.GetDependencies(), converter.GetUsedScriptStrings());
manager->AddAsset(ASSET_TYPE_WEAPON,
assetName,
&weaponFullDef->weapVariantDef,
converter.GetDependencies(),
converter.GetUsedScriptStrings(),
converter.GetIndirectAssetReferences());
return true;
}

View File

@ -41,7 +41,7 @@ bool InfoStringToStructConverterBase::ParseAsArray(const std::string& value, std
return true;
}
bool InfoStringToStructConverterBase::ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray) const
bool InfoStringToStructConverterBase::ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray)
{
std::string key;
auto isKey = true;
@ -227,6 +227,7 @@ bool InfoStringToStructConverterBase::ConvertEnumInt(const std::string& value, c
std::vector<scr_string_t> InfoStringToStructConverterBase::GetUsedScriptStrings() const
{
std::vector<scr_string_t> scrStringList;
scrStringList.reserve(m_used_script_string_list.size());
for (auto scrStr : m_used_script_string_list)
{
scrStringList.push_back(scrStr);
@ -238,6 +239,7 @@ std::vector<scr_string_t> InfoStringToStructConverterBase::GetUsedScriptStrings(
std::vector<XAssetInfoGeneric*> InfoStringToStructConverterBase::GetDependencies() const
{
std::vector<XAssetInfoGeneric*> dependencyList;
dependencyList.reserve(m_dependencies.size());
for (auto* dependency : m_dependencies)
{
dependencyList.push_back(dependency);
@ -245,3 +247,15 @@ std::vector<XAssetInfoGeneric*> InfoStringToStructConverterBase::GetDependencies
return dependencyList;
}
std::vector<IndirectAssetReference> InfoStringToStructConverterBase::GetIndirectAssetReferences() const
{
std::vector<IndirectAssetReference> indirectAssetReferences;
indirectAssetReferences.reserve(m_indirect_asset_references.size());
for (auto& assetReference : m_indirect_asset_references)
{
indirectAssetReferences.emplace_back(assetReference);
}
return indirectAssetReferences;
}

View File

@ -17,11 +17,12 @@ protected:
ZoneScriptStrings& m_zone_script_strings;
std::unordered_set<scr_string_t> m_used_script_string_list;
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
MemoryManager* m_memory;
void* m_structure;
static bool ParseAsArray(const std::string& value, std::vector<std::string>& valueArray);
bool ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray) const;
static bool ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray);
bool ConvertString(const std::string& value, size_t offset);
bool ConvertStringBuffer(const std::string& value, size_t offset, size_t bufferSize);
@ -45,4 +46,5 @@ public:
virtual bool Convert() = 0;
_NODISCARD std::vector<scr_string_t> GetUsedScriptStrings() const;
_NODISCARD std::vector<XAssetInfoGeneric*> GetDependencies() const;
_NODISCARD std::vector<IndirectAssetReference> GetIndirectAssetReferences() const;
};