123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using System;
- using System.IO;
- using System.Text;
- using System.Text.RegularExpressions;
- using NTERA.EmuEra.Game.EraEmu.Sub;
- namespace NTERA.EmuEra.Game.EraEmu.GameData
- {
- internal sealed class GameBase
- {
- public string ScriptAutherName = "";
- public string ScriptDetail = "";//詳細な説明
- public string ScriptYear = "";
- public string ScriptTitle = "";
- public Int64 ScriptUniqueCode;
- //1.713 訂正。eramakerのバージョンの初期値は1000ではなく0だった
- public Int64 ScriptVersion;//1000;
- //1.713 上の変更とあわせて。セーブデータのバージョンが1000であり、現在のバージョンが未定義である場合、セーブデータのバージョンを同じとみなす
- public bool ScriptVersionDefined;
- public Int64 ScriptCompatibleMinVersion = -1;
- public string Compatible_EmueraVer = "0.000.0.0";
- //1.727 追加。Form.Text
- public string ScriptWindowTitle;
- public string ScriptVersionText
- {
- get
- {
- StringBuilder versionStr = new StringBuilder();
- versionStr.Append((ScriptVersion / 1000).ToString());
- versionStr.Append(".");
- if ((ScriptVersion % 10) != 0)
- versionStr.Append((ScriptVersion % 1000).ToString("000"));
- else
- versionStr.Append((ScriptVersion % 1000 / 10).ToString("00"));
- return versionStr.ToString();
- }
- }
- public bool UniqueCodeEqualTo(Int64 target)
- {
- //1804 UniqueCode Int64への拡張に伴い修正
- if (target == 0L)
- return true;
- return target == ScriptUniqueCode;
- }
- public bool CheckVersion(Int64 target)
- {
- if (!ScriptVersionDefined && target != 1000)
- return true;
- if (ScriptCompatibleMinVersion <= target)
- return true;
- return ScriptVersion == target;
- }
- public Int64 DefaultCharacter = -1;
- public Int64 DefaultNoItem;
- private bool tryatoi(string str, out Int64 i)
- {
- if (Int64.TryParse(str, out i))
- return true;
- StringStream st = new StringStream(str);
- StringBuilder sb = new StringBuilder(str.Length);
- while (true)
- {
- if (st.EOS)
- break;
- if (!char.IsNumber(st.Current))
- break;
- sb.Append(st.Current);
- st.ShiftNext();
- }
- if (sb.Length > 0)
- if (Int64.TryParse(sb.ToString(), out i))
- return true;
- return false;
- }
- public bool LoadGameBaseCsv(string basePath)
- {
- if (!File.Exists(basePath))
- {
- return true;
- }
- ScriptPosition pos = null;
- EraStreamReader eReader = new EraStreamReader(false);
- if (!eReader.Open(basePath))
- {
- //output.PrintLine(eReader.Filename + "のオープンに失敗しました");
- return true;
- }
- try
- {
- StringStream st = null;
- while ((st = eReader.ReadEnabledLine()) != null)
- {
- string[] tokens = st.Substring().Split(',');
- if (tokens.Length < 2)
- continue;
- string param = tokens[1].Trim();
- pos = new ScriptPosition(eReader.Filename, eReader.LineNo, st.RowString);
- switch (tokens[0])
- {
- case "コード":
- if (tryatoi(tokens[1], out ScriptUniqueCode))
- {
- if (ScriptUniqueCode == 0L)
- ParserMediator.Warn("コード:0のセーブデータはいかなるコードのスクリプトからも読めるデータとして扱われます", pos, 0);
- }
- break;
- case "バージョン":
- ScriptVersionDefined = tryatoi(tokens[1], out ScriptVersion);
- break;
- case "バージョン違い認める":
- tryatoi(tokens[1], out ScriptCompatibleMinVersion);
- break;
- case "最初からいるキャラ":
- tryatoi(tokens[1], out DefaultCharacter);
- break;
- case "アイテムなし":
- tryatoi(tokens[1], out DefaultNoItem);
- break;
- case "タイトル":
- ScriptTitle = tokens[1];
- break;
- case "作者":
- ScriptAutherName = tokens[1];
- break;
- case "製作年":
- ScriptYear = tokens[1];
- break;
- case "追加情報":
- ScriptDetail = tokens[1];
- break;
- case "ウィンドウタイトル":
- ScriptWindowTitle = tokens[1];
- break;
-
- case "動作に必要なEmueraのバージョン":
- Compatible_EmueraVer = tokens[1];
- if (!Regex.IsMatch(Compatible_EmueraVer, @"^\d+\.\d+\.\d+\.\d+$"))
- {
- ParserMediator.Warn("バージョン指定を読み取れなかったので処理を省略します", pos, 0);
- break;
- }
- Version curerntVersion = new Version(GlobalStatic.MainWindow.InternalEmueraVer);
- Version targetVersoin = new Version(Compatible_EmueraVer);
- if (curerntVersion < targetVersoin)
- {
- ParserMediator.Warn("このバリアント動作させるにはVer. " + GlobalStatic.MainWindow.EmueraVerText + "以降のバージョンのEmueraが必要です", pos, 2);
- return false;
- }
- break;
- }
- }
- }
- catch
- {
- ParserMediator.Warn("GAMEBASE.CSVの読み込み中にエラーが発生したため、読みこみを中断します", pos, 1);
- return true;
- }
- finally
- {
- eReader.Close();
- }
- if (ScriptWindowTitle == null)
- {
- if (string.IsNullOrEmpty(ScriptTitle))
- ScriptWindowTitle = "Emuera";
- else
- ScriptWindowTitle = ScriptTitle + " " + ScriptVersionText;
- }
- return true;
- }
- }
- }
|