예제 #1
0
    private void AddBackgroundSprites(SerialisableTile serialisableTile, EditorMazeTile tile)
    {
        EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(tile);

        foreach (SerialisableTileBackground serialisableTileBackground in serialisableTile.TileBackgrounds)
        {
            Type type = Type.GetType(serialisableTileBackground.BackgroundType);

            if (type.Equals(typeof(SerialisableTilePathBackground)))
            {
                SerialisableTilePathBackground serialisableTilePathBackground = (SerialisableTilePathBackground)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type);
                tileBackgroundPlacer.PlacePath(new MazeLevelDefaultPathType(), new TileConnectionScoreInfo(serialisableTilePathBackground.TileConnectionScore));
            }
            else if (type.Equals(typeof(SerialisableTileBaseGround)))
            {
                SerialisableTileBaseGround serialisableTileBaseGround = (SerialisableTileBaseGround)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type);
                tileBackgroundPlacer.PlaceGround(new MazeLevelDefaultGroundType(), new TileConnectionScoreInfo(serialisableTileBaseGround.TileConnectionScore));
            }
            else if (type.Equals(typeof(SerialisableTileBaseWater)))
            {
                tileBackgroundPlacer.PlaceCoveringBaseWater();
            }
            else
            {
                Logger.Error($"Unknown TileBackgroundType {serialisableTileBackground.BackgroundType}");
            }
        }
    }
    public override void RemoveTileObstacle(TileObstacle tileObstacle = null)
    {
        if (!tileObstacle)
        {
            tileObstacle = (TileObstacle)_tile.GetAttributes().FirstOrDefault(attribute => attribute is TileObstacle);
        }

        if (tileObstacle == null)
        {
            return;
        }
        if (tileObstacle is PlayerExit)
        {
            return;
        }

        _tile.SetWalkable(true);

        ObstacleType obstacleType       = tileObstacle.ObstacleType;
        int          oldConnectionScore = tileObstacle.ConnectionScore;

        // If needed, place a background in the gap that the removed path left.
        // OPTIMISATION: Currently only looking at connection score from obstacles, but should also take eg. door attributes into account.
        if (oldConnectionScore == NeighbourTileCalculator.ConnectionOnAllSidesScore)
        {
            EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(_tile);
            tileBackgroundPlacer.PlaceBackground <MazeTileBaseGround>();
        }

        _tile.RemoveAttribute(tileObstacle);
        tileObstacle.Remove();

        //After removing tile, check with neighbour tiles if wall connections should be updated
        UpdateNeighboursForRemovedObstacle(obstacleType);
    }
    private void UpdateNeighboursForRemovedObstacle(ObstacleType obstacleType)
    {
        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                continue;
            }

            TileObstacle tileObstacleOnNeighbour = neighbour.Value.TryGetTileObstacle();

            if (tileObstacleOnNeighbour == null)
            {
                continue;
            }
            Logger.Log($"We will look for connections for neighbour {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y}, which is {neighbour.Key} of {_tile.GridLocation.X},{_tile.GridLocation.Y}");
            TileConnectionScoreInfo obstacleConnectionScoreOnNeighbour = NeighbourTileCalculator.MapNeighbourObstaclesOfTile(neighbour.Value, obstacleType);
            Logger.Log($"We calculated an obstacle connection type score of {obstacleConnectionScoreOnNeighbour.RawConnectionScore} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}");

            //update connection score on neighbour
            tileObstacleOnNeighbour.WithConnectionScoreInfo(obstacleConnectionScoreOnNeighbour);

            // If needed, place a background
            if (obstacleConnectionScoreOnNeighbour.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore)
            {
                MazeTileBaseGround oldMazeTileBaseGround = (MazeTileBaseGround)neighbour.Value.GetBackgrounds().FirstOrDefault(background => background is MazeTileBaseGround);
                if (oldMazeTileBaseGround == null)
                {
                    EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(neighbour.Value as EditorMazeTile);
                    tileBackgroundPlacer.PlaceBackground <MazeTileBaseGround>();
                }
            }
        }
    }
