mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 08:05:45 +00:00
ZoneCodeGenerator: Add a preprocessor extracting a member chain to get the name of the asset in the template
This commit is contained in:
parent
5f0f73838f
commit
b0780ca565
@ -32,7 +32,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
|||||||
|
|
||||||
public bool IsLeaf { get; set; }
|
public bool IsLeaf { get; set; }
|
||||||
|
|
||||||
public bool HasNameMember => Type.Members.Any(variable => variable.Name.Equals("name", StringComparison.CurrentCultureIgnoreCase));
|
public List<MemberInformation> NameChain { get; set; }
|
||||||
|
|
||||||
public StructureInformation(DataTypeWithMembers type)
|
public StructureInformation(DataTypeWithMembers type)
|
||||||
{
|
{
|
||||||
@ -45,6 +45,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
|||||||
Usages = new List<StructureInformation>();
|
Usages = new List<StructureInformation>();
|
||||||
OrderedMembers = new List<MemberInformation>();
|
OrderedMembers = new List<MemberInformation>();
|
||||||
IsLeaf = true;
|
IsLeaf = true;
|
||||||
|
NameChain = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -248,8 +248,8 @@ void $LoaderClassName(context.Asset)$::Load($context.Asset.Type.FullName$** pAss
|
|||||||
GetNameMethod(context) ::= <<
|
GetNameMethod(context) ::= <<
|
||||||
std::string $LoaderClassName(context.Asset)$::GetAssetName($context.Asset.Type.FullName$* p$context.Asset.Type.Name$)
|
std::string $LoaderClassName(context.Asset)$::GetAssetName($context.Asset.Type.FullName$* p$context.Asset.Type.Name$)
|
||||||
{
|
{
|
||||||
$if(context.Asset.HasNameMember)$
|
$if(context.Asset.NameChain)$
|
||||||
return p$context.Asset.Type.Name$->name;
|
return p$context.Asset.Type.Name$->$first(context.Asset.NameChain):{member | $member.Member.Name$}$$rest(context.Asset.NameChain):{member | .$member.Member.Name$}$;
|
||||||
$else$
|
$else$
|
||||||
return "$context.Asset.Type.Name$";
|
return "$context.Asset.Type.Name$";
|
||||||
$endif$
|
$endif$
|
||||||
|
@ -13,6 +13,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
|
|||||||
{
|
{
|
||||||
private static readonly IDataPostProcessor[] postProcessors =
|
private static readonly IDataPostProcessor[] postProcessors =
|
||||||
{
|
{
|
||||||
|
new PostProcessorAssetName(),
|
||||||
new PostProcessorDefaultBlock(),
|
new PostProcessorDefaultBlock(),
|
||||||
new PostProcessorUsages(),
|
new PostProcessorUsages(),
|
||||||
new PostProcessorLeafs()
|
new PostProcessorLeafs()
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user