private static void IncludeProperty(this PropertyGridDisplayer displayer, IEnumerable<property> propertyList, TMXGlueLib.property property) { string name = property.name; TypeConverter typeConverter = GetTypeConverterForProperty(property); displayer.IncludeMember(property.name, typeof(string), (sender, args) => { var foundProperty = GetPropertyByName(args.Member, propertyList); if (foundProperty != null) { if (args.Value == null) { foundProperty.value = null; } else { foundProperty.value = args.Value.ToString(); } } } , () => { var found = propertyList.FirstOrDefault((candidate) => candidate.name == name); if (property != null) { return property.value; } return null; }, typeConverter ); }
public static LayeredTileMap FromReducedTileMapInfo(TMXGlueLib.DataTypes.ReducedTileMapInfo rtmi, string contentManagerName, string tilbToLoad) { var toReturn = new LayeredTileMap(); string oldRelativeDirectory = FileManager.RelativeDirectory; FileManager.RelativeDirectory = FileManager.GetDirectory(tilbToLoad); MapDrawableBatch mdb; for (int i = 0; i < rtmi.Layers.Count; i++) { mdb = MapDrawableBatch.FromReducedLayer(rtmi.Layers[i], contentManagerName, rtmi.CellWidthInPixels, rtmi.CellHeightInPixels, rtmi.QuadWidth, rtmi.QuadHeight); mdb.AttachTo(toReturn, false); mdb.RelativeZ = i; toReturn.mMapLists.Add(mdb); } FileManager.RelativeDirectory = oldRelativeDirectory; return toReturn; }
internal static MapDrawableBatch FromReducedLayer(TMXGlueLib.DataTypes.ReducedLayerInfo reducedLayerInfo, string contentManagerName, int tileDimensionWidth, int tileDimensionHeight, float quadWidth, float quadHeight) { string textureName = reducedLayerInfo.Texture; Texture2D texture = FlatRedBallServices.Load<Texture2D>(textureName, contentManagerName); #if DEBUG if (!MathFunctions.IsPowerOfTwo(texture.Width) || !MathFunctions.IsPowerOfTwo(texture.Height)) { throw new Exception("The dimensions of the texture file " + texture.Name + " are not power of 2!"); } #endif MapDrawableBatch toReturn = new MapDrawableBatch(reducedLayerInfo.Quads.Count, tileDimensionWidth, tileDimensionHeight, texture); Vector3 position = new Vector3(); Vector2 tileDimensions = new Vector2(quadWidth, quadHeight); foreach (var quad in reducedLayerInfo.Quads) { position.X = quad.LeftQuadCoordinate; position.Y = quad.BottomQuadCorodinate; var textureValues = new Vector4(); textureValues.X = (float)quad.LeftTexturePixel / (float)texture.Width; // Left textureValues.Y = (float)(quad.LeftTexturePixel + tileDimensionWidth) / (float)texture.Width; // Right textureValues.Z = (float)quad.TopTexturePixel / (float)texture.Height; // Top textureValues.W = (float)(quad.TopTexturePixel + tileDimensionHeight) / (float)texture.Height; // Bottom const bool pad = true; if (pad) { const float amountToAdd = .0000001f; textureValues.X += amountToAdd; // Left textureValues.Y -= amountToAdd; // Right textureValues.Z += amountToAdd; // Top textureValues.W -= amountToAdd; // Bottom } int tileIndex = toReturn.AddTile(position, tileDimensions, //quad.LeftTexturePixel, quad.TopTexturePixel, quad.LeftTexturePixel + tileDimensionWidth, quad.TopTexturePixel + tileDimensionHeight); textureValues); toReturn.RegisterName(quad.Name, tileIndex); } return toReturn; }
internal static MapDrawableBatch FromReducedLayer(TMXGlueLib.DataTypes.ReducedLayerInfo reducedLayerInfo, TMXGlueLib.DataTypes.ReducedTileMapInfo rtmi, string contentManagerName) { int tileDimensionWidth = rtmi.CellWidthInPixels; int tileDimensionHeight = rtmi.CellHeightInPixels; float quadWidth = rtmi.QuadWidth; float quadHeight = rtmi.QuadHeight; string textureName = reducedLayerInfo.Texture; #if IOS || ANDROID textureName = textureName.ToLowerInvariant(); #endif Texture2D texture = FlatRedBallServices.Load<Texture2D>(textureName, contentManagerName); #if DEBUG if (!MathFunctions.IsPowerOfTwo(texture.Width) || !MathFunctions.IsPowerOfTwo(texture.Height)) { throw new Exception("The dimensions of the texture file " + texture.Name + " are not power of 2!"); } #endif MapDrawableBatch toReturn = new MapDrawableBatch(reducedLayerInfo.Quads.Count, tileDimensionWidth, tileDimensionHeight, texture); toReturn.Name = reducedLayerInfo.Name; Vector3 position = new Vector3(); Vector2 tileDimensions = new Vector2(quadWidth, quadHeight); IEnumerable<TMXGlueLib.DataTypes.ReducedQuadInfo> quads = null; if (rtmi.NumberCellsWide > rtmi.NumberCellsTall) { quads = reducedLayerInfo.Quads.OrderBy(item => item.LeftQuadCoordinate); toReturn.mSortAxis = SortAxis.X; } else { quads = reducedLayerInfo.Quads.OrderBy(item => item.BottomQuadCoordinate); toReturn.mSortAxis = SortAxis.Y; } foreach (var quad in quads) { position.X = quad.LeftQuadCoordinate; position.Y = quad.BottomQuadCoordinate; // The Z of the quad should be relative to this layer, not absolute Z values. // A multi-layer map will offset the individual layer Z values, the quads should have a Z of 0. // position.Z = reducedLayerInfo.Z; var textureValues = new Vector4(); textureValues.X = (float)quad.LeftTexturePixel / (float)texture.Width; // Left textureValues.Y = (float)(quad.LeftTexturePixel + tileDimensionWidth) / (float)texture.Width; // Right textureValues.Z = (float)quad.TopTexturePixel / (float)texture.Height; // Top textureValues.W = (float)(quad.TopTexturePixel + tileDimensionHeight) / (float)texture.Height; // Bottom // pad before doing any rotations/flipping const bool pad = true; if (pad) { const float amountToAdd = .0000001f; textureValues.X += amountToAdd; // Left textureValues.Y -= amountToAdd; // Right textureValues.Z += amountToAdd; // Top textureValues.W -= amountToAdd; // Bottom } if ((quad.FlipFlags & TMXGlueLib.DataTypes.ReducedQuadInfo.FlippedHorizontallyFlag) == TMXGlueLib.DataTypes.ReducedQuadInfo.FlippedHorizontallyFlag) { var temp = textureValues.Y; textureValues.Y = textureValues.X; textureValues.X = temp; } if ((quad.FlipFlags & TMXGlueLib.DataTypes.ReducedQuadInfo.FlippedVerticallyFlag) == TMXGlueLib.DataTypes.ReducedQuadInfo.FlippedVerticallyFlag) { var temp = textureValues.Z; textureValues.Z = textureValues.W; textureValues.W = temp; } int tileIndex = toReturn.AddTile(position, tileDimensions, //quad.LeftTexturePixel, quad.TopTexturePixel, quad.LeftTexturePixel + tileDimensionWidth, quad.TopTexturePixel + tileDimensionHeight); textureValues); if ((quad.FlipFlags & TMXGlueLib.DataTypes.ReducedQuadInfo.FlippedDiagonallyFlag) == TMXGlueLib.DataTypes.ReducedQuadInfo.FlippedDiagonallyFlag) { toReturn.ApplyDiagonalFlip(tileIndex); } toReturn.RegisterName(quad.Name, tileIndex); } return toReturn; }
public static LayeredTileMap FromReducedTileMapInfo(TMXGlueLib.DataTypes.ReducedTileMapInfo rtmi, string contentManagerName, string tilbToLoad) { var toReturn = new LayeredTileMap(); string oldRelativeDirectory = FileManager.RelativeDirectory; FileManager.RelativeDirectory = FileManager.GetDirectory(tilbToLoad); MapDrawableBatch mdb; if (rtmi.NumberCellsWide != 0) { toReturn.mNumberTilesWide = rtmi.NumberCellsWide; } if (rtmi.NumberCellsTall != 0) { toReturn.mNumberTilesTall = rtmi.NumberCellsTall; } toReturn.mWidthPerTile = rtmi.QuadWidth; toReturn.mHeightPerTile = rtmi.QuadHeight; for (int i = 0; i < rtmi.Layers.Count; i++) { var reducedLayer = rtmi.Layers[i]; mdb = MapDrawableBatch.FromReducedLayer(reducedLayer, rtmi, contentManagerName); mdb.AttachTo(toReturn, false); mdb.RelativeZ = reducedLayer.Z; toReturn.mMapLists.Add(mdb); } FileManager.RelativeDirectory = oldRelativeDirectory; return toReturn; }