ZoneCodeGenerator: Change block Statement to get the number of fastfileblock from the enum entry instead of manually specifying it

This commit is contained in:
Jan 2019-10-30 15:01:45 +01:00
parent 7ab7447827
commit 799d3cbce7
5 changed files with 36 additions and 32 deletions

View File

@ -52,13 +52,13 @@ asset FootstepFXTableDef ASSET_TYPE_FOOTSTEPFX_TABLE;
asset ZBarrierDef ASSET_TYPE_ZBARRIER; asset ZBarrierDef ASSET_TYPE_ZBARRIER;
// Setup blocks // Setup blocks
block 0 temp XFILE_BLOCK_TEMP default; block temp XFILE_BLOCK_TEMP default;
block 1 runtime XFILE_BLOCK_RUNTIME_VIRTUAL default; block runtime XFILE_BLOCK_RUNTIME_VIRTUAL default;
block 2 runtime XFILE_BLOCK_RUNTIME_PHYSICAL; block runtime XFILE_BLOCK_RUNTIME_PHYSICAL;
block 3 delay XFILE_BLOCK_DELAY_VIRTUAL default; block delay XFILE_BLOCK_DELAY_VIRTUAL default;
block 4 delay XFILE_BLOCK_DELAY_PHYSICAL; block delay XFILE_BLOCK_DELAY_PHYSICAL;
block 5 normal XFILE_BLOCK_VIRTUAL default; block normal XFILE_BLOCK_VIRTUAL default;
block 6 normal XFILE_BLOCK_PHYSICAL; block normal XFILE_BLOCK_PHYSICAL;
// ========================================= // =========================================
// XModelPieces // XModelPieces

View File

@ -11,7 +11,7 @@
} }
public string Name { get; } public string Name { get; }
public int Index { get; } public long Index { get; }
public Type BlockType { get; } public Type BlockType { get; }
public bool IsDefault { get; } public bool IsDefault { get; }
public bool IsTemp => BlockType == Type.Temp; public bool IsTemp => BlockType == Type.Temp;
@ -19,7 +19,7 @@
public bool IsDelay => BlockType == Type.Delay; public bool IsDelay => BlockType == Type.Delay;
public bool IsNormal => BlockType == Type.Normal; 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; Name = name;
Index = index; Index = index;

View File

@ -9,19 +9,17 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
{ {
class TestBlock : AbstractTokenTest<ICommandParserState> class TestBlock : AbstractTokenTest<ICommandParserState>
{ {
private const string BlockNumberToken = "num";
private const string BlockTypeToken = "type"; private const string BlockTypeToken = "type";
private const string BlockNameToken = "name"; private const string BlockEnumMemberToken = "enumEntry";
private const string DefaultToken = "default"; private const string DefaultToken = "default";
private static readonly TokenMatcher[] matchers = { private static readonly TokenMatcher[] matchers = {
new MatcherLiteral("block"), new MatcherLiteral("block"),
new MatcherNumber().WithName(BlockNumberToken),
new MatcherName().WithName(BlockTypeToken), new MatcherName().WithName(BlockTypeToken),
new MatcherName().WithName(BlockNameToken), new MatcherName().WithName(BlockEnumMemberToken),
new MatcherGroupLoop(MatcherGroupLoop.LoopMode.ZeroOneMultiple,new MatcherGroupOr( new MatcherGroupOptional(
new MatcherLiteral("default").WithName(DefaultToken) new MatcherLiteral("default").WithName(DefaultToken)
)), ),
new MatcherLiteral(";") new MatcherLiteral(";")
}; };
@ -32,8 +30,14 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
protected override void ProcessMatch(ICommandParserState state) protected override void ProcessMatch(ICommandParserState state)
{ {
var blockName = NextMatch(BlockNameToken); var blockEnumEntryName = NextMatch(BlockEnumMemberToken);
var blockNumber = int.Parse(NextMatch(BlockNumberToken)); 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); var blockTypeInput = NextMatch(BlockTypeToken);
if (!Enum.TryParse(blockTypeInput, true, out FastFileBlock.Type blockType)) 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)}"); 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); state.FastFileBlocks.Add(block);
} }

View File

@ -6,19 +6,6 @@ namespace T6
{ {
#include "T6_Assets.h" #include "T6_Assets.h"
enum XFileBlock
{
XFILE_BLOCK_TEMP,
XFILE_BLOCK_RUNTIME_VIRTUAL,
XFILE_BLOCK_RUNTIME_PHYSICAL,
XFILE_BLOCK_DELAY_VIRTUAL,
XFILE_BLOCK_DELAY_PHYSICAL,
XFILE_BLOCK_VIRTUAL,
XFILE_BLOCK_PHYSICAL,
XFILE_BLOCK_STREAMER_RESERVE,
MAX_XFILE_COUNT,
};
struct ScriptStringList struct ScriptStringList
{ {
int count; int count;

View File

@ -285,6 +285,19 @@ enum XAssetType
ASSET_TYPE_FULL_COUNT = 0x40, ASSET_TYPE_FULL_COUNT = 0x40,
}; };
enum XFileBlock
{
XFILE_BLOCK_TEMP,
XFILE_BLOCK_RUNTIME_VIRTUAL,
XFILE_BLOCK_RUNTIME_PHYSICAL,
XFILE_BLOCK_DELAY_VIRTUAL,
XFILE_BLOCK_DELAY_PHYSICAL,
XFILE_BLOCK_VIRTUAL,
XFILE_BLOCK_PHYSICAL,
XFILE_BLOCK_STREAMER_RESERVE,
MAX_XFILE_COUNT,
};
union XAssetHeader union XAssetHeader
{ {
//XModelPieces *xmodelPieces; // Not an asset //XModelPieces *xmodelPieces; // Not an asset