public void AttributeSetShouldBeMakeANameTileMappping() { var firstTile = new TileAttribute("first", new StringTile("1")); var secondTile = new TileAttribute("second", new StringTile("2")); var set = new AttributeSet("TILE", new List<TileAttribute> { firstTile, secondTile }); Assert.That(set.Count, Is.EqualTo(2)); }
public void ContainsOnTileAttributesShouldReturnTrueForExistingName() { var firstTile = new TileAttribute("first", new StringTile("1")); var secondTile = new TileAttribute("second", new StringTile("2")); var set = new AttributeSet("TILE", new List<TileAttribute> { firstTile, secondTile }); Assert.That(set.HasDefinitionFor("first")); }
public List <TileAttribute> GetTileAttribute() { double MapResolution = CommonUtil.QueryMapResolution(this.Level, "..\\..\\..\\MapTileSupport\\Data\\MapResolution.xml"); int maxRow = Convert.ToInt32(Math.Ceiling((180.0 + this.TopRight.Lng) / MapResolution * 256.0) - 1); int maxColumn = Convert.ToInt32(Math.Ceiling((90 - this.TopRight.Lat) / MapResolution * 256) - 1); int minRow = Convert.ToInt32(Math.Ceiling((180.0 + this.BottomLeft.Lng) / MapResolution * 256.0) - 1); int minColumn = Convert.ToInt32(Math.Ceiling((90 - this.BottomLeft.Lat) / MapResolution * 256) - 1); for (int i = minRow; i <= maxRow; i++) { for (int j = minColumn; j <= maxColumn; j++) { TileAttribute tileAttribute = new TileAttribute(i, j, this.Level, "TianMap"); this.TileAttributeCollection.Add(tileAttribute); } } return(this.TileAttributeCollection); }
public void Copy(TileAttribute tileToCopy) { transform.localScale = new Vector3(1, 1, 0); transform.localPosition = new Vector2(0, 0); mainTileColour = tileToCopy.mainTileColour; thisAttributeRenderer.color = mainTileColour.colour; thisAttributeRenderer.sprite = tileToCopy.thisAttributeRenderer.sprite; //stuff for edge tiles: if (tileToCopy.edgeTileArrow) { edgeTileArrow.transform.rotation = tileToCopy.edgeTileArrow.transform.rotation; } //stuff for game tiles: if (tileToCopy.leftRectangleWithArrow && tileToCopy.topRectangleWithArrow && tileToCopy.rightRectangleWithArrow && tileToCopy.bottomRectangleWithArrow) { leftRectangleWithArrow.SetActive(tileToCopy.leftRectangleWithArrow.activeSelf); topRectangleWithArrow.SetActive(tileToCopy.topRectangleWithArrow.activeSelf); rightRectangleWithArrow.SetActive(tileToCopy.rightRectangleWithArrow.activeSelf); bottomRectangleWithArrow.SetActive(tileToCopy.bottomRectangleWithArrow.activeSelf); //for the rainbow sprite on the bottom rectangle bottomRectangleWithArrow.GetComponent <SpriteRenderer>().sprite = tileToCopy.bottomRectangleWithArrow.GetComponent <SpriteRenderer>().sprite; } type = tileToCopy.type; rotation = tileToCopy.rotation; colorArrayNumber = tileToCopy.colorArrayNumber; isLocked = tileToCopy.isLocked; if (lockedImage) { lockedImage.SetActive(isLocked); } }
//Adds scripts by Type, and then sets/initializes their parameters with TileAttribute.setParameters() public void addAttribute(string[] args) { //args[0] and [1] are the tile loc //args[2] is the script type int scriptType = 0; if (int.TryParse(args[2], out scriptType)) { TileAttribute attrib = addAttributeScript(scriptType); //If the script was added, set parameters if (attrib) { attrib.setParameters(args); attributes.Add(attrib); //TBD : Inform Board.cs of this attribute so it can track them // TBD : So that we can find attributes later more easily, like EnemySpawns or OrePatches without having to loop all tiles, etc } } }
internal static void SerializeToToken(Microsoft.Phone.Shell.StandardTileData data /*Due static extracted this is here*/, IToken token) { foreach (System.Reflection.PropertyInfo info in data.GetType().GetProperties()) { foreach (Attribute attribute in info.GetCustomAttributes(true)) { TileAttribute attribute2 = attribute as TileAttribute; //if ((attribute2 != null) && data.TemplateTypeProperties.Contains<TOKEN_PROPERTY_TYPE>(attribute2.PropertyId)) //{ // object obj2 = info.GetValue(data, null); // string defaultValue = attribute2.DefaultValue; // if (obj2 != null) // { // if (attribute2.ValueConverter == null) // { // defaultValue = string.Format("{0}", obj2); // } // else // { // var converter = (System.Windows.Data.IValueConverter)Activator.CreateInstance(Type.GetType(attribute2.ValueConverter)); // defaultValue = (string)converter.Convert(obj2, typeof(string), null, CultureInfo.InvariantCulture); // } // } // if (defaultValue != null) // { // uint num = (uint)(5 /*5 = default*//*data.TemplateType*/ << 0x10); // uint propertyId = (uint)(((TOKEN_PROPERTY_TYPE)num) | attribute2.PropertyId); // if (defaultValue.Length > 0x200) // { // throw new ArgumentException("The serialized property " + info.Name + " is too long"); // } // token.set_Property(propertyId, defaultValue); // } //} } } }
public TileAttributeArgs(TileAttribute attribute, Tile tile) { this.Attribute = attribute; this.Tile = tile; }
public override MapDescriptor <LayerDescriptor <TileDescriptor <SpriteInfo> > > Load(IDataManagerArguments arguments) { MapDescriptor <LayerDescriptor <TileDescriptor <SpriteInfo> > > map = null; var mapArguments = (arguments as ContentFileDataLoaderArguments); using (var fileStream = new FileStream(this.RootPath + mapArguments.FileName + EngineConstants.MAP_FILE_EXT, FileMode.Open)) { using (var bR = new BinaryReader(fileStream)) { // Load the tileset information int tilesetCount = bR.ReadInt32(); List <string> tilesetPaths = new List <string>(); for (int i = 0; i < tilesetCount; i++) { // We can throw this information away as it is used only in the editor suite. string tilesetPath = bR.ReadString(); tilesetPaths.Add(tilesetPath); } string name = bR.ReadString(); var dimensions = new Vector(bR.ReadInt32(), bR.ReadInt32()); map = new MapDescriptor <LayerDescriptor <TileDescriptor <SpriteInfo> > >(dimensions, name) { Dark = bR.ReadBoolean() }; map.TilesetPaths.AddRange(tilesetPaths); map.Bounds = new Rect(0, 0, (int)map.Dimensions.X, (int)map.Dimensions.Y); int layerCount = bR.ReadInt32(); for (int i = 0; i < layerCount; i++) { string layerName = bR.ReadString(); int lIndex = bR.ReadInt32(); var layer = new LayerDescriptor <TileDescriptor <SpriteInfo> >(map.Dimensions, layerName, lIndex); for (int x = 0; x < layer.Tiles.GetLength(0); x++) { for (int y = 0; y < layer.Tiles.GetLength(1); y++) { if (bR.ReadBoolean()) { layer.Tiles[x, y] = new TileDescriptor <SpriteInfo>(new Vector(x * EngineConstants.TILE_SIZE, y * EngineConstants.TILE_SIZE)); if (bR.ReadBoolean()) // Is there a valid attribute saved for this tile? { int attributeDataLength = bR.ReadInt32(); byte[] attributeData = bR.ReadBytes(attributeDataLength); layer.Tiles[x, y].Attribute = TileAttribute.Deserialize(attributeData); } if (bR.ReadBoolean()) { layer.Tiles[x, y].Animated = bR.ReadBoolean(); layer.Tiles[x, y].LightSource = bR.ReadBoolean(); string spriteName = bR.ReadString(); float zIndex = bR.ReadSingle(); // We can throw this away layer.Tiles[x, y].Sprite = new SpriteInfo(spriteName) { Transform = { Position = new Vector(x * EngineConstants.TILE_SIZE, y * EngineConstants.TILE_SIZE), Color = new Color(bR.ReadByte(), bR.ReadByte(), bR.ReadByte(), bR.ReadByte()), Rect = new Rect(bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32()), LayerDepth = zIndex } }; layer.Tiles[x, y].FrameCount = bR.ReadInt32(); } } } } //int mapObjectCount = bR.ReadInt32(); //for (int mI = 0; mI < mapObjectCount; mI++) //{ // var mapObject = new MapObjectDescriptor() // { // Position = new Vector(bR.ReadSingle(), bR.ReadSingle()) // }; // if (bR.ReadBoolean()) // { // string texturePath = bR.ReadString(); // mapObject.Sprite = new SpriteInfo(texturePath) // { // Transform = // { // Rect = new Rect(bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32(), bR.ReadInt32()) // } // }; // } // mapObject.Animated = bR.ReadBoolean(); // mapObject.FrameTime = bR.ReadInt32(); // string scriptPath = bR.ReadString(); // var lightSource = bR.ReadBoolean(); // var lightRadius = bR.ReadSingle(); // var lightColor = new Color(bR.ReadByte(), bR.ReadByte(), bR.ReadByte(), bR.ReadByte()); // if (lightSource) // { // mapObject.LightInformation = new LightInformation() // { // Radius = lightRadius, // Color = lightColor // }; // } //} map.AddLayer(layerName, layer); } } } return(map); }
public void addTileAttribute(TileAttribute tileAttribute) { setDirty(); this.tileType.addTileAttribute(tileAttribute); tileAttribute.applyEffect(this); }
private void ConvertTMX(TmxMap map) { // Set general properties. this.Width = map.Width; this.Height = map.Height; var tilesets = map.Tileset; // Load the layers. int layerCount = 0; for (int i = 0; i < map.Layer.Length; i++) { if (!map.Layer[i].Name.StartsWith("attribute")) { layerCount++; } } this.Layers = new Layer[layerCount]; this.Attributes = new TileAttribute[this.Width * this.Height]; for (int i = 0; i < map.Layer.Length; i++) { this.Layers[i] = new Layer(this.Width, this.Height); var layer = this.Layers[i]; // Get attributes. if (map.Layer[i].Name.StartsWith("attribute")) { for (int tileID = 0; tileID < map.Layer[i].Data.Length; tileID++) { int gid = map.Layer[i].Data[tileID].GID; if (this.Attributes[i] == null) { this.Attributes[i] = new TileAttribute(); } foreach (var tileset in tilesets) { if (tileset.Name == "mapattributes") { this.Attributes[i].AddAttribute(TileAttribute.GIDToName(gid)); } else { gid -= tileset.Image.Width * tileset.Image.Height; } } } continue; } // Get tile information for (int tileID = 0; tileID < map.Layer[i].Data.Length; tileID++) { int gid = map.Layer[i].Data[tileID].GID; foreach (var tileset in tilesets) { if (gid - tileset.Image.Width * tileset.Image.Height < 0) { layer.Tiles[tileID] = new Tile(tileset.Name, gid, tileset.Image.Width, tileset.Image.Height); break; } else { gid -= tileset.Image.Width * tileset.Image.Height; } } } } }
public TileAttributePlayerArgs(TileAttribute attribute, Tile tile, Player player) : base(attribute, tile) { this.Player = player; }
public bool HasFlag(TileAttribute flag) { return(Attributes.ContainsKey(flag)); }
public void TileAttributesShouldThrowExceptionWhenAddingTheSameName() { var firstTile = new TileAttribute("first", new StringTile("1")); var secondTile = new TileAttribute("first", new StringTile("2")); try { new AttributeSet("TILE", new List<TileAttribute> { firstTile, secondTile }); Assert.Fail("Expected exception"); } catch (TileException Te) { Assert.That(Te.Message, Is.EqualTo(TileException.AttributeNameAlreadyUsed("first", "TILE").Message)); } }
public void TileAttributesShouldThrowExceptionOnNonExistingName() { var firstTile = new TileAttribute("first", new StringTile("1")); var secondTile = new TileAttribute("second", new StringTile("2")); var set = new AttributeSet("TILE", new List<TileAttribute> { firstTile, secondTile }); try { Assert.That(set["nonexisting"], Is.Not.Null); Assert.Fail("Expected exception"); } catch (TileException Te) { Assert.That(Te.Message, Is.EqualTo(TileException.AttributeNotFound("nonexisting", "TILE").Message)); } }
public void TileAttributesShouldBeRetrievableByName() { var firstTile = new TileAttribute("first", new StringTile("1")); var secondTile = new TileAttribute("second", new StringTile("2")); var set = new AttributeSet("TILE", new List<TileAttribute> { firstTile, secondTile }); Assert.That(set["first"], Is.Not.Null); Assert.That(set["first"], Is.SameAs(firstTile)); }
public void TileAnimation(TileAttribute att, bool IsRoad) { isRoad = IsRoad; if (att == TileAttribute.None) { } if (att == TileAttribute.Water) { float rand = UnityEngine.Random.Range(.12f, .14f); animationTime = rand; StartCoroutine(WaterTile(animationTime)); } if (att == TileAttribute.Fire) { float rand = UnityEngine.Random.Range(.04f, .10f); animationTime = rand; StartCoroutine(FireTile(animationTime)); } if (att == TileAttribute.Magic) { float rand = UnityEngine.Random.Range(.08f, .11f); animationTime = rand; StartCoroutine(MagicTile(animationTime)); } if (att == TileAttribute.Nature) { float rand = UnityEngine.Random.Range(.03f, .05f); animationTime = rand; StartCoroutine(NatureTile(animationTime)); } if (att == TileAttribute.Poison) { float rand = UnityEngine.Random.Range(.01f, .20f); animationTime = rand; PoisonTile(rand); } if (att == TileAttribute.Electric) { float rand = UnityEngine.Random.Range(.03f, .05f); animationTime = rand; ElectricTile(rand); } if (att == TileAttribute.Ice) { float rand = UnityEngine.Random.Range(.01f, .20f); animationTime = rand; IceTile(rand); } if (att == TileAttribute.Shadow) { float rand = UnityEngine.Random.Range(-.07f, .07f); animationTime = rand; ShadowTile(rand); } if (att == TileAttribute.Mechanical) { float rand = UnityEngine.Random.Range(.01f, .1f); animationTime = rand; MechanicalTile(rand); } if (att == TileAttribute.Normal) { float rand = UnityEngine.Random.Range(.03f, .12f); animationTime = rand; StartCoroutine(NormalTile(animationTime)); } }
public override void SerializeImpl(SerializerObject s) { TileIndex = s.Serialize <byte>(TileIndex, name: nameof(TileIndex)); Attribute = s.SerializeObject <TileAttribute>(Attribute, name: nameof(Attribute)); }
public TileAttributeUpdateArgs(TileAttribute attribute, GameTime gameTime, Tile tile) : base(attribute, tile) { this.GameTime = gameTime; }