Skip to content

Commit

Permalink
MapHelper now uses property rather than fields
Browse files Browse the repository at this point in the history
  • Loading branch information
iconstudio committed Oct 3, 2023
1 parent c9ecf01 commit a33c715
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions Editor/TestEditor/Contents/MapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,25 @@ namespace TestEditor.Contents
internal static class MapHelper
{
public const string mapFileExtension = ".gmap";
public static readonly JsonSerializerOptions mapLoadSetting;
public static readonly JsonSerializerOptions mapSaveSetting;

private static StorageFile lastFile;
private static Map? loadedMap;
private static List<Map> storedMaps;

public static StorageFile LastFile => lastFile;
public static StorageFile LastFile { get; private set; }
public static JsonSerializerOptions MapLoadSetting { get; }
public static JsonSerializerOptions MapSaveSetting { get; }

static MapHelper()
{
lastFile = null;

loadedMap = null;
storedMaps = new();
#if !NET5_0_OR_GREATER
storedMaps.Clear();
#endif
LastFile = null;

mapLoadSetting = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true };
mapSaveSetting = new() { WriteIndented = true };
MapLoadSetting = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true };
MapSaveSetting = new() { WriteIndented = true };
}
public static async Task<Map?> LoadMap(StorageFile file)
{
Expand All @@ -55,7 +53,7 @@ static MapHelper()

try
{
var map = JsonSerializer.Deserialize<Map?>(json, mapLoadSetting);
var map = JsonSerializer.Deserialize<Map?>(json, MapLoadSetting);

if (map is Map gmap)
{
Expand Down Expand Up @@ -115,7 +113,7 @@ public static Task SaveMap(in Map? map, in string filepath)
}
public static void MemoLastFile(in StorageFile file)
{
lastFile = file;
LastFile = file;
}
public static string GetMapExtension() => mapFileExtension;
public static List<Map> GetMaps() => storedMaps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Map Deserialize()
[Pure]
public override readonly string ToString()
{
return JsonSerializer.Serialize(this, MapHelper.mapSaveSetting);
return JsonSerializer.Serialize(this, MapHelper.MapSaveSetting);
}
}
}

0 comments on commit a33c715

Please sign in to comment.