Ejemplo n.º 1
0
    public Tilemap(Tileset Tileset, Lisp.List Data)
    {
        this.Tileset = Tileset;

        Properties Props = new Properties(Data);
        uint Width = 0;
        uint Height = 0;
        Props.Get("width", ref Width);
        Props.Get("height", ref Height);
        if(Width == 0 || Height == 0)
            throw new Exception("Width or Height of Tilemap invalid");

        List<uint> Tiles = new List<uint>();
        Props.GetUIntList("tiles", Tiles);
        if(Tiles.Count != (int) (Width * Height))
            throw new Exception("TileCount != Width*Height");
        Props.Get("solid", ref Solid);
        Props.PrintUnusedWarnings();

        Field = new Field<uint>(Tiles, Width, Height);
    }
Ejemplo n.º 2
0
    /// <summary>Parse a list of tiles (from a tiles block in the tileset file)</summary>
    /// <exception cref="System.Exception">
    /// Thrown when width and/or height of ids/attributes of a tiles block is wrong.
    /// </exception>
    private void ParseTiles(List list)
    {
        Properties props = new Properties(list);

        int width = 0;
        int height = 0;
        string image = "";
        props.Get("width", ref width);
        props.Get("height", ref height);
        props.Get("image", ref image);
        if(width == 0 || height == 0)
            throw new ApplicationException("Width and Height of tiles block must be > 0");

        List<int> ids = new List<int> ();
        List<uint> attributes = new List<uint> ();
        props.GetIntList("ids", ids);
        props.GetUIntList("attributes", attributes);
        if(ids.Count != width * height)
            throw new ApplicationException("Must have width*height ids in tiles block");
        if(attributes.Count != width * height)
            throw new ApplicationException("Must have width*height attributes in tiles block");

        int id = 0;
        for(int y = 0; y < height; ++y) {
            for(int x = 0; x < width; ++x) {
                Tile tile = new Tile();

                Tile.ImageResource res = new Tile.ImageResource();
                res.Filename = image;
                res.x = x * TILE_WIDTH;
                res.y = y * TILE_HEIGHT;
                res.w = TILE_WIDTH;
                res.h = TILE_HEIGHT;
                tile.Images = new List<Tile.ImageResource>();
                tile.Images.Add(res);
                tile.Id = ids[id];
                tile.Attributes = (Tile.Attribute) attributes[id];

                while(tiles.Count <= tile.Id)
                    tiles.Add(null);
                tiles[tile.Id] = tile;

                id++;
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>Parse a list of tiles (from a tiles block in the tileset file)</summary>
    /// <exception cref="System.Exception">
    /// Thrown when width and/or height of ids/attributes of a tiles block is wrong.
    /// </exception>
    private void ParseTiles(List list)
    {
        Properties props = new Properties(list);

        int width = 0;
        int height = 0;
        string image = String.Empty;
        string editor_images = String.Empty;
        props.Get("width", ref width);
        props.Get("height", ref height);
        props.Get("image", ref image);
        if (image.Equals (String.Empty))
            props.Get("images", ref image);
        props.Get("editor-images", ref editor_images);
        if(width == 0 || height == 0)
            throw new ApplicationException("Width and Height of tiles block must be > 0");

        List<int> ids = new List<int> ();
        List<uint> attributes = new List<uint> ();
        List<uint> datas = new List<uint> ();
        props.GetIntList("ids", ids);
        props.GetUIntList("attributes", attributes);
        props.GetUIntList("datas", datas);
        if(ids.Count != width * height)
            throw new ApplicationException("Must have width*height ids in tiles block");
        if((attributes.Count != width * height) && attributes.Count > 0)	//missing atributes == all-are-0-attributes
            throw new ApplicationException("Must have width*height attributes in tiles block");
        if((datas.Count != width * height) && datas.Count > 0)	//missing DATAs == all-are-0-DATAs
            throw new ApplicationException("Must have width*height DATAs in tiles block");

        int id = 0;
        for(int y = 0; y < height; ++y) {
            for(int x = 0; x < width; ++x) {
                if (ids[id] != 0) {
                    Tile tile = new Tile();

                    if (!image.Equals (String.Empty)) {
                        Tile.ImageResource res = new Tile.ImageResource();
                        res.Filename = image;
                        res.x = x * TILE_WIDTH;
                        res.y = y * TILE_HEIGHT;
                        res.w = TILE_WIDTH;
                        res.h = TILE_HEIGHT;
                        tile.Images = new List<Tile.ImageResource>();
                        tile.Images.Add(res);
                    }
                    if (!editor_images.Equals (String.Empty)) {
                        Tile.ImageResource eres = new Tile.ImageResource();
                        eres.Filename = editor_images;
                        eres.x = x * TILE_WIDTH;
                        eres.y = y * TILE_HEIGHT;
                        eres.w = TILE_WIDTH;
                        eres.h = TILE_HEIGHT;
                        tile.EditorImages = new List<Tile.ImageResource>();
                        tile.EditorImages.Add(eres);
                    }
                    tile.Id = ids[id];
                    tile.Attributes = (attributes.Count > 0)?(Tile.Attribute) attributes[id]:0;	//missing atributes == all-are-0-attributes
                    tile.Data = (datas.Count > 0)?(int) datas[id]:0;	//missing DATAs == all-are-0-DATAs

                    while(tiles.Count <= tile.Id)
                        tiles.Add(null);

                    tiles[tile.Id] = tile;
                }

                id++;
            }
        }
    }