diff --git a/src/ZoneCodeGenerator/Domain/TypeDeclaration.cs b/src/ZoneCodeGenerator/Domain/TypeDeclaration.cs index dad77550..88aece28 100644 --- a/src/ZoneCodeGenerator/Domain/TypeDeclaration.cs +++ b/src/ZoneCodeGenerator/Domain/TypeDeclaration.cs @@ -7,21 +7,8 @@ namespace ZoneCodeGenerator.Domain { private const int PointerSize = 4; - private DataType type; - public DataType Type - { - get - { - if (type is DataTypeTypedef typedef) - { - return typedef.TypeDefinition.Type; - } + public DataType Type { get; set; } - return type; - } - - set => type = value; - } public int? CustomBitSize { get; set; } @@ -32,7 +19,7 @@ namespace ZoneCodeGenerator.Domain private readonly List references; public IReadOnlyList References => references.AsReadOnly(); - public int Alignment => references.OfType().Any() ? PointerSize : type.Alignment; + public int Alignment => references.OfType().Any() ? PointerSize : Type.Alignment; public int Size { @@ -59,9 +46,9 @@ namespace ZoneCodeGenerator.Domain public TypeDeclaration(DataType type, List references) { - this.type = type; + Type = type; this.references = references ?? new List(); CustomBitSize = null; } } -} +} \ No newline at end of file diff --git a/src/ZoneCodeGenerator/Generating/RenderingContext.cs b/src/ZoneCodeGenerator/Generating/RenderingContext.cs index 4b9cfd05..70522d96 100644 --- a/src/ZoneCodeGenerator/Generating/RenderingContext.cs +++ b/src/ZoneCodeGenerator/Generating/RenderingContext.cs @@ -13,10 +13,13 @@ namespace ZoneCodeGenerator.Generating { public string Game { get; set; } public StructureInformation Asset { get; set; } - public HashSet Structures { get; } + + public ISet Structures { get; } + public ISet MemberTypes { get; } + public IEnumerable ReferencedAssets => Structures.Where(inf => inf.IsAsset && inf != Asset); - public List Blocks { get; private set; } + public IList Blocks { get; private set; } public FastFileBlock DefaultNormalBlock => Blocks.FirstOrDefault(block => block.IsDefault && block.IsNormal) ?? Blocks.FirstOrDefault(block => block.IsNormal); @@ -24,6 +27,7 @@ namespace ZoneCodeGenerator.Generating private RenderingContext() { Structures = new HashSet(); + MemberTypes = new HashSet(); } private void AddToContext(StructureInformation structureInformation) @@ -51,6 +55,12 @@ namespace ZoneCodeGenerator.Generating }; context.AddToContext(asset); + context.MemberTypes.UnionWith(context.Structures.Where(information => !information.IsAsset || information == asset) + .SelectMany(information => information.OrderedMembers) + .Select(information => information.Member.VariableType.Type) + .Where(type => !(type is DataTypeBaseType) && type != asset.Type) + .Distinct()); + return context; }