public static LevelMap FromString(string token)
    {
        var parts = token.Split(Separator[0]);

        if (!parts[0].Equals(Header))
        {
            throw new ArgumentException("Invalid Token");
        }

        var name            = parts[1];
        var size            = parts[2].Substring(4).TrimStart('[').TrimEnd(']').Split(',');
        var width           = int.Parse(size[0]);
        var height          = int.Parse(size[1]);
        var levelMapBuilder = new LevelMapBuilder(name, width, height);

        var floor = parts[2];

        new TwoDimensionalIterator(width, height)
        .ForEach(p => levelMapBuilder.With(
                     new TilePoint(p.Item1, p.Item2),
                     MapPieceSymbol.Piece(floor[p.Item1 + p.Item2 * width].ToString())));

        var objects = parts[3];

        new TwoDimensionalIterator(width, height)
        .ForEach(p => levelMapBuilder.With(
                     new TilePoint(p.Item1, p.Item2),
                     MapPieceSymbol.Piece(objects[p.Item1 + p.Item2 * width].ToString())));

        return(levelMapBuilder.Build());
    }
Esempio n. 2
0
    public LevelMap GetLevelMap()
    {
        var builder = new LevelMapBuilder(levelName, Mathf.CeilToInt(max.x + 1), Mathf.CeilToInt(max.y + 1));

        walkableTiles.ForEach(x =>
        {
            var t           = new TilePoint(x);
            var fallingTile = x.GetComponent <FallingTile>();
            if (fallingTile)
            {
                builder.With(t, MapPiece.FailsafeFloor);
            }
            else
            {
                builder.With(t, MapPiece.Floor);
            }
        });

        jumpableObjects.ForEach(x =>
        {
            var t = new TilePoint(x);
            if (x.GetComponent <DestroyIfDoubleJumped>())
            {
                builder.With(t, MapPiece.DoubleRoutine);
            }
            else if (x.GetComponent <TeleportingPiece>())
            {
                builder.With(t, MapPiece.JumpingRoutine);
            }
            else if (x.GetComponent <DestroyIfJumped>())
            {
                builder.With(t, MapPiece.Routine);
            }
        });

        collectibleObjects.ForEach(x => builder.With(new TilePoint(x), MapPiece.DataCube));

        builder.With(bitVaultLocation, MapPiece.Root);
        builder.With(new TilePoint(hero), MapPiece.RootKey);

        return(builder.Build());
    }
 public void RegisterAsMapPiece(GameObject obj, MapPiece piece) => _builder = _builder.With(new TilePoint(obj), piece);
 public void Init(string name)
 {
     _builder = new LevelMapBuilder(name);
 }