/// <summary> /// Tries to get all relevant references that the commands needs to execute. /// </summary> /// <param name="map">The map that the changes are done to.</param> /// <param name="changeTo">The TilesetTile that the change will change the tile to.</param> /// <param name="tile">The affected tile.</param> /// <returns>Wheter all references were set.</returns> protected bool TryGetTiles(out Map map, out TilesetTile changeTo, out Tile tile) { map = null; tile = null; if (TryGetChangeTilesetTile(out changeTo) == false) { return(false); } MapControl mc = MapControl.Instance; if ((map = mc.Map) == null) { return(false); } tile = mc.GetTileFromMousePosition(); if (tile == null) { return(false); } return(true); }
public MapLayer(int x, int y) { width = x; height = y; tiles = new TilesetTile[x * y]; int length = x * y; for (int i = 0; i < length; i++) { tiles[i] = new TilesetTile(); } // Debug.Log (this.ToString () + " width = " + width); }
public override void Add() { if (TryGetTiles(out _, out TilesetTile changeTo, out Tile tile) == false) { return; } TilesetTile prevTile = tile.referencedTile; if (prevTile == changeTo) { return; } tile.referencedTile = changeTo; changes.Add(new Change(tile, prevTile, changeTo)); }
private static TilesetTile TilesetTile(BinaryReader b) { var t = new TilesetTile { sound_id = b.ReadUInt16().SwapBytes(), time_per_move = b.ReadUInt16().SwapBytes(), solid_type = b.ReadUInt16().SwapBytes(), is_shore = b.ReadUInt16().SwapBytes(), is_need_boat = b.ReadUInt16().SwapBytes(), is_path = b.ReadUInt16().SwapBytes(), blocks_los = b.ReadUInt16().SwapBytes(), need_fly_float = b.ReadUInt16().SwapBytes(), special_type = b.ReadUInt16().SwapBytes(), unknown5 = b.ReadInt16().SwapBytes() }; for (int i = 0; i < 9; i++) { t.battle_expansion[i] = b.ReadInt16().SwapBytes(); } t.unknown6 = b.ReadInt16().SwapBytes(); return(t); }
public void Draw(SpriteBatch batch) { if (map == null) { return; } Rectangle source = new Rectangle(0, 0, map.tileWidth, map.tileHeight); Rectangle destin = new Rectangle(0, 0, map.tileWidth, map.tileHeight); // Iterate over each layer for (int l = 0; l < map.layers.Count; l++) { // skip if layer is invisible if (map.layers[l].visible == false) { continue; } // iterate over each tile for (int x = 0; x < map.xSize; x++) { for (int y = 0; y < map.ySize; y++) { // Get the tile and reference TilesetTile Tile tile = map.layers[l].tiles.Get(x, y); TilesetTile tilesetTile = tile.referencedTile; // If the tilesetTile is null or no texture was found for the tileset. if (tilesetTile == null || loadedTextures.TryGetValue(tilesetTile.parentTileset, out Texture2D texture) == false) { // draw the emptyTile texture to the position of the tile if we are at the base layer, i.e. layer 0. if (l != 0) { continue; } else { texture = emptyTile; source.X = 0; source.Y = 0; source.Width = emptyTile.Width; source.Height = emptyTile.Height; } } else // tilesetTile texture was found. { source.Width = tilesetTile.parentTileset.tileWidth; source.Height = tilesetTile.parentTileset.tileHeight; source.X = tilesetTile.x * source.Width; source.Y = tilesetTile.y * source.Height; } destin.X = x * map.tileWidth; destin.Y = y * map.tileHeight; // draw the tile onto screen. batch.Draw(texture, destin, source, Color.White, 0, new Vector2(), SpriteEffects.None, 0); } } } }
/// <summary> /// The tileset tile that the command is changing affected tiles to. /// </summary> /// <param name="changeTo">The TilesetTile that a tile is changing to.</param> /// <returns>Wheter a valid replacement was found.</returns> protected virtual bool TryGetChangeTilesetTile(out TilesetTile changeTo) { changeTo = HighlitingTilesetTile.Instance.highlighted; return(changeTo != null); }
/// <summary> /// Standard constructor. /// </summary> /// <param name="changedTile">The affected tile.</param> /// <param name="prev">The previous tilesetTile Before the change.</param> /// <param name="now">The current TilesetTile after the change.</param> public Change(Tile changedTile, TilesetTile prev, TilesetTile now) { this.changedTile = changedTile; this.prev = prev; this.now = now; }
public override void Apply() { if (TryGetTiles(out Map map, out TilesetTile changeTo, out Tile tile) == false) { return; } Layer layer = map.layers[MapControl.Instance.SelectedLayer]; TilesetTile replaceFrom = tile.referencedTile; List <Tile> openList = new List <Tile>(); // Tiles that are still need to be processed. List <Tile> closedList = new List <Tile>(); // Tiles that are going to change. // If the pressed tile is the same as the toChange to then simply return. if (tile.referencedTile == changeTo) { return; } openList.Add(tile); while (openList.Count > 0) { Tile current = openList[0]; closedList.Add(current); openList.RemoveAt(0); // Look above, right, left and beneath the currentTile. Point[] toExamine = new Point[4]; toExamine[0] = new Point(current.x - 1, current.y); toExamine[1] = new Point(current.x + 1, current.y); toExamine[2] = new Point(current.x, current.y - 1); toExamine[3] = new Point(current.x, current.y + 1); for (int i = 0; i < toExamine.Length; i++) { // out of bounds? if (toExamine[i].X < 0 || toExamine[i].Y < 0 || toExamine[i].X >= map.xSize || toExamine[i].Y >= map.ySize) { continue; } // not the same tilesettile? Tile newTile = layer.tiles.Get(toExamine[i].X, toExamine[i].Y); if (newTile.referencedTile != replaceFrom) { continue; } // already in the closed or open list? if (closedList.Contains(newTile) == true || openList.Contains(newTile) == true) { continue; } openList.Add(newTile); } } // For each tile in the closed list, change the tile to the new tileset tile and save the command. for (int i = 0; i < closedList.Count; i++) { changes.Add(new Change(closedList[i], closedList[i].referencedTile, changeTo)); closedList[i].referencedTile = changeTo; } base.Apply(); }
protected override bool TryGetChangeTilesetTile(out TilesetTile changeTo) { base.TryGetChangeTilesetTile(out changeTo); return(true); }
protected override bool TryGetChangeTilesetTile(out TilesetTile changeTo) { changeTo = null; return(true); }
public void SetTile(int x, int y, TilesetTile tile) { tiles [x + y * width] = tile; }