public Padding(Tile originalTile, Overlay originalOverlay, List <Overlay> overlayList, PaddingCoords paddingCoords, PaddingCoords paddingCoordsSelf, PaddingType paddingType) { _originalTile = originalTile; _originalOverlay = originalOverlay; _overlayList = overlayList; this.paddingCoords = paddingCoords; this.paddingCoordsSelf = paddingCoordsSelf; this.type = paddingType; }
public Padding GetPaddingForTile(PaddingType paddingType, Overlay overlay, int x, int y) { Tile tile = overlay.GetTile(x, y); List <Overlay> selfPaddingOverlayList = new List <Overlay>() { overlay }; PaddingCoords paddingCoords = this.GetPaddingSourceCoords(tile, paddingType, false); List <TileDepthInfo> overlayNumbers = new List <TileDepthInfo>(); if (paddingCoords.tileCol < this.TDMap.SizeX && paddingCoords.tileRow < this.TDMap.SizeY && this.TDMap.TileMap[paddingCoords.tileCol, paddingCoords.tileRow] != null) { overlayNumbers = new List <TileDepthInfo>(this.TDMap.TileMap[paddingCoords.tileCol, paddingCoords.tileRow]); } PaddingCoords selfCoords = this.GetPaddingSourceCoords(tile, paddingType, true); if (paddingCoords.selfPadding || overlayNumbers.Count < 1) // || overlay.IsAnimation() || overlay.IsAlpha()) { // case closed let's get drunk return(new Padding(tile, overlay, selfPaddingOverlayList, selfCoords, selfCoords, paddingType)); } if (overlay.IsAlpha() || overlay.IsAnimation()) { return(new Padding(tile, overlay, new List <Overlay>() { overlay }, paddingCoords, selfCoords, paddingType)); } int sourceDepth = overlay.info.curZ + tile.info.depth; List <Overlay> paddingOverlayList = new List <Overlay>(); var currentNumber = overlay.GetOrderNumber(); //int numberToRemove = _getOverlayToRemove(currentNumber, paddingType, x, y); //if (numberToRemove != -1) //{ // for (var i = 0; i < overlayNumbers.Count; i++) // { // var elem = overlayNumbers[i]; // if (elem.orderNumber == numberToRemove) // { // overlayNumbers.Remove(elem); // break; // } // } //} // this one is original order //overlayNumbers.Sort(delegate (TileDepthInfo first, TileDepthInfo second) //{ // return (Math.Abs(first.depth - sourceDepth)).CompareTo(Math.Abs(second.depth - sourceDepth)); //}); // this one is not List <TileDepthInfo> greater = new List <TileDepthInfo>(); List <TileDepthInfo> lesserOrEquals = new List <TileDepthInfo>(); foreach (var element in overlayNumbers) { if (element.depth > sourceDepth) { greater.Add(element); } else { lesserOrEquals.Add(element); } } greater.Reverse(); overlayNumbers = lesserOrEquals.Concat(greater).ToList(); for (int i = 0; i < overlayNumbers.Count; i++) { var item = overlayNumbers[i]; if (overlayNumbers[i].orderNumber == currentNumber) { if (i > 0) { overlayNumbers.RemoveAt(i); overlayNumbers.Insert(0, item); } break; } } // String depths = ""; for (var i = 0; i < overlayNumbers.Count; i++) { int number = overlayNumbers[i].orderNumber; paddingOverlayList.Add(this.GetOverlay(number)); // depths += $"depth {overlayNumbers[i].depth}, orderNumber {overlayNumbers[i].orderNumber}\n "; } // Log.Message(depths); return(new Padding(tile, overlay, paddingOverlayList, paddingCoords, selfCoords, paddingType)); }
private PaddingCoords GetPaddingSourceCoords(Tile tile, PaddingType paddingType, bool forceSelf) { int tileCol, tileRow, ox, oy, backupX, backupY, originalTileX, originalTileY; bool selfPadding = false; switch (paddingType) { case PaddingType.Left: tileCol = tile.x - 1; tileRow = tile.y; ox = -1; oy = 0; originalTileX = 0; originalTileY = 0; backupX = 0; backupY = 0; break; case PaddingType.Right: tileCol = tile.x + 1; tileRow = tile.y; ox = 0; oy = 0; originalTileX = -1; originalTileY = 0; backupX = -1; backupY = 0; break; case PaddingType.Down: tileCol = tile.x; tileRow = tile.y - 1; ox = 0; oy = 0; originalTileX = 0; originalTileY = -1; backupX = 0; backupY = -1; break; case PaddingType.Up: tileCol = tile.x; tileRow = tile.y + 1; ox = 0; oy = -1; originalTileX = 0; originalTileY = 0; backupX = 0; backupY = 0; break; case PaddingType.DownLeft: tileCol = tile.x - 1; tileRow = tile.y - 1; ox = -1; oy = 0; originalTileX = 0; originalTileY = -1; backupX = 0; backupY = -1; break; case PaddingType.DownRight: tileCol = tile.x + 1; tileRow = tile.y - 1; ox = 0; oy = 0; originalTileX = -1; originalTileY = -1; backupX = -1; backupY = -1; break; case PaddingType.UpLeft: tileCol = tile.x - 1; tileRow = tile.y + 1; ox = -1; oy = -1; originalTileX = 0; originalTileY = 0; backupX = 0; backupY = 0; break; case PaddingType.UpRight: tileCol = tile.x - 1; tileRow = tile.y + 1; ox = 0; oy = -1; originalTileX = -1; originalTileY = 0; backupX = -1; backupY = 0; break; default: tileCol = tile.x; tileRow = tile.y; ox = -1; oy = -1; originalTileX = 0; originalTileY = 0; backupX = 0; backupY = 0; break; } if (forceSelf || tileRow < 0 || tileRow >= this.SizeY || tileCol < 0 || tileCol >= this.SizeX) //|| paddingType > PaddingType.Up) { tileCol = tile.x; tileRow = tile.y; ox = backupX; oy = backupY; selfPadding = true; } PaddingCoords paddingCoords = new PaddingCoords { tileCol = tileCol, tileRow = tileRow, ox = ox, oy = oy, originalTileX = originalTileX, originalTileY = originalTileY, selfPadding = selfPadding }; return(paddingCoords); }