Working World roundtrip serialization
There are probably still reference equality issues here since Unit still has Season and Power objects. The test case builder also still works on reference equality in some places so the second part of adjudication is broken.
This commit is contained in:
parent
31bd6a45cb
commit
73d849e117
@ -88,12 +88,12 @@ public class Map
|
||||
/// </summary>
|
||||
public Power GetPower(string powerName)
|
||||
=> Powers.SingleOrDefault(p => p!.Name == powerName || p.Name.StartsWith(powerName), null)
|
||||
?? throw new KeyNotFoundException($"Power {powerName} not found");
|
||||
?? throw new KeyNotFoundException($"Power {powerName} not found (powers: {string.Join(", ", Powers)})");
|
||||
|
||||
public static Map FromType(MapType type)
|
||||
=> type switch {
|
||||
MapType.Test => Test,
|
||||
MapType.Classical => Test,
|
||||
MapType.Classical => Classical,
|
||||
_ => throw new NotImplementedException($"Unknown variant {type}"),
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MultiversalDiplomacy.Model;
|
||||
|
||||
/// <summary>
|
||||
@ -33,9 +35,10 @@ public class Unit
|
||||
/// <summary>
|
||||
/// A unique designation for this unit.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string Designation => $"{Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
|
||||
|
||||
private Unit(string? past, string location, Season season, Power power, UnitType type)
|
||||
public Unit(string? past, string location, Season season, Power power, UnitType type)
|
||||
{
|
||||
this.Past = past;
|
||||
this.Location = location;
|
||||
|
@ -64,11 +64,9 @@ public class SerializationTest
|
||||
Assert.That(tyr0, Is.NotDislodged);
|
||||
setup.UpdateWorld();
|
||||
|
||||
// Serialize the world
|
||||
// Serialize and deserialize the world
|
||||
string serialized = JsonSerializer.Serialize(setup.World, Options);
|
||||
|
||||
// Deserialize the world
|
||||
Console.WriteLine(serialized);
|
||||
// Console.WriteLine(serialized);
|
||||
World reserialized = JsonSerializer.Deserialize<World>(serialized, Options)
|
||||
?? throw new AssertionException("Failed to reserialize world");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user