CCTileSetInfo TilesetForLayer(CCTileLayerInfo layerInfo) { CCTileMapCoordinates size = layerInfo.LayerDimensions; List <CCTileSetInfo> tilesets = MapInfo.Tilesets; int numOfTiles = size.Row * size.Column; if (tilesets != null) { for (int tilesetIdx = 0; tilesetIdx < tilesets.Count; tilesetIdx++) { CCTileSetInfo tileset = tilesets[tilesetIdx]; short tilesetLastGid = (short)(tilesetIdx < tilesets.Count - 1 ? tilesets[tilesetIdx + 1].FirstGid - 1 : short.MaxValue); for (uint tileIdx = 0; tileIdx < numOfTiles; tileIdx++) { CCTileGidAndFlags gidAndFlags = layerInfo.TileGIDAndFlags[tileIdx]; if (gidAndFlags.Gid != 0 && gidAndFlags.Gid >= tileset.FirstGid && gidAndFlags.Gid <= tilesetLastGid) { return(tileset); } } } } CCLog.Log("CocosSharp: Warning: CCTileMapLayer: TileMap layer '{0}' has no tiles", layerInfo.Name); return(null); }
CCTileMapLayer(CCTileSetInfo[] tileSetInfos, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles, int tileCapacity) { tileRenderCommand = new CCCustomCommand(RenderTileMapLayer); this.mapInfo = mapInfo; LayerName = layerInfo.Name; LayerSize = layerSize; Opacity = layerInfo.Opacity; LayerProperties = new Dictionary <string, string>(layerInfo.Properties); TileCoordOffset = new CCTileMapCoordinates(layerInfo.TileCoordOffset); ContentSize = LayerSize.Size * TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios; TileGIDAndFlagsArray = layerInfo.TileGIDAndFlags; UpdateTileCoordsToNodeTransform(); ParseInternalProperties(); InitialiseTileAnimations(); InitialiseDrawBuffers(tileSetInfos); GenerateMinVertexZ(); }
CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles, int tileCapacity, CCTexture2D texture) { if (texture.ContentSizeInPixels == CCSize.Zero) { CCLog.Log("Tilemap Layer Texture {0} not loaded for layer {1}", tileSetInfo.TilesheetFilename, layerInfo.Name); } LayerName = layerInfo.Name; LayerSize = layerSize; Opacity = layerInfo.Opacity; LayerProperties = new Dictionary <string, string>(layerInfo.Properties); MapType = mapInfo.MapType; TileTexelSize = mapInfo.TileTexelSize; TileSetInfo = tileSetInfo; Position = LayerOffset(layerInfo.TileCoordOffset); ContentSize = LayerSize.Size * TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios; tileSetTexture = texture; tileGIDAndFlagsArray = layerInfo.TileGIDAndFlags; TileSetInfo.TilesheetSize = tileSetTexture.ContentSizeInPixels; UpdateTileCoordsToNodeTransform(); ParseInternalProperties(); InitialiseDrawBuffers(); }
void ParseTileElement() { if (currentParentElement == CCTileMapProperty.Layer) { int layersCount = Layers != null ? Layers.Count : 0; CCTileLayerInfo layer = layersCount > 0 ? Layers[layersCount - 1] : null; uint gidAndFlags = uint.Parse(currentAttributeDict[TileElementGidAndFlags]); if (currentXmlTileIndex < layer.NumberOfTiles) { layer.TileGIDAndFlags[currentXmlTileIndex++] = CCTileMapFileEncodedTileFlags.DecodeGidAndFlags(gidAndFlags); } } else { int tilesetCount = Tilesets != null ? Tilesets.Count : 0; CCTileSetInfo info = tilesetCount > 0 ? Tilesets[tilesetCount - 1] : null; var dict = new Dictionary <string, string>(); ParentGID = (short)(info.FirstGid + short.Parse(currentAttributeDict[TileElementId])); TileProperties.Add(ParentGID, dict); currentParentElement = CCTileMapProperty.Tile; } }
void ParsePropertyElement() { if (currentParentElement == CCTileMapProperty.None) { CCLog.Log("CCTileMapInfo: ParsePropertyElement: Parent element is unsupported. Cannot add property named '{0}' with value '{1}'", currentAttributeDict[PropertyElementName], currentAttributeDict[PropertyElementValue]); } else if (currentParentElement == CCTileMapProperty.Map) { // The parent element is the map string value = currentAttributeDict[PropertyElementValue]; string key = currentAttributeDict[PropertyElementName]; MapProperties.Add(key, value); } else if (currentParentElement == CCTileMapProperty.Layer) { int layersCount = Layers != null ? Layers.Count : 0; CCTileLayerInfo layer = layersCount > 0 ? Layers[layersCount - 1] : null; string value = currentAttributeDict[PropertyElementValue]; string key = currentAttributeDict[PropertyElementName]; // Add the property to the layer layer.Properties.Add(key, value); } else if (currentParentElement == CCTileMapProperty.ObjectGroup) { int objGroupsCount = ObjectGroups != null ? ObjectGroups.Count : 0; CCTileMapObjectGroup objectGroup = objGroupsCount > 0 ? ObjectGroups[objGroupsCount - 1] : null; string value = currentAttributeDict[PropertyElementValue]; string key = currentAttributeDict[PropertyElementName]; objectGroup.Properties.Add(key, value); } else if (currentParentElement == CCTileMapProperty.Object) { // The parent element is the last object int objGroupsCount = ObjectGroups != null ? ObjectGroups.Count : 0; CCTileMapObjectGroup objectGroup = objGroupsCount > 0 ? ObjectGroups[objGroupsCount - 1] : null; List <Dictionary <string, string> > objects = objectGroup.Objects; int objCount = objects != null ? objects.Count : 0; Dictionary <string, string> dict = objCount > 0 ? objects[objCount - 1] : null; string propertyName = currentAttributeDict[PropertyElementName]; string propertyValue = currentAttributeDict[PropertyElementValue]; dict.Add(propertyName, propertyValue); } else if (currentParentElement == CCTileMapProperty.Tile) { Dictionary <string, string> dict = TileProperties[ParentGID]; string propertyName = currentAttributeDict[PropertyElementName]; string propertyValue = currentAttributeDict[PropertyElementValue]; dict.Add(propertyName, propertyValue); } }
void ParseDataEndElement() { byte[] encoded = null; if ((tileDataCompressionType & CCTileDataCompressionType.Base64) != 0) { storingCharacters = false; int layersCount = Layers != null ? Layers.Count : 0; CCTileLayerInfo layer = layersCount > 0 ? Layers[layersCount - 1] : null; if ((tileDataCompressionType & (CCTileDataCompressionType.Gzip | CCTileDataCompressionType.Zlib)) != 0) { if ((tileDataCompressionType & CCTileDataCompressionType.Gzip) != 0) { try { encoded = ZipUtils.Inflate(new MemoryStream(currentString), ZipUtils.CompressionFormat.Gzip); } catch (Exception ex) { CCLog.Log("failed to decompress embedded data object in TMX file."); CCLog.Log(ex.ToString()); } } if ((tileDataCompressionType & CCTileDataCompressionType.Zlib) != 0) { encoded = ZipUtils.Inflate(new MemoryStream(currentString), ZipUtils.CompressionFormat.Zlib); } } else { encoded = currentString; } for (int i = 0; i < layer.TileGIDAndFlags.Length; i++) { int i4 = i * 4; uint gidAndFlags = (uint)( encoded[i4] | encoded[i4 + 1] << 8 | encoded[i4 + 2] << 16 | encoded[i4 + 3] << 24); layer.TileGIDAndFlags[i] = CCTileMapFileEncodedTileFlags.DecodeGidAndFlags(gidAndFlags); } currentString = null; } else if ((tileDataCompressionType & CCTileDataCompressionType.None) != 0) { currentXmlTileIndex = 0; } }
void ParseLayerElement() { var layerInfo = new CCTileLayerInfo(); layerInfo.Name = currentAttributeDict[LayerElementName]; CCTileMapCoordinates layerSize; layerSize.Column = (int)CCUtils.CCParseFloat(currentAttributeDict[LayerElementNumOfColumns]); layerSize.Row = (int)CCUtils.CCParseFloat(currentAttributeDict[LayerElementNumOfRows]); layerInfo.LayerDimensions = layerSize; layerInfo.TileGIDAndFlags = new CCTileGidAndFlags[layerSize.Column * layerSize.Row]; if (currentAttributeDict.ContainsKey(LayerElementVisible)) { string visible = currentAttributeDict[LayerElementVisible]; layerInfo.Visible = !(visible == "0"); } else { layerInfo.Visible = true; } if (currentAttributeDict.ContainsKey(LayerElementOpacity)) { string opacity = currentAttributeDict[LayerElementOpacity]; layerInfo.Opacity = (byte)(byte.MaxValue * CCUtils.CCParseFloat(opacity)); } else { layerInfo.Opacity = byte.MaxValue; } float x = currentAttributeDict.ContainsKey(LayerElementXOffset) ? CCUtils.CCParseFloat(currentAttributeDict[LayerElementXOffset]) : 0; float y = currentAttributeDict.ContainsKey(LayerElementYOffset) ? CCUtils.CCParseFloat(currentAttributeDict[LayerElementYOffset]) : 0; layerInfo.TileCoordOffset = new CCPoint(x, y); Layers.Add(layerInfo); currentParentElement = CCTileMapProperty.Layer; }
CCTileSetInfo[] TilesetForLayer(CCTileLayerInfo layerInfo) { CCTileMapCoordinates size = layerInfo.LayerDimensions; List <CCTileSetInfo> tilesets = MapInfo.Tilesets; List <CCTileSetInfo> results = new List <CCTileSetInfo>(); int numOfTiles = size.Row * size.Column; if (tilesets != null) { for (int tilesetIdx = 0; tilesetIdx < tilesets.Count; tilesetIdx++) { CCTileSetInfo tileset = tilesets[tilesetIdx]; bool contains = false; short tilesetLastGid = (short)(tilesetIdx < tilesets.Count - 1 ? tilesets[tilesetIdx + 1].FirstGid - 1 : short.MaxValue); for (uint tileIdx = 0; tileIdx < numOfTiles; tileIdx++) { CCTileGidAndFlags gidAndFlags = layerInfo.TileGIDAndFlags[tileIdx]; if (gidAndFlags.Gid != 0 && gidAndFlags.Gid >= tileset.FirstGid && gidAndFlags.Gid <= tilesetLastGid) { //return tileset; results.Add(tileset); contains = true; break; } } if (contains) { continue; } } } if (results.Count > 0) { return(results.ToArray()); } else { CCLog.Log("CocosSharp: Warning: CCTileMapLayer: TileMap layer '{0}' has no tiles", layerInfo.Name); return(null); } }
public CCTileMapLayer(CCTileSetInfo[] tileSetInfos, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo) : this(tileSetInfos, layerInfo, mapInfo, layerInfo.LayerDimensions) { }
CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles) : this(tileSetInfo, layerInfo, mapInfo, layerSize, totalNumberOfTiles, (int)(totalNumberOfTiles * 0.35f + 1), CCTextureCache.SharedTextureCache.AddImage(tileSetInfo.TilesheetFilename)) { }
public CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo) : this(tileSetInfo, layerInfo, mapInfo, layerInfo.LayerDimensions) { }
CCTileMapLayer(CCTileSetInfo[] tileSetInfos, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles, int tileCapacity) { tileRenderCommand = new CCCustomCommand(RenderTileMapLayer); this.mapInfo = mapInfo; LayerName = layerInfo.Name; LayerSize = layerSize; Opacity = layerInfo.Opacity; LayerProperties = new Dictionary<string, string>(layerInfo.Properties); TileCoordOffset = new CCTileMapCoordinates(layerInfo.TileCoordOffset); ContentSize = LayerSize.Size * TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios; TileGIDAndFlagsArray = layerInfo.TileGIDAndFlags; UpdateTileCoordsToNodeTransform(); ParseInternalProperties(); InitialiseTileAnimations(); InitialiseDrawBuffers(tileSetInfos); GenerateMinVertexZ(); }
CCTileMapLayer(CCTileSetInfo[] tileSetInfos, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles) : this(tileSetInfos, layerInfo, mapInfo, layerSize, totalNumberOfTiles, (int)(totalNumberOfTiles * 0.35f + 1)) { }
CCTileSetInfo[] TilesetsForLayer(CCTileLayerInfo layerInfo) { CCTileMapCoordinates size = layerInfo.LayerDimensions; List<CCTileSetInfo> tilesets = MapInfo.Tilesets; List<CCTileSetInfo> results = new List<CCTileSetInfo>(); int numOfTiles = size.Row * size.Column; if (tilesets != null) { for (int tilesetIdx = 0; tilesetIdx < tilesets.Count; tilesetIdx++) { CCTileSetInfo tileset = tilesets[tilesetIdx]; short tilesetLastGid = (short)(tilesetIdx < tilesets.Count - 1 ? tilesets[tilesetIdx + 1].FirstGid - 1 : short.MaxValue); for (uint tileIdx = 0; tileIdx < numOfTiles; tileIdx++) { CCTileGidAndFlags gidAndFlags = layerInfo.TileGIDAndFlags[tileIdx]; if (gidAndFlags.Gid != 0 && gidAndFlags.Gid >= tileset.FirstGid && gidAndFlags.Gid <= tilesetLastGid) { results.Add(tileset); break; } } } } if (results.Count > 0) return results.ToArray(); else { CCLog.Log("CocosSharp: Warning: CCTileMapLayer: TileMap layer '{0}' has no tiles", layerInfo.Name); return null; } }
// Private constructor chaining CCTileMapLayer(CCTileSetInfo[] tileSetInfos, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize) : this(tileSetInfos, layerInfo, mapInfo, layerSize, (int)(layerSize.Row * layerSize.Column)) { }
// Private constructor chaining CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize) : this(tileSetInfo, layerInfo, mapInfo, layerSize, (int)(layerSize.Row * layerSize.Column)) { }
void ParseDataEndElement() { byte[] encoded = null; if ((tileDataCompressionType & CCTileDataCompressionType.Base64) != 0) { storingCharacters = false; int layersCount = Layers != null ? Layers.Count : 0; CCTileLayerInfo layer = layersCount > 0 ? Layers[layersCount - 1] : null; if ((tileDataCompressionType & (CCTileDataCompressionType.Gzip | CCTileDataCompressionType.Zlib)) != 0) { if ((tileDataCompressionType & CCTileDataCompressionType.Gzip) != 0) { try { encoded = ZipUtils.Inflate(new MemoryStream(currentString), ZipUtils.CompressionFormat.Gzip); } catch (Exception ex) { CCLog.Log("failed to decompress embedded data object in TMX file."); CCLog.Log(ex.ToString()); } } if ((tileDataCompressionType & CCTileDataCompressionType.Zlib) != 0) { encoded = ZipUtils.Inflate(new MemoryStream(currentString), ZipUtils.CompressionFormat.Zlib); } } else { encoded = currentString; } // encoded could be null because the compressed data could not be decompressed if (encoded != null) { for (int i = 0; i < layer.TileGIDAndFlags.Length; i++) { int i4 = i * 4; uint gidAndFlags = (uint)( (uint)encoded[i4] | (uint)encoded[(int)(i4 + 1)] << 8 | (uint)encoded[(int)(i4 + 2)] << 16 | (uint)encoded[(int)(i4 + 3)] << 24); layer.TileGIDAndFlags[i] = CCTileMapFileEncodedTileFlags.DecodeGidAndFlags(gidAndFlags); } } currentString = null; } else if (tileDataCompressionType == CCTileDataCompressionType.Csv) { storingCharacters = false; int layersCount = Layers != null ? Layers.Count : 0; CCTileLayerInfo layer = layersCount > 0 ? Layers[layersCount - 1] : null; var str = System.Text.Encoding.UTF8.GetString(currentString, 0, currentString.Length).Split(','); for (int i = 0; i < layer.TileGIDAndFlags.Length; i++) { uint gidAndFlags = uint.Parse(str[i]); layer.TileGIDAndFlags[i] = CCTileMapFileEncodedTileFlags.DecodeGidAndFlags(gidAndFlags); } currentString = null; } else if ((tileDataCompressionType & CCTileDataCompressionType.None) != 0) { currentXmlTileIndex = 0; } }
CCTileMapLayer(CCTileSetInfo tileSetInfo, CCTileLayerInfo layerInfo, CCTileMapInfo mapInfo, CCTileMapCoordinates layerSize, int totalNumberOfTiles, int tileCapacity, CCTexture2D texture) { //Debug.Assert(texture.ContentSizeInPixels != CCSize.Zero, string.Format("Tilemap Texture {0} not loaded for layer {1}", tileSetInfo.TilesheetFilename, layerInfo.Name)); if (texture.ContentSizeInPixels == CCSize.Zero) CCLog.Log("Tilemap Layer Texture {0} not loaded for layer {1}", tileSetInfo.TilesheetFilename, layerInfo.Name); LayerName = layerInfo.Name; LayerSize = layerSize; Opacity = layerInfo.Opacity; LayerProperties = new Dictionary<string, string>(layerInfo.Properties); MapType = mapInfo.MapType; TileTexelSize = mapInfo.TileTexelSize; TileSetInfo = tileSetInfo; Position = LayerOffset(layerInfo.TileCoordOffset); ContentSize = LayerSize.Size * TileTexelSize * CCTileMapLayer.DefaultTexelToContentSizeRatios; tileSetTexture = texture; tileGIDAndFlagsArray = layerInfo.TileGIDAndFlags; TileSetInfo.TilesheetSize = tileSetTexture.ContentSizeInPixels; UpdateTileCoordsToNodeTransform(); ParseInternalProperties(); InitialiseQuadsVertexBuffer(); InitialiseIndexBuffer(); }