private static void SaveGameFile() { var data = new IniData(); //State data.Sections.AddSection("State"); var state = data["State"]; state.AddKey("Map", MapBase.MapFileName); state.AddKey("Npc", NpcManager.FileName); state.AddKey("Obj", ObjManager.FileName); state.AddKey("Bgm", BackgroundMusic.FileName); state.AddKey("Chr", Globals.PlayerIndex.ToString()); state.AddKey("Time", string.Format( "{0:yyyy} 年{0:MM} 月{0:dd} 日 {0:HH} 时{0:mm} 分{0:ss} 秒", DateTime.Now)); state.AddKey("ScriptShowMapPos", Globals.ScriptShowMapPos ? "1" : "0"); //Save npc obj NpcManager.SaveNpc(); ObjManager.Save(); //Option data.Sections.AddSection("Option"); var option = data["Option"]; option.AddKey("MapTime", MapBase.MapTime.ToString()); option.AddKey("SnowShow", (WeatherManager.IsSnowing ? 1 : 0).ToString()); option.AddKey("RainFile", WeatherManager.IsRaining ? WeatherManager.RainFileName : ""); option.AddKey("Water", Globals.IsWaterEffectEnabled ? "1" : "0"); option.AddKey("MpcStyle", StorageBase.GetStringFromColor(MapBase.DrawColor)); option.AddKey("AsfStyle", StorageBase.GetStringFromColor(Sprite.DrawColor)); if (Globals.IsSaveDisabled) { option.AddKey("SaveDisabled", "1"); } if (Globals.IsDropGoodWhenDefeatEnemyDisabled) { option.AddKey("IsDropGoodWhenDefeatEnemyDisabled", "1"); } //Timer data.Sections.AddSection("Timer"); var timer = data["Timer"]; timer.AddKey("IsOn", GuiManager.IsTimerStarted() ? "1" : "0"); if (GuiManager.IsTimerStarted()) { timer.AddKey("TotalSecond", GuiManager.GetTimerCurrentSeconds().ToString()); timer.AddKey("IsTimerWindowShow", GuiManager.IsTimerWindowHided() ? "0" : "1"); timer.AddKey("IsScriptSet", ScriptExecuter.IsTimeScriptSet ? "1" : "0"); timer.AddKey("TimerScript", ScriptExecuter.TimeScriptFileName); timer.AddKey("TriggerTime", ScriptExecuter.TimeScriptSeconds.ToString()); } //Variables data.Sections.AddSection("Var"); ScriptExecuter.SaveVariables(data["Var"]); //ParallelScript data.Sections.AddSection("ParallelScript"); ScriptManager.SaveParallelScript(data["ParallelScript"]); //Wirte to file File.WriteAllText(StorageBase.GameIniFilePath, data.ToString(), Globals.LocalEncoding); }
private static void LoadGameFile() { try { var parser = new FileIniDataParser(); var data = parser.ReadFile(StorageBase.GameIniFilePath); //state var state = data["State"]; MapBase.OpenMap(state["Map"]); NpcManager.Load(state["Npc"]); ObjManager.Load(state["Obj"]); BackgroundMusic.Play(state["Bgm"]); Globals.PlayerIndex = int.Parse(state["Chr"]); //option var option = data["Option"]; MapBase.MapTime = int.Parse(option["MapTime"]); WeatherManager.ShowSnow(int.Parse(option["SnowShow"]) != 0); if (!string.IsNullOrEmpty(option["RainFile"])) { WeatherManager.BeginRain(option["RainFile"]); } if (string.IsNullOrEmpty(option["Water"])) { Globals.IsWaterEffectEnabled = false; } else { Globals.IsWaterEffectEnabled = int.Parse(option["Water"]) != 0; } if (string.IsNullOrEmpty(option["MpcStyle"])) { MapBase.DrawColor = Color.White; } else { MapBase.DrawColor = StorageBase.GetColorFromString(option["MpcStyle"]); } if (string.IsNullOrEmpty(option["AsfStyle"])) { Sprite.DrawColor = Color.White; } else { Sprite.DrawColor = StorageBase.GetColorFromString(option["AsfStyle"]); } if (string.IsNullOrEmpty(option["SaveDisabled"])) { Globals.IsSaveDisabled = false; } else { Globals.IsSaveDisabled = int.Parse(option["SaveDisabled"]) > 0; } if (string.IsNullOrEmpty(option["IsDropGoodWhenDefeatEnemyDisabled"])) { Globals.IsDropGoodWhenDefeatEnemyDisabled = false; } else { Globals.IsDropGoodWhenDefeatEnemyDisabled = int.Parse(option["IsDropGoodWhenDefeatEnemyDisabled"]) > 0; } //Timer var timer = data["Timer"]; if (timer != null) { var isOn = timer["IsOn"] != "0"; if (isOn) { ScriptExecuter.OpenTimeLimit(int.Parse(timer["TotalSecond"])); var isHide = timer["IsTimerWindowShow"] != "1"; if (isHide) { ScriptExecuter.HideTimerWnd(); } if (timer["IsScriptSet"] != "0") { ScriptExecuter.SetTimeScript(int.Parse(timer["TriggerTime"]), timer["TimerScript"]); } } } //Variables ScriptExecuter.LoadVariables(data["Var"]); //ParallelScript ScriptManager.LoadParallelScript(data["ParallelScript"]); } catch (Exception exception) { Log.LogFileLoadError("Game.ini", StorageBase.GameIniFilePath, exception); } }