示例#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 (ProjectIOForm form = new ProjectIOForm(file, true))
     {
         form.ShowDialog();
         return(form.GMProject);
     }
 }
示例#2
0
        /// <summary>
        /// Gets objects
        /// </summary>
        /// <param name="file">The path to the Game Maker project file</param>
        public static bool GetObjects(string file)
        {
            // Create a new Game Maker project form
            using (ProjectIOForm form = new ProjectIOForm(file, true))
            {
                // Show the form
                form.ShowDialog();

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

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

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

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

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

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

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

                    // Get the sprite object
                    GMSprite sprite = form.GMProject.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
                            App.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
                    App.Room.Objects.Add(new GMareObject(resource, image, resource.SpriteId, resource.Depth, originX, originY));
                }

                // Get the object nodes
                App.Room.Nodes = form.GMProject.ProjectTree.Nodes[objectIndex].Nodes;

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