2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-07 13:33:02 +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

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

View File

@@ -7,10 +7,17 @@
namespace
{
static constexpr auto TAG_DEFAULT = 1;
constexpr auto CAPTURE_TYPE = 1;
constexpr auto CAPTURE_ASSET_NAME = 2;
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_ASSET_TYPE_ENUM_ENTRY = 2;
bool AssetWithNameIsKnown(const std::string& assetName, const IDataRepository& repository)
{
return std::ranges::any_of(repository.GetAllStructureInformation(),
[&assetName](const StructureInformation* info)
{
return !info->m_asset_name.empty() && info->m_asset_name == assetName;
});
}
} // namespace
SequenceAssetRef::SequenceAssetRef()
@@ -22,17 +29,18 @@ SequenceAssetRef::SequenceAssetRef()
create.Keyword("set"),
create.Keyword("assetref"),
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
create.Identifier().Capture(CAPTURE_ASSET_TYPE_ENUM_ENTRY),
create.Identifier().Capture(CAPTURE_ASSET_NAME),
create.Char(';'),
});
}
void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{
const auto& enumEntryToken = result.NextCapture(CAPTURE_ASSET_TYPE_ENUM_ENTRY);
const auto* enumMember = state->GetRepository()->GetEnumMemberByName(enumEntryToken.IdentifierValue());
if (enumMember == nullptr)
throw ParsingException(enumEntryToken.GetPos(), "Unknown asset type enum entry");
const auto& assetNameToken = result.NextCapture(CAPTURE_ASSET_NAME);
auto assetName = assetNameToken.IdentifierValue();
if (!AssetWithNameIsKnown(assetName, *state->GetRepository()))
throw ParsingException(assetNameToken.GetPos(), "No asset with this name");
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)
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;
// 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;
return true;