mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 08:05:45 +00:00
ZoneCodeGenerator: Add postprocessor to inspect whether a structure is a leaf (No complex tasks for loading/writing required, like pointers, strings, scriptstrings)
This commit is contained in:
parent
ef8a040db4
commit
f777c049c6
@ -30,6 +30,8 @@ namespace ZoneCodeGenerator.Domain.Information
|
||||
public bool ArrayPointerReferenceExists { get; set; }
|
||||
public bool ArrayReferenceExists { get; set; }
|
||||
|
||||
public bool IsLeaf { get; set; }
|
||||
|
||||
public bool HasNameMember => Type.Members.Any(variable => variable.Name.Equals("name", StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
public StructureInformation(DataTypeWithMembers type)
|
||||
|
@ -15,6 +15,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
|
||||
{
|
||||
new PostProcessorDefaultBlock(),
|
||||
new PostProcessorUsages(),
|
||||
new PostProcessorLeafs()
|
||||
};
|
||||
|
||||
public static bool ReadFile(string path, CUISession session, bool verbose = false)
|
||||
|
@ -0,0 +1,58 @@
|
||||
using System.Linq;
|
||||
using ZoneCodeGenerator.Domain;
|
||||
using ZoneCodeGenerator.Domain.Information;
|
||||
using ZoneCodeGenerator.Persistence;
|
||||
|
||||
namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
|
||||
{
|
||||
class PostProcessorLeafs : IDataPostProcessor
|
||||
{
|
||||
private static bool IsLeaf(StructureInformation structureInformation)
|
||||
{
|
||||
foreach (var member in structureInformation.OrderedMembers)
|
||||
{
|
||||
// If there is a condition to this member and it always evaluates to false: Skip this member
|
||||
if (member.Condition != null && member.Condition.IsStatic && member.Condition.EvaluateNumeric() == 0)
|
||||
continue;
|
||||
|
||||
// Any ScriptStrings or Strings need to be processed.
|
||||
if (member.IsScriptString
|
||||
|| member.IsString)
|
||||
return false;
|
||||
|
||||
// If there are any Pointer members that are not always count 0 it needs to be processed.
|
||||
var hasNoPointerMembers = member.Member.VariableType.References.OfType<ReferenceTypePointer>().All(pointer =>
|
||||
{
|
||||
if (!pointer.Count.IsStatic)
|
||||
return false;
|
||||
|
||||
return pointer.Count.EvaluateNumeric() == 0;
|
||||
});
|
||||
|
||||
if (!hasNoPointerMembers)
|
||||
return false;
|
||||
|
||||
if (member.StructureType != null
|
||||
&& member.StructureType != structureInformation
|
||||
&& !IsLeaf(member.StructureType))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool PostProcess(IDataRepository repository)
|
||||
{
|
||||
foreach (var dataTypeWithMembers in repository.GetAllStructs()
|
||||
.AsEnumerable<DataTypeWithMembers>()
|
||||
.Concat(repository.GetAllUnions()))
|
||||
{
|
||||
var information = repository.GetInformationFor(dataTypeWithMembers);
|
||||
|
||||
information.IsLeaf = IsLeaf(information);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user