private static void loadBuildResource() { try { buildMap = new Dictionary <string, ItemBuildData>(); if (!Directory.Exists(BUILD_FILES_DIR)) { //message return; } foreach (string buildFile in Directory.GetFiles(BUILD_FILES_DIR)) { ItemBuildData buildData = ItemBuildData.ReadBuildFile(buildFile); string key = FileNameToHeroName(buildFile); if (buildData != null && !buildMap.ContainsKey(key)) { buildMap.Add(key, buildData); } } } catch (Exception e) { Console.WriteLine(e); Console.Error.WriteLine("CSV parse error"); } }
//めんどいからある程度ファイルフォーマット決め打ち public static ItemBuildData ReadBuildFile(string filePath) { ItemBuildData data = new ItemBuildData(); try{ ReadPhase phase = ReadPhase.Header; ItemBuildSection currentSection = null; foreach (string temp in File.ReadAllLines(filePath)) { string line = temp.Trim(); if (line.StartsWith(COMMENT) || line == "") { continue; //コメント行 } //Console.WriteLine(line); switch (phase) { case ReadPhase.Header: data.FileHeader = line; phase = ReadPhase.HeaderAfter; break; case ReadPhase.HeaderAfter: if (line == "{") { phase = ReadPhase.ItemsHeaderSection; } break; case ReadPhase.ItemsHeaderSection: if (line == "{") { phase = ReadPhase.SectionHeader; } else if (line.ToLower() != "items") { data.AddItemsHeader(line); } break; case ReadPhase.SectionHeader: if (line == "}") { //アイテムセクションの終了 phase = ReadPhase.Finalize; continue; } currentSection = new ItemBuildSection(); currentSection.SectionLabel = line.Replace("\"", ""); //"外して渡す phase = ReadPhase.SectionContent; break; case ReadPhase.SectionContent: if (line == "{") { continue; //Section開始括弧 次 } //セクション終了 データへ登録し次のヘッダ探しへ if (line == "}") { data.Sections.Add(currentSection); phase = ReadPhase.SectionHeader; continue; } ItemData item = ItemData.FromItemBuildFileLine(line); if (item != null) { currentSection.Items.Add(item); } break; case ReadPhase.Finalize: //特になんもしない break; } } return(data); } catch { MessageBox.Show("読み込み失敗。", "エラー"); } return(null); }