From 8351f49f6d328bdf5ebcb3ed904190200b235d89 Mon Sep 17 00:00:00 2001 From: Triceraptodactyl Date: Tue, 24 Apr 2018 22:03:00 +0200 Subject: [PATCH] Code Cleanup --- .../Scripts/Generation/GenerationProcessor.cs | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/Assets/Scripts/Generation/GenerationProcessor.cs b/Assets/Scripts/Generation/GenerationProcessor.cs index 1e0f684..e2806ea 100644 --- a/Assets/Scripts/Generation/GenerationProcessor.cs +++ b/Assets/Scripts/Generation/GenerationProcessor.cs @@ -55,25 +55,21 @@ public class GenerationProcessor { return tmp; } - private int CountSpecificNeighbours(Dictionary tiles, Vector2Int position, Room.TileType type) { - int counter = 0; - Vector2Int toCheck = position + new Vector2Int(0, -1); - if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == type ) - counter++; - toCheck = position + new Vector2Int(-1, 0); - if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == type ) - counter++; - toCheck = position + new Vector2Int(0, 1); - if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == type ) - counter++; - toCheck = position + new Vector2Int(1, 0); - if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == type ) - counter++; - return counter; - } - private ExtendedTileType GetCorrectWallType(Dictionary tiles, Vector2Int position) { - int groundNumber = CountSpecificNeighbours(tiles, position, Room.TileType.GROUND) + CountSpecificNeighbours(tiles, position, Room.TileType.ROCK) + CountSpecificNeighbours(tiles, position, Room.TileType.DOOR); + int groundNumber = 0; + Vector2Int toCheck = position + new Vector2Int(0, -1); + if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL ) + groundNumber++; + toCheck = position + new Vector2Int(-1, 0); + if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL ) + groundNumber++; + toCheck = position + new Vector2Int(0, 1); + if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL ) + groundNumber++; + toCheck = position + new Vector2Int(1, 0); + if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL ) + groundNumber++; + switch ( groundNumber ) { case 0: return ExtendedTileType.BorderInner; @@ -185,7 +181,20 @@ public class GenerationProcessor { } private ExtendedTileType GetCorrectDoorType(Dictionary tiles, Vector2Int position) { - int neighbourDoors = CountSpecificNeighbours(tiles, position, Room.TileType.DOOR); + int neighbourDoors = 0; + Vector2Int toCheck = position + new Vector2Int(0, -1); + if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR ) + neighbourDoors++; + toCheck = position + new Vector2Int(-1, 0); + if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR ) + neighbourDoors++; + toCheck = position + new Vector2Int(0, 1); + if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR ) + neighbourDoors++; + toCheck = position + new Vector2Int(1, 0); + if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR ) + neighbourDoors++; + switch ( neighbourDoors ) { case 1: return ExtendedTileType.DoorOuter;