Passage en ObservableCollection et changement du chemin d'accès de la persistance

pull/97/head
Rémi LAVERGNE 11 months ago
parent bf84bfa906
commit ac794f5c16
No known key found for this signature in database
GPG Key ID: 7BCBAE9031E39160

@ -26,13 +26,13 @@ namespace DataContractPersistence
/// <summary>
/// Path (relative to the project)
/// </summary>
public string FilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
public string FilePath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Trek_12");
/// <summary>
/// Load all the data from JSON file
/// </summary>
/// <returns>A tuple with the lists of players, games, maps and best scores</returns>
public (List<Player>, List<Game>, List<Map>, List<BestScore>) LoadData()
public (ObservableCollection<Player>, ObservableCollection<Game>, ObservableCollection<Map>, ObservableCollection<BestScore>) LoadData()
{
var JsonSerializer = new DataContractJsonSerializer(typeof(DataToPersist));
DataToPersist? data = new DataToPersist();
@ -52,8 +52,9 @@ namespace DataContractPersistence
/// <param name="games"></param>
/// <param name="maps"></param>
/// <param name="bestScores"></param>
public void SaveData(List<Player> players, List<Game> games, List<Map> maps, List<BestScore> bestScores)
public void SaveData(ObservableCollection<Player> players, ObservableCollection<Game> games, ObservableCollection<Map> maps, ObservableCollection<BestScore> bestScores)
{
Debug.WriteLine("Saving data at " + Path.Combine(FilePath, FileName));
if (!Directory.Exists(FilePath))
{
Debug.WriteLine("Directory created");

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
@ -23,13 +24,13 @@ namespace DataContractPersistence
/// <summary>
/// Path (relative to the project)
/// </summary>
public string FilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
public string FilePath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Trek_12");
/// <summary>
/// Load all the data from XML file
/// </summary>
/// <returns>A tuple with the lists of players, games, maps and best scores</returns>
public (List<Player>, List<Game>, List<Map>, List<BestScore>) LoadData()
public (ObservableCollection<Player>, ObservableCollection<Game>, ObservableCollection<Map>, ObservableCollection<BestScore>) LoadData()
{
var serializer = new DataContractSerializer(typeof(DataToPersist));
DataToPersist? data = new DataToPersist();
@ -49,7 +50,7 @@ namespace DataContractPersistence
/// <param name="games"></param>
/// <param name="maps"></param>
/// <param name="bestScores"></param>
public void SaveData(List<Player> players, List<Game> games, List<Map> maps, List<BestScore> bestScores)
public void SaveData(ObservableCollection<Player> players, ObservableCollection<Game> games, ObservableCollection<Map> maps, ObservableCollection<BestScore> bestScores)
{
if(!Directory.Exists(FilePath))
{

@ -8,21 +8,21 @@ namespace DataContractPersistence
/// <summary>
/// List of players
/// </summary>
public List<Player> Players { get; set; }
public ObservableCollection<Player> Players { get; set; }
/// <summary>
/// List of games (with all the data in it to be able to recreate the game)
/// </summary>
public List<Game> Games { get; set; }
public ObservableCollection<Game> Games { get; set; }
/// <summary>
/// List of maps with their boards
/// </summary>
public List<Map> Maps { get; set; }
public ObservableCollection<Map> Maps { get; set; }
/// <summary>
/// List of best scores
/// </summary>
public List<BestScore> BestScores { get; set; }
public ObservableCollection<BestScore> BestScores { get; set; }
}
}
Loading…
Cancel
Save