//TODO Once finished use flatbuffer to save player game data public void SaveProfileToFlat(PlayerProfileModel prof) { float start = Time.realtimeSinceStartup; List <Offset <CharacterModelFlat> > charList = new List <Offset <CharacterModelFlat> >(); FlatBufferBuilder fbb = new FlatBufferBuilder(1); StringOffset item = fbb.CreateString(prof.itemString); foreach (CharacterModel model in prof.characters) { charList.Add(AddCharacterToFlat(fbb, model)); } VectorOffset charVector = fbb.CreateVectorOfTables <CharacterModelFlat>(charList.ToArray()); PlayerProfileFlat.StartPlayerProfileFlat(fbb); PlayerProfileFlat.AddGold(fbb, prof.Gold); PlayerProfileFlat.AddItems(fbb, item); PlayerProfileFlat.AddCharacters(fbb, charVector); Offset <PlayerProfileFlat> offset = PlayerProfileFlat.EndPlayerProfileFlat(fbb); PlayerProfileFlat.FinishPlayerProfileFlatBuffer(fbb, offset); MemoryStream ms = new MemoryStream(fbb.DataBuffer.Data, fbb.DataBuffer.Position, fbb.Offset); File.WriteAllBytes(XmlSaver.PersistentDataPath() + "/SAVEDATA", ms.ToArray()); Debug.Log("Flat Saving time " + (Time.realtimeSinceStartup - start)); }
public GameDataManager() { gameData = new GameData(); xmlSaver = new XmlSaver(); // gameData.Key = SystemInfo.deviceUniqueIdentifier; Load(); }
public void Should_Return_Error_Msg_For_Null_GetFishList_Tank() { var sut = new XmlSaver(Config, null); var actual = sut.Save(); Assert.AreEqual("XML file could not be created!", actual); }
private void button1_Click(object sender, RoutedEventArgs e) { XmlSaver <Playlist> writePl = new XmlSaver <Playlist>(filePlaylists, playlistCollection.playlists); writePl.Write(); MessageBox.Show("Saved"); }
private void SaveStory(string path, Story story) { XmlSaver xs = new XmlSaver(); string datastring = xs.SerializeObject(story, typeof(Story)); xs.CreateXML(path, datastring); Debug.Log("save to " + path + " success!"); }
public void LoadOptions() { ComPortSettings = XmlSaver <List <ComPortSetting> > .Load(FileNames.ComPorts); Compressors = XmlSaver <List <CompressorSetting> > .Load(FileNames.Compressors); //ClearCompressorsValues(); LoadCompressorIndexes(); }
/// <summary> /// Reakce na kliknuti na save /// </summary> private void MenuSave_Click(object sender, RoutedEventArgs e) { try { XmlSaver.CreateXml(Editor.GalaxyMap); this.ProgramStatus.Content = "Saved"; } catch { this.ProgramStatus.Content = "Unable to save"; } }
public void Should_Return_Error_Msg_For_Fault_File_Name() { var faultConfig = new ConfigurationBuilder() .AddInMemoryCollection(new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("FaultFileName", "TestTank.xml"), }) .Build(); var sut = new XmlSaver(faultConfig, _tank); var actual = sut.Save(); Assert.AreEqual("File path is not found!", actual); }
private void PaneAlarm_Load(object sender, EventArgs e) { DataTable table = initDataTable(); dgAlarms.DataSource = table; alarms = XmlSaver.Load("alarm"); if (alarms == null) { return; } foreach (AlarmData alarm in alarms) { } }
public override MovementSequence loadSequence(XmlSaver xmlSaver) { MovementSequence loadingSequence = null; try { using (XmlTextReader xmlReader = new XmlTextReader(Assembly.GetManifestResourceStream(EmbeddedResourceName))) { loadingSequence = xmlSaver.restoreObject(xmlReader) as MovementSequence; loadingSequence.Name = Name; } } catch (Exception e) { Log.Error("Could not read muscle sequence {0}.\nReason: {1}.", EmbeddedResourceName, e.Message); } return(loadingSequence); }
public void LoadFlatProfile() {//TODO Finish this in final version, convert to useable ProfileManager float start = Time.realtimeSinceStartup; if (!File.Exists(XmlSaver.PersistentDataPath() + "/SAVEDATA")) { return; } ByteBuffer bb = new ByteBuffer(File.ReadAllBytes(XmlSaver.PersistentDataPath() + "/SAVEDATA")); if (!PlayerProfileFlat.PlayerProfileFlatBufferHasIdentifier(bb)) { return; } PlayerProfileFlat flat = PlayerProfileFlat.GetRootAsPlayerProfileFlat(bb); Debug.Log("Flat Loading time " + (Time.realtimeSinceStartup - start) + " " + flat.Characters(0).Value.Name); }
private void SaveXmlProtocolFile(string fileName = null) { if (!ValidateIndexes()) { return; } if (_currentNode?.Tag is CustomType) { _customTypeEditor.Value.UpdateGrid(); } if (string.IsNullOrWhiteSpace(fileName)) { using (var dlg = new SaveFileDialog() { Filter = "XML файлы|*.xml|Все файлы|*.*", Title = "Сохранить протокол работы с компрессором", FileName = Indexes.Name //FilterIndex = 2 }) { if (dlg.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dlg.FileName)) { fileName = dlg.FileName; } } } if (!string.IsNullOrWhiteSpace(fileName)) { if (XmlSaver <Indexes> .Save(Indexes, fileName)) { _hasChanges = false; _protocolFileName = fileName; toolStripStatusLabel1.Text = $"{fileName} успешно сохранен"; } else { toolStripStatusLabel1.Text = "Ошибка при сохранении протокола"; } } }
public override MovementSequence loadSequence(XmlSaver xmlSaver) { MovementSequence loadingSequence = null; try { VirtualFileSystem archive = VirtualFileSystem.Instance; using (XmlTextReader xmlReader = new XmlTextReader(archive.openStream(FileName, FileMode.Open, FileAccess.Read))) { loadingSequence = xmlSaver.restoreObject(xmlReader) as MovementSequence; VirtualFileInfo fileInfo = archive.getFileInfo(FileName); loadingSequence.Name = fileInfo.Name.Substring(0, fileInfo.Name.Length - 4); } } catch (Exception e) { Log.Error("Could not read muscle sequence {0}.\nReason: {1}.", FileName, e.Message); } return(loadingSequence); }
IEnumerator Load() { print(fileName + ".xml"); WWW www = new WWW(fileName + ".xml"); yield return(www); if (www.isDone) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(XmlSaver.UTF8ByteArrayToString(www.bytes).Trim()); if (OnLoadFinish != null) { OnLoadFinish(xmlDoc); } Destroy(this); } }
private void OpenXmlProtocol_Click(object sender, EventArgs e) { if (!CheckSavingChanges()) { return; } using (var openFileDialog1 = new OpenFileDialog { Filter = "XML файлы|*.xml|Все файлы|*.*", Title = "Открыть протокол работы с компрессором" }) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { if (File.Exists(openFileDialog1.FileName)) { var result = XmlSaver <Indexes> .Load(openFileDialog1.FileName); if (result != null) { Indexes = result; _protocolFileName = openFileDialog1.FileName; toolStripStatusLabel1.Text = $"{openFileDialog1.FileName} успешно загружен"; } else { toolStripStatusLabel1.Text = "Ошибка при открытии протокола"; } } } catch (Exception ex) { ExceptionHelper.ShowException(ex); toolStripStatusLabel1.Text = "Ошибка при открытии протокола"; } } } }
static void Main(string[] args) { if (args.Length == 0) { throw new ArgumentNullException("Nie podano parametrów."); } try { var reader = new CsvReader(args[0]); var list = reader.Read(); var students = new StudentsList(list).Validate(); var fileName = "result.xml"; var format = "xml"; if (args.Length >= 2) { fileName = args[1]; } if (args.Length == 3) { format = args[2]; } if (format == "xml") { var xmlSaver = new XmlSaver <Student>(students); xmlSaver.Save(fileName); } else { throw new ArgumentOutOfRangeException("Nieznany format: " + format); } } catch (FileNotFoundException) { throw new FileNotFoundException("Nie znaleziono pliku: " + args[0]); } }
public static void SaveMonster(CharacterModel model) { XmlSaver.SaveXmlToFile <CharacterModel>("/" + model.name + ".xml", model); }
public void SaveComPorts() { XmlSaver <List <ComPortSetting> > .Save(ComPortSettings, FileNames.ComPorts); }
void GridUpdate(SceneView sceneview) { Handles.BeginGUI(); GUILayout.BeginArea(new Rect(0, 0, 1000, 640)); // GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Scene Name: ", GUILayout.Width(128)); grid.scenename = GUILayout.TextField(grid.scenename, GUILayout.Width(128)); GUILayout.EndHorizontal(); focus = GUILayout.Toolbar(focus, catecory, GUILayout.Width(64 * catecory.Length)); focus_tile[focus] = GUILayout.Toolbar(focus_tile[focus], TileTextures[focus], GUILayout.Width(64 * TileTextures[focus].Length), GUILayout.Height(64)); // GUILayout.EndHorizontal(); GUILayout.Label("press a to add, s to save, d to load,\nwhen the scene window is activated."); GUILayout.EndArea(); Handles.EndGUI(); Event e = Event.current; Ray r = Camera.current.ScreenPointToRay(new Vector3(e.mousePosition.x, -e.mousePosition.y + Camera.current.pixelHeight)); Vector3 mousePos = r.origin; if (e.isKey) { switch (e.character) { case 'a': string name = TileNames[focus][focus_tile[focus]]; Object loaded = Resources.Load("Prefabs\\" + catecory[focus] + "\\" + name, typeof(GameObject)); GameObject pre = PrefabUtility.InstantiatePrefab(loaded) as GameObject; pre.name = name; pre.tag = catecory[focus]; Vector3 aligned = new Vector3(Mathf.Floor(mousePos.x / grid.width) * grid.width + grid.width / 2, Mathf.Floor(mousePos.y / grid.height) * grid.height + grid.height / 2, 0); pre.transform.position = aligned; break; //save the map case 's': Debug.Log("save map start!"); string path = "Level"; //check the directory if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path += "/" + grid.scenename + ".lv"; LevelInfo levelinfo = new LevelInfo(); GameObject[] AllGameObjects = FindObjectsOfType(typeof(GameObject)) as GameObject[]; foreach (GameObject go in AllGameObjects) { if (go.name == "grid" || go.name == "scenario") { continue; } if (go.name == "Main Camera") { levelinfo.Rooms = go.GetComponent <CameraFollow>().Rooms; continue; } if (go.transform.parent != null) { continue; } if (go.tag == "Event") { EventItem ei = new EventItem(); ei.name = go.name; ei.x = go.transform.position.x; ei.y = go.transform.position.y; if (go.name == "GotoPlot") { ei.arg = go.GetComponent <Plot>().plotno; } else if (go.name == "GotoScene") { ei.arg = go.GetComponent <GotoScene>().scenename; } levelinfo.events.Add(ei); } else { LevelItem li = new LevelItem(); li.tag = go.tag; li.name = go.name; li.x = go.transform.position.x; li.y = go.transform.position.y; levelinfo.items.Add(li); } } XmlSaver xs = new XmlSaver(); string datastring = xs.SerializeObject(levelinfo, typeof(LevelInfo)); xs.CreateXML(path, datastring); Debug.Log("save map success!"); break; // load the map case 'd': // clear the map AllGameObjects = SceneManager.GetActiveScene().GetRootGameObjects(); foreach (GameObject go in AllGameObjects) { if (go.name == "grid" || go.name == "Main Camera" || go.name == "scenario") { continue; } if (go.transform.parent != null) { continue; } GameObject.DestroyImmediate(go); } // load the map xs = new XmlSaver(); path = "Level/" + grid.scenename + ".lv"; if (xs.hasFile(path)) { datastring = xs.LoadXML(path); levelinfo = xs.DeserializeObject(datastring, typeof(LevelInfo)) as LevelInfo; Camera.main.GetComponent <CameraFollow>().CameraMode = 0; Camera.main.GetComponent <CameraFollow>().Rooms = levelinfo.Rooms; foreach (LevelItem li in levelinfo.items) { string tag = li.tag; name = li.name; float x = li.x; float y = li.y; loaded = Resources.Load("Prefabs\\" + tag + "\\" + name, typeof(GameObject)); pre = PrefabUtility.InstantiatePrefab(loaded) as GameObject; pre.name = name; pre.transform.position = new Vector3(x, y, 0); } } else { Debug.Log("the level data does not exist."); } break; } } }
public void SaveCompressors() { ClearCompressorsValues(); XmlSaver <List <CompressorSetting> > .Save(Compressors, FileNames.Compressors); }
private void LoadMap(string MapName) { XmlSaver xs = new XmlSaver(); string path = "Level/" + MapName + ".lv"; if (xs.hasFile(path)) { string datastring = xs.LoadXML(path); LevelInfo levelinfo = xs.DeserializeObject(datastring, typeof(LevelInfo)) as LevelInfo; Camera.main.GetComponent <CameraFollow>().CameraMode = 0; Camera.main.GetComponent <CameraFollow>().Rooms = levelinfo.Rooms; foreach (LevelItem li in levelinfo.items) { string tag = li.tag; string name = li.name; float x = li.x; float y = li.y; if (li.tag != "Player" || (li.tag == "Player" && player == null)) { GameObject pre = Resources.Load("Prefabs\\" + tag + "\\" + name, typeof(GameObject)) as GameObject; if (!pre) { Debug.Log("tile " + name + " load failed."); } pre = Instantiate(pre, new Vector3(x, y, 0), Quaternion.identity); pre.name = name; } else { player.transform.position = new Vector3(x, y, 0); Camera.main.GetComponent <CameraFollow>().FindCurrentRoom(); } } foreach (EventItem ei in levelinfo.events) { string tag = "Event"; string name = ei.name; float x = ei.x; float y = ei.y; GameObject pre = Resources.Load("Prefabs\\" + tag + "\\" + name, typeof(GameObject)) as GameObject; if (!pre) { Debug.Log("tile " + name + " load failed."); } pre = Instantiate(pre, new Vector3(x, y, 0), Quaternion.identity); pre.name = name; if (name == "GotoPlot") { pre.GetComponent <Plot>().plotno = ei.arg; } else if (name == "GotoScene") { pre.GetComponent <GotoScene>().scenename = ei.arg; } } } else { Debug.Log("the level data does not exist."); } }
/// <summary> /// Saves an object to an xml file /// </summary> /// <param name="obj">The object to save</param> /// <param name="filepath">The xml file path</param> public static void SaveDataObject(object obj, string filepath) { XmlSaver.SaveDataObject(obj, filepath); }
public GameData gameData;//实例 public GameDataMgr(GameMainProgram gameMain) : base(gameMain) { xs = new XmlSaver(); }
public static void SaveSettings(string path = "settings.cfg") { XmlSaver.SaveDataObject(Settings, _modPath + "/" + path); }
void GridUpdate(SceneView sceneview) { Handles.BeginGUI(); GUILayout.BeginArea(new Rect(0, 0, 1000, 640)); // GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Scene Name: ", GUILayout.Width(128)); grid.scenename = GUILayout.TextField(grid.scenename, GUILayout.Width(128)); GUILayout.EndHorizontal(); focus = GUILayout.Toolbar(focus, catecory, GUILayout.Width(64 * catecory.Length)); focus_tile[focus] = GUILayout.Toolbar(focus_tile[focus], TileTextures[focus], GUILayout.Width(64 * TileTextures[focus].Length), GUILayout.Height(64)); // GUILayout.EndHorizontal(); GUILayout.Label("press a to add, s to save, d to load,\nwhen the scene window is activated."); GUILayout.EndArea(); Handles.EndGUI(); Event e = Event.current; Ray r = Camera.current.ScreenPointToRay(new Vector3(e.mousePosition.x, -e.mousePosition.y + Camera.current.pixelHeight)); Vector3 mousePos = r.origin; if (e.isKey) { switch (e.character) { case 'a': string name = TileNames[focus][focus_tile[focus]]; Object loaded = Resources.Load("Prefabs\\" + catecory[focus] + "\\" + name, typeof(GameObject)); GameObject pre = PrefabUtility.InstantiatePrefab(loaded) as GameObject; pre.name = name; pre.tag = catecory[focus]; Vector3 aligned = new Vector3(Mathf.Floor(mousePos.x / grid.width) * grid.width + grid.width / 2, Mathf.Floor(mousePos.y / grid.height) * grid.height + grid.height / 2, 0); pre.transform.position = aligned; break; //save the map case 's': Debug.Log("save map start!"); string path = "Level"; //check the directory if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path += "/" + grid.scenename + ".lv"; LevelInfo levelinfo = new LevelInfo(); GameObject[] AllGameObjects = FindObjectsOfType(typeof(GameObject)) as GameObject[]; foreach (GameObject go in AllGameObjects) { if (go.name == "grid" || go.name == "scenario" || go.name == "ACTManager") { continue; } if (go.name == "Main Camera") { levelinfo.Rooms = go.GetComponent <CameraFollow>().Rooms; continue; } if (go.transform.parent != null) { continue; } if (go.tag == "Event") { EventItem ei = new EventItem(); ei.name = go.name; ei.x = go.transform.position.x; ei.y = go.transform.position.y; ei.arg = go.GetComponent <Plot>().plotno; levelinfo.events.Add(ei); } else if (go.name == "Background") { SpriteRenderer[] spriteRenderers = go.GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer spriteRenderer in spriteRenderers) { Background background = new Background(); background.name = spriteRenderer.name; background.x = spriteRenderer.transform.position.x; background.y = spriteRenderer.transform.position.y; levelinfo.backgrounds.Add(background); } } else { LevelItem li = new LevelItem(); li.tag = go.tag; li.name = go.name; li.x = go.transform.position.x; li.y = go.transform.position.y; levelinfo.items.Add(li); } } XmlSaver xs = new XmlSaver(); string datastring = xs.SerializeObject(levelinfo, typeof(LevelInfo)); xs.CreateXML(path, datastring); Debug.Log("save map success!"); break; // load the map case 'd': ACTManager.Clear(); ACTManager.SetThisLevel(grid.scenename); ACTManager.LoadLevel(true); break; } } }
public static void saveSettings(string path = "psi-settings.cfg") { XmlSaver.SaveDataObject((object)settings, path); }
private GameController() { playerStateData = GameManager._instance.playerStateData.text; playerTypeData = GameManager._instance.playerTypeData.text; bagData = GameManager._instance.bagData.text; itemListData = GameManager._instance.itemListData.text; itemComposeData = GameManager._instance.itemComposeData.text; playerQuestData = GameManager._instance.playerQuestData.text; questListData = GameManager._instance.questListData.text; NPCData = GameManager._instance.NPCData.text; skillData = GameManager._instance.skillData.text; openingData = GameManager._instance.openingData.text; eventData = GameManager._instance.eventData.text; portalData = GameManager._instance.portalData.text; areaData = GameManager._instance.sceneData.text; enemyPositionData = GameManager._instance.enemyPositionData.text; enemyInfoData = GameManager._instance.enemyInfoData.text; //Application.targetFrameRate = 45; xs = new XmlSaver(); gameData = new GameData(); gameData.key = GameManager._instance.gameDataKey; //Load(0); #region test testLoad(); lastChangeSceneType = EntryType.Portal; playerInFloor = -8; #endregion }
private void toolStripBtnSave_Click(object sender, EventArgs e) { var xmlString = XmlSaver.SaveXml(m_project); }
public MainWindowViewModel() { MainWindowSingleton = this; ClassViewModels = new ObservableCollection <ClassViewModel>(); ClassViewModels.Add(new ClassViewModel() { Name = "Test", Attributes = new ObservableCollection <FieldViewModel>() { new FieldViewModel() { Name = "TestAt", Type = VisibilityType.Public } }, Methods = new ObservableCollection <FieldViewModel>() { new FieldViewModel() { Name = "TestMet", Type = VisibilityType.Private } }, Id = 0, Position = new Point(100, 100), Height = 160, Width = 200 }); ClassViewModels.Add(new ClassViewModel() { Name = "Test", Attributes = new ObservableCollection <FieldViewModel>() { new FieldViewModel() { Name = "TestAt", Type = VisibilityType.Public } }, Methods = new ObservableCollection <FieldViewModel>() { new FieldViewModel() { Name = "TestMet", Type = VisibilityType.Private } }, Id = 1, Position = new Point(700, 100), Height = 160, Width = 200 }); LineaViewModels = new ObservableCollection <LineViewModel>(); LineaViewModels.Add(new LineViewModel(ClassViewModels[0], ClassViewModels[1])); AddClass = new Command(() => { var att = new ObservableCollection <FieldViewModel>(); att.Add(new FieldViewModel() { Name = "New Attribute" }); var met = new ObservableCollection <FieldViewModel>(); met.Add(new FieldViewModel() { Name = "New Method" }); ClassViewModels.Add(new ClassViewModel() { Id = ClassViewModels.GetMaxId() + 1, Name = "Class", Position = MainWindow.MousePosition, Attributes = att, Methods = met, Height = 160, Width = 200 }); }); Load = new Command(() => { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { XmlParser xmlParser = new XmlParser(openFileDialog.FileName); ClassViewModels.Clear(); foreach (var classViewModel in xmlParser.GetClasses().ToClassViewModels()) { ClassViewModels.Add(classViewModel); } LineaViewModels.Clear(); foreach (var line in xmlParser.GetLines()) { LineaViewModels.Add(new LineViewModel(ClassViewModels.GetById(line.First), ClassViewModels.GetById(line.Second))); } } }); Save = new Command(() => { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { XmlSaver xmlSaver = new XmlSaver(openFileDialog.FileName); xmlSaver.SetClasses(ClassViewModels.ToClass()); xmlSaver.SetLines(LineaViewModels.ToLine()); } }); }
/// <summary> /// 默认在游戏开始时会读取Setting文件 /// </summary> /// <param name="gameMain"></param> public GameDataMgr(GameMainProgram gameMain) : base(gameMain) { xmlSaver = new XmlSaver(); LoadSetting(); }
public static void SavePsiSettings(string path = "ColonistBarPSIKF.xml") { string configFolder = Path.GetDirectoryName(GenFilePaths.ModsConfigFilePath); XmlSaver.SaveDataObject(PsiSettings, configFolder + "/" + path); }