Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select all order not respected #15

Open
caffeinepills opened this issue Aug 26, 2016 · 1 comment
Open

Select all order not respected #15

caffeinepills opened this issue Aug 26, 2016 · 1 comment

Comments

@caffeinepills
Copy link

When choosing the select all order it doesn't actually select them in the correct order, making each of the frames export in the proper order. Tried with numerous sprite sheets. The order seems all over the place. Top left may export 1, 0, 4, 3, etc.

@caffeinepills
Copy link
Author

It's been a long time, I forgot I made this post, but I did end up fixing this, atleast for top left ONLY (selectAllOrder is completely ignored). This will force the order to top left down no matter what. Obviously, this isn't optimal, but it gets the job done.

Just change OrderBoxes to the following and compile.:

public static List<Rectangle> OrderBoxes(List<Rectangle> boxes, Enums.SelectAllOrder selectAllOrder, Size spriteSheetSize)
        {
            List<List<Rectangle>> listsOfBoxes = new List<List<Rectangle>>();
            bool found = false;

            List<Rectangle> returnedOrder = boxes.OrderBy(w => w.Y + w.Height).ToList();
            foreach (Rectangle box in returnedOrder)
            {
                foreach (Rectangle compareBox in returnedOrder)
                {
                    // Find a rect on the same Y axis.
                    if (box.Top < compareBox.Bottom && box.Bottom > compareBox.Top)
                    {
                        found = false;
                        // Look for a list containing the matched rect.
                        foreach (List<Rectangle> groupedList in listsOfBoxes)
                        {
                            // Add our rect to a list we found.
                            if (groupedList.Contains(compareBox))
                            {
                                groupedList.Add(box);
                                found = true;
                                break;
                            }
                        }

                        // No list was found, create a new list and put the rect in it.
                        if (found == false)
                        {
                            List<Rectangle> newList = new List<Rectangle>();
                            listsOfBoxes.Add(newList);

                            newList.Add(box);
                        }
                        // We found a rect, stop searching for others.
                        break;
                    }
                }
            }

            // Begin to sort all of the lists by the X axis and dump into a single list.
            List<Rectangle> properOrder = new List<Rectangle>();

            foreach (List<Rectangle> groupedList in listsOfBoxes)
            {
                List<Rectangle> orderedList = groupedList.OrderBy(w => w.X).ToList();
                properOrder.AddRange(orderedList);
            }

            return properOrder;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant