public void Apply(Action <ArrangeNode <T> > a) { if (Content == null) { return; } a(this); left?.Apply(a); bottom?.Apply(a); }
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); }