mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-07 11:41:57 +00:00
ZoneCodeGenerator: Remove PostProcessor for asset names and instead add a statement for command files due to different member names for names
This commit is contained in:
@ -13,7 +13,6 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
|
||||
{
|
||||
private static readonly IDataPostProcessor[] postProcessors =
|
||||
{
|
||||
new PostProcessorAssetName(),
|
||||
new PostProcessorDefaultBlock(),
|
||||
new PostProcessorUsages(),
|
||||
new PostProcessorLeafs()
|
||||
|
@ -20,6 +20,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Impl
|
||||
new TestCondition(),
|
||||
new TestCount(),
|
||||
new TestGame(),
|
||||
new TestName(),
|
||||
new TestReorder(),
|
||||
new TestReusable(),
|
||||
new TestScriptString(),
|
||||
|
@ -1,56 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZoneCodeGenerator.Domain;
|
||||
using ZoneCodeGenerator.Domain.Information;
|
||||
using ZoneCodeGenerator.Persistence;
|
||||
|
||||
namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
|
||||
{
|
||||
class PostProcessorAssetName : IDataPostProcessor
|
||||
{
|
||||
private const string NameMemberName = "name";
|
||||
|
||||
private static List<MemberInformation> FindNameMember(StructureInformation information)
|
||||
{
|
||||
var nameMemberInformation =
|
||||
information.OrderedMembers.FirstOrDefault(memberInformation =>
|
||||
memberInformation.Member.Name.Equals(NameMemberName));
|
||||
|
||||
if (nameMemberInformation != null)
|
||||
{
|
||||
var result = new List<MemberInformation> {nameMemberInformation};
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (var embeddedMembers in information.OrderedMembers.Where(memberInformation =>
|
||||
memberInformation.Computations.IsEmbeddedReference && memberInformation.StructureType != null))
|
||||
{
|
||||
var embeddedMemberName = FindNameMember(embeddedMembers.StructureType);
|
||||
|
||||
if (embeddedMemberName == null) continue;
|
||||
|
||||
embeddedMemberName.Insert(0, embeddedMembers);
|
||||
return embeddedMemberName;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool PostProcess(IDataRepository repository)
|
||||
{
|
||||
var assetDataTypes =
|
||||
repository.GetAllStructs()
|
||||
.AsEnumerable<DataTypeWithMembers>()
|
||||
.Concat(repository.GetAllUnions())
|
||||
.Select(repository.GetInformationFor)
|
||||
.Where(information => information.IsAsset);
|
||||
|
||||
foreach (var assetInformation in assetDataTypes)
|
||||
{
|
||||
assetInformation.NameChain = FindNameMember(assetInformation);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
67
src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestName.cs
Normal file
67
src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestName.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ZoneCodeGenerator.Domain.Information;
|
||||
using ZoneCodeGenerator.Parsing.Matching;
|
||||
using ZoneCodeGenerator.Parsing.Matching.Matchers;
|
||||
using ZoneCodeGenerator.Parsing.Testing;
|
||||
|
||||
namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
||||
{
|
||||
class TestName : AbstractTokenTest<ICommandParserState>
|
||||
{
|
||||
private const string MemberTypeNameToken = "name";
|
||||
|
||||
private static readonly TokenMatcher[] matchers = {
|
||||
new MatcherLiteral("set"),
|
||||
new MatcherLiteral("name"),
|
||||
new MatcherTypename().WithName(MemberTypeNameToken),
|
||||
new MatcherLiteral(";")
|
||||
};
|
||||
|
||||
public TestName() : base(matchers)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void ProcessMatch(ICommandParserState state)
|
||||
{
|
||||
var typeName = NextMatch(MemberTypeNameToken);
|
||||
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 == null || !memberList.Any())
|
||||
{
|
||||
throw new TestFailedException("Need to specify a member when trying to set to a structure name.");
|
||||
}
|
||||
|
||||
for (var i = 0; i < memberList.Count - 1; i++)
|
||||
{
|
||||
if (!memberList[i].Computations.IsEmbeddedReference)
|
||||
{
|
||||
throw new TestFailedException("Can only add embedded members to name chain.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!memberList[memberList.Count - 1].IsString)
|
||||
{
|
||||
throw new TestFailedException("Final name member must be a string.");
|
||||
}
|
||||
|
||||
structure.NameChain = memberList;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user