private void SaveCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { if (scenLoaded) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "劇本檔 (*.json)|*.json"; saveFileDialog.InitialDirectory = @"Content\Data\Scenario"; if (saveFileDialog.ShowDialog() == true) { String filename = saveFileDialog.FileName; String scenName = filename.Substring(filename.LastIndexOf(@"\") + 1, filename.LastIndexOf(".") - filename.LastIndexOf(@"\") - 1); String scenPath = filename.Substring(0, filename.LastIndexOf(@"\")); scen.SaveGameScenario(filename, true, false, false, false, true, true); // GameCommonData.json String commonPath = @"Content\Data\Common\CommonData.json"; saveGameCommonData(commonPath); // Scenarios.json String scenariosPath = scenPath + @"\Scenarios.json"; List <GameManager.Scenario> scesList = null; if (File.Exists(scenariosPath)) { scesList = SimpleSerializer.DeserializeJsonFile <List <GameManager.Scenario> >(scenariosPath, false).NullToEmptyList(); } if (scesList == null) { scesList = new List <GameManager.Scenario>(); } GameManager.Scenario s1 = createScenarioObject(scen, scenName); if (s1 != null) { int index = scesList.FindIndex(x => x.Name == scenName); if (index >= 0) { scesList[index] = s1; } else { scesList.Add(s1); } } string s2 = Newtonsoft.Json.JsonConvert.SerializeObject(scesList, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(scenariosPath, s2); MessageBox.Show("劇本已儲存為" + filename); } } else { // GameCommonData.json String commonPath = @"Content\Data\Common\CommonData.json"; saveGameCommonData(commonPath); MessageBox.Show("CommonData已儲存為" + commonPath); } }
public static void Init(bool prepare) { try { string file1 = "Setting.config"; //string file2 = "settings.config"; if (Platform.Current.UserFileExist(new string[] { file1 })[0]) { try { Current = SimpleSerializer.DeserializeJsonFile <Setting>(file1, true, false); if (prepare) { Prepare(); } Save(); } catch (Exception ex) { } } } catch (Exception ex) { WebTools.TakeWarnMsg("初始用户设置失败:Setting.config", "Init:", ex); } if (Current == null) { Current = new Setting(); if (prepare) { Prepare(); } Save(); } //if (Platform.PlatFormType == PlatFormType.iOS) //|| Platform.PlatForm == PlatForm.WinRT || Platform.PlatForm == PlatForm.WP) //{ // Session.RealResolution = Session.Resolution = Platform.PreferResolution; //} }
public static void Init() { try { string file1 = "Setting.config"; //string file2 = "settings.config"; if (Platform.Current.UserFileExist(new string[] { file1 })[0]) { try { Current = SimpleSerializer.DeserializeJsonFile <Setting>(file1, true, false); Prepare(); Save(); } #pragma warning disable CS0168 // The variable 'ex' is declared but never used catch (Exception ex) #pragma warning restore CS0168 // The variable 'ex' is declared but never used { } } } catch (Exception ex) { WebTools.TakeWarnMsg("初始用户设置失败:Setting.config", "Init:", ex); } if (Current == null) { Current = new Setting(); Prepare(); Save(); } //if (Platform.PlatFormType == PlatFormType.iOS) //|| Platform.PlatForm == PlatForm.WinRT || Platform.PlatForm == PlatForm.WP) //{ // Session.RealResolution = Session.Resolution = Platform.PreferResolution; //} }
private void SaveCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "劇本檔 (*.json)|*.json"; saveFileDialog.InitialDirectory = @"Content\Data\Scenario"; if (saveFileDialog.ShowDialog() == true) { String filename = saveFileDialog.FileName; String scenName = filename.Substring(filename.LastIndexOf(@"\") + 1, filename.LastIndexOf(".") - filename.LastIndexOf(@"\") - 1); String scenPath = filename.Substring(0, filename.LastIndexOf(@"\")); scen.SaveGameScenario(filename, true, false, false, false, true, true); // GameCommonData.json String commonPath = @"Content\Data\Common\CommonData.json"; GameScenario.SaveGameCommonData(scen); string ss1 = ""; System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(CommonData)); using (MemoryStream stream = new MemoryStream()) { //lock (Platform.SerializerLock) { serializer.WriteObject(stream, scen.GameCommonData); } var array = stream.ToArray(); ss1 = Encoding.UTF8.GetString(array, 0, array.Length); } ss1 = ss1.Replace("{\"", "{\r\n\""); ss1 = ss1.Replace("[{", "[\r\n{"); ss1 = ss1.Replace(",\"", ",\r\n\""); ss1 = ss1.Replace("}", "\r\n}"); ss1 = ss1.Replace("},{", "},\r\n{"); ss1 = ss1.Replace("}]", "}\r\n]"); File.WriteAllText(commonPath, ss1); // Scenarios.json String scenariosPath = scenPath + @"\Scenarios.json"; List <GameManager.Scenario> scesList = null; if (File.Exists(scenariosPath)) { scesList = SimpleSerializer.DeserializeJsonFile <List <GameManager.Scenario> >(scenariosPath, false).NullToEmptyList(); } if (scesList == null) { scesList = new List <GameManager.Scenario>(); } string time = scen.Date.Year + "-" + scen.Date.Month + "-" + scen.Date.Day; GameManager.Scenario s1 = new GameManager.Scenario() { Create = DateTime.Now.ToSeasonDateTime(), Desc = scen.ScenarioDescription, First = StaticMethods.SaveToString(scen.ScenarioMap.JumpPosition), IDs = scen.Factions.GameObjects.Select(x => x.ID.ToString()).Aggregate((a, b) => a + "," + b), Info = "电脑", Name = scenName, Names = scen.Factions.GameObjects.Select(x => x.Name).Aggregate((a, b) => a + "," + b), // Path = "", // PlayTime = scenario.GameTime.ToString(), // Player = "", // Players = String.Join(",", scenario.PlayerList.NullToEmptyList()), Time = time.ToSeasonDate(), Title = scen.ScenarioTitle }; int index = scesList.FindIndex(x => x.Name == scenName); if (index >= 0) { scesList[index] = s1; } else { scesList.Add(s1); } string s2 = Newtonsoft.Json.JsonConvert.SerializeObject(scesList, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(scenariosPath, s2); MessageBox.Show("劇本已儲存為" + filename); } }
void InitScenarioList() { string path = @"Content\Data\Scenario\"; string file = path + "Scenarios.json"; pageIndex = pageIndex1 = 1; CurrentScenario = null; btScenarioSelectList = new List <ButtonTexture>(); btScenarioPlayersList = new List <ButtonTexture>(); ScenarioList = SimpleSerializer.DeserializeJsonFile <List <Scenario> >(file, false, false, false); //var str = SimpleSerializer.SerializeJson(ScenarioList, false, true, true); foreach (var sce in ScenarioList) { //var path0 = @"Content\Data\Scenario\" + sce.Name + ".json"; //var str = Platform.Current.LoadText(path0); //var str2 = WordTools.TranslationWords(str, false, true); //Platform.Current.WriteAllText(sce.Name + ".json", str2); var btOne = new ButtonTexture(@"Content\Textures\Resources\Start\CheckBox", "CheckBox", null) { ID = sce.Name }; btOne.OnButtonPress += (sender, e) => { string id = ((ButtonTexture)sender).ID; btScenarioSelectList.ForEach(bt => bt.Selected = false); ((ButtonTexture)sender).Selected = true; CurrentScenario = ScenarioList.FirstOrDefault(sc => sc.Name == id); var iDs = CurrentScenario.IDs.Split(',').NullToEmptyList(); var names = CurrentScenario.Names.Split(',').NullToEmptyList(); btScenarioPlayersList = new List <ButtonTexture>(); for (int i = 0; i < iDs.Count; i++) { var id0 = iDs[i]; var btPlayer = new ButtonTexture(@"Content\Textures\Resources\Start\CheckBox", "CheckBox", null) { ID = id0 }; btPlayer.OnButtonPress += (sender0, e0) => { var btP = (ButtonTexture)sender0; btP.Selected = !btP.Selected; }; btScenarioPlayersList.Add(btPlayer); } pageIndex1 = 1; }; btScenarioSelectList.Add(btOne); } //var sces = new List<Scenario>(); //var files = Platform.Current.GetFiles(path).NullToEmptyList().Where(fi => fi.EndsWith(".mdb")).NullToEmptyList(); //foreach (var fi in files) //{ // var sce = GetScenario(fi); // sces.Add(sce); //} //var sers = SimpleSerializer.SerializeJson(sces, true).TranslationWords(false, false); }