From 0cd4984b9f1aaaaf96e1d672de0dc227d44fe979 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Fri, 19 Apr 2024 14:53:29 +0200
Subject: [PATCH] Add emojis to categories

---
 android/gradle.properties                     |  4 +--
 .../metadata/android/en-US/changelogs/25.txt  |  1 +
 .../metadata/android/fr-FR/changelogs/25.txt  |  1 +
 lib/data/fetch_data_helper.dart               | 35 ++++++++++++-------
 lib/data/game_data.dart                       | 12 +++++++
 lib/models/data/category.dart                 |  3 ++
 lib/ui/widgets/games/buttons_yes_no.dart      |  8 +++++
 pubspec.yaml                                  |  2 +-
 scripts/data.json                             | 12 +++++++
 scripts/manage_data.php                       |  2 ++
 10 files changed, 65 insertions(+), 15 deletions(-)
 create mode 100644 fastlane/metadata/android/en-US/changelogs/25.txt
 create mode 100644 fastlane/metadata/android/fr-FR/changelogs/25.txt

diff --git a/android/gradle.properties b/android/gradle.properties
index c2a871a..357cef3 100644
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -1,5 +1,5 @@
 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
diff --git a/fastlane/metadata/android/en-US/changelogs/25.txt b/fastlane/metadata/android/en-US/changelogs/25.txt
new file mode 100644
index 0000000..85b2fff
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/25.txt
@@ -0,0 +1 @@
+Add emojis to categories.
diff --git a/fastlane/metadata/android/fr-FR/changelogs/25.txt b/fastlane/metadata/android/fr-FR/changelogs/25.txt
new file mode 100644
index 0000000..ae9f8c0
--- /dev/null
+++ b/fastlane/metadata/android/fr-FR/changelogs/25.txt
@@ -0,0 +1 @@
+Ajout d'emojis aux catégories.
diff --git a/lib/data/fetch_data_helper.dart b/lib/data/fetch_data_helper.dart
index 9904c8b..7585817 100644
--- a/lib/data/fetch_data_helper.dart
+++ b/lib/data/fetch_data_helper.dart
@@ -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)));
       }
     }
 
diff --git a/lib/data/game_data.dart b/lib/data/game_data.dart
index 2cea22a..8def8fe 100644
--- a/lib/data/game_data.dart
+++ b/lib/data/game_data.dart
@@ -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"],
diff --git a/lib/models/data/category.dart b/lib/models/data/category.dart
index 9e561ec..ca3d2cc 100644
--- a/lib/models/data/category.dart
+++ b/lib/models/data/category.dart
@@ -1,16 +1,19 @@
 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,
     };
   }
 
diff --git a/lib/ui/widgets/games/buttons_yes_no.dart b/lib/ui/widgets/games/buttons_yes_no.dart
index 3efd687..0a72653 100644
--- a/lib/ui/widgets/games/buttons_yes_no.dart
+++ b/lib/ui/widgets/games/buttons_yes_no.dart
@@ -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,
diff --git a/pubspec.yaml b/pubspec.yaml
index 0453b56..9300eb7 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -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'
diff --git a/scripts/data.json b/scripts/data.json
index 12afbd2..f817fc0 100644
--- a/scripts/data.json
+++ b/scripts/data.json
@@ -9,6 +9,18 @@
     "solide",
     "végétal"
   ],
+  "resources": {
+    "categories": {
+      "animal": "🐈",
+      "artificiel": "✨",
+      "gazeux": "☁️",
+      "inerte": "🪨",
+      "liquide": "💧",
+      "naturel": "🏞️",
+      "solide": "💎",
+      "végétal": "🌿"
+    }
+  },
   "exclusions": [
     [
       "liquide",
diff --git a/scripts/manage_data.php b/scripts/manage_data.php
index fd16dc0..f45e985 100644
--- a/scripts/manage_data.php
+++ b/scripts/manage_data.php
@@ -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.');
-- 
GitLab