summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorTheDrawingCoding-Gamer <bulbyvr@gmail.com>2024-05-01 13:38:29 -0400
committerTheDrawingCoding-Gamer <bulbyvr@gmail.com>2024-05-08 18:32:09 -0400
commita6090f4a1ca25100c6d570779d00c2950501498d (patch)
treea3437398937d137db3b95d90e8c9564a26c57845 /scripts
parentMerge pull request #1717 from Integral-Tech/optimize-qstring (diff)
downloadnheko-a6090f4a1ca25100c6d570779d00c2950501498d.tar.xz
fix naming issues with emoji, edit how codegen works
Diffstat (limited to 'scripts')
-rw-r--r--scripts/codegen.sh5
-rwxr-xr-xscripts/emoji_codegen.py49
2 files changed, 45 insertions, 9 deletions
diff --git a/scripts/codegen.sh b/scripts/codegen.sh
index 9ba5c5df..f55fa50f 100644
--- a/scripts/codegen.sh
+++ b/scripts/codegen.sh
@@ -1,7 +1,8 @@
 #!/bin/bash
 ROOT=$(realpath "$PWD/$(dirname "$0")/..")
 cd $ROOT
-cat resources/provider-header.txt > src/emoji/Provider.cpp 
+cat resources/provider-head.txt > src/emoji/Provider.cpp 
 cat resources/extra_emoji.txt resources/emoji-test.txt > resources/complete-emoji.txt
-scripts/emoji_codegen.py resources/complete-emoji.txt resources/shortcodes.txt >> src/emoji/Provider.cpp
+scripts/emoji_codegen.py impl resources/complete-emoji.txt resources/shortcodes.txt >> src/emoji/Provider.cpp
+scripts/emoji_codegen.py header resources/complete-emoji.txt resources/shortcodes.txt > src/emoji/Provider.h
 cd - > /dev/null
diff --git a/scripts/emoji_codegen.py b/scripts/emoji_codegen.py
index 53c3d2e8..5378b32d 100755
--- a/scripts/emoji_codegen.py
+++ b/scripts/emoji_codegen.py
@@ -12,10 +12,34 @@ class Emoji(object):
         self.shortname = shortname
         self.unicodename = unicodename
 
+def generate_provider_class(**kwargs):
+    entrycount = sum([len(c[1]) for c in kwargs.items()])
+    tmpl = Template('''\
+    // SPDX-FileCopyrightText: Nheko Contributors
+    //
+    // SPDX-License-Identifier: GPL-3.0-or-later
+
+    // DO NOT EDIT Provider.h DIRECTLY! EDIT IT IN scripts/emoji_codegen.py AND RUN scripts/codegen.sh!
+
+    #pragma once
+    #include <array>
+    #include "Emoji.h"
+
+    namespace emoji {
+    class Provider
+    {
+    public:
+        // all emoji for QML purposes
+        static const std::array<Emoji, {{ entrycount }}> emoji;
+    };
+    } // namespace emoji
+    ''')
+    d = dict(entrycount=entrycount)
+    print(tmpl.render(d))
 def generate_qml_list(**kwargs):
     entrycount = sum([len(c[1]) for c in kwargs.items()])
     tmpl = Template('''
-constexpr const std::array<Emoji, {{ entrycount }} > emoji::Provider::emoji = {
+    std::array<Emoji, {{ entrycount }} > emoji::Provider::emoji = {
     {%- for c in kwargs.items() %}
     // {{ c[0].capitalize() }}
     {%- for e in c[1] %}
@@ -26,13 +50,19 @@ constexpr const std::array<Emoji, {{ entrycount }} > emoji::Provider::emoji = {
     ''')
     d = dict(kwargs=kwargs, entrycount=entrycount)
     print(tmpl.render(d))
+def usage():
+    print('usage: emoji_codegen.py {impl|header} /path/to/emoji-test /path/to/shortcodes.txt')
 if __name__ == '__main__':
-    if len(sys.argv) < 3:
-        print('usage: emoji_codegen.py /path/to/emoji-test.txt /path/to/shortcodes.txt')
+    if len(sys.argv) < 4:
+        usage()
         sys.exit(1)
 
-    filename = sys.argv[1]
-    shortcodefilename = sys.argv[2]
+    mode = sys.argv[1]
+    if mode != 'impl' and mode != 'header':
+        usage()
+        sys.exit(1)
+    filename = sys.argv[2]
+    shortcodefilename = sys.argv[3]
 
     people = []
     nature = []
@@ -99,7 +129,7 @@ if __name__ == '__main__':
             if shortname.endswith(': curly hair'):
                 shortname = "curly_haired_" + shortname[:-12]
             if shortname.endswith(': white hair'):
-                shortname = "white_haried_" + shortname[:-12]
+                shortname = "white_haired_" + shortname[:-12]
             if shortname.endswith(': bald'):
                 shortname = "bald_" + shortname[:-6]
             if shortname.endswith(': beard'):
@@ -134,4 +164,9 @@ if __name__ == '__main__':
     # Use xclip to pipe the output to clipboard.
     # e.g ./emoji_codegen.py emoji.json | xclip -sel clip
     # alternatively - delete the var from src/emoji/Provider.cpp, and do ./codegen.sh emojis shortcodes >> ../src/emoji/Provider.cpp
-    generate_qml_list(people=people, nature=nature, food=food, activity=activity, travel=travel, objects=objects, symbols=symbols, flags=flags)
+    func = None
+    if mode == 'impl':
+        func = generate_qml_list
+    else:
+        func = generate_provider_class
+    func(people=people, nature=nature, food=food, activity=activity, travel=travel, objects=objects, symbols=symbols, flags=flags)