コード例 #1
0
    public override void PlaceBackground(EditorOverworldTile tile)
    {
        EditorOverworldTileBackgroundPlacer tileBackgroundPlacer  = new EditorOverworldTileBackgroundPlacer(tile);
        OverworldTileBackgroundRemover      tileBackgroundRemover = new OverworldTileBackgroundRemover(tile);
        OverworldTileAttributeRemover       tileAttributeRemover  = new OverworldTileAttributeRemover(tile);

        List <ITileBackground> backgrounds            = tile.GetBackgrounds();
        ITileBackground        overworldTileBaseWater = (OverworldTileBaseWater)tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTileBaseWater);

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

            if (oldMainMaterial == null || oldMainMaterial == typeof(GroundMainMaterial))
            {
                tileBackgroundRemover.RemoveBackground <OverworldTilePath>();
            }
            OverworldTileBaseWater water = tileBackgroundPlacer.PlaceBackground <OverworldTileBaseWater>();

            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 <OverworldTileBaseGround>();
                }
            }
        }
    }
コード例 #2
0
    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} 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)
            {
                EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(neighbour.Value as EditorOverworldTile);
                tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>();
            }
        }
    }
コード例 #3
0
    public override void RemoveTileObstacle(TileObstacle tileObstacle = null)
    {
        _tile.SetWalkable(true);

        if (!tileObstacle)
        {
            tileObstacle = (TileObstacle)_tile.GetAttributes().FirstOrDefault(attribute => attribute is TileObstacle);
        }
        if (tileObstacle == null)
        {
            return;
        }
        if (tileObstacle is PlayerExit)
        {
            return;
        }

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

        if (oldConnectionScore == NeighbourTileCalculator.ConnectionOnAllSidesScore)
        {
            EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(_tile);
            tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>();
        }

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

        //After removing tile, check with neighbour tiles if wall connections should be updated
        UpdateNeighboursForRemovedObstacle(obstacleType);
    }
コード例 #4
0
    public void AddBackgroundSprites(SerialisableTile serialisableTile, EditorOverworldTile tile)
    {
        EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(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 OverworldDefaultPathType(), new TileConnectionScoreInfo(serialisableTilePathBackground.TileConnectionScore));
            }
            else if (type.Equals(typeof(SerialisableTileBaseGround)))
            {
                SerialisableTileBaseGround serialisableTileBaseGround = (SerialisableTileBaseGround)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type);
                tileBackgroundPlacer.PlaceGround(new OverworldDefaultGroundType(), new TileConnectionScoreInfo(serialisableTileBaseGround.TileConnectionScore));
            }
            else if (type.Equals(typeof(SerialisableTileBaseWater)))
            {
                tileBackgroundPlacer.PlaceCoveringBaseWater();
                //tileBackgroundPlacer.PlaceBackground<OverworldTileBaseWater>();
            }
            else
            {
                Logger.Error($"Unknown TileBackgroundType {serialisableTileBackground.BackgroundType}");
            }
        }
    }
コード例 #5
0
    public override void RemovePath()
    {
        OverworldTilePath overworldTilePath = (OverworldTilePath)_tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTilePath);

        if (overworldTilePath == null)
        {
            return;
        }

        Logger.Log(overworldTilePath.TilePathType);
        IPathType overworldTilePathType = overworldTilePath.TilePathType;
        int       oldConnectionScore    = overworldTilePath.ConnectionScore;

        // If needed, place a background in the gap that the removed path left
        if (oldConnectionScore == NeighbourTileCalculator.ConnectionOnAllSidesScore)
        {
            EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(_tile);
            tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>();
        }

        _tile.RemoveBackground(overworldTilePath);
        overworldTilePath.Remove();

        //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 overworldTilePathOnNeighbour = neighbour.Value.TryGetTilePath();

            if (overworldTilePathOnNeighbour == null)
            {
                continue;
            }

            int oldConnectionScoreOnNeighbour = overworldTilePathOnNeighbour.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 overworldTilePathConnectionScoreOnNeighbourInfo = NeighbourTileCalculator.MapNeighbourPathsOfTile(neighbour.Value, overworldTilePathType);
            Logger.Log($"We calculated an path connection type score of {overworldTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}");

            //update connection score on neighbour
            overworldTilePathOnNeighbour.WithConnectionScoreInfo(overworldTilePathConnectionScoreOnNeighbourInfo);

            //Add background where needed
            if (oldConnectionScoreOnNeighbour == NeighbourTileCalculator.ConnectionOnAllSidesScore && overworldTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore)
            {
                EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(neighbour.Value as EditorOverworldTile);
                tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>();
            }
        }
    }
コード例 #6
0
    public override void PlaceBackgroundVariation(EditorOverworldTile tile)
    {
        ITileBackground overworldTilePath = (OverworldTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTilePath);

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

        tileBackgroundPlacer.PlacePathVariation((OverworldTilePath)overworldTilePath);
    }
コード例 #7
0
    public override void PlaceBackground(EditorOverworldTile tile)
    {
        EditorOverworldTileBackgroundPlacer tileBackgroundPlacer  = new EditorOverworldTileBackgroundPlacer(tile);
        OverworldTileBackgroundRemover      tileBackgroundRemover = new OverworldTileBackgroundRemover(tile);
        OverworldTileAttributeRemover       tileAttributeRemover  = new OverworldTileAttributeRemover(tile);

        Type            oldMainMaterial         = tile.TileMainMaterial?.GetType(); // old material before updating it
        ITileBackground overworldTileBaseGround = (OverworldTileBaseGround)tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTileBaseGround);


        OverworldTileBaseGround oldOverworldTileBaseGround = (OverworldTileBaseGround)tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTileBaseGround);

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

            //if (oldMainMaterial == typeof(WaterMainMaterial) || tile.TileMainMaterial == null)
            //{
            //    tileBackgroundRemover.RemoveBackground<OverworldTileBaseWater>();
            //}

            //if(overworldTileBaseGround == null)
            //{
            //    tileBackgroundPlacer.PlaceBackground<OverworldTileBaseGround>();
            //}
            //else
            //{
            //    tileBackgroundPlacer.UpdateGroundConnectionsOnNeighbours(new OverworldDefaultGroundType());
            //}

            if (oldOverworldTileBaseGround != null && oldOverworldTileBaseGround.ConnectionScore != 16)
            {
                tileBackgroundRemover.RemoveBackground <OverworldTileBaseGround>();
            }

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

        // Place corner fillers
        TileCornerFillerRegister.TryPlaceCornerFillers(tile);
        TileCornerFillerRegister.TryPlaceCornerFillersForNeighbours(tile);
    }
コード例 #8
0
    public override void PlaceBackgroundVariation(EditorOverworldTile tile)
    {
        Logger.Log("Try place background variation");
        ITileBackground overworldTileGround = (OverworldTileBaseGround)tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTileBaseGround);

        if (overworldTileGround == null)
        {
            return;
        }

        EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(tile);

        tileBackgroundPlacer.PlaceGroundVariation((OverworldTileBaseGround)overworldTileGround);
    }
コード例 #9
0
    private void AddCornerFillers(SerialisableTile serialisableTile, EditorOverworldTile tile)
    {
        EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(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}");
            }
        }
    }
コード例 #10
0
    public override void PlaceBackground(EditorOverworldTile tile)
    {
        if (tile.TileMainMaterial.GetType() != typeof(GroundMainMaterial))
        {
            return;
        }

        EditorOverworldTileBackgroundPlacer tileBackgroundPlacer  = new EditorOverworldTileBackgroundPlacer(tile);
        OverworldTileBackgroundRemover      tileBackgroundRemover = new OverworldTileBackgroundRemover(tile);

        ITileBackground overworldTilePath = (OverworldTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTilePath);

        if (overworldTilePath == null)
        {
            OverworldTileAttributeRemover tileAttributeRemover = new OverworldTileAttributeRemover(tile);
            tileAttributeRemover.RemoveTileObstacle();

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

        // This path already exists on this tile, so remove it
        tileBackgroundRemover.RemovePath();
    }