2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-03 23:37:26 +00:00

ZoneCodeGenerator: Make members have a block they are being loaded into instead of structures

This commit is contained in:
Jan
2019-12-06 16:31:20 +01:00
parent 8a99a49486
commit f4a2639e30
13 changed files with 94 additions and 91 deletions

View File

@@ -13,7 +13,6 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
{
private static readonly IDataPostProcessor[] postProcessors =
{
new PostProcessorDefaultBlock(),
new PostProcessorUsages(),
new PostProcessorLeafs()
};

View File

@@ -1,33 +0,0 @@
using System.Linq;
using ZoneCodeGenerator.Domain;
using ZoneCodeGenerator.Domain.FastFileStructure;
using ZoneCodeGenerator.Persistence;
namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
{
class PostProcessorDefaultBlock : IDataPostProcessor
{
public bool PostProcess(IDataRepository repository)
{
var memberDataTypes =
repository.GetAllStructs()
.AsEnumerable<DataTypeWithMembers>()
.Concat(repository.GetAllUnions());
var defaultTemp = repository.GetAllFastFileBlocks().First(block => block.BlockType == FastFileBlock.Type.Temp && block.IsDefault) ??
repository.GetAllFastFileBlocks().First(block => block.BlockType == FastFileBlock.Type.Temp);
var defaultNormal = repository.GetAllFastFileBlocks().First(block => block.BlockType == FastFileBlock.Type.Normal && block.IsDefault) ??
repository.GetAllFastFileBlocks().First(block => block.BlockType == FastFileBlock.Type.Normal);
foreach (var memberType in memberDataTypes)
{
var info = repository.GetInformationFor(memberType);
info.Block = info.IsAsset ? defaultTemp : defaultNormal;
}
return true;
}
}
}

View File

@@ -39,6 +39,9 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
if (member.Computations.ContainsArrayReference)
member.StructureType.ArrayReferenceExists = true;
if (member.Computations.IsNotDefaultNormalBlock)
member.StructureType.ReferenceFromNonDefaultNormalBlockExists = true;
member.StructureType.Usages.Add(currentStructure);
processingQueue.Enqueue(member.StructureType);
}

View File

@@ -34,14 +34,13 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
{
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;
// Do nothing
}
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out structure, out memberList))
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out _, out memberList))
{
// Do nothing
}
@@ -50,19 +49,18 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
throw new TestFailedException($"Could not find type '{typeName}'.");
}
if (memberList.Any())
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.");
throw new TestFailedException("Must specify a member and not a type when setting a block.");
}
var member = memberList.Last();
var blockName = NextMatch(TokenBlockEnumEntry);
var block = state.FastFileBlocks
.FirstOrDefault(fastFileBlock => fastFileBlock.Name.Equals(blockName));
structure.Block =
member.Block =
block ?? throw new TestFailedException($"Could not find fastfile block with name '{blockName}'");
}
}