예제 #4
0
    public override void PlaceBackgroundVariation(EditorMazeTile tile)
    {
        ITileBackground mazeTilePath = (MazeTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath);

        if (mazeTilePath == null)
        {
            return;                       // only place variation if there is already a path
        }
        EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(tile);

        tileBackgroundPlacer.PlacePathVariation((MazeTilePath)mazeTilePath);
    }
    public override void PlaceBackgroundVariation(EditorMazeTile tile)
    {
        Logger.Log("Try place background variation");
        ITileBackground mazeTileGround = (MazeTileBaseGround)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTileBaseGround);

        if (mazeTileGround == null)
        {
            return;
        }

        EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(tile);

        tileBackgroundPlacer.PlaceGroundVariation((MazeTileBaseGround)mazeTileGround);
    }
예제 #6
0
    private void AddCornerFillers(SerialisableTile serialisableTile, EditorMazeTile tile)
    {
        EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(tile);   // corner filler is also an IBackground

        foreach (SerialisableTileCornerFiller serialisableTileCornerFiller in serialisableTile.TileCornerFillers)
        {
            if (Enum.TryParse(serialisableTileCornerFiller.TileCorner, out TileCorner tileCorner))
            {
                tileBackgroundPlacer.PlaceCornerFiler(tileCorner);
            }
            else
            {
                Logger.Error($"Could not parse the TileCorner value{serialisableTileCornerFiller.TileCorner}");
            }
        }
    }
예제 #7
0
    public override void PlaceBackground(EditorMazeTile tile)
    {
        EditorMazeTileBackgroundPlacer tileBackgroundPlacer  = new EditorMazeTileBackgroundPlacer(tile);
        MazeTileBackgroundRemover      tileBackgroundRemover = new MazeTileBackgroundRemover(tile);
        MazeTileAttributeRemover       tileAttributeRemover  = new MazeTileAttributeRemover(tile);

        List <ITileBackground> backgrounds       = tile.GetBackgrounds();
        ITileBackground        mazeTileBaseWater = backgrounds.FirstOrDefault(background => background is MazeTileBaseWater);

        // Only act if there is no water
        if (mazeTileBaseWater == null)
        {
            Type oldMainMaterial = tile.TileMainMaterial?.GetType(); // old material before updating it

            // Remove any background overlays for Ground tiles, such as paths.
            if (oldMainMaterial == null || oldMainMaterial == typeof(GroundMainMaterial))
            {
                tileBackgroundRemover.RemoveBackground <MazeTilePath>();
            }

            MazeTileBaseWater water = tileBackgroundPlacer.PlaceBackground <MazeTileBaseWater>();

            List <ITileAttribute> attributes = tile.GetAttributes();
            for (int i = 0; i < attributes.Count; i++)
            {
                tileAttributeRemover.Remove(attributes[i]);
            }

            if (oldMainMaterial == null || oldMainMaterial == typeof(GroundMainMaterial))
            {
                if (water.ConnectionScore == 16) // remove background if we completely covered the tile with water
                {
                    tileBackgroundRemover.RemoveBackground <MazeTileBaseGround>();
                }
            }
        }
    }
예제 #8
0
    public override void PlaceBackground(EditorMazeTile tile)
    {
        if (tile.TileMainMaterial.GetType() != typeof(GroundMainMaterial))
        {
            return;
        }

        EditorMazeTileBackgroundPlacer tileBackgroundPlacer  = new EditorMazeTileBackgroundPlacer(tile);
        MazeTileBackgroundRemover      tileBackgroundRemover = new MazeTileBackgroundRemover(tile);

        ITileBackground mazeTilePath = (MazeTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath);

        if (mazeTilePath == null)
        {
            MazeTileAttributeRemover tileAttributeRemover = new MazeTileAttributeRemover(tile);
            tileAttributeRemover.RemoveTileObstacle();

            tileBackgroundPlacer.PlacePath(new MazeLevelDefaultPathType());
            return;
        }

        // This path already exists on this tile, so remove it
        tileBackgroundRemover.RemovePath();
    }
    public override void PlaceBackground(EditorMazeTile tile)
    {
        EditorMazeTileBackgroundPlacer tileBackgroundPlacer  = new EditorMazeTileBackgroundPlacer(tile);
        MazeTileBackgroundRemover      tileBackgroundRemover = new MazeTileBackgroundRemover(tile);
        MazeTileAttributeRemover       tileAttributeRemover  = new MazeTileAttributeRemover(tile);

        Type oldMainMaterial = tile.TileMainMaterial?.GetType(); // old material before updating it

        MazeTileBaseGround oldMazeTileBaseGround = (MazeTileBaseGround)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTileBaseGround);

        if ((oldMainMaterial != typeof(GroundMainMaterial)))
        {
            List <ITileAttribute> attributes = tile.GetAttributes();
            for (int i = 0; i < attributes.Count; i++)
            {
                tileAttributeRemover.Remove(attributes[i]);
            }

            // Remove the old land background, because we are going to fully cover it with a new land background
            if (oldMazeTileBaseGround != null && oldMazeTileBaseGround.ConnectionScore != 16)
            {
                tileBackgroundRemover.RemoveBackground <MazeTileBaseGround>();
            }

            MazeTileBaseGround newMazeTileBaseGround = tileBackgroundPlacer.PlaceBackground <MazeTileBaseGround>();
            // Remove water from the tile that is fully covered by land
            if (newMazeTileBaseGround.ConnectionScore == 16)
            {
                tileBackgroundRemover.RemoveBackground <MazeTileBaseWater>();
            }
        }

        // Place corner fillers
        TileCornerFillerRegister.TryPlaceCornerFillers(tile);
        TileCornerFillerRegister.TryPlaceCornerFillersForNeighbours(tile);
    }
예제 #10
0
    public override void RemovePath()
    {
        MazeTilePath mazeTilePath = (MazeTilePath)_tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath);

        if (mazeTilePath == null)
        {
            return;
        }

        Logger.Log(mazeTilePath.TilePathType);
        IPathType mazeTilePathType   = mazeTilePath.TilePathType;
        int       oldConnectionScore = mazeTilePath.ConnectionScore;

        Logger.Log($"Old path score: {oldConnectionScore}");

        // If needed, place a background in the gap that the removed path left
        if (oldConnectionScore == NeighbourTileCalculator.ConnectionOnAllSidesScore)
        {
            Logger.Log($"Place background in gap at {_tile.GridLocation.X},{_tile.GridLocation.Y}.");
            EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(_tile);
            tileBackgroundPlacer.PlaceCoveringBaseGround(); // place background with connections on all sides
        }

        _tile.RemoveBackground(mazeTilePath);
        mazeTilePath.Remove();

        TrySetTileNotMarkable();


        //After removing tile, check with neighbour tiles if wall connections should be updated
        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                continue;
            }

            TilePath mazeTilePathOnNeighbour = neighbour.Value.TryGetTilePath();

            if (mazeTilePathOnNeighbour == null)
            {
                continue;
            }

            int oldConnectionScoreOnNeighbour = mazeTilePathOnNeighbour.ConnectionScore;

            Logger.Warning($"We will now look for connections for neighbour {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y}, which is {neighbour.Key} of {_tile.GridLocation.X},{_tile.GridLocation.Y}");
            TileConnectionScoreInfo mazeTilePathConnectionScoreOnNeighbourInfo = NeighbourTileCalculator.MapNeighbourPathsOfTile(neighbour.Value, mazeTilePathType);
            Logger.Log($"We calculated an path connection type score of {mazeTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}");

            //update connection score on neighbour
            mazeTilePathOnNeighbour.WithConnectionScoreInfo(mazeTilePathConnectionScoreOnNeighbourInfo);

            //Add background where needed
            if (oldConnectionScoreOnNeighbour == NeighbourTileCalculator.ConnectionOnAllSidesScore &&
                mazeTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore)
            {
                EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(neighbour.Value as EditorMazeTile);
                tileBackgroundPlacer.PlaceCoveringBaseGround();
            }
        }

        _tile.RemoveTileAsBeautificationTrigger();
    }