private void SetDictValue(string key, IRedType value) { if (value == null) { _properties.Remove(key); } else { if (value.GetType().IsGenericType) { if (value.GetType().GetGenericTypeDefinition() == typeof(CArrayFixedSize <>)) { var propertyInfo = RedReflection.GetPropertyByRedName(GetType(), key); var flags = propertyInfo.Flags; var size = flags.MoveNext() ? flags.Current : 0; if (((IRedArray)value).Count > size) { throw new ArgumentException(); } } if (value.GetType().GetGenericTypeDefinition() == typeof(CStatic <>)) { var propertyInfo = RedReflection.GetPropertyByRedName(GetType(), key); var flags = propertyInfo.Flags; var maxSize = flags.MoveNext() ? flags.Current : 0; ((IRedArray)value).MaxSize = maxSize; } } _properties[key] = value; } }
private object GetSerializableValue(IRedType value) { if (value is CColor col) { return(new Dictionary <string, byte> { { nameof(col.Red), col.Red }, { nameof(col.Green), col.Green }, { nameof(col.Blue), col.Blue }, { nameof(col.Alpha), col.Alpha }, }); } if (value is CName cName) { return((string)cName); } if (value is CFloat cFloat) { return((float)cFloat); } if (value is Vector4 vec) { return(new Dictionary <string, float> { { nameof(vec.X), vec.X }, { nameof(vec.Y), vec.Y }, { nameof(vec.Z), vec.Z }, { nameof(vec.W), vec.W }, }); } if (value is IRedResourceReference rRef) { return((string)rRef.DepotPath); } throw new NotImplementedException(value.GetType().Name); }
public void WriteWidgetAttributes(XmlWriter writer, IRedType value, string property = "") { if (property != "") { property += "."; } var childSets = new List <IRedType>(); var pis = RedReflection.GetTypeInfo(value.GetType()).PropertyInfos; pis.Sort((a, b) => a.Name.CompareTo(b.Name)); pis.ForEach((pi) => { IRedType propertyValue; if (pi.RedName == null) { propertyValue = (IRedType)value.GetType().GetProperty(pi.Name).GetValue(value, null); } else { propertyValue = (IRedType)pi.GetValue((RedBaseClass)value); } var redType = RedReflection.GetRedTypeFromCSType(pi.Type); if (!RedReflection.IsDefault(value.GetType(), pi, propertyValue)) { var propertyName = pi.RedName; switch (propertyName) { case "children": case "backendData": case "parentWidget": return; default: break; } switch (propertyValue) { case IRedBaseHandle handle: var resolvedValue = handle.GetValue(); if (resolvedValue is inkWidget widget) { writer.WriteAttributeString(property + propertyName + "Path", widget.GetPath()); } else { WriteWidgetAttributes(writer, resolvedValue, property + propertyName); } break; case inkWidgetReference inkRef: if (inkRef.Widget != null && inkRef.Widget.GetValue() is inkWidget widgetRef) { writer.WriteAttributeString(property + propertyName, widgetRef.GetPath()); } break; case CArray <CHandle <inkIEffect> > : case CArray <CHandle <inkWidgetLogicController> > : case CArray <CHandle <inkUserData> > : childSets.Add(propertyValue); break; case CArray <inkPropertyBinding> ary: //writer.WriteStartElement("bindings"); foreach (var ipb in ary) { //writer.WriteStartElement("propertyBinding"); writer.WriteAttributeString(ipb.PropertyName + ".binding", ipb.StylePath); //writer.WriteEndElement(); } //writer.WriteEndElement(); break; case inkMargin margin: writer.WriteAttributeString(property + propertyName, margin.Left + "," + margin.Top + "," + margin.Right + "," + margin.Bottom); break; case inkUITransform: case inkWidgetLayout: case textWrappingInfo: WriteWidgetAttributes(writer, propertyValue, property + propertyName); break; case LocalizationString lockey: writer.WriteAttributeString(property + propertyName, lockey.Value.ToString()); break; case HDRColor color: writer.WriteAttributeString(property + propertyName, $"color(srgb {color.Red} {color.Green} {color.Blue} / {color.Alpha})"); //writer.WriteAttributeString(property + propertyName + ".Red", color.Red.ToString()); //writer.WriteAttributeString(property + propertyName + ".Green", color.Green.ToString()); //writer.WriteAttributeString(property + propertyName + ".Blue", color.Blue.ToString()); //writer.WriteAttributeString(property + propertyName + ".Alpha", color.Alpha.ToString()); break; case Vector2 vector2: writer.WriteAttributeString(property + propertyName, $"{vector2.X},{vector2.Y}"); //writer.WriteAttributeString(property + propertyName + ".X", vector2.X.ToString()); //writer.WriteAttributeString(property + propertyName + ".Y", vector2.Y.ToString()); break; default: writer.WriteAttributeString(property + propertyName, propertyValue.ToString()); break; } } }); foreach (var childSet in childSets) { switch (childSet) { case CArray <CHandle <inkIEffect> > effects: writer.WriteStartElement("effects"); foreach (var handle in effects) { var effect = handle.GetValue(); if (effect != null) { writer.WriteStartElement(effect.GetType().Name); WriteWidgetAttributes(writer, effect); writer.WriteEndElement(); } } writer.WriteEndElement(); break; case CArray <CHandle <inkWidgetLogicController> > controllers: writer.WriteStartElement("secondaryControllers"); foreach (var handle in controllers) { var controller = handle.GetValue(); if (controller != null) { writer.WriteStartElement(controller.GetType().Name); WriteWidgetAttributes(writer, controller); writer.WriteEndElement(); } } writer.WriteEndElement(); break; case CArray <CHandle <inkUserData> > ary: writer.WriteStartElement("userData"); foreach (var handle in ary) { var item = handle.GetValue(); if (item != null) { writer.WriteStartElement(item.GetType().Name); WriteWidgetAttributes(writer, item); writer.WriteEndElement(); } } writer.WriteEndElement(); break; } } }