private static List <Tile.ImageResource> ParseTileImages(List list) { List <Tile.ImageResource> result = new List <Tile.ImageResource>(); for (int i = 1; i < list.Length; ++i) { if (list[i] is string) { Tile.ImageResource resource = new Tile.ImageResource(); resource.Filename = (string)list[i]; result.Add(resource); } else { if (!(list[i] is List)) { LogManager.Log(LogLevel.Warning, "Unexpected data in images part: " + list[i]); continue; } List region = (List)list[i]; if (!(region[0] is Symbol)) { LogManager.Log(LogLevel.Warning, "Expected symbol in sublist of images"); continue; } Symbol symbol = (Symbol)region[0]; if (symbol.Name != "region") { LogManager.Log(LogLevel.Warning, "Non-supported image type '" + symbol.Name + "'"); continue; } if (region.Length != 6) { LogManager.Log(LogLevel.Warning, "region list has to contain 6 elements"); continue; } Tile.ImageResource resource = new Tile.ImageResource(); resource.Filename = (string)region[1]; resource.x = (int)region[2]; resource.y = (int)region[3]; resource.w = (int)region[4]; resource.h = (int)region[5]; result.Add(resource); } } return(result); }
/// <summary>Parse a list of tiles (from a tiles block in the tileset file)</summary> /// <exception cref="System.Exception"> /// Thrown when width and/or height of ids/attributes of a tiles block is wrong. /// </exception> private void ParseTiles(List list) { Properties props = new Properties(list); int width = 0; int height = 0; string image = String.Empty; string editor_images = String.Empty; props.Get("width", ref width); props.Get("height", ref height); props.Get("image", ref image); if (image.Equals(String.Empty)) { props.Get("images", ref image); } props.Get("editor-images", ref editor_images); if (width == 0 || height == 0) { throw new ApplicationException("Width and Height of tiles block must be > 0"); } List <int> ids = new List <int> (); List <uint> attributes = new List <uint> (); List <uint> datas = new List <uint> (); props.GetIntList("ids", ids); props.GetUIntList("attributes", attributes); props.GetUIntList("datas", datas); if (ids.Count != width * height) { throw new ApplicationException("Must have width*height ids in tiles block"); } if ((attributes.Count != width * height) && attributes.Count > 0) //missing atributes == all-are-0-attributes { throw new ApplicationException("Must have width*height attributes in tiles block"); } if ((datas.Count != width * height) && datas.Count > 0) //missing DATAs == all-are-0-DATAs { throw new ApplicationException("Must have width*height DATAs in tiles block"); } int id = 0; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { if (ids[id] != 0) { Tile tile = new Tile(); if (!image.Equals(String.Empty)) { Tile.ImageResource res = new Tile.ImageResource(); res.Filename = image; res.x = x * TILE_WIDTH; res.y = y * TILE_HEIGHT; res.w = TILE_WIDTH; res.h = TILE_HEIGHT; tile.Images = new List <Tile.ImageResource>(); tile.Images.Add(res); } if (!editor_images.Equals(String.Empty)) { Tile.ImageResource eres = new Tile.ImageResource(); eres.Filename = editor_images; eres.x = x * TILE_WIDTH; eres.y = y * TILE_HEIGHT; eres.w = TILE_WIDTH; eres.h = TILE_HEIGHT; tile.EditorImages = new List <Tile.ImageResource>(); tile.EditorImages.Add(eres); } tile.Id = ids[id]; tile.Attributes = (attributes.Count > 0)?(Tile.Attribute)attributes[id]:0; //missing atributes == all-are-0-attributes tile.Data = (datas.Count > 0)?(int)datas[id]:0; //missing DATAs == all-are-0-DATAs while (tiles.Count <= tile.Id) { tiles.Add(null); } tiles[tile.Id] = tile; } id++; } } }
private static List<Tile.ImageResource> ParseTileImages(List list) { List<Tile.ImageResource> result = new List<Tile.ImageResource>(); for(int i = 1; i < list.Length; ++i) { if(list[i] is string) { Tile.ImageResource resource = new Tile.ImageResource(); resource.Filename = (string) list[i]; result.Add(resource); } else { if(!(list[i] is List)) { Console.WriteLine("Unexpected data in images part: " + list[i]); continue; } List region = (List) list[i]; if(!(region[0] is Symbol)) { Console.WriteLine("Expected symbol in sublist of images"); continue; } Symbol symbol = (Symbol) region[0]; if(symbol.Name != "region") { Console.WriteLine("Non-supported image type '" + symbol.Name + "'"); continue; } if(region.Length != 6) { Console.WriteLine("region list has to contain 6 elemetns"); continue; } Tile.ImageResource resource = new Tile.ImageResource(); resource.Filename = (string) region[1]; resource.x = (int) region[2]; resource.y = (int) region[3]; resource.w = (int) region[4]; resource.h = (int) region[5]; result.Add(resource); } } return result; }
/// <summary>Parse a list of tiles (from a tiles block in the tileset file)</summary> /// <exception cref="System.Exception"> /// Thrown when width and/or height of ids/attributes of a tiles block is wrong. /// </exception> private void ParseTiles(List list) { Properties props = new Properties(list); int width = 0; int height = 0; string image = ""; props.Get("width", ref width); props.Get("height", ref height); props.Get("image", ref image); if(width == 0 || height == 0) throw new ApplicationException("Width and Height of tiles block must be > 0"); List<int> ids = new List<int> (); List<uint> attributes = new List<uint> (); props.GetIntList("ids", ids); props.GetUIntList("attributes", attributes); if(ids.Count != width * height) throw new ApplicationException("Must have width*height ids in tiles block"); if(attributes.Count != width * height) throw new ApplicationException("Must have width*height attributes in tiles block"); int id = 0; for(int y = 0; y < height; ++y) { for(int x = 0; x < width; ++x) { Tile tile = new Tile(); Tile.ImageResource res = new Tile.ImageResource(); res.Filename = image; res.x = x * TILE_WIDTH; res.y = y * TILE_HEIGHT; res.w = TILE_WIDTH; res.h = TILE_HEIGHT; tile.Images = new List<Tile.ImageResource>(); tile.Images.Add(res); tile.Id = ids[id]; tile.Attributes = (Tile.Attribute) attributes[id]; while(tiles.Count <= tile.Id) tiles.Add(null); tiles[tile.Id] = tile; id++; } } }
/// <summary>Parse a list of tiles (from a tiles block in the tileset file)</summary> /// <exception cref="System.Exception"> /// Thrown when width and/or height of ids/attributes of a tiles block is wrong. /// </exception> private void ParseTiles(List list) { Properties props = new Properties(list); int width = 0; int height = 0; string image = String.Empty; string editor_images = String.Empty; props.Get("width", ref width); props.Get("height", ref height); props.Get("image", ref image); if (image.Equals (String.Empty)) props.Get("images", ref image); props.Get("editor-images", ref editor_images); if(width == 0 || height == 0) throw new ApplicationException("Width and Height of tiles block must be > 0"); List<int> ids = new List<int> (); List<uint> attributes = new List<uint> (); List<uint> datas = new List<uint> (); props.GetIntList("ids", ids); props.GetUIntList("attributes", attributes); props.GetUIntList("datas", datas); if(ids.Count != width * height) throw new ApplicationException("Must have width*height ids in tiles block"); if((attributes.Count != width * height) && attributes.Count > 0) //missing atributes == all-are-0-attributes throw new ApplicationException("Must have width*height attributes in tiles block"); if((datas.Count != width * height) && datas.Count > 0) //missing DATAs == all-are-0-DATAs throw new ApplicationException("Must have width*height DATAs in tiles block"); int id = 0; for(int y = 0; y < height; ++y) { for(int x = 0; x < width; ++x) { if (ids[id] != 0) { Tile tile = new Tile(); if (!image.Equals (String.Empty)) { Tile.ImageResource res = new Tile.ImageResource(); res.Filename = image; res.x = x * TILE_WIDTH; res.y = y * TILE_HEIGHT; res.w = TILE_WIDTH; res.h = TILE_HEIGHT; tile.Images = new List<Tile.ImageResource>(); tile.Images.Add(res); } if (!editor_images.Equals (String.Empty)) { Tile.ImageResource eres = new Tile.ImageResource(); eres.Filename = editor_images; eres.x = x * TILE_WIDTH; eres.y = y * TILE_HEIGHT; eres.w = TILE_WIDTH; eres.h = TILE_HEIGHT; tile.EditorImages = new List<Tile.ImageResource>(); tile.EditorImages.Add(eres); } tile.Id = ids[id]; tile.Attributes = (attributes.Count > 0)?(Tile.Attribute) attributes[id]:0; //missing atributes == all-are-0-attributes tile.Data = (datas.Count > 0)?(int) datas[id]:0; //missing DATAs == all-are-0-DATAs while(tiles.Count <= tile.Id) tiles.Add(null); tiles[tile.Id] = tile; } id++; } } }