예제 #1
0
 /// <summary>
 /// Gets data from a Game Maker project file
 /// </summary>
 /// <param name="file">The path to the Game Maker project file</param>
 /// <returns>A GM project</returns>
 public static GMProject GetGMProject(string file)
 {
     // Read in the selected GM project file and show progress of read
     using (GMProjectLoadForm form = new GMProjectLoadForm(file))
     {
         form.ShowDialog();
         return(form.Project);
     }
 }
예제 #2
0
        /// <summary>
        /// Gets objects
        /// </summary>
        /// <param name="file">The path to the Game Maker project file</param>
        public static void GetObjects(string file)
        {
            // Create a new Game Maker project form
            using (GMProjectLoadForm form = new GMProjectLoadForm(file))
            {
                // Show the form
                form.ShowDialog();

                // If the project is empty, return
                if (form.Project == null || form.Project.ProjectTree == null || form.Project.ProjectTree.Nodes == null)
                {
                    return;
                }

                // The object node index
                int objectIndex = -1;

                // Get the object node
                for (int i = 0; i < form.Project.ProjectTree.Nodes.Length; i++)
                {
                    if (form.Project.ProjectTree.Nodes[i].ResourceType == GMResourceType.Objects)
                    {
                        objectIndex = i;
                    }
                }

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

                // Check instances for differences
                CheckInstances(form.Project);

                // Clear previous objects if any
                ProjectManager.Room.Objects.Clear();

                // Iterate through project objects
                foreach (GMObject resource in form.Project.Objects)
                {
                    // GMare object variables
                    int    originX = 0;
                    int    originY = 0;
                    Bitmap image   = null;

                    // Get the sprite object
                    GMSprite sprite = form.Project.Sprites.Find(i => i.Id == resource.SpriteId);

                    // If a sprite was found
                    if (sprite != null)
                    {
                        // Get sprite data
                        originX = sprite.OriginX;
                        originY = sprite.OriginY;

                        // If there are no sub-images, skip image data
                        if (sprite.SubImages.Length <= 0)
                        {
                            // Add new gmare object
                            ProjectManager.Room.Objects.Add(new GMareObject(resource, image, resource.SpriteId, resource.Depth, originX, originY));
                            continue;
                        }

                        image = GameMaker.Common.GMUtilities.GetBitmap(sprite.SubImages[0]);

                        // Set transparency if needed
                        if (sprite.Transparent && sprite.SubImages[0].Compressed)
                        {
                            image.MakeTransparent(image.GetPixel(0, image.Height - 1));
                        }
                    }

                    // Add new gmare object
                    ProjectManager.Room.Objects.Add(new GMareObject(resource, image, resource.SpriteId, resource.Depth, originX, originY));
                }

                // Get the object nodes
                ProjectManager.Room.Nodes = form.Project.ProjectTree.Nodes[objectIndex].Nodes;

                // Set textures for loaded objects
                SetTextures();
            }
        }