private GMProjectWriter _writer = new GMProjectWriter();  // Project writer

        #endregion

        #region Constructor

        /// <summary>
        /// Constructs a new game maker export form
        /// </summary>
        /// <param name="projectPath">Path to a Game Maker project</param>
        public ExportGMProjectForm(GMProject project, string projectPath)
        {
            InitializeComponent();

            // Set image keys
            GMUtilities.ImageKeyGroup         = imgProjectTree.Images.Keys[0];
            GMUtilities.ImageKeyGroupSelected = imgProjectTree.Images.Keys[1];
            GMUtilities.ImageKeyRoom          = imgProjectTree.Images.Keys[2];
            GMUtilities.ImageKeyRoomSelected  = imgProjectTree.Images.Keys[2];

            // Set project target Game Maker path
            _projectPath = projectPath;

            // Set Game Maker project
            _project = project;

            // Populate the backgrounds listbox
            foreach (GMBackground background in _project.Backgrounds)
            {
                // If the background has image data, add it to the list
                if (background.Image.Data != null)
                {
                    lstBackgrounds.Items.Add(background);
                }
            }

            // If there is at least one item to select, do so
            if (lstBackgrounds.Items.Count > 0)
            {
                lstBackgrounds.SelectedIndex = 0;
            }

            // The object node index
            int roomIndex = GetResourceIndex(GMResourceType.Rooms);

            // If no object node was found, return
            if (roomIndex == -1)
            {
                return;
            }

            // Add room nodes to treeview
            //tvRooms.Nodes.Add(GMUtilities.GetTreeNodeFromGMNode(_project, _project.ProjectTree, null));
            tvRooms.Nodes.Add(GMUtilities.GetTreeNodeFromGMNode(_project, _project.ProjectTree.Nodes[roomIndex], null));
            tvRooms.SelectedNode = tvRooms.Nodes[0];
            tvRooms.Nodes[0].Expand();

            // Set name of room in text box
            txtName.Text = App.Room.Name;

            // Verify requistes
            Verify();
        }
Example #2
0
        /// <summary>
        /// Checks existing instances against newly imported objects
        /// </summary>
        /// <param name="project">The Game Maker project to check against</param>
        private static void CheckInstances(GMProject project)
        {
            // If no instances exist, return
            if (App.Room.Instances.Count == 0)
            {
                return;
            }

            // Get object node
            List <Image> images = new List <Image>();
            TreeNode     root   = GMUtilities.GetTreeNodeFromGMNode(project, project.ProjectTree.Nodes[7], images);

            // A list of checked object resources
            Dictionary <int, GMResource> ids = new Dictionary <int, GMResource>();

            // A list of object nodes
            List <TreeNode> nodes = new List <TreeNode>();

            // Get all the child nodes
            foreach (TreeNode node in root.Nodes)
            {
                nodes.Add(node);
            }

            // Iterate through existing instances
            foreach (GMareInstance instance in App.Room.Instances)
            {
                // If the instance's resource id does not match any new objects
                if (project.Objects.Find(o => o.Id == instance.ObjectId || o.Name == instance.ObjectName) == null)
                {
                    // If the id check has already processed the instance's object id
                    if (ids.ContainsKey(instance.ObjectId) == true)
                    {
                        // Set new instance data.
                        int key = instance.ObjectId;
                        instance.ObjectId   = ids[key].Id;
                        instance.ObjectName = ids[key].Name;
                        continue;
                    }

                    // Get original glyph graphic
                    Bitmap glyph = App.Room.Objects.Find(o => o.Resource.Id == instance.ObjectId).Image.ToBitmap();

                    // Give the user a choice of either replacing the instance's parent object id, or just delete them
                    using (InstanceConflictForm form = new InstanceConflictForm(nodes.ToArray(), instance.ObjectName, images.ToArray(), glyph))
                    {
                        // Show the instance options form
                        form.ShowDialog();

                        // Set resource as one that has been checked
                        ids.Add(instance.ObjectId, form.Object);

                        // Iterate through blocks
                        foreach (GMareInstance block in App.Room.Blocks)
                        {
                            if (block.ObjectId == instance.ObjectId)
                            {
                                block.ObjectId   = form.Object.Id;
                                block.ObjectName = form.Object.Name;
                            }
                        }

                        // Set instance with new data
                        instance.ObjectId   = form.Object.Id;
                        instance.ObjectName = form.Object.Name;
                    }
                }
            }

            // Dispose
            foreach (Image img in images)
            {
                img.Dispose();
            }

            // Remove all instances that have an empty id
            App.Room.Instances.RemoveAll(i => i.ObjectId == -1);
            App.Room.Blocks.RemoveAll(b => b.ObjectId == -1);
        }