Remove manifest file and auto-discover images from folder

Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-14 15:11:04 +00:00
parent 1618e3de47
commit 1f1dd1705f
3 changed files with 40 additions and 49 deletions

View file

@ -46,27 +46,39 @@ public sealed class GameService
{
_availableWords = [];
var commonWords = new[]
{
"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 imagePath = $"images/{word}.svg";
try
{
var manifest = await _httpClient.GetStringAsync("images-manifest.txt");
var imageNames = manifest.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
foreach (var imageName in imageNames)
var response = await _httpClient.GetAsync(imagePath, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var germanWord = ConvertToGermanWord(imageName);
_availableWords.Add(new GameWord
var germanWord = ConvertToGermanWord(word);
return new GameWord
{
Word = germanWord,
ImagePath = $"images/{imageName}.svg",
ImagePath = imagePath,
CorrectCount = 0,
IncorrectCount = 0
});
};
}
}
catch
{
_availableWords = [];
}
return null;
});
var results = await Task.WhenAll(loadTasks);
_availableWords = results.Where(w => w != null).Cast<GameWord>().ToList();
}
private static string ConvertToGermanWord(string englishWord)

View file

@ -1,20 +0,0 @@
ball
bed
book
car
cat
chair
clock
cup
dog
door
fork
hat
house
knife
phone
shoe
spoon
table
tree
window

View file

@ -133,13 +133,18 @@ MemoryGame/
## Adding New Words/Images
The game dynamically loads images from the `wwwroot/images/` folder. To add new words and images:
The game automatically discovers images from the `wwwroot/images/` folder. To add new words and images:
1. **Add your image**: Place an SVG image in `wwwroot/images/` with the English filename (e.g., `apple.svg`, `orange.svg`)
2. **Update the manifest**: Add the filename (without extension) to `wwwroot/images-manifest.txt`:
```
apple
orange
2. **Add to discovery list**: Add the filename (without extension) to the `commonWords` array in `Services/GameService.cs`:
```csharp
var commonWords = new[]
{
"ball", "bed", "book", "car", "cat", "chair", "clock", "cup",
"dog", "door", "fork", "hat", "house", "knife", "phone",
"shoe", "spoon", "table", "tree", "window",
"apple", "orange" // Add new words here
};
```
3. **Add German translation** (optional): If you want a custom German translation, update the `ConvertToGermanWord` method in `Services/GameService.cs`:
```csharp
@ -149,13 +154,7 @@ The game dynamically loads images from the `wwwroot/images/` folder. To add new
If no translation is provided, the filename will be capitalized and used as-is.
4. **Regenerate manifest** (alternative): You can automatically regenerate the manifest by running:
```bash
cd MemoryGame/wwwroot/images
ls *.svg | sed 's/\.svg$//' > ../images-manifest.txt
```
The game will automatically load and use the new images in the next session!
The game will automatically discover and load images that exist in the folder. No manifest file needed!
## Browser Compatibility