Exemplo n.º 1
0
        public static BinTreeObject Serialize <T>(MetaEnvironment environment, uint pathHash, T metaClass)
            where T : IMetaClass
        {
            Type metaClassType = metaClass.GetType();
            MetaClassAttribute metaClassAttribute = metaClassType.GetCustomAttribute(typeof(MetaClassAttribute)) as MetaClassAttribute;

            if (metaClassAttribute is null)
            {
                throw new InvalidOperationException("The provided MetaClass does not have a MetaClass Attribute");
            }

            // Create Tree Properties for meta properties
            List <BinTreeProperty> properties = new();

            foreach (PropertyInfo propertyInfo in metaClassType.GetProperties())
            {
                BinTreeProperty treeProperty = ConvertPropertyToTreeProperty(environment, metaClass, propertyInfo);

                if (treeProperty is not null)
                {
                    properties.Add(treeProperty);
                }
            }

            BinTreeObject treeObject = new BinTreeObject(metaClassAttribute.NameHash, pathHash, properties);

            return(treeObject);
        }
Exemplo n.º 2
0
 public void Complete(BinTreeObject treeObject)
 {
     if (Utils.FindTexture(treeObject, out var texture))
     {
         Texture = texture;
     }
 }
Exemplo n.º 3
0
        public static T Deserialize <T>(MetaEnvironment environment, BinTreeObject treeObject)
            where T : IMetaClass
        {
            Type metaClassType = typeof(T);
            MetaClassAttribute metaClassAttribute = metaClassType.GetCustomAttribute(typeof(MetaClassAttribute)) as MetaClassAttribute;

            // Verify attribute
            if (metaClassAttribute is null)
            {
                throw new InvalidOperationException("The provided MetaClass does not have a MetaClass Attribute");
            }
            if (metaClassAttribute.NameHash != treeObject.MetaClassHash)
            {
                throw new InvalidOperationException("Meta Class name does not match class name of treeObject");
            }

            // Create an instance of T and get its runtime type
            T    metaClassObject     = Activator.CreateInstance <T>();
            Type metaClassObjectType = metaClassObject.GetType();

            // Assign values to the object properties
            AssignMetaClassProperties(environment, metaClassObject, metaClassObjectType, treeObject.Properties);

            // Registered the object in the environment for link resolving
            environment.RegisterObject(treeObject.PathHash, metaClassObject);

            return(metaClassObject);
        }
Exemplo n.º 4
0
        internal static bool FindTexture(BinTreeObject treeObject, out string texture)
        {
            texture = string.Empty;
            var samplers = treeObject.Properties.FirstOrDefault(p => p.NameHash == 175050421); //samplerValues

            if (samplers == null)
            {
                return(false);
            }
            foreach (BinTreeEmbedded sampler in ((BinTreeContainer)samplers).Properties)
            {
                var samplerNameProperty = sampler.Properties.FirstOrDefault(p => p.NameHash == 48757580); //samplerName
                if (samplerNameProperty == null)
                {
                    continue;
                }
                var textureProperty = sampler.Properties.FirstOrDefault(p => p.NameHash == 3004290287); //textureName
                if (textureProperty == null)
                {
                    continue;
                }
                var samplerName = ((BinTreeString)samplerNameProperty).Value;
                if (!Converter.Config.SamplerNames.Contains(samplerName))
                {
                    continue;
                }
                texture = ((BinTreeString)textureProperty).Value.ToLower().Replace('/', '\\');
                return(true);
            }
            return(false);
        }
Exemplo n.º 5
0
        private static IEnumerable <string> ProcessBinTreeObject(BinTreeObject treeObject)
        {
            List <string> strings = new List <string>();

            foreach (BinTreeProperty treeProperty in treeObject.Properties)
            {
                strings.AddRange(ProcessBinTreeProperty(treeProperty));
            }

            return(strings);
        }