Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdebever committed May 16, 2024
1 parent 6a10dfe commit 107345a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
27 changes: 21 additions & 6 deletions Backend/FightCore.Exporters/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public static class Exporter
};

public static async Task Export(IEnumerable toExport, string folder, string name)
{
await ExportJson(toExport, folder, name);
await ExportCsv(toExport, folder, name);
}

public static async Task ExportCsv(IEnumerable toExport, string folder, string name)
{
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}

var movesJson = JsonConvert.SerializeObject(toExport, _noNestedJsonSettings);
var jsonPath = Path.Combine(folder, $"{name}.json");
Console.WriteLine($"Writing to {jsonPath}");
await File.WriteAllTextAsync(jsonPath, movesJson);

var csvPath = Path.Combine(folder, $"{name}.csv");
await using var writer = new StreamWriter(csvPath, false);
await using var csv = new CsvWriter(writer, new CsvConfiguration(CultureInfo.InvariantCulture)
Expand All @@ -45,5 +45,20 @@ public static async Task Export(IEnumerable toExport, string folder, string name

await csv.WriteRecordsAsync(toExport);
}

public static Task ExportJson(object toExport, string folder, string name)
{
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}

var json = JsonConvert.SerializeObject(toExport, _noNestedJsonSettings);
var jsonPath = Path.Combine(folder, $"{name}.json");
Console.WriteLine($"Writing to {jsonPath}");
return File.WriteAllTextAsync(jsonPath, json);


}
}
}
4 changes: 4 additions & 0 deletions Backend/FightCore.Exporters/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
{
move.Character = null;
move.CharacterId = default;
move.MoveSubactions = null;
return move;
});
moves = moves.OrderBy(move => move.Id).ToList();

character.Moves = moves.ToList();

await Exporter.Export(moves, Path.Combine(folder, character.NormalizedName), "moves");
await Exporter.ExportJson(character, Path.Combine(folder, "characters"), character.NormalizedName);
}
10 changes: 5 additions & 5 deletions Backend/FightCore.Repositories/CharacterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public Task<List<Character>> ExportAll()
.Include(character => character.Moves)
.ThenInclude(move => move.Hitboxes)
.Include(character => character.Moves)
.ThenInclude(move => move.MoveSubactions)
.ThenInclude(moveSubaction => moveSubaction.Subaction)
.ThenInclude(subaction => subaction.Commands)
.Include(character => character.Subactions)
.ThenInclude(subaction => subaction.Commands)
// .ThenInclude(move => move.MoveSubactions)
// .ThenInclude(moveSubaction => moveSubaction.Subaction)
// .ThenInclude(subaction => subaction.Commands)
//.Include(character => character.Subactions)
// .ThenInclude(subaction => subaction.Commands)
.AsSplitQuery()
.ToListAsync();
}
Expand Down

0 comments on commit 107345a

Please sign in to comment.