Skip to content

Commit

Permalink
Added fallback to convert a map to char. Pending tool to export it to…
Browse files Browse the repository at this point in the history
… a file
  • Loading branch information
JamesVeug committed Jan 9, 2023
1 parent 5292242 commit 7c9418d
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion Core/ChessboardMapExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,16 @@ public void LoadData()
private static List<GrimoraChessboard> LoadChessboardsFromFile(string fileName)
{
string jsonString = File.ReadAllText(FileUtils.FindFileInPluginDir(fileName));
List<List<List<char>>> chessboardsFromJson = SimpleJson.DeserializeObject<List<List<List<char>>>>(jsonString);

List<List<List<char>>> chessboardsFromJson = null;
try
{
chessboardsFromJson = SimpleJson.DeserializeObject<List<List<List<char>>>>(jsonString);
}
catch (Exception)
{
chessboardsFromJson = ConvertMapToCorrectFormat(jsonString, fileName);
}

List<GrimoraChessboard> chessboards = new List<GrimoraChessboard>();
for (int i = 0; i < chessboardsFromJson.Count; i++)
Expand All @@ -196,6 +205,35 @@ private static List<GrimoraChessboard> LoadChessboardsFromFile(string fileName)
return chessboards;
}

private static List<List<List<char>>> ConvertMapToCorrectFormat(string jsonString, string fileName)
{
Log.LogError($"Failed to load map {fileName}. Map does not use strings!");
List<List<List<int>>> chessboardsAsNumbers = null;
try
{
chessboardsAsNumbers = SimpleJson.DeserializeObject<List<List<List<int>>>>(jsonString);
}
catch (Exception exception)
{
Log.LogError($"Failed to correct map {fileName}. Is there a something wrong with the JSON?");
Log.LogError(exception);
}

List<List<List<char>>> chessboardsFromJson = new List<List<List<char>>>();
foreach (List<List<int>> data in chessboardsAsNumbers)
{
List<List<char>> column = new List<List<char>>();
foreach (List<int> row in data)
{
List<char> convertedRow = row.Select(a=>a.ToString()[0]).ToList();
column.Add(convertedRow);
}
chessboardsFromJson.Add(column);
}

return chessboardsFromJson;
}

public static string[] CardsLeftInDeck => CardDrawPiles3D
.Instance
.Deck
Expand Down

0 comments on commit 7c9418d

Please sign in to comment.