private void LoadMapData(string FriendlyName, string FilePath, string FileName, string FileExtension) { // make sure resource exists var fullDirectory = ReadWrite.CreateIfNotExists(FilePath, FileName, FileExtension, false); if (!string.IsNullOrEmpty(fullDirectory)) { var mapData = ReadWrite.ReadJson <LevelObj>(FilePath, FileName, FileExtension, false); if (mapData != null) { MapData.Add(FriendlyName, mapData); } else { ReadWrite.WriteToLog(String.Format("LoadMapData - Data is null. FriendlyName: {0}. Root: {1}. Path: {2}. FileName: {3}. FileExtension: {4}", FriendlyName, ReadWrite.GetRoot, FilePath, FileName, FileExtension)); throw new FileLoadException("Could not Load resource"); } } else { ReadWrite.WriteToLog(String.Format("LoadMapData - Could not load resource. FriendlyName: {0}. Root: {1}. Path: {2}. FileName: {3}. FileExtension: {4}", FriendlyName, ReadWrite.GetRoot, FilePath, FileName, FileExtension)); throw new FileLoadException("Could not Load resource"); } }
private void LoadSettings() { Settings = ReadWrite.ReadJson <SettingsObj>(PathSettings, @"\settings", ".json"); if (Settings != null) { EnableWriteToLog = Settings.Log; if (Settings.Log) { ReadWrite = new ReadWrite(EnableWriteToLog); } } }
public void TestReadJson() { //Arrange var init = new OlcSideScrollingConsoleGame.Core.ReadWrite(); string Path = "\\Resources\\Settings"; string FileName = "\\settings"; string FileExtension = ".json"; //Act var returnObj = init.ReadJson <SettingsObj>(Path, FileName, FileExtension); //Assert Assert.IsNotNull(returnObj); Assert.IsTrue(returnObj is SettingsObj); //Assert.IsNotNull(returnObj.misc); //Assert.IsTrue(returnObj.misc == "Unit test"); }
private void LoadHighScore() { HighScoreList = ReadWrite.ReadJson <List <HighScoreObj> > (PathSettings, @"\highscore", ".json"); //High Score if (HighScoreList == null) { HighScoreList = new List <HighScoreObj>(); } if (HighScoreList.Count < 6) { int addToFive = 5 - HighScoreList.Count; for (int i = 0; i < addToFive; i++) { HighScoreList.Add(new HighScoreObj { DateTime = DateTime.Now, Handle = "Empty", TimeSpan = new TimeSpan(7, 23, 59, 59) }); } } HighScoreList = HighScoreList.OrderBy(x => x.TimeSpan).ThenBy(y => y.DateTime).ToList(); }