mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
ZoneCodeGenerator: Add expression to apply a certain fastfile block to a structure
This commit is contained in:
parent
799a999a66
commit
c05f04e28a
@ -24,6 +24,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Impl
|
|||||||
new TestReorder(),
|
new TestReorder(),
|
||||||
new TestReusable(),
|
new TestReusable(),
|
||||||
new TestScriptString(),
|
new TestScriptString(),
|
||||||
|
new TestSetBlock(),
|
||||||
new TestString(),
|
new TestString(),
|
||||||
new TestUse()
|
new TestUse()
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ZoneCodeGenerator.Domain;
|
||||||
|
using ZoneCodeGenerator.Domain.FastFileStructure;
|
||||||
|
using ZoneCodeGenerator.Domain.Information;
|
||||||
|
using ZoneCodeGenerator.Parsing.Matching;
|
||||||
|
using ZoneCodeGenerator.Parsing.Matching.Matchers;
|
||||||
|
using ZoneCodeGenerator.Parsing.Testing;
|
||||||
|
|
||||||
|
namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
||||||
|
{
|
||||||
|
class TestSetBlock : AbstractTokenTest<ICommandParserState>
|
||||||
|
{
|
||||||
|
private const string TokenTypeName = "name";
|
||||||
|
private const string TokenBlockEnumEntry = "block";
|
||||||
|
|
||||||
|
private static readonly TokenMatcher[] matchers =
|
||||||
|
{
|
||||||
|
new MatcherLiteral("set"),
|
||||||
|
new MatcherLiteral("block"),
|
||||||
|
new MatcherTypename().WithName(TokenTypeName),
|
||||||
|
new MatcherName().WithName(TokenBlockEnumEntry),
|
||||||
|
new MatcherLiteral(";")
|
||||||
|
};
|
||||||
|
|
||||||
|
public TestSetBlock() : base(matchers)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ProcessMatch(ICommandParserState state)
|
||||||
|
{
|
||||||
|
var typeName = NextMatch(TokenTypeName);
|
||||||
|
var typeNameParts = typeName.Split(new[] {"::"}, StringSplitOptions.None);
|
||||||
|
StructureInformation structure;
|
||||||
|
|
||||||
|
if (state.DataTypeInUse != null &&
|
||||||
|
state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var memberList))
|
||||||
|
{
|
||||||
|
structure = state.DataTypeInUse;
|
||||||
|
}
|
||||||
|
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out structure, out memberList))
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new TestFailedException($"Could not find type '{typeName}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memberList.Any())
|
||||||
|
{
|
||||||
|
var lastMember = memberList.Last();
|
||||||
|
|
||||||
|
structure = lastMember.StructureType ?? throw new TestFailedException(
|
||||||
|
$"Specified member '{lastMember.Member.Name}' is not a structure or union and therefore cannot have its block set.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var blockName = NextMatch(TokenBlockEnumEntry);
|
||||||
|
var block = state.FastFileBlocks
|
||||||
|
.FirstOrDefault(fastFileBlock => fastFileBlock.Name.Equals(blockName));
|
||||||
|
|
||||||
|
structure.Block =
|
||||||
|
block ?? throw new TestFailedException($"Could not find fastfile block with name '{blockName}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user