using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CsvParser {
    public static string[,] Parse(string csv) {
        string[] lines = csv.Split('\n');

        int width = 0;
        List<string[]> mapLines = new List<string[]>();
        foreach (string line in lines) {
            if (line.Trim().Trim(',').Length == 0 || line.Trim()[0] == '#') {
                continue;
            }

            string[] parts = line.Trim(',').Split(',');
            width = Mathf.Max(width, parts.Length);
            mapLines.Add(parts);
        }

        string[,] map = new string[width, mapLines.Count];
        for (int y = 0; y < mapLines.Count ; y++) {
            string[] cells = mapLines[y];
            for (int x = 0; x < width; x++) {
                if (x >= cells.Length) {
                    map[x, y] = "";
                    continue;
                }

                map[x, y] = cells[x].Trim();
            }
        }

        return map;
	}
}
