/// <summary>
        /// Creates a new instance of Calculator form.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="vehicleName"></param>
        public CalculatorForm(AiFile file, string vehicleName)
        {
            InitializeComponent();

            // Add vehicle name to window title
            this.Text       += vehicleName;
            this.WorkingFile = file;

            // Set default index
            VehicleStrengthSelect.SelectedIndex = 0;

            // Get an array of PCO positions
            AiTemplate[] Pcos = (
                from x in file.Objects
                where x.Value.TemplateType == TemplateType.AiTemplate
                select x.Value as AiTemplate
                ).ToArray();

            // Create PCO Values array, making a slot for each template
            PcoValueArray = new PcoObject[Pcos.Length];

            // Current vehicle index
            int index = 0;

            // Add each vehicle position to the seat selector
            foreach (AiTemplate template in Pcos)
            {
                // Add PCO position
                ObjectSelect.Items.Add(template);

                // Create PCO values
                PcoValueArray[index++] = new PcoObject();

                // Only the main vehicle will have an armor type
                if (template.Plugins.ContainsKey(AiTemplatePluginType.Physical))
                {
                    string T = template.Plugins[AiTemplatePluginType.Physical].Properties["setStrType"][0].Values[0];
                    switch (T.ToLowerInvariant())
                    {
                    case "lightarmour":
                        VehicleStrengthSelect.SelectedIndex = 1;
                        break;

                    case "heavyarmour":
                        VehicleStrengthSelect.SelectedIndex = 2;
                        break;

                    case "helicopter":
                    case "airplane":
                        VehicleStrengthSelect.SelectedIndex = 3;
                        break;
                    }
                }
            }

            // Set main set as index, which will also remove the Suppression of events
            ObjectSelect.SelectedIndex = 0;
        }
Пример #2
0
        /// <summary>
        /// Converts the parsed Ai Templates back to the format they have to be in the file.
        /// </summary>
        /// <param name="templates"></param>
        /// <returns></returns>
        public static string ToFileFormat(AiFile File)
        {
            StringBuilder Output = new StringBuilder();

            foreach (ObjectTemplate Template in File.Objects.Values)
            {
                // Add the object
                BuildObjectString(Template, ref Output);
            }

            return(Output.ToString().TrimEnd());
        }
Пример #3
0
        /// <summary>
        /// Loads the KIT object template
        /// </summary>
        protected void LoadKitTemplate()
        {
            string path = Path.Combine(Application.StartupPath, "Temp", "Kits", "ai", "Objects.ai");

            // Xpack doesnt have a kits folder!
            if (File.Exists(path))
            {
                TreeNode topNode = new TreeNode("Kits");
                Dictionary <AiFileType, AiFile> files = new Dictionary <AiFileType, AiFile>();
                AiFile file = new AiFile(path, AiFileType.Kit);
                ObjectManager.RegisterFileObjects(file);
                files.Add(AiFileType.Kit, file);
                topNode.Tag = files;
                treeView1.Nodes.Add(topNode);
            }
        }
        /// <summary>
        /// Loads all of the AiFiles objects into the Global Namespace
        /// </summary>
        /// <param name="ConFile">The AI file to parse</param>
        /// <returns>Returns whether or not the file could be fully parsed</returns>
        public static bool RegisterFileObjects(AiFile ConFile)
        {
            // Parsing this file will add all objects to the Globals
            try
            {
                AiFileParser.Parse(ConFile);
                return(true);
            }
            catch (Exception)
            {
                // Remove all objects in the AiFile
                foreach (var item in Globals.Where(x => x.Value.FilePath == ConFile.FilePath).ToList())
                {
                    Globals.Remove(item.Key);
                }

                return(false);
            }
        }
Пример #5
0
        /// <summary>
        /// Loads all of the *.ai files located in the SubDir name, into
        /// the ObjectManager
        /// </summary>
        /// <param name="Name"></param>
        protected void LoadTemplates(string Name)
        {
            string   path    = Path.Combine(Application.StartupPath, "Temp", Name);
            TreeNode topNode = new TreeNode(Name);

            // Make sure our tempalte directory exists
            if (!Directory.Exists(path))
            {
                return;
            }

            // Now loop through each object type
            foreach (string dir in Directory.EnumerateDirectories(path))
            {
                string dirName = dir.Remove(0, path.Length + 1);

                // Skip common folder
                if (dirName.ToLowerInvariant() == "common")
                {
                    continue;
                }

                TreeNode dirNode = new TreeNode(dirName);
                foreach (string subdir in Directory.EnumerateDirectories(dir))
                {
                    string subdirName = subdir.Remove(0, dir.Length + 1);

                    // Skip common folder
                    if (subdirName.ToLowerInvariant() == "common")
                    {
                        continue;
                    }

                    // Skip dirs that dont have an ai folder
                    if (!Directory.Exists(Path.Combine(subdir, "ai")))
                    {
                        continue;
                    }

                    TreeNode subNode = new TreeNode(subdirName);
                    Dictionary <AiFileType, AiFile> files = new Dictionary <AiFileType, AiFile>();

                    // Load the Objects.ai file if we have one
                    if (File.Exists(Path.Combine(subdir, "ai", "Objects.ai")))
                    {
                        TaskForm.UpdateStatus("Loading: " + Path.Combine(subdirName, "ai", "Object.ai"));
                        AiFile file = new AiFile(Path.Combine(subdir, "ai", "Objects.ai"), AiFileType.Vehicle);
                        if (ObjectManager.RegisterFileObjects(file))
                        {
                            files.Add(AiFileType.Vehicle, file);
                        }
                    }

                    // Load the Weapons.ai file if we have one
                    if (File.Exists(Path.Combine(subdir, "ai", "Weapons.ai")))
                    {
                        TaskForm.UpdateStatus("Loading: " + Path.Combine(subdirName, "ai", "Weapons.ai"));
                        AiFile file = new AiFile(Path.Combine(subdir, "ai", "Weapons.ai"), AiFileType.Weapon);
                        if (ObjectManager.RegisterFileObjects(file))
                        {
                            files.Add(AiFileType.Weapon, file);
                        }
                    }

                    if (files.Count > 0)
                    {
                        subNode.Tag = files;
                        dirNode.Nodes.Add(subNode);
                    }
                }

                if (dirNode.Nodes.Count > 0)
                {
                    topNode.Nodes.Add(dirNode);
                }
            }

            if (topNode.Nodes.Count > 0)
            {
                treeView1.Nodes.Add(topNode);
            }
        }
 /// <summary>
 /// USED BY PARSER - Registers a new object into the namespace
 /// </summary>
 /// <param name="objectName"></param>
 /// <param name="file"></param>
 public static void RegisterObject(string objectName, AiFile file)
 {
     Globals.Add(objectName, file);
 }
Пример #7
0
        // ====

        /// <summary>
        /// Parses an AiTemplate file, loading all of its objects into the ObjectManager
        /// </summary>
        /// <param name="FilePath">The full path to the extracted AiTemplate.ai file</param>
        public static void Parse(AiFile ConFile)
        {
            // Split our contents into an object araray
            IEnumerable <Token> FileTokens = Tokenize(
                String.Join(Environment.NewLine, File.ReadAllLines(ConFile.FilePath).Where(x => !String.IsNullOrWhiteSpace(x)))
                );

            // Create our needed objects
            RemComment Comment = new RemComment();

            // Create an empty object template
            ObjectTemplate template = new ObjectTemplate();

            // Add our file objects
            ConFile.Objects = new Dictionary <string, ObjectTemplate>();

            // proceed
            foreach (Token Tkn in FileTokens)
            {
                // Clean line up
                string TokenValue = Tkn.Value.TrimStart().TrimEnd(Environment.NewLine.ToCharArray());

                // Handle Rem Comments
                if (Tkn.Kind == RemComment)
                {
                    StringBuilder CommentBuilder = new StringBuilder();
                    CommentBuilder.AppendLine(TokenValue);
                    Comment.Position = Tkn.Position;
                    Comment.Value   += CommentBuilder.ToString();
                }

                // Handle Object Starts
                else if (Tkn.Kind == ObjectStart)
                {
                    // Split line into function call followed by and arguments
                    string[] funcArgs = TokenValue.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                    // Get function info [0] => templateName [1] => methodOrVariable
                    string[] funcInfo = funcArgs[0].Split(new char[] { '.' });

                    // Get our template type
                    TemplateType Type = (TemplateType)Enum.Parse(typeof(TemplateType), funcInfo[0], true);

                    // Create the new object
                    template      = (Type == TemplateType.AiTemplate) ? new AiTemplate() : new ObjectTemplate();
                    template.Name = funcArgs.Last();
                    template.TemplateTypeString = funcInfo[0];
                    template.ObjectType         = (funcArgs.Length > 2) ? funcArgs[1] : "";
                    template.TemplateType       = Type;
                    template.Comment            = Comment;
                    template.Position           = Tkn.Position;
                    template.Properties         = new Dictionary <string, List <ObjectProperty> >();
                    template.File = ConFile;

                    // Add object to our objects array, and our object manager
                    ConFile.Objects.Add(template.Name, template);
                    ObjectManager.RegisterObject(template.Name, ConFile);

                    // Reset comment
                    Comment = new RemComment();
                }

                // handle properties
                else if (Tkn.Kind == ObjectProperty)
                {
                    // Split line into function call followed by and arguments
                    string[] funcArgs = TokenValue.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                    // Get function info [0] => templateName [1] => methodOrVariable
                    string[] funcInfo = funcArgs[0].Split(new char[] { '.' });

                    // Sub object?
                    if (funcInfo[1] == "addPlugIn")
                    {
                        // Throw an exception if we are invalidly adding a plugin
                        if (template.TemplateType != TemplateType.AiTemplate)
                        {
                            throw new Exception("Attempting to add a plugin to object type: " + template.TemplateType.ToString());
                        }

                        // Fetch the plugin
                        ObjectTemplate plugin = ObjectManager.GetObjectByName(funcArgs[1]);

                        // Add template plugin
                        (template as AiTemplate).Plugins.Add(
                            (AiTemplatePluginType)Enum.Parse(typeof(AiTemplatePluginType), plugin.ObjectType, true),
                            plugin
                            );
                    }

                    // Create the object property
                    ObjectProperty prop = new ObjectProperty()
                    {
                        Name     = funcInfo[1],
                        Comment  = Comment,
                        Position = Tkn.Position,
                        Values   = funcArgs.Skip(1).ToArray(),
                    };

                    // Add template property if we dont have one
                    if (!template.Properties.ContainsKey(funcInfo[1]))
                    {
                        template.Properties.Add(funcInfo[1], new List <ObjectProperty>());
                    }

                    // Add the porperty
                    template.Properties[funcInfo[1]].Add(prop);

                    // Reset comment
                    Comment = new RemComment();
                }
            }
        }