private TileSet LoadTileSet(XElement root, string fileId) { TileSet ts = null; string name = (string)root.Attribute("name"); int? tileWidth = (int?)root.Attribute("tileWidth"); int? tileHeight = (int?)root.Attribute("tileHeight"); string image = (string)root.Attribute("image"); if (name != null && tileWidth != null && tileHeight != null && image != null) { Texture tex = engine.GetTexture(image); if (tex != null) { ts = new TileSet(name); ts.AddImage(tex); ts.TileWidth = (int)tileWidth; ts.TileHeight = (int)tileHeight; foreach (var node in from item in root.Descendants("tile") select item) { int?id = (int?)node.Attribute("id"); var img = node.Descendants().FirstOrDefault(); if (id != null && img != null) { int? x = (int?)img.Attribute("x"); int? y = (int?)img.Attribute("y"); int? width = (int?)img.Attribute("width"); int? height = (int?)img.Attribute("height"); int? offsetX = (int?)img.Attribute("offsetX"); int? offsetY = (int?)img.Attribute("offsetY"); string tileName = (string)img.Attribute("name"); if (x != null && y != null && width != null && height != null && offsetX != null && offsetY != null) { ts.AddTile((int)id, (int)x, (int)y, (int)width, (int)height, (int)offsetX, (int)offsetY, tileName); foreach (var frameNode in from item in node.Descendants("frame") select item) { x = (int?)frameNode.Attribute("x"); y = (int?)frameNode.Attribute("y"); int?duration = (int?)frameNode.Attribute("duration"); if (duration != null) { ts.AddAnim((int)id, (int)x, (int)y, (int)duration); } } } } } } } return(ts); }
private TileSet InternalLoadTileSet(IniFile ini, string fileId) { TileSet ts = null; string img = ini.ReadString("", "img"); if (!string.IsNullOrEmpty(img)) { Texture tex = engine.GetTexture(img); if (tex != null) { ts = new TileSet(fileId); var sec = ini.Sections.FirstOrDefault(sn => sn.Name.Equals("")); int[] values = null; if (sec != null) { foreach (var k in sec.KeyList) { switch (k.Ident) { case "tile": values = k.Value.ToIntValues(); if (values.Length >= 6) { int index = values[0]; int clipX = values[1]; int clipY = values[2]; int clipW = values[3]; int clipH = values[4]; int offsetX = values[5]; int offsetY = values[6]; ts.AddTile(index, clipX, clipY, clipW, clipH, offsetX, offsetY); } break; case "animation": var sValues = k.Value.ToStrValues(';'); var tileId = sValues[0].ToIntValue(); for (int i = 1; i < sValues.Length; i++) { var subValue = sValues[i]; if (subValue.EndsWith("ms")) { subValue = subValue.Replace("ms", ""); } values = subValue.ToIntValues(); if (values.Length >= 3) { ts.AddAnim(tileId, values[0], values[1], values[2]); } } break; case "img": tex = engine.GetTexture(k.Value); ts.AddImage(tex); break; } } } } } return(ts); }