ALOT again

This commit is contained in:
2024-10-23 22:11:14 +02:00
parent a98a463531
commit e2c9116575
11 changed files with 499 additions and 266 deletions
+12 -5
View File
@@ -12,13 +12,20 @@ public class SnakeLevelLoader{
if(!File.Exists(SaveFileName)){
throw new FileNotFoundException("Save file not found", SaveFileName);
}
string file_content = File.ReadAllText(SaveFileName);
_stored_levels = JsonSerializer.Deserialize<List<StoredSnakeLevel>>(file_content, new JsonSerializerOptions(){PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower})
?? throw new JsonException("Failed to deserialize stored levels");
}
private List<StoredSnakeLevel> _stored_levels;
public ReadOnlyCollection<StoredSnakeLevel> StoredLevels => _stored_levels.AsReadOnly();
public async Task ReadAllDataAsync()
{
string file_content = await File.ReadAllTextAsync(SaveFileName);
_stored_levels = JsonSerializer.Deserialize<List<StoredSnakeLevel>>(file_content, new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower })
?? throw new JsonException("Failed to deserialize stored levels");
await Task.Delay(2000);
}
private List<StoredSnakeLevel>? _stored_levels;
public ReadOnlyCollection<StoredSnakeLevel> StoredLevels => _stored_levels?.AsReadOnly()
?? throw new InvalidOperationException("Can not query stored levels before loading the data");
public SnakeLevel LoadLevel(StoredSnakeLevel level){
return new SnakeLevel(level.Size,