Skip to content
Snippets Groups Projects
Commit 859227b6 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '25-add-images-to-categories' into 'master'

Resolve "Add images to categories"

Closes #25

See merge request !24
parents 761d41a6 0cd4984b
No related branches found
No related tags found
1 merge request!24Resolve "Add images to categories"
Pipeline #5587 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.24
app.versionCode=24
app.versionName=0.0.25
app.versionCode=25
Add emojis to categories.
Ajout d'emojis aux catégories.
......@@ -20,22 +20,37 @@ class FetchDataHelper {
final List<GameItem> _mapping = [];
Category getCategory(String code) {
return _categories.firstWhere((category) => (category.key == code));
}
void init() {
try {
const gameData = GameData.data;
final Map<String, String> emojis = {};
final Map<String, dynamic> rawResources = gameData['resources'] as Map<String, dynamic>;
final Map<String, String> rawEmojis = rawResources['categories'] as Map<String, String>;
rawEmojis.forEach((categoryCode, emoji) {
emojis[categoryCode] = emoji;
});
final List<dynamic> rawCategories = gameData['categories'] as List<dynamic>;
for (var rawElement in rawCategories) {
final element = rawElement.toString();
_categories.add(Category(key: element, text: element));
final categoryCode = rawElement.toString();
_categories.add(Category(
key: categoryCode,
text: categoryCode,
emoji: emojis[categoryCode] ?? '',
));
}
final Map<String, dynamic> rawThemes = gameData['themes'] as Map<String, dynamic>;
rawThemes.forEach((code, rawCategories) {
final List<Category> categories = [];
for (var rawElement in rawCategories) {
final element = rawElement.toString();
categories.add(Category(key: element, text: element));
final category = getCategory(rawElement.toString());
categories.add(category);
}
_themes.add(GameTheme(code: code, categories: categories));
});
......@@ -65,12 +80,8 @@ class FetchDataHelper {
key: itemName,
text: itemName,
),
isCategory: rawIsCategories
.map((String category) => Category(key: category, text: category))
.toList(),
isNotCategory: rawIsNotCategories
.map((String category) => Category(key: category, text: category))
.toList(),
isCategory: rawIsCategories.map((String code) => getCategory(code)).toList(),
isNotCategory: rawIsNotCategories.map((String code) => getCategory(code)).toList(),
));
},
);
......@@ -94,9 +105,9 @@ class FetchDataHelper {
final GameTheme gameTheme = _themes[theme];
for (GameItem item in items) {
item.isCategory.removeWhere((Category category) =>
(!gameTheme.categories.map((c) => c.key).contains(category.key)));
(!gameTheme.categories.map((Category c) => c.key).contains(category.key)));
item.isNotCategory.removeWhere((Category category) =>
(!gameTheme.categories.map((c) => c.key).contains(category.key)));
(!gameTheme.categories.map((Category c) => c.key).contains(category.key)));
}
}
......
......@@ -10,6 +10,18 @@ class GameData {
"solide",
"végétal"
],
"resources": {
"categories": {
"animal": "🐈",
"artificiel": "✨",
"gazeux": "☁️",
"inerte": "🪨",
"liquide": "💧",
"naturel": "🏞️",
"solide": "💎",
"végétal": "🌿"
}
},
"exclusions": [
["liquide", "solide", "gazeux"],
["inerte", "animal", "végétal"],
......
class Category {
final String key;
final String text;
final String emoji;
const Category({
required this.key,
required this.text,
required this.emoji,
});
Map<String, dynamic> toJson() {
return {
'key': key,
'text': text,
'emoji': emoji,
};
}
......
......@@ -49,6 +49,14 @@ class GameButtonsYesNo extends StatelessWidget {
},
icon: const Icon(UniconsLine.thumbs_up),
),
Text(
category.emoji,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontSize: 40,
fontWeight: FontWeight.bold,
),
),
IconButton(
color: Theme.of(context).colorScheme.onSurface,
iconSize: 80,
......
......@@ -3,7 +3,7 @@ description: A sorting game application.
publish_to: 'none'
version: 0.0.24+24
version: 0.0.25+25
environment:
sdk: '^3.0.0'
......
......@@ -9,6 +9,18 @@
"solide",
"végétal"
],
"resources": {
"categories": {
"animal": "🐈",
"artificiel": "✨",
"gazeux": "☁️",
"inerte": "🪨",
"liquide": "💧",
"naturel": "🏞️",
"solide": "💎",
"végétal": "🌿"
}
},
"exclusions": [
[
"liquide",
......
......@@ -122,11 +122,13 @@ $categories = array_clean($categories);
$items = array_clean($items);
$themes = (\array_key_exists('themes', $data) && \is_array($data['themes'])) ? $data['themes'] : [];
$resources = (\array_key_exists('resources', $data) && \is_array($data['resources'])) ? $data['resources'] : [];
$data['categories'] = $categories;
$data['items'] = $items;
$data['exclusions'] = $exclusions;
$data['themes'] = $themes;
$data['resources'] = $resources;
dump('');
dump('Found ' . \count($categories) . ' unique categories.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment