2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-02-10 17:43:03 +00:00

refactor: asset refs are specified via asset name not enum entry

This commit is contained in:
Jan Laupetin
2026-02-04 20:41:28 +00:00
parent 504f67fc2c
commit 1540b69ac1
17 changed files with 48 additions and 41 deletions

View File

@@ -35,7 +35,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxTrailDef // FxTrailDef
use FxTrailDef; use FxTrailDef;

View File

@@ -7,7 +7,7 @@ set string szInternalName;
set string szDisplayName; set string szDisplayName;
set string szOverlayName; set string szOverlayName;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set string szModeName; set string szModeName;
set scriptstring hideTags; set scriptstring hideTags;
set scriptstring notetrackSoundMapKeys; set scriptstring notetrackSoundMapKeys;

View File

@@ -37,7 +37,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxElemExtendedDefPtr // FxElemExtendedDefPtr
use FxElemExtendedDefPtr; use FxElemExtendedDefPtr;

View File

@@ -10,7 +10,7 @@ set reusable hideTags;
set scriptstring hideTags; set scriptstring hideTags;
set count hideTags 32; set count hideTags 32;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set reusable szXAnims; set reusable szXAnims;
set count szXAnims 37; set count szXAnims 37;
set string szAltWeaponName; set string szAltWeaponName;
@@ -26,11 +26,11 @@ set reusable gunXModel;
set count gunXModel 16; set count gunXModel 16;
set reusable szXAnimsRightHanded; set reusable szXAnimsRightHanded;
set string szXAnimsRightHanded; set string szXAnimsRightHanded;
set assetref szXAnimsRightHanded ASSET_TYPE_XANIMPARTS; set assetref szXAnimsRightHanded AssetXAnim;
set count szXAnimsRightHanded 37; set count szXAnimsRightHanded 37;
set reusable szXAnimsLeftHanded; set reusable szXAnimsLeftHanded;
set string szXAnimsLeftHanded; set string szXAnimsLeftHanded;
set assetref szXAnimsLeftHanded ASSET_TYPE_XANIMPARTS; set assetref szXAnimsLeftHanded AssetXAnim;
set count szXAnimsLeftHanded 37; set count szXAnimsLeftHanded 37;
set string szModeName; set string szModeName;
set reusable notetrackSoundMapKeys; set reusable notetrackSoundMapKeys;

View File

@@ -38,7 +38,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxElemExtendedDefPtr // FxElemExtendedDefPtr
use FxElemExtendedDefPtr; use FxElemExtendedDefPtr;

View File

@@ -16,7 +16,7 @@ set count underBarrels 3;
set reusable others; set reusable others;
set count others 4; set count others 4;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set reusable szXAnims; set reusable szXAnims;
set count szXAnims WEAP_ANIM_COUNT; set count szXAnims WEAP_ANIM_COUNT;
set reusable animOverrides; set reusable animOverrides;
@@ -39,8 +39,8 @@ set count aiVsPlayerAccuracyGraphKnots aiVsPlayerAccuracyGraphKnotCount;
use AnimOverrideEntry; use AnimOverrideEntry;
set string overrideAnim; set string overrideAnim;
set string altmodeAnim; set string altmodeAnim;
set assetref overrideAnim ASSET_TYPE_XANIMPARTS; set assetref overrideAnim AssetXAnim;
set assetref altmodeAnim ASSET_TYPE_XANIMPARTS; set assetref altmodeAnim AssetXAnim;
// NoteTrackToSoundEntry // NoteTrackToSoundEntry
use NoteTrackToSoundEntry; use NoteTrackToSoundEntry;
@@ -58,11 +58,11 @@ set reusable gunXModel;
set count gunXModel 16; set count gunXModel 16;
set reusable szXAnimsRightHanded; set reusable szXAnimsRightHanded;
set string szXAnimsRightHanded; set string szXAnimsRightHanded;
set assetref szXAnimsRightHanded ASSET_TYPE_XANIMPARTS; set assetref szXAnimsRightHanded AssetXAnim;
set count szXAnimsRightHanded WEAP_ANIM_COUNT; set count szXAnimsRightHanded WEAP_ANIM_COUNT;
set reusable szXAnimsLeftHanded; set reusable szXAnimsLeftHanded;
set string szXAnimsLeftHanded; set string szXAnimsLeftHanded;
set assetref szXAnimsLeftHanded ASSET_TYPE_XANIMPARTS; set assetref szXAnimsLeftHanded AssetXAnim;
set count szXAnimsLeftHanded WEAP_ANIM_COUNT; set count szXAnimsLeftHanded WEAP_ANIM_COUNT;
set string szModeName; set string szModeName;
set reusable notetrackSoundMapKeys; set reusable notetrackSoundMapKeys;
@@ -121,4 +121,4 @@ set condition sound never;
// snd_alias_list_name // snd_alias_list_name
use snd_alias_list_name; use snd_alias_list_name;
set string soundName; set string soundName;
set assetref soundName ASSET_TYPE_SOUND; set assetref soundName AssetSound;

View File

@@ -37,7 +37,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxTrailDef // FxTrailDef
use FxTrailDef; use FxTrailDef;

View File

@@ -8,7 +8,7 @@ set reusable weapDef;
set string szDisplayName; set string szDisplayName;
set string szAltWeaponName; set string szAltWeaponName;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set count szXAnims NUM_WEAP_ANIMS; set count szXAnims NUM_WEAP_ANIMS;
set reusable szXAnims; set reusable szXAnims;
set scriptstring hideTags; set scriptstring hideTags;

View File

@@ -38,7 +38,7 @@ set condition material FxElemDef::elemType == FX_ELEM_TYPE_SPRITE_BILLBOARD
use FxEffectDefRef; use FxEffectDefRef;
set condition handle never; set condition handle never;
set string name; set string name;
set assetref name ASSET_TYPE_FX; set assetref name AssetFx;
// FxElemExtendedDefPtr // FxElemExtendedDefPtr
use FxElemExtendedDefPtr; use FxElemExtendedDefPtr;

View File

@@ -12,7 +12,7 @@ set reusable hideTags;
set string viewModelTag; set string viewModelTag;
set string worldModelTag; set string worldModelTag;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set count szXAnims 88; set count szXAnims 88;
set reusable szXAnims; set reusable szXAnims;
set count locationDamageMultipliers 21; set count locationDamageMultipliers 21;

View File

@@ -13,7 +13,7 @@ set reusable attachments;
set count attachmentUniques 95; set count attachmentUniques 95;
set reusable attachmentUniques; set reusable attachmentUniques;
set string szXAnims; set string szXAnims;
set assetref szXAnims ASSET_TYPE_XANIMPARTS; set assetref szXAnims AssetXAnim;
set count szXAnims NUM_WEAP_ANIMS; set count szXAnims NUM_WEAP_ANIMS;
set reusable szXAnims; set reusable szXAnims;
set scriptstring hideTags; set scriptstring hideTags;

View File

@@ -8,7 +8,6 @@ MemberInformation::MemberInformation(StructureInformation* parent, StructureInfo
m_is_script_string(false), m_is_script_string(false),
m_is_reusable(false), m_is_reusable(false),
m_is_leaf(false), m_is_leaf(false),
m_fast_file_block(nullptr), m_fast_file_block(nullptr)
m_asset_ref(nullptr)
{ {
} }

View File

@@ -25,5 +25,5 @@ public:
std::unique_ptr<IEvaluation> m_alloc_alignment; std::unique_ptr<IEvaluation> m_alloc_alignment;
std::unique_ptr<CustomAction> m_post_load_action; std::unique_ptr<CustomAction> m_post_load_action;
const FastFileBlock* m_fast_file_block; const FastFileBlock* m_fast_file_block;
const EnumMember* m_asset_ref; std::string m_asset_ref;
}; };

View File

@@ -397,22 +397,22 @@ namespace
{ {
if (modifier.IsArray()) if (modifier.IsArray())
{ {
LINEF("MarkArray_IndirectAssetRef({0}, {1}, {2});", LINEF("MarkArray_IndirectAssetRef({0}::EnumEntry, {1}, {2});",
member->m_asset_ref->m_name, member->m_asset_ref,
MakeMemberAccess(info, member, modifier), MakeMemberAccess(info, member, modifier),
modifier.GetArraySize()) modifier.GetArraySize())
} }
else else
{ {
LINEF("MarkArray_IndirectAssetRef({0}, {1}, {2});", LINEF("MarkArray_IndirectAssetRef({0}::EnumEntry, {1}, {2});",
member->m_asset_ref->m_name, member->m_asset_ref,
MakeMemberAccess(info, member, modifier), MakeMemberAccess(info, member, modifier),
MakeEvaluation(modifier.GetPointerArrayCountEvaluation())) MakeEvaluation(modifier.GetPointerArrayCountEvaluation()))
} }
} }
else if (loadType == MemberLoadType::SINGLE_POINTER) else if (loadType == MemberLoadType::SINGLE_POINTER)
{ {
LINEF("Mark_IndirectAssetRef({0}, {1});", member->m_asset_ref->m_name, MakeMemberAccess(info, member, modifier)) LINEF("Mark_IndirectAssetRef({0}::EnumEntry, {1});", member->m_asset_ref, MakeMemberAccess(info, member, modifier))
} }
else else
{ {
@@ -505,7 +505,7 @@ namespace
{ {
MarkMember_ScriptString(info, member, modifier, loadType); MarkMember_ScriptString(info, member, modifier, loadType);
} }
else if (member->m_asset_ref) else if (!member->m_asset_ref.empty())
{ {
MarkMember_AssetRef(info, member, modifier, loadType); MarkMember_AssetRef(info, member, modifier, loadType);
} }
@@ -740,7 +740,7 @@ namespace
if (computations.ShouldIgnore() || computations.IsInRuntimeBlock()) if (computations.ShouldIgnore() || computations.IsInRuntimeBlock())
return; return;
if (member->m_is_script_string || member->m_asset_ref if (member->m_is_script_string || !member->m_asset_ref.empty()
|| member->m_type && (member->m_type->m_requires_marking || StructureComputations(member->m_type).IsAsset())) || member->m_type && (member->m_type->m_requires_marking || StructureComputations(member->m_type).IsAsset()))
{ {
if (info->m_definition->GetType() == DataDefinitionType::UNION) if (info->m_definition->GetType() == DataDefinitionType::UNION)

View File

@@ -5,8 +5,8 @@
namespace namespace
{ {
static constexpr auto CAPTURE_TYPE = 1; constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_ASSET_NAME = 2; constexpr auto CAPTURE_ASSET_NAME = 2;
} // namespace } // namespace
SequenceAsset::SequenceAsset() SequenceAsset::SequenceAsset()
@@ -31,7 +31,7 @@ void SequenceAsset::ProcessMatch(CommandsParserState* state, SequenceResult<Comm
if (definition == nullptr) if (definition == nullptr)
throw ParsingException(typeNameToken.GetPos(), "Unknown type"); throw ParsingException(typeNameToken.GetPos(), "Unknown type");
auto* definitionWithMembers = dynamic_cast<DefinitionWithMembers*>(definition); const auto* definitionWithMembers = dynamic_cast<DefinitionWithMembers*>(definition);
if (definitionWithMembers == nullptr) if (definitionWithMembers == nullptr)
throw ParsingException(typeNameToken.GetPos(), "Type must be struct or union"); throw ParsingException(typeNameToken.GetPos(), "Type must be struct or union");

View File

@@ -7,10 +7,17 @@
namespace namespace
{ {
static constexpr auto TAG_DEFAULT = 1; constexpr auto CAPTURE_TYPE = 1;
constexpr auto CAPTURE_ASSET_NAME = 2;
static constexpr auto CAPTURE_TYPE = 1; bool AssetWithNameIsKnown(const std::string& assetName, const IDataRepository& repository)
static constexpr auto CAPTURE_ASSET_TYPE_ENUM_ENTRY = 2; {
return std::ranges::any_of(repository.GetAllStructureInformation(),
[&assetName](const StructureInformation* info)
{
return !info->m_asset_name.empty() && info->m_asset_name == assetName;
});
}
} // namespace } // namespace
SequenceAssetRef::SequenceAssetRef() SequenceAssetRef::SequenceAssetRef()
@@ -22,17 +29,18 @@ SequenceAssetRef::SequenceAssetRef()
create.Keyword("set"), create.Keyword("set"),
create.Keyword("assetref"), create.Keyword("assetref"),
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE), create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
create.Identifier().Capture(CAPTURE_ASSET_TYPE_ENUM_ENTRY), create.Identifier().Capture(CAPTURE_ASSET_NAME),
create.Char(';'), create.Char(';'),
}); });
} }
void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{ {
const auto& enumEntryToken = result.NextCapture(CAPTURE_ASSET_TYPE_ENUM_ENTRY); const auto& assetNameToken = result.NextCapture(CAPTURE_ASSET_NAME);
const auto* enumMember = state->GetRepository()->GetEnumMemberByName(enumEntryToken.IdentifierValue()); auto assetName = assetNameToken.IdentifierValue();
if (enumMember == nullptr)
throw ParsingException(enumEntryToken.GetPos(), "Unknown asset type enum entry"); if (!AssetWithNameIsKnown(assetName, *state->GetRepository()))
throw ParsingException(assetNameToken.GetPos(), "No asset with this name");
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE); const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
@@ -75,5 +83,5 @@ void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<C
if (typeDecl->m_type->GetType() != DataDefinitionType::BASE_TYPE) if (typeDecl->m_type->GetType() != DataDefinitionType::BASE_TYPE)
throw ParsingException(typeNameToken.GetPos(), "Invalid type for string, must be a base type"); throw ParsingException(typeNameToken.GetPos(), "Invalid type for string, must be a base type");
lastMember->m_asset_ref = enumMember; lastMember->m_asset_ref = std::move(assetName);
} }

View File

@@ -47,7 +47,7 @@ namespace
continue; continue;
// Any script strings, asset refs and assets need to be processed. // Any script strings, asset refs and assets need to be processed.
if (member->m_is_script_string || member->m_asset_ref || member->m_type && StructureComputations(member->m_type).IsAsset()) if (member->m_is_script_string || !member->m_asset_ref.empty() || member->m_type && StructureComputations(member->m_type).IsAsset())
{ {
info->m_requires_marking = true; info->m_requires_marking = true;
return true; return true;