Esempio n. 1
0
        private static string MakeTypeDeclaration(string innerType, Core.ContainerType containerType, uint arraySize)
        {
            if (containerType == Core.ContainerType.StaticArray && arraySize == 1)
            {
                return(innerType);
            }

            if (containerType == Core.ContainerType.StringMap)
            {
                return($"Dictionary<string, {innerType}>");
            }

            return($"List<{innerType}>");
        }
Esempio n. 2
0
 public PropertyInfoAttribute(
     Core.PropertyInfoType type,
     uint offset,
     uint arraySize = 1,
     Core.ContainerType container = Core.ContainerType.StaticArray,
     PropertyExport readable      = PropertyExport.EditorAndGame,
     PropertyExport writable      = PropertyExport.EditorAndGame,
     Type ptrType            = null,
     Type enumType           = null,
     PropertyStorage storage = PropertyStorage.Instance)
 {
     this.Type      = type;
     this.Offset    = offset;
     this.ArraySize = arraySize;
     this.Container = container;
     this.Storage   = storage;
     this.PtrType   = ptrType ?? typeof(Entity);
     this.Enum      = enumType;
     this.Readable  = readable;
     this.Writable  = writable;
 }
Esempio n. 3
0
 /// <summary>
 /// Asserts that a property has a container of a given type.
 /// </summary>
 /// <param name="property">The property whose type to check.</param>
 /// <param name="expectedContainerType">The expected container type.</param>
 private static void CheckContainerType(Core.PropertyInfo property, Core.ContainerType expectedContainerType)
 {
     Assert.IsTrue(
         property.ContainerType == expectedContainerType,
         $"Expected container type {expectedContainerType} but found {property.ContainerType} in property {property.Name}.");
 }
Esempio n. 4
0
        private object ExtractPropertyValue <TRaw, TConverted>(Core.PropertyInfo property, Func <TRaw, TConverted> conversionFunc, Core.ContainerType containerType, uint arraySize)
        {
            // Non-array
            if (containerType == Core.ContainerType.StaticArray && arraySize == 1)
            {
                var rawValue = DataSetUtils.GetStaticArrayPropertyValue <TRaw>(property);

                if (conversionFunc == null)
                {
                    return(rawValue);
                }

                var convertedValue = conversionFunc(rawValue);

                if (property.Type == Core.PropertyInfoType.EntityLink)
                {
                    // TODO DataIdentifiers
                    var link = convertedValue as EntityLink;
                    if (link.Entity == null)
                    {
                        this.entityLinks.Add(link);
                    }
                }
                if (property.Type == Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path)
                {
                    this.desiredFiles.Add(new FilePtrEntry(property.Name, null), convertedValue as string);
                }

                return(convertedValue);
            }

            // Array
            if (containerType == Core.ContainerType.StaticArray)
            {
                var rawValues = DataSetUtils.GetStaticArrayValues <TRaw>(property);

                if (conversionFunc == null)
                {
                    return(rawValues);
                }

                var convertedValues = (from rawValue in rawValues
                                       select conversionFunc(rawValue)).ToList();

                if (property.Type == Core.PropertyInfoType.EntityLink)
                {
                    foreach (var convertedValue in convertedValues)
                    {
                        // TODO DataIdentifiers
                        var link = convertedValue as EntityLink;
                        if (link.Entity == null)
                        {
                            this.entityLinks.Add(link);
                        }
                    }

                    return(convertedValues);
                }

                if (property.Type != Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path)
                {
                    return(convertedValues);
                }

                for (var i = 0; i < convertedValues.Count; i++)
                {
                    this.desiredFiles.Add(new FilePtrEntry(property.Name, i), convertedValues[i] as string);
                }

                return(convertedValues);
            }
            if (containerType == Core.ContainerType.DynamicArray)
            {
                var rawValues = DataSetUtils.GetDynamicArrayValues <TRaw>(property);

                if (conversionFunc == null)
                {
                    return(rawValues);
                }

                var convertedValues = (from rawValue in rawValues
                                       select conversionFunc(rawValue)).ToList();

                if (property.Type == Core.PropertyInfoType.EntityLink)
                {
                    foreach (var convertedValue in convertedValues)
                    {
                        // TODO DataIdentifiers
                        var link = convertedValue as EntityLink;
                        if (link.Entity == null)
                        {
                            this.entityLinks.Add(link);
                        }
                    }

                    return(convertedValues);
                }

                if (property.Type != Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path)
                {
                    return(convertedValues);
                }

                for (var i = 0; i < convertedValues.Count; i++)
                {
                    this.desiredFiles.Add(new FilePtrEntry(property.Name, i), convertedValues[i] as string);
                }

                return(convertedValues);
            }
            if (containerType == Core.ContainerType.List)
            {
                var rawValues = DataSetUtils.GetListValues <TRaw>(property);

                if (conversionFunc == null)
                {
                    return(rawValues);
                }

                var convertedValues = (from rawValue in rawValues
                                       select conversionFunc(rawValue)).ToList();

                if (property.Type == Core.PropertyInfoType.EntityLink)
                {
                    foreach (var convertedValue in convertedValues)
                    {
                        // TODO DataIdentifiers
                        var link = convertedValue as EntityLink;
                        if (link.Entity == null)
                        {
                            this.entityLinks.Add(link);
                        }
                    }

                    return(convertedValues);
                }

                if (property.Type != Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path)
                {
                    return(convertedValues);
                }

                for (var i = 0; i < convertedValues.Count; i++)
                {
                    this.desiredFiles.Add(new FilePtrEntry(property.Name, i), convertedValues[i] as string);
                }

                return(convertedValues);
            }

            // StringMap
            if (containerType == Core.ContainerType.StringMap)
            {
                var rawValues = DataSetUtils.GetStringMap <TRaw>(property);

                if (conversionFunc == null)
                {
                    return(rawValues);
                }

                var convertedValues = rawValues.ToDictionary(item => item.Key, item => conversionFunc(item.Value));

                if (property.Type == Core.PropertyInfoType.EntityLink)
                {
                    foreach (var convertedValue in convertedValues)
                    {
                        // TODO DataIdentifiers
                        var link = convertedValue.Value as EntityLink;
                        if (link.Entity == null)
                        {
                            this.entityLinks.Add(link);
                        }
                    }

                    return(convertedValues);
                }

                if (property.Type != Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path)
                {
                    return(convertedValues);
                }

                foreach (var kvp in convertedValues)
                {
                    this.desiredFiles.Add(new FilePtrEntry(property.Name, kvp.Key), kvp.Value as string);
                }

                return(convertedValues);
            }

            Assert.IsTrue(false, $"Unrecognized containerType {containerType}");
            return(null);
        }
Esempio n. 5
0
        private static void AppendFieldAttributes(StringBuilder stringBuilder, PropertyDefinition property, Core.ContainerType containerType, Func <string, string> getNamespace)
        {
            var propertyInfoStringBuilder = new StringBuilder();

            propertyInfoStringBuilder.Append($"{nameof(PropertyInfoAttribute)}(");
            propertyInfoStringBuilder.Append($"Core.PropertyInfoType.{ParsePropertyType(property.Type)}");
            propertyInfoStringBuilder.Append(", ");
            propertyInfoStringBuilder.Append(property.Offset);
            propertyInfoStringBuilder.Append(", ");
            propertyInfoStringBuilder.Append(property.ArraySize);
            propertyInfoStringBuilder.Append(", ");
            propertyInfoStringBuilder.Append($"Core.ContainerType.{containerType}");
            propertyInfoStringBuilder.Append(", ");
            propertyInfoStringBuilder.Append($"PropertyExport.{ParseReadableFlag(property.ExportFlag)}");
            propertyInfoStringBuilder.Append(", ");
            propertyInfoStringBuilder.Append($"PropertyExport.{ParseWritableFlag(property.ExportFlag)}");
            propertyInfoStringBuilder.Append(", ");

            var ptrType       = ParsePtrType(property.PtrType);
            var ptrTypeString = "null";

            if (ptrType != "null")
            {
                var ptrTypeNamespace = getNamespace(ptrType);
                ptrTypeString = ptrType;
                if (!string.IsNullOrEmpty(ptrTypeNamespace))
                {
                    ptrTypeString = $"typeof({ptrTypeNamespace}.{ptrTypeString})";
                }
                else
                {
                    ptrTypeString = $"typeof({ptrTypeString})";
                }
            }

            propertyInfoStringBuilder.Append(ptrTypeString);
            propertyInfoStringBuilder.Append(", ");
            propertyInfoStringBuilder.Append(string.IsNullOrEmpty(property.Enum) ? "null" : $"typeof({property.Enum})");
            propertyInfoStringBuilder.Append(")");

            AppendLineWithIndent(stringBuilder, $"[{nameof(OdinSerializeAttribute)}, {nameof(NonSerializedAttribute)}, {propertyInfoStringBuilder}]", 2);
        }