Ejemplo n.º 1
0
        public static List <List <string> > ReadCsv(string path)
        {
            List <List <string> > rows = new List <List <string> >();

            foreach (string line in File.ReadAllLines(path))
            {
                rows.Add(CsvLineParserImpl.UnescapeLineToFieldList(line, ','));
            }

            return(rows);
        }
Ejemplo n.º 2
0
        public static List <List <string> > Load(string path, Encoding encoding)
        {
            StringBuilder sbLog = new StringBuilder();

            List <List <string> > rows = new List <List <string> >();

            foreach (string line in File.ReadAllLines(path, encoding))
            {
                rows.Add(CsvLineParserImpl.UnescapeLineToFieldList(line, ','));
            }


            // 最初の2行は削除。
            rows.RemoveRange(0, 2);

            // 各行の先頭3列は削除。
            foreach (List <string> row in rows)
            {
                row.RemoveRange(0, 3);
            }


            //------------------------------
            // データ部だけが残っています。
            //------------------------------


            // コメント行、データ行が交互に出てきます。
            // コメント行を削除します。
            List <List <string> > rows2;

            {
                rows2 = new List <List <string> >();

                int rowCount1 = 0;
                foreach (List <string> row in rows)
                {
                    // 奇数行がデータです。
                    if (rowCount1 % 2 == 1)
                    {
                        rows2.Add(row);
                    }

                    rowCount1++;
                }
            }

            // デバッグ出力
            {
                StringBuilder sb = new StringBuilder();

                foreach (List <string> row2 in rows2)
                {
                    foreach (string field in row2)
                    {
                        sb.Append(field);
                        sb.Append(",");
                    }
                    sb.AppendLine();
                }

                File.WriteAllText("配役転換表Load(1)_データ行のみ.txt", sb.ToString());
            }



            Data_HaiyakuTransition.map = new Dictionary <PieceType, Kh185[]>();


            int rowCount2 = 0;

            Kh185[] table81 = null;
            foreach (List <string> row2 in rows2)
            {
                if (rowCount2 % 9 == 0)
                {
                    table81 = new Kh185[81];

                    int syuruiNumber = rowCount2 / 9 + 1;
                    if (15 <= syuruiNumber)
                    {
                        goto gt_EndMethod;
                    }
                    Data_HaiyakuTransition.map.Add(Ks14Array.Items_All[syuruiNumber], table81);
                }


                //----------
                // テーブル作り
                //----------

                int columnCount = 0;
                foreach (string column in row2)
                {
                    // 空っぽの列は無視します。
                    if ("" == column)
                    {
                        goto gt_NextColumn;
                    }

                    // 空っぽでない列の値を覚えます。

                    // 数値型のはずです。
                    int cellValue;
                    if (!int.TryParse(column, out cellValue))
                    {
                        throw new Exception($@"エラー。
path=[{path}]
「配役転換表」に、int型数値でないものが指定されていました。
rowCount=[{rowCount2}]
columnCount=[{columnCount}]");
                    }

                    int masuHandle = (8 - columnCount) * 9 + (rowCount2 % 9);//0~80

                    sbLog.AppendLine("(" + rowCount2 + "," + columnCount + ")[" + masuHandle + "]" + cellValue);

                    table81[masuHandle] = Kh185Array.Items[cellValue];

gt_NextColumn:
                    columnCount++;
                }

                rowCount2++;
            }

gt_EndMethod:

            File.WriteAllText("../../Logs/_log_配役転換表Load(2).txt", sbLog.ToString());

            return(rows);
        }