public TextureSetFixture CreateTextureSet(int width, int height, TileType tileType) { var textureSet = new TextureSetFile { Width = width, Height = height, TileType = tileType }; var gridParent = new TileTextureCollection { Parent = textureSet }; var grid = new TextureGrid { MatcherType = MatcherType.Basic }; grid.Tiles.Add(new TextureTile(false, 0, 0)); grid.Tiles.Add(new TextureTile(false, 1, 0)); grid.FormattingMetaData.Border = 1; grid.FormattingMetaData.BorderColor = border; grid.FormattingMetaData.Padding = 1; grid.FormattingMetaData.BackgroundColor = background; grid.TextureTileFormattingMetaData.TileOutlineColor = outline; grid.CellSpacing = 1; gridParent.Grids.Add(grid); return(new TextureSetFixture(textureSet, gridParent, grid)); }
public void ValidateEmptyTextureFileMetadata() { var f = new TextureSetFile(); var root = TextureSetFileWriter.GenerateRoot(f); var md = root.Element(Namespace + "metadata"); md.HasAttributes.Should().Be(false); md.HasElements.Should().Be(false); }
public void SavingEmptyTextureFileMustNotCrash() { var f = new TextureSetFile(); var root = TextureSetFileWriter.GenerateRoot(f); root.Name.Should().Be(Namespace + "tileset"); root.Should().HaveAttribute("width", "0"); root.Should().HaveAttribute("height", "0"); root.Should().HaveAttribute("type", "Grid"); root.Should().HaveElement(Namespace + "metadata"); }
public void SetUp() { var textureCollection = new TileTextureCollection(); var tf = new TextureSetFile { Width = 64, Height = 32, TileType = TileType.Grid }; tf.Collections.Add(textureCollection); collection = textureCollection; }
public void ValidateTextureFileProperties() { var f = new TextureSetFile { Properties = new ReadOnlyDictionary <string, string>(new Dictionary <string, string> { { "pname1", "pvalue1" }, { "pname2", "pvalue2" } }) }; var root = TextureSetFileWriter.GenerateRoot(f); var md = root.Element(Namespace + "metadata"); md.HasAttributes.Should().Be(false); var elements = md.Elements(Namespace + "property").ToList(); elements.Should().HaveCount(2); elements[0].Should().HaveAttribute("name", "pname1").And.HaveValue("pvalue1"); elements[1].Should().HaveAttribute("name", "pname2").And.HaveValue("pvalue2"); }
public async Task SaveFile(string fileName) { var textureSet = SelectedItem switch { TextureSetFile s => s, TileTextureCollection c => c.Parent, TextureGrid g => g.Parent?.Parent, TextureTile t => t.Parent?.Parent?.Parent, _ => null }; if (textureSet == null) { return; } GeneratorPreferencesWriter.EnsureParentDirectoryExists(fileName); var doc = TextureSetFileWriter.GenerateXml(textureSet); await using var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true); await doc.SaveAsync(stream, default, default);
void OnArrangeTiles() { var collections = selectedItem switch { TextureSetFile tf => tf.Collections.ToArray(), TileTextureCollection tc => new[] { tc }, TextureGrid gd => new[] { gd.Parent }, TextureTile t => new[] { t.Parent?.Parent }, _ => Array.Empty <TileTextureCollection>() }; foreach (var c in collections) { if (c != null) { TextureGridAutoLayout.ArrangeGrids(UserPreferences.Preferences, c); } } } void OnGenerateTiles() { var grids = selectedItem switch { TextureSetFile tf => tf.Collections.SelectMany(e => e.Grids), TileTextureCollection tc => tc.Grids, TextureGrid gd => Enumerable.Repeat(gd, 1), TextureTile t => Enumerable.Repeat(t.Parent, 1), _ => Array.Empty <TextureGrid>() }; foreach (var g in grids) { if (g != null) { TextureTileGenerator.Regenerate(g); } } }
void OnTreeSelectionChanged() { var collection = structureTree.SelectedItem switch { TextureSetFile f => f.Collections.FirstOrDefault(), TileTextureCollection c => c, TextureGrid g => g.Parent, TextureTile t => t.Parent?.Parent, _ => null }; var textureSet = structureTree.SelectedItem switch { TextureSetFile f => f, TileTextureCollection c => c.Parent, TextureGrid g => g.Parent?.Parent, TextureTile t => t.Parent?.Parent?.Parent, _ => null }; Console.WriteLine("Selection changed " + structureTree.SelectedItem + " -> " + collection + " | " + textureSet); SelectedTextureCollection = collection; SelectedTextureSet = textureSet; }
void OnAddCollection() { var textureSet = SelectedItem switch { TextureSetFile s => s, TileTextureCollection c => c.Parent, TextureGrid g => g.Parent?.Parent, TextureTile t => t.Parent?.Parent?.Parent, _ => null }; textureSet?.Collections.Add(new TileTextureCollection() { Id = "New Collection" }.WithTextureGrid(new TextureGrid() { Name = "New Texture Grid" })); } void OnAddGrid() { var textureCollection = SelectedItem switch { TileTextureCollection c => c, TextureGrid g => g.Parent, TextureTile t => t.Parent?.Parent, _ => null }; textureCollection?.Grids.Add(new TextureGrid() { Name = "New Texture Grid" }); } void OnAddTile() { var textureGrid = SelectedItem switch { TextureGrid g => g, TextureTile t => t.Parent, _ => null }; textureGrid?.Tiles.Add(new TextureTile()); } bool HasAnySelection(object?selectedItem) => selectedItem != null; bool CanAddGrid(object?selectedItem) => selectedItem switch { TileTextureCollection => true, TextureGrid => true, TextureTile => true, _ => false }; bool CanAddTile(object?selectedItem) => selectedItem switch { TextureGrid => true, TextureTile => true, _ => false }; public Task OpenFile(string fileName) { try { var x = TextureSetFileLoader.Read(fileName); TextureFiles.Add(x); return(Task.CompletedTask); } catch (Exception e) { return(Task.FromException(e)); } }
public void Deconstruct(out TextureSetFile file, out TileTextureCollection collection, out TextureGrid grid) { file = File; collection = Collection; grid = Grid; }
public TextureSetFixture(TextureSetFile file, TileTextureCollection collection, TextureGrid grid) { File = file; Collection = collection; Grid = grid; }