enhanced persistence with interfaces + fixed some code smells
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
8ab9642c9c
commit
88f7dc08c3
@ -1,16 +1 @@
|
|||||||
{
|
<Leaderboard xmlns="http://schemas.datacontract.org/2004/07/QwirkleClassLibrary.Players" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><leaderboard><Score><Date>2024-05-31T00:00:00+02:00</Date><PlayerName>Jérémy</PlayerName><Points>0</Points><Victories>1</Victories></Score><Score><Date>2024-05-31T00:00:00+02:00</Date><PlayerName>Jules</PlayerName><Points>0</Points><Victories>0</Victories></Score></leaderboard></Leaderboard>
|
||||||
"leaderboard": [
|
|
||||||
{
|
|
||||||
"Date": "\/Date(1717106400000+0200)\/",
|
|
||||||
"PlayerName": "Jérémy",
|
|
||||||
"Points": 0,
|
|
||||||
"Victories": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Date": "\/Date(1717106400000+0200)\/",
|
|
||||||
"PlayerName": "Jules",
|
|
||||||
"Points": 0,
|
|
||||||
"Victories": 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
File diff suppressed because one or more lines are too long
@ -1,7 +1,12 @@
|
|||||||
namespace QwirkleClassLibrary.Events
|
namespace QwirkleClassLibrary.Events
|
||||||
{
|
{
|
||||||
public class SwapTilesNotifiedEventArgs(string reason)
|
public class SwapTilesNotifiedEventArgs
|
||||||
{
|
{
|
||||||
public string Reason { get; private set; } = reason;
|
public string Reason { get; private set; }
|
||||||
|
|
||||||
|
public SwapTilesNotifiedEventArgs(string reason)
|
||||||
|
{
|
||||||
|
Reason = reason;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +0,0 @@
|
|||||||
namespace QwirkleClassLibrary.Persistences;
|
|
||||||
|
|
||||||
public class GamePersistence
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,27 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
using QwirkleClassLibrary.Games;
|
||||||
|
|
||||||
|
namespace QwirkleClassLibrary.Persistences;
|
||||||
|
|
||||||
|
public class GamePersistenceJson : IGamePersistence
|
||||||
|
{
|
||||||
|
public void SaveGame(Game game)
|
||||||
|
{
|
||||||
|
var serializer = new DataContractSerializer(typeof(Game));
|
||||||
|
|
||||||
|
using (Stream writer = File.Create("Game.json"))
|
||||||
|
{
|
||||||
|
serializer.WriteObject(writer, game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Game LoadGame()
|
||||||
|
{
|
||||||
|
var serializer = new DataContractSerializer(typeof(Game));
|
||||||
|
|
||||||
|
using (Stream reader = File.OpenRead("Game.json"))
|
||||||
|
{
|
||||||
|
return serializer.ReadObject(reader) as Game ?? throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
using QwirkleClassLibrary.Games;
|
||||||
|
|
||||||
|
namespace QwirkleClassLibrary.Persistences;
|
||||||
|
|
||||||
|
public interface IGamePersistence
|
||||||
|
{
|
||||||
|
void SaveGame(Game game);
|
||||||
|
|
||||||
|
Game LoadGame();
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
using QwirkleClassLibrary.Players;
|
||||||
|
|
||||||
|
namespace QwirkleClassLibrary.Persistences;
|
||||||
|
|
||||||
|
public interface ILeaderboardPersistence
|
||||||
|
{
|
||||||
|
void SaveLeaderboard(Leaderboard leaderboard);
|
||||||
|
|
||||||
|
Leaderboard LoadLeaderboard();
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using QwirkleClassLibrary.Players;
|
|
||||||
|
|
||||||
namespace QwirkleClassLibrary.Persistences;
|
|
||||||
|
|
||||||
public class LeaderboardPersistence
|
|
||||||
{
|
|
||||||
public void SaveLeaderboard(Leaderboard leaderboard)
|
|
||||||
{
|
|
||||||
var leaderboardSerializer = new DataContractSerializer(typeof(Leaderboard));
|
|
||||||
|
|
||||||
using (Stream s = File.Create("LeaderBoard.json "))
|
|
||||||
{
|
|
||||||
leaderboardSerializer.WriteObject(s, leaderboard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Leaderboard LoadLeaderboard()
|
|
||||||
{
|
|
||||||
var leaderboardSerializer = new DataContractSerializer(typeof(Leaderboard));
|
|
||||||
|
|
||||||
using (Stream s = File.OpenRead("LeaderBoard.json"))
|
|
||||||
{
|
|
||||||
return leaderboardSerializer.ReadObject(s) as Leaderboard ?? throw new NullReferenceException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,27 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
using QwirkleClassLibrary.Players;
|
||||||
|
|
||||||
|
namespace QwirkleClassLibrary.Persistences;
|
||||||
|
|
||||||
|
public class LeaderboardPersistenceJson : ILeaderboardPersistence
|
||||||
|
{
|
||||||
|
public void SaveLeaderboard(Leaderboard leaderboard)
|
||||||
|
{
|
||||||
|
var serializer = new DataContractSerializer(typeof(Leaderboard));
|
||||||
|
|
||||||
|
using (Stream writer = File.Create("Leaderboard.json"))
|
||||||
|
{
|
||||||
|
serializer.WriteObject(writer, leaderboard);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Leaderboard LoadLeaderboard()
|
||||||
|
{
|
||||||
|
var serializer = new DataContractSerializer(typeof(Leaderboard));
|
||||||
|
|
||||||
|
using (Stream reader = File.OpenRead("Leaderboard.json"))
|
||||||
|
{
|
||||||
|
return serializer.ReadObject(reader) as Leaderboard ?? throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue