private static void MakeOffsetProperty(MultiStructItemTemplateBase template, uint indentation, MhwMultiStructData.Entry entry, string propName) { template.WriteLine(""); template.WriteLine(indentation, " [DisplayName(\"Offset\")]"); template.WriteLine(indentation, $" public long {propName}_offset {{ get; private set; }}"); }
private static void MakeButtonProperty(MultiStructItemTemplateBase template, uint indentation, MhwMultiStructData.Entry entry, string propName) { var dataSourceLookup = GenerationHelper.GetDataSourceType(entry.dataSourceType ?? throw new Exception()); template.WriteLine(""); template.WriteLine(indentation, $" [SortOrder({propName}_sortIndex)]"); template.WriteLine(indentation, $" [DisplayName({propName}_displayName)]"); template.WriteLine(indentation, $" [CustomSorter(typeof({entry.dataSourceCustomSorter}))]"); template.WriteLine(indentation, $" public string {propName}_button => {dataSourceLookup}.TryGet({propName}).ToStringWithId({propName});"); }
private static void MakeMainProperty(MultiStructItemTemplateBase template, uint indentation, MhwMultiStructData.Entry entry, string entryName, string propName, int sortIndex) { var accessLevel = entry.accessLevel; if (entry.name == "Index") { accessLevel += " override"; } else if (accessLevel != "private") { accessLevel += " virtual"; } var typeString = COMPILER.GetTypeOutput(new CodeTypeReference(entry.type)); if (entry.arrayCount > -1) { typeString += "[]"; } string returnString; var setCast = ""; var getCast = ""; if (entry.enumReturn == null) { returnString = typeString; } else { returnString = COMPILER.GetTypeOutput(new CodeTypeReference(entry.enumReturn)); getCast = $"({returnString}) "; setCast = $"({typeString}) "; } if (entry.name == "Index") { getCast = "(ulong) "; setCast = $"({returnString}) "; returnString = "ulong"; } // Main Property. template.WriteLine(""); template.WriteLine(indentation, $" protected {typeString} {entryName};"); template.WriteLine(indentation, $" public const string {propName}_displayName = \"{entry.name}\";"); if (!entry.overrideSortIndex) { template.WriteLine(indentation, $" public const int {propName}_sortIndex = {sortIndex};"); } template.WriteLine(indentation, $" [SortOrder({propName}_sortIndex)]"); template.WriteLine(indentation, $" [DisplayName({propName}_displayName)]"); if (entry.dataSourceType != null) { template.WriteLine(indentation, $" [DataSource(DataSourceType.{entry.dataSourceType})]"); } if (entry.readOnly) { template.WriteLine(indentation, " [IsReadOnly]"); } if (entry.showAsHex) { template.WriteLine(indentation, " [ShowAsHex]"); } template.WriteLine(indentation, $" {accessLevel} {returnString} {propName} {{"); if (returnString == "bool") { template.WriteLine(indentation, $" get => {getCast}Convert.ToBoolean({entryName});"); } else if (typeString == "char[]") { template.WriteLine(indentation, $" get => {getCast}new string({entryName});"); } else { template.WriteLine(indentation, $" get => {getCast}{entryName};"); } // Always include a setter, even for readOnly. This enables us to bypass readOnly via command line switch. template.WriteLine(indentation, " set {"); if (returnString == "bool") { template.WriteLine(indentation, $" if (Convert.ToBoolean({entryName}) == {entry.valueString}) return;"); // Do nothing if the value is the same. template.WriteLine(indentation, $" {entryName} = Convert.ToByte({entry.valueString});"); } else if (typeString == "char[]") { template.WriteLine(indentation, $" if ({getCast}new string({entryName}) == {entry.valueString}) return;"); // Do nothing if the value is the same. template.WriteLine(indentation, $" {entryName} = {setCast}{entry.valueString}.ToCharArray(0, {entry.arrayCount - 1});"); } else { template.WriteLine(indentation, $" if ({getCast}{entryName} == {entry.valueString}) return;"); // Do nothing if the value is the same. template.WriteLine(indentation, $" {entryName} = {setCast}{entry.valueString};"); } template.WriteLine(indentation, $" ChangedItems.Add(nameof({propName}));"); template.WriteLine(indentation, $" OnPropertyChanged(nameof({propName}));"); if (entry.dataSourceType != null) { template.WriteLine(indentation, $" OnPropertyChanged(nameof({propName}_button));"); } if (entry.extraOnPropertyChanged != null) { foreach (var propertyToChange in entry.extraOnPropertyChanged) { var propertyToChangeName = Regex.Replace(propertyToChange, @"[^\w\d]+", "_"); template.WriteLine(indentation, $" OnPropertyChanged(nameof({propertyToChangeName}));"); } } template.WriteLine(indentation, " }"); template.WriteLine(indentation, " }"); }
private static void MakeSubProperty(MultiStructItemTemplateBase template, uint indentation, MhwMultiStructData.Entry entry, string entryName, string propName, int sortIndex) { var accessLevel = entry.accessLevel; if (accessLevel != "private") { accessLevel += " virtual"; } var typeString = $"ObservableCollection<{entry.subStruct.SafeName}>"; // Auto-Property for sub-struct. template.WriteLine(""); template.WriteLine(indentation, $" public const string {propName}_displayName = \"{entry.name}\";"); if (!entry.overrideSortIndex) { template.WriteLine(indentation, $" public const int {propName}_sortIndex = {sortIndex};"); } template.WriteLine(indentation, $" [SortOrder({propName}_sortIndex)]"); template.WriteLine(indentation, $" [DisplayName({propName}_displayName)]"); template.WriteLine(indentation, $" {accessLevel} {typeString} {entryName} {{ get; {(accessLevel.Contains("protected") ? "" : "protected ")}set; }}"); }
private static void CreateStructField(MultiStruct010TemplateBase template, MhwMultiStructData.StructData @struct, MhwMultiStructData.Entry entry = null, uint indentation = 0) { var name = @struct.SafeName; string entryText; if (@struct.fixedSizeCount > 1) { entryText = $"{name} {name}_[{@struct.fixedSizeCount}]<optimize=false, name=\"{@struct.name}\">;"; } else if (@struct.Has010Link) { var linkStruct = @struct._010Link.@struct; var linkEntry = @struct._010Link.entry; string countTarget; // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (linkStruct == null || linkStruct.showVertically) { countTarget = linkEntry.SafeName; } else { countTarget = $"{linkStruct.SafeName}_.{linkEntry.SafeName}"; } entryText = $"{name} {name}_[{countTarget}]<optimize=false, name=\"{@struct.name}\">;"; } else { entryText = $"{name} {name}_<name=\"{@struct.name}\">;"; } if (entry?.condition != null) { var condition = entry.condition.Replace("|ref|", "").Replace("_raw", "").Replace("parent.", ""); template.WriteLine(indentation, $"{condition} {{ {entryText} }}"); } else { template.WriteLine(indentation, entryText); } }