private void loadCharacterDataFile(string csvPath, string csvName, bool disp) { CharacterTemplate tmpl = null; EraStreamReader eReader = new EraStreamReader(); if (!eReader.Open(csvPath, csvName)) { output.PrintError(eReader.Filename + "のオープンに失敗しました"); return; } ScriptPosition position = null; if (disp) output.PrintLine(eReader.Filename + "読み込み中・・・"); try { Int64 index = -1; StringStream st = null; while ((st = eReader.ReadEnabledLine()) != null) { position = new ScriptPosition(eReader.Filename, eReader.LineNo, st.RowString); string[] tokens = st.Substring().Split(','); if (tokens.Length < 2) { ParserMediator.Warn("\",\"が必要です", position, 1); continue; } if (tokens[0].Length == 0) { ParserMediator.Warn("\",\"で始まっています", position, 1); continue; } if ((tokens[0].Equals("NO", Config.SCVariable)) || (tokens[0].Equals("番号", Config.SCVariable))) { if (tmpl != null) { ParserMediator.Warn("番号が二重に定義されました", position, 1); continue; } if (!Int64.TryParse(tokens[1].TrimEnd(), out index)) { ParserMediator.Warn(tokens[1] + "を整数値に変換できません", position, 1); continue; } tmpl = new CharacterTemplate(index, this); string no = eReader.Filename.ToUpper(); no = no.Substring(no.IndexOf("CHARA") + 5); StringBuilder sb = new StringBuilder(); StringStream ss = new StringStream(no); while (!ss.EOS && char.IsDigit(ss.Current)) { sb.Append(ss.Current); ss.ShiftNext(); } if (sb.Length > 0) tmpl.csvNo = Convert.ToInt64(sb.ToString()); else tmpl.csvNo = 0; //tmpl.csvNo = index; CharacterTmplList.Add(tmpl); continue; } if (tmpl == null) { ParserMediator.Warn("番号が定義される前に他のデータが始まりました", position, 1); continue; } toCharacterTemplate(gamebase, position, tmpl, tokens); } } catch { System.Media.SystemSounds.Hand.Play(); if (position != null) ParserMediator.Warn("予期しないエラーが発生しました", position, 3); else output.PrintError("予期しないエラーが発生しました"); return; } finally { eReader.Dispose(); } }
private void toCharacterTemplate(GameBase gamebase, ScriptPosition position, CharacterTemplate chara, string[] tokens) { if (chara == null) return; int length = -1; Int64 p1 = -1; Int64 p2 = -1; Dictionary<int, Int64> intArray = null; Dictionary<int, string> strArray = null; Dictionary<string, int> namearray = null; string errPos = null; string varname = tokens[0].ToUpper(); switch (varname) { case "NAME": case "名前": chara.Name = tokens[1]; return; case "CALLNAME": case "呼び名": chara.Callname = tokens[1]; return; case "NICKNAME": case "あだ名": chara.Nickname = tokens[1]; return; case "MASTERNAME": case "主人の呼び方": chara.Mastername = tokens[1]; return; case "MARK": case "刻印": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.MARK)]; intArray = chara.Mark; namearray = nameToIntDics[markIndex]; errPos = "mark.csv"; break; case "EXP": case "経験": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.EXP)]; intArray = chara.Exp; namearray = nameToIntDics[expIndex];//ExpName; errPos = "exp.csv"; break; case "ABL": case "能力": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.ABL)]; intArray = chara.Abl; namearray = nameToIntDics[ablIndex];//AblName; errPos = "abl.csv"; break; case "BASE": case "基礎": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.MAXBASE)]; intArray = chara.Maxbase; namearray = nameToIntDics[baseIndex];//BaseName; errPos = "base.csv"; break; case "TALENT": case "素質": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.TALENT)]; intArray = chara.Talent; namearray = nameToIntDics[talentIndex];//TalentName; errPos = "talent.csv"; break; case "RELATION": case "相性": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.RELATION)]; intArray = chara.Relation; namearray = null; break; case "CFLAG": case "フラグ": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.CFLAG)]; intArray = chara.CFlag; namearray = nameToIntDics[cflagIndex];//CFlagName; errPos = "cflag.csv"; break; case "EQUIP": case "装着物": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.EQUIP)]; intArray = chara.Equip; namearray = nameToIntDics[equipIndex];//EquipName; errPos = "equip.csv"; break; case "JUEL": case "珠": length = CharacterIntArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.JUEL)]; intArray = chara.Juel; namearray = nameToIntDics[paramIndex];//ParamName; errPos = "palam.csv"; break; case "CSTR": length = CharacterStrArrayLength[(int)(VariableCode.__LOWERCASE__ & VariableCode.CSTR)]; strArray = chara.CStr; namearray = nameToIntDics[cstrIndex];//CStrName; errPos = "cstr.csv"; break; default: ParserMediator.Warn("\"" + tokens[0] + "\"は解釈できない識別子です", position, 1); return; } if (length < 0) { ParserMediator.Warn("プログラムミス", position, 3); return; } bool p1isNumeric = tryToInt64(tokens[1].TrimEnd(), out p1); if (p1isNumeric && ((p1 < 0) || (p1 >= length))) { ParserMediator.Warn(p1.ToString() + "は配列の範囲外です", position, 1); return; } int index = (int)p1; if ((!p1isNumeric) && (namearray != null)) { if (!namearray.TryGetValue(tokens[1], out index)) { ParserMediator.Warn(errPos + "に\"" + tokens[1] + "\"の定義がありません", position, 1); //ParserMediator.Warn("\"" + tokens[1] + "\"は解釈できない識別子です", position, 1); return; } else if (index >= length) { ParserMediator.Warn("\"" + tokens[1] + "\"は配列の範囲外です", position, 1); return; } } if ((index < 0) || (index >= length)) { if (p1isNumeric) ParserMediator.Warn(index.ToString() + "は配列の範囲外です", position, 1); else if (tokens[1].Length == 0) ParserMediator.Warn("二つ目の識別子がありません", position, 1); else ParserMediator.Warn("\"" + tokens[1] + "\"は解釈できない識別子です", position, 1); return; } if (strArray != null) { if (tokens.Length < 3) ParserMediator.Warn("三つ目の識別子がありません", position, 1); if (strArray.ContainsKey(index)) ParserMediator.Warn(varname + "の" + index.ToString() + "番目の要素は既に定義されています(上書きします)", position, 1); strArray[index] = tokens[2]; } else { if ((tokens.Length < 3) || !tryToInt64(tokens[2], out p2)) p2 = 1; if (intArray.ContainsKey(index)) ParserMediator.Warn(varname + "の" + index.ToString() + "番目の要素は既に定義されています(上書きします)", position, 1); intArray[index] = p2; } }