private static void SerializeField(Field field, XmlWriter xw) { string def = $"{field.DisplayType} {field.InternalName}"; if (ParamUtil.IsBitType(field.DisplayType) && field.BitSize != -1) { def += $":{field.BitSize}"; } else if (ParamUtil.IsArrayType(field.DisplayType)) { def += $"[{field.ArrayLength}]"; } if (field.Default != 0) { def += $" = {field.Default.ToString("R", CultureInfo.InvariantCulture)}"; } xw.WriteAttributeString("Def", def); xw.WriteDefaultElement("DisplayName", field.DisplayName, field.InternalName); xw.WriteDefaultElement("Enum", field.InternalType, field.DisplayType.ToString()); xw.WriteDefaultElement("Description", field.Description, null); xw.WriteDefaultElement("DisplayFormat", field.DisplayFormat, ParamUtil.GetDefaultFormat(field.DisplayType)); xw.WriteDefaultElement("EditFlags", field.EditFlags.ToString(), ParamUtil.GetDefaultEditFlags(field.DisplayType).ToString()); xw.WriteDefaultElement("Minimum", field.Minimum, ParamUtil.GetDefaultMinimum(field.DisplayType), "R", CultureInfo.InvariantCulture); xw.WriteDefaultElement("Maximum", field.Maximum, ParamUtil.GetDefaultMaximum(field.DisplayType), "R", CultureInfo.InvariantCulture); xw.WriteDefaultElement("Increment", field.Increment, ParamUtil.GetDefaultIncrement(field.DisplayType), "R", CultureInfo.InvariantCulture); xw.WriteDefaultElement("SortID", field.SortID, 0); xw.WriteDefaultElement("UnkB8", field.UnkB8, null); xw.WriteDefaultElement("UnkC0", field.UnkC0, null); xw.WriteDefaultElement("UnkC8", field.UnkC8, null); }
internal void XmlSerialize(XmlWriter xw) { string def = $"{DisplayType} {InternalName}"; if (ParamUtil.IsBitType(DisplayType) && BitSize != -1) { def += $":{BitSize}"; } else if (ParamUtil.IsArrayType(DisplayType)) { def += $"[{ArrayLength}]"; } if (Default != 0) { def += $" = {Default.ToString("R", CultureInfo.InvariantCulture)}"; } xw.WriteAttributeString("Def", def); xw.WriteDefaultElement(nameof(DisplayName), DisplayName, InternalName); xw.WriteDefaultElement("Enum", InternalType, DisplayType.ToString()); xw.WriteDefaultElement(nameof(Description), Description, null); xw.WriteDefaultElement(nameof(DisplayFormat), DisplayFormat, ParamUtil.GetDefaultFormat(DisplayType)); xw.WriteDefaultElement(nameof(EditFlags), EditFlags.ToString(), ParamUtil.GetDefaultEditFlags(DisplayType).ToString()); xw.WriteDefaultElement(nameof(Minimum), Minimum, ParamUtil.GetDefaultMinimum(DisplayType), "R", CultureInfo.InvariantCulture); xw.WriteDefaultElement(nameof(Maximum), Maximum, ParamUtil.GetDefaultMaximum(DisplayType), "R", CultureInfo.InvariantCulture); xw.WriteDefaultElement(nameof(Increment), Increment, ParamUtil.GetDefaultIncrement(DisplayType), "R", CultureInfo.InvariantCulture); xw.WriteDefaultElement(nameof(SortID), SortID, 0); }
/// <summary> /// Creates a Field with the given type, name, and appropriate default values. /// </summary> public Field(DefType displayType, string internalName) { DisplayName = internalName; DisplayType = displayType; DisplayFormat = ParamUtil.GetDefaultFormat(DisplayType); Minimum = ParamUtil.GetDefaultMinimum(DisplayType); Maximum = ParamUtil.GetDefaultMaximum(DisplayType); Increment = ParamUtil.GetDefaultIncrement(DisplayType); EditFlags = ParamUtil.GetDefaultEditFlags(DisplayType); ArrayLength = 1; InternalType = DisplayType.ToString(); InternalName = internalName; BitSize = -1; }
private static Field DeserializeField(XmlNode node) { var field = new Field(); string def = node.Attributes["Def"].InnerText; Match outerMatch = defOuterRx.Match(def); field.DisplayType = (DefType)Enum.Parse(typeof(DefType), outerMatch.Groups["type"].Value.Trim()); if (outerMatch.Groups["default"].Success) { field.Default = float.Parse(outerMatch.Groups["default"].Value, CultureInfo.InvariantCulture); } string internalName = outerMatch.Groups["name"].Value.Trim(); Match bitMatch = defBitRx.Match(internalName); Match arrayMatch = defArrayRx.Match(internalName); field.BitSize = -1; field.ArrayLength = 1; if (ParamUtil.IsBitType(field.DisplayType) && bitMatch.Success) { field.BitSize = int.Parse(bitMatch.Groups["size"].Value); internalName = bitMatch.Groups["name"].Value; } else if (ParamUtil.IsArrayType(field.DisplayType)) { field.ArrayLength = int.Parse(arrayMatch.Groups["length"].Value); internalName = arrayMatch.Groups["name"].Value; } field.InternalName = internalName; field.DisplayName = node.ReadStringOrDefault("DisplayName", field.InternalName); field.InternalType = node.ReadStringOrDefault("Enum", field.DisplayType.ToString()); field.Description = node.ReadStringIfExist("Description"); field.DisplayFormat = node.ReadStringOrDefault("DisplayFormat", ParamUtil.GetDefaultFormat(field.DisplayType)); field.EditFlags = (EditFlags)Enum.Parse(typeof(EditFlags), node.ReadStringOrDefault("EditFlags", ParamUtil.GetDefaultEditFlags(field.DisplayType).ToString())); field.Minimum = node.ReadSingleOrDefault("Minimum", ParamUtil.GetDefaultMinimum(field.DisplayType), CultureInfo.InvariantCulture); field.Maximum = node.ReadSingleOrDefault("Maximum", ParamUtil.GetDefaultMaximum(field.DisplayType), CultureInfo.InvariantCulture); field.Increment = node.ReadSingleOrDefault("Increment", ParamUtil.GetDefaultIncrement(field.DisplayType), CultureInfo.InvariantCulture); field.SortID = node.ReadInt32OrDefault("SortID", 0); field.UnkB8 = node.ReadStringIfExist("UnkB8"); field.UnkC0 = node.ReadStringIfExist("UnkC0"); field.UnkC8 = node.ReadStringIfExist("UnkC8"); return(field); }
internal Field(XmlNode node) { string def = node.Attributes["Def"].InnerText; Match outerMatch = defOuterRx.Match(def); DisplayType = (DefType)Enum.Parse(typeof(DefType), outerMatch.Groups["type"].Value.Trim()); if (outerMatch.Groups["default"].Success) { Default = float.Parse(outerMatch.Groups["default"].Value, CultureInfo.InvariantCulture); } string internalName = outerMatch.Groups["name"].Value.Trim(); Match bitMatch = defBitRx.Match(internalName); Match arrayMatch = defArrayRx.Match(internalName); BitSize = -1; ArrayLength = 1; if (ParamUtil.IsBitType(DisplayType) && bitMatch.Success) { BitSize = int.Parse(bitMatch.Groups["size"].Value); internalName = bitMatch.Groups["name"].Value; } else if (ParamUtil.IsArrayType(DisplayType)) { ArrayLength = int.Parse(arrayMatch.Groups["length"].Value); internalName = arrayMatch.Groups["name"].Value; } InternalName = internalName; DisplayName = node.ReadStringOrDefault(nameof(DisplayName), InternalName); InternalType = node.ReadStringOrDefault("Enum", DisplayType.ToString()); Description = node.ReadStringOrDefault(nameof(Description), null); DisplayFormat = node.ReadStringOrDefault(nameof(DisplayFormat), ParamUtil.GetDefaultFormat(DisplayType)); EditFlags = (EditFlags)Enum.Parse(typeof(EditFlags), node.ReadStringOrDefault(nameof(EditFlags), ParamUtil.GetDefaultEditFlags(DisplayType).ToString())); Minimum = node.ReadSingleOrDefault(nameof(Minimum), ParamUtil.GetDefaultMinimum(DisplayType), CultureInfo.InvariantCulture); Maximum = node.ReadSingleOrDefault(nameof(Maximum), ParamUtil.GetDefaultMaximum(DisplayType), CultureInfo.InvariantCulture); Increment = node.ReadSingleOrDefault(nameof(Increment), ParamUtil.GetDefaultIncrement(DisplayType), CultureInfo.InvariantCulture); SortID = node.ReadInt32OrDefault(nameof(SortID), 0); }