Пример #1
0
        public void ImportFrom(List <string> lines, ref int index, string fileName)
        {
            FormatsNode lastNode = null;

            while (index < lines.Count)
            {
                if (lines[index] == "{")
                {
                    index++;
                    lastNode.ImportFrom(lines, ref index, fileName);
                }
                else
                {
                    if (lines[index] == "}")
                    {
                        index++;
                        break;
                    }
                    else
                    {
                        lastNode                = new FormatsNode(lines[index]);
                        lastNode.FileName       = fileName;
                        lastNode.FileLineNumber = index + 1;
                        Properties.Add(lastNode);
                        index++;
                    }
                }
            }
        }
Пример #2
0
        public static List <string> GetFlagsProperty(FormatsNode rootNode, string propertyName)
        {
            var propertyNode = rootNode.Properties.FirstOrDefault(n => n.Name == propertyName);

            if (propertyNode == null)
            {
                throw new ArgumentNullException(propertyNode.Name, string.Format("No property found with name {0}", propertyName));
            }

            var attributes = propertyNode.Attributes;

            if (attributes.Count != 2)
            {
                throw new ArgumentException(string.Format("Property {0}: expected {1} arguments, found {2}", propertyName, 2, attributes.Count));
            }

            List <string> flags = new List <string>();

            if (attributes[1] != "-")
            {
                for (int i = 1; i < attributes.Count; i++)
                {
                    flags.Add(attributes[i]);
                }
            }

            return(flags);
        }
Пример #3
0
        public static bool CheckVersion(FormatsNode versionNode, FormatsType Type, FormatsVersion Version)
        {
            if (versionNode == null || versionNode.Attributes.Count != 3)
            {
                Debug.WriteLine("Invalid version node");
                return(false);
            }

            string keyword          = versionNode.Attributes[0];
            int    typeAttribute    = int.Parse(versionNode.Attributes[1]);
            int    versionAttribute = int.Parse(versionNode.Attributes[2]);

            if (keyword != "Version")
            {
                Debug.WriteLine("Invalid keyword, expected 'Version', found {0}", keyword);
                return(false);
            }

            if (typeAttribute != (int)Type)
            {
                Debug.WriteLine("Invalid type, expected {0}, found {1}", Type, typeAttribute);
                return(false);
            }

            if (versionAttribute != (int)Version)
            {
                Debug.WriteLine("Invalid version, expected {0}, found {1}", Version, versionAttribute);
                return(false);
            }

            return(true);
        }
Пример #4
0
        public static bool GetBoolProperty(FormatsNode rootNode, string propertyName)
        {
            var propertyNode = rootNode.Properties.FirstOrDefault(n => n.Name == propertyName);

            if (propertyNode == null)
            {
                throw new ArgumentNullException(propertyNode.Name, string.Format("No property found with name {0}", propertyName));
            }

            return(bool.Parse(propertyNode.Value));
        }
Пример #5
0
        public static Vector3 GetVector3Property(FormatsNode rootNode, string propertyName)
        {
            var propertyNode = rootNode.Properties.FirstOrDefault(n => n.Name == propertyName);

            if (propertyNode == null)
            {
                throw new ArgumentNullException(propertyNode.Name, string.Format("No property found with name {0}", propertyName));
            }

            var attributes = propertyNode.Attributes;

            if (attributes.Count != 4)
            {
                throw new ArgumentException(string.Format("Property {0}: expected {1} arguments, found {2}", propertyName, 4, attributes.Count));
            }

            float x = float.Parse(attributes[1]);
            float y = float.Parse(attributes[2]);
            float z = float.Parse(attributes[3]);

            return(new Vector3(x, y, z));
        }
Пример #6
0
 public FormatsFile(string filePath)
 {
     FileName = filePath;
     Root     = new FormatsNode("root", filePath, -1);
     Load(filePath);
 }