コード例 #1
0
        void Print(int indent, StringBuilder b)
        {
            b.AppendLine("".PadLeft(indent) + this);
            if (left != null)
            {
                b.AppendLine("".PadLeft(indent) + "Left:");
                left.Print(indent + 5, b);
            }

            if (bottom != null)
            {
                b.AppendLine("".PadLeft(indent) + "Bottom:");
                bottom.Print(indent + 5, b);
            }
        }
コード例 #2
0
        public static bool ArrangeGrids(GeneratorPreferences prefs, TileTextureCollection c)
        {
            _ = prefs ?? throw new ArgumentNullException(nameof(prefs));
            var grids = c.Grids.Select(g => new TextureGridLayoutNode(prefs, g)).OrderBy(e => - e.Size.Width).ToList();

            foreach (var node in grids)
            {
                Logger.Verbose("Layout: {GridName} Weight: {Weight} Size:{Size}", node.Grid.Name, node.Size.Width * node.Size.Height, node.Size);
            }

            // All grids sorted by largest space consumed.
            var root    = new ArrangeNode <TextureGridLayoutNode>(2048, 2048);
            var success = true;

            foreach (var grid in grids)
            {
                if (!root.Insert(grid.Size, grid))
                {
                    success = false;
                }

                root.Print();
            }

            if (success)
            {
                root.Apply(n =>
                {
                    var content = n.Content;
                    if (content != null)
                    {
                        content.Offset = new IntPoint(n.X, n.Y);
                    }
                });
            }

            return(success);
        }