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

Add emojis to categories

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