Improve image loading
This commit is contained in:
parent
f197f92306
commit
9543bbb009
2 changed files with 25 additions and 38 deletions
|
|
@ -46,25 +46,20 @@ public sealed class GameService
|
||||||
{
|
{
|
||||||
_availableWords = [];
|
_availableWords = [];
|
||||||
|
|
||||||
var commonWords = new[]
|
var manifest = await _httpClient.GetStringAsync("manifest.txt");
|
||||||
{
|
var imageNames = manifest.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||||
"ball", "bed", "book", "car", "cat", "chair", "clock", "cup",
|
|
||||||
"dog", "door", "fork", "hat", "house", "knife", "phone",
|
|
||||||
"shoe", "spoon", "table", "tree", "window"
|
|
||||||
};
|
|
||||||
|
|
||||||
var loadTasks = commonWords.Select(async word =>
|
var loadTasks = imageNames.Select(async imageName =>
|
||||||
{
|
{
|
||||||
var imagePath = $"images/{word}.svg";
|
var imagePath = $"images/{imageName}";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await _httpClient.GetAsync(imagePath, HttpCompletionOption.ResponseHeadersRead);
|
var response = await _httpClient.GetAsync(imagePath, HttpCompletionOption.ResponseHeadersRead);
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var germanWord = ConvertToGermanWord(word);
|
|
||||||
return new GameWord
|
return new GameWord
|
||||||
{
|
{
|
||||||
Word = germanWord,
|
Word = Path.GetFileNameWithoutExtension(imageName),
|
||||||
ImagePath = imagePath,
|
ImagePath = imagePath,
|
||||||
CorrectCount = 0,
|
CorrectCount = 0,
|
||||||
IncorrectCount = 0
|
IncorrectCount = 0
|
||||||
|
|
@ -81,34 +76,6 @@ public sealed class GameService
|
||||||
_availableWords = results.Where(w => w != null).Cast<GameWord>().ToList();
|
_availableWords = results.Where(w => w != null).Cast<GameWord>().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ConvertToGermanWord(string englishWord)
|
|
||||||
{
|
|
||||||
return englishWord.ToLower() switch
|
|
||||||
{
|
|
||||||
"fork" => "Gabel",
|
|
||||||
"knife" => "Messer",
|
|
||||||
"spoon" => "Löffel",
|
|
||||||
"door" => "Tür",
|
|
||||||
"window" => "Fenster",
|
|
||||||
"ball" => "Ball",
|
|
||||||
"house" => "Haus",
|
|
||||||
"tree" => "Baum",
|
|
||||||
"car" => "Auto",
|
|
||||||
"cat" => "Katze",
|
|
||||||
"dog" => "Hund",
|
|
||||||
"chair" => "Stuhl",
|
|
||||||
"table" => "Tisch",
|
|
||||||
"cup" => "Tasse",
|
|
||||||
"book" => "Buch",
|
|
||||||
"clock" => "Uhr",
|
|
||||||
"bed" => "Bett",
|
|
||||||
"phone" => "Telefon",
|
|
||||||
"shoe" => "Schuh",
|
|
||||||
"hat" => "Hut",
|
|
||||||
_ => char.ToUpper(englishWord[0]) + englishWord[1..].ToLower()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameSession CreateNewGame()
|
public GameSession CreateNewGame()
|
||||||
{
|
{
|
||||||
var rounds = new List<Round>();
|
var rounds = new List<Round>();
|
||||||
|
|
|
||||||
20
MemoryGame/wwwroot/manifest.txt
Normal file
20
MemoryGame/wwwroot/manifest.txt
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
ball.svg
|
||||||
|
bed.svg
|
||||||
|
book.svg
|
||||||
|
car.svg
|
||||||
|
cat.svg
|
||||||
|
chair.svg
|
||||||
|
clock.svg
|
||||||
|
cup.svg
|
||||||
|
dog.svg
|
||||||
|
door.svg
|
||||||
|
fork.svg
|
||||||
|
hat.svg
|
||||||
|
house.svg
|
||||||
|
knife.svg
|
||||||
|
phone.svg
|
||||||
|
shoe.svg
|
||||||
|
spoon.svg
|
||||||
|
table.svg
|
||||||
|
tree.svg
|
||||||
|
window.svg
|
||||||
Loading…
Reference in a new issue