mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
ZoneCodeGenerator: Change block Statement to get the number of fastfileblock from the enum entry instead of manually specifying it
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public int Index { get; }
|
||||
public long Index { get; }
|
||||
public Type BlockType { get; }
|
||||
public bool IsDefault { get; }
|
||||
public bool IsTemp => BlockType == Type.Temp;
|
||||
@ -19,7 +19,7 @@
|
||||
public bool IsDelay => BlockType == Type.Delay;
|
||||
public bool IsNormal => BlockType == Type.Normal;
|
||||
|
||||
public FastFileBlock(string name, int index, Type blockType, bool isDefault)
|
||||
public FastFileBlock(string name, long index, Type blockType, bool isDefault)
|
||||
{
|
||||
Name = name;
|
||||
Index = index;
|
||||
|
@ -9,19 +9,17 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
||||
{
|
||||
class TestBlock : AbstractTokenTest<ICommandParserState>
|
||||
{
|
||||
private const string BlockNumberToken = "num";
|
||||
private const string BlockTypeToken = "type";
|
||||
private const string BlockNameToken = "name";
|
||||
private const string BlockEnumMemberToken = "enumEntry";
|
||||
private const string DefaultToken = "default";
|
||||
|
||||
private static readonly TokenMatcher[] matchers = {
|
||||
new MatcherLiteral("block"),
|
||||
new MatcherNumber().WithName(BlockNumberToken),
|
||||
new MatcherLiteral("block"),
|
||||
new MatcherName().WithName(BlockTypeToken),
|
||||
new MatcherName().WithName(BlockNameToken),
|
||||
new MatcherGroupLoop(MatcherGroupLoop.LoopMode.ZeroOneMultiple,new MatcherGroupOr(
|
||||
new MatcherName().WithName(BlockEnumMemberToken),
|
||||
new MatcherGroupOptional(
|
||||
new MatcherLiteral("default").WithName(DefaultToken)
|
||||
)),
|
||||
),
|
||||
new MatcherLiteral(";")
|
||||
};
|
||||
|
||||
@ -32,8 +30,14 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
||||
|
||||
protected override void ProcessMatch(ICommandParserState state)
|
||||
{
|
||||
var blockName = NextMatch(BlockNameToken);
|
||||
var blockNumber = int.Parse(NextMatch(BlockNumberToken));
|
||||
var blockEnumEntryName = NextMatch(BlockEnumMemberToken);
|
||||
var blockEnumEntry = state.Repository.GetAllEnums()
|
||||
.SelectMany(_enum => _enum.Members)
|
||||
.FirstOrDefault(member => member.Name.Equals(blockEnumEntryName));
|
||||
if (blockEnumEntry == null)
|
||||
{
|
||||
throw new TestFailedException($"Could not find enum entry '{blockEnumEntryName}' for block.");
|
||||
}
|
||||
|
||||
var blockTypeInput = NextMatch(BlockTypeToken);
|
||||
if (!Enum.TryParse(blockTypeInput, true, out FastFileBlock.Type blockType))
|
||||
@ -44,7 +48,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
||||
throw new TestFailedException($"Unknown fastfile block type '{blockTypeInput}'. Must be one of the following: {string.Join(", ", blockTypeValues)}");
|
||||
}
|
||||
|
||||
var block = new FastFileBlock(blockName, blockNumber, blockType, HasMatcherTokens(DefaultToken));
|
||||
var block = new FastFileBlock(blockEnumEntry.Name, blockEnumEntry.Value, blockType, HasMatcherTokens(DefaultToken));
|
||||
|
||||
state.FastFileBlocks.Add(block);
|
||||
}
|
||||
|
Reference in New Issue
Block a user