Esempio n. 1
0
    /// <summary>
    /// Creates a new Brush by loading a list of valid patterns from the given file
    /// </summary>
    // TODO: change file syntax from CSV to Lisp
    public static TileBrush loadFromFile(string fname, Tileset tileset)
    {
        FileStream fs  = new FileStream(fname, FileMode.Open);
        TextReader trd = new StreamReader(fs);

        TileBrush brush = new TileBrush(3, 3, tileset);

        try {
            string s;
            while ((s = trd.ReadLine()) != null)
            {
                string[] v = s.Split(',');
                if (v.Length < 9)
                {
                    continue;
                }
                TileBlock tb = (TileBlock) new TileBlock(3, 3, 0);
                tb[0, 0] = int.Parse(v[0]);
                tb[1, 0] = int.Parse(v[1]);
                tb[2, 0] = int.Parse(v[2]);
                tb[0, 1] = int.Parse(v[3]);
                tb[1, 1] = int.Parse(v[4]);
                tb[2, 1] = int.Parse(v[5]);
                tb[0, 2] = int.Parse(v[6]);
                tb[1, 2] = int.Parse(v[7]);
                tb[2, 2] = int.Parse(v[8]);
                if (brush.FindPattern(tb) == null)
                {
                    brush.patterns.Add(tb);
                }
            }
        } finally {
            trd.Close();
            fs.Close();
        }

        return(brush);
    }
Esempio n. 2
0
    /// <summary>
    /// Creates a new Brush by loading a list of valid patterns from the given file
    /// </summary>
    // TODO: change file syntax from CSV to Lisp
    public static TileBrush loadFromFile(string fname, Tileset tileset)
    {
        FileStream fs = new FileStream(fname, FileMode.Open);
        TextReader trd = new StreamReader(fs);

        TileBrush brush = new TileBrush(3, 3, tileset);

        try {
            string s;
            while ((s = trd.ReadLine()) != null) {
                string[] v = s.Split(',');
                if (v.Length < 9) continue;
                TileBlock tb = (TileBlock)new TileBlock(3,3,0);
                tb[0, 0] = int.Parse(v[0]);
                tb[1, 0] = int.Parse(v[1]);
                tb[2, 0] = int.Parse(v[2]);
                tb[0, 1] = int.Parse(v[3]);
                tb[1, 1] = int.Parse(v[4]);
                tb[2, 1] = int.Parse(v[5]);
                tb[0, 2] = int.Parse(v[6]);
                tb[1, 2] = int.Parse(v[7]);
                tb[2, 2] = int.Parse(v[8]);
                if (brush.FindPattern(tb) == null) brush.patterns.Add(tb);
            }
        } finally {
            trd.Close();
            fs.Close();
        }

        return brush;
    }