Skip to content

Commit 13d573e

Browse files
committed
Refactor emoji initialization for Electron and Otto boards to use Assets system
- Removed direct emoji initialization from `InitializeElectronEmojis` and `InitializeOttoEmojis` methods, delegating the responsibility to the Assets system. - Updated `CMakeLists.txt` to set `DEFAULT_EMOJI_COLLECTION` to `otto-gif` for both boards. - Enhanced `build_default_assets.py` to support alias mapping for Otto GIF emojis. - Updated `idf_component.yml` to bump `otto-emoji-gif-component` version to `^1.0.5` for improved functionality.
1 parent 2f3c1d0 commit 13d573e

5 files changed

Lines changed: 60 additions & 117 deletions

File tree

main/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,12 @@ elseif(CONFIG_BOARD_TYPE_OTTO_ROBOT)
581581
set(BOARD_TYPE "otto-robot")
582582
set(BUILTIN_TEXT_FONT font_puhui_16_4)
583583
set(BUILTIN_ICON_FONT font_awesome_16_4)
584+
set(DEFAULT_EMOJI_COLLECTION otto-gif)
584585
elseif(CONFIG_BOARD_TYPE_ELECTRON_BOT)
585586
set(BOARD_TYPE "electron-bot")
586587
set(BUILTIN_TEXT_FONT font_puhui_20_4)
587588
set(BUILTIN_ICON_FONT font_awesome_20_4)
589+
set(DEFAULT_EMOJI_COLLECTION otto-gif)
588590
elseif(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI_CAM)
589591
set(BOARD_TYPE "bread-compact-wifi-s3cam")
590592
set(BUILTIN_TEXT_FONT font_puhui_basic_16_4)

main/boards/electron-bot/electron_emoji_display.cc

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#include <esp_log.h>
44

55
#include <cstring>
6+
#include <vector>
67

8+
#include "assets.h"
79
#include "assets/lang_config.h"
810
#include "display/lvgl_display/emoji_collection.h"
911
#include "display/lvgl_display/lvgl_image.h"
1012
#include "display/lvgl_display/lvgl_theme.h"
11-
#include "otto_emoji_gif.h"
1213

1314
#define TAG "ElectronEmojiDisplay"
1415
ElectronEmojiDisplay::ElectronEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y,
@@ -19,64 +20,12 @@ ElectronEmojiDisplay::ElectronEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, e
1920
}
2021

2122
void ElectronEmojiDisplay::InitializeElectronEmojis() {
22-
ESP_LOGI(TAG, "初始化Electron GIF表情");
23-
24-
auto otto_emoji_collection = std::make_shared<EmojiCollection>();
25-
26-
// 中性/平静类表情 -> staticstate
27-
otto_emoji_collection->AddEmoji("staticstate", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
28-
otto_emoji_collection->AddEmoji("neutral", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
29-
otto_emoji_collection->AddEmoji("relaxed", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
30-
otto_emoji_collection->AddEmoji("sleepy", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
31-
otto_emoji_collection->AddEmoji("idle", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
32-
33-
// 积极/开心类表情 -> happy
34-
otto_emoji_collection->AddEmoji("happy", new LvglRawImage((void*)happy.data, happy.data_size));
35-
otto_emoji_collection->AddEmoji("laughing", new LvglRawImage((void*)happy.data, happy.data_size));
36-
otto_emoji_collection->AddEmoji("funny", new LvglRawImage((void*)happy.data, happy.data_size));
37-
otto_emoji_collection->AddEmoji("loving", new LvglRawImage((void*)happy.data, happy.data_size));
38-
otto_emoji_collection->AddEmoji("confident", new LvglRawImage((void*)happy.data, happy.data_size));
39-
otto_emoji_collection->AddEmoji("winking", new LvglRawImage((void*)happy.data, happy.data_size));
40-
otto_emoji_collection->AddEmoji("cool", new LvglRawImage((void*)happy.data, happy.data_size));
41-
otto_emoji_collection->AddEmoji("delicious", new LvglRawImage((void*)happy.data, happy.data_size));
42-
otto_emoji_collection->AddEmoji("kissy", new LvglRawImage((void*)happy.data, happy.data_size));
43-
otto_emoji_collection->AddEmoji("silly", new LvglRawImage((void*)happy.data, happy.data_size));
44-
45-
// 悲伤类表情 -> sad
46-
otto_emoji_collection->AddEmoji("sad", new LvglRawImage((void*)sad.data, sad.data_size));
47-
otto_emoji_collection->AddEmoji("crying", new LvglRawImage((void*)sad.data, sad.data_size));
48-
49-
// 愤怒类表情 -> anger
50-
otto_emoji_collection->AddEmoji("anger", new LvglRawImage((void*)anger.data, anger.data_size));
51-
otto_emoji_collection->AddEmoji("angry", new LvglRawImage((void*)anger.data, anger.data_size));
52-
53-
// 惊讶类表情 -> scare
54-
otto_emoji_collection->AddEmoji("scare", new LvglRawImage((void*)scare.data, scare.data_size));
55-
otto_emoji_collection->AddEmoji("surprised", new LvglRawImage((void*)scare.data, scare.data_size));
56-
otto_emoji_collection->AddEmoji("shocked", new LvglRawImage((void*)scare.data, scare.data_size));
57-
58-
// 思考/困惑类表情 -> buxue
59-
otto_emoji_collection->AddEmoji("buxue", new LvglRawImage((void*)buxue.data, buxue.data_size));
60-
otto_emoji_collection->AddEmoji("thinking", new LvglRawImage((void*)buxue.data, buxue.data_size));
61-
otto_emoji_collection->AddEmoji("confused", new LvglRawImage((void*)buxue.data, buxue.data_size));
62-
otto_emoji_collection->AddEmoji("embarrassed", new LvglRawImage((void*)buxue.data, buxue.data_size));
63-
64-
// 将表情集合添加到主题中
65-
auto& theme_manager = LvglThemeManager::GetInstance();
66-
auto light_theme = theme_manager.GetTheme("light");
67-
auto dark_theme = theme_manager.GetTheme("dark");
68-
69-
if (light_theme != nullptr) {
70-
light_theme->set_emoji_collection(otto_emoji_collection);
71-
}
72-
if (dark_theme != nullptr) {
73-
dark_theme->set_emoji_collection(otto_emoji_collection);
74-
}
23+
ESP_LOGI(TAG, "Electron表情初始化将由Assets系统处理");
24+
// 表情初始化已移至assets系统,通过DEFAULT_EMOJI_COLLECTION=otto-gif配置
25+
// assets.cc会从assets分区加载GIF表情并设置到theme
7526

7627
// 设置默认表情为staticstate
7728
SetEmotion("staticstate");
78-
79-
ESP_LOGI(TAG, "Electron GIF表情初始化完成");
8029
}
8130

8231
void ElectronEmojiDisplay::SetupChatLabel() {

main/boards/otto-robot/otto_emoji_display.cc

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#include <esp_log.h>
44

55
#include <cstring>
6+
#include <vector>
67

8+
#include "assets.h"
79
#include "assets/lang_config.h"
810
#include "display/lvgl_display/emoji_collection.h"
911
#include "display/lvgl_display/lvgl_image.h"
1012
#include "display/lvgl_display/lvgl_theme.h"
11-
#include "otto_emoji_gif.h"
1213

1314
#define TAG "OttoEmojiDisplay"
1415
OttoEmojiDisplay::OttoEmojiDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy)
@@ -24,64 +25,12 @@ void OttoEmojiDisplay::SetupPreviewImage() {
2425
}
2526

2627
void OttoEmojiDisplay::InitializeOttoEmojis() {
27-
ESP_LOGI(TAG, "初始化Otto GIF表情");
28-
29-
auto otto_emoji_collection = std::make_shared<EmojiCollection>();
30-
31-
// 中性/平静类表情 -> staticstate
32-
otto_emoji_collection->AddEmoji("staticstate", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
33-
otto_emoji_collection->AddEmoji("neutral", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
34-
otto_emoji_collection->AddEmoji("relaxed", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
35-
otto_emoji_collection->AddEmoji("sleepy", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
36-
otto_emoji_collection->AddEmoji("idle", new LvglRawImage((void*)staticstate.data, staticstate.data_size));
37-
38-
// 积极/开心类表情 -> happy
39-
otto_emoji_collection->AddEmoji("happy", new LvglRawImage((void*)happy.data, happy.data_size));
40-
otto_emoji_collection->AddEmoji("laughing", new LvglRawImage((void*)happy.data, happy.data_size));
41-
otto_emoji_collection->AddEmoji("funny", new LvglRawImage((void*)happy.data, happy.data_size));
42-
otto_emoji_collection->AddEmoji("loving", new LvglRawImage((void*)happy.data, happy.data_size));
43-
otto_emoji_collection->AddEmoji("confident", new LvglRawImage((void*)happy.data, happy.data_size));
44-
otto_emoji_collection->AddEmoji("winking", new LvglRawImage((void*)happy.data, happy.data_size));
45-
otto_emoji_collection->AddEmoji("cool", new LvglRawImage((void*)happy.data, happy.data_size));
46-
otto_emoji_collection->AddEmoji("delicious", new LvglRawImage((void*)happy.data, happy.data_size));
47-
otto_emoji_collection->AddEmoji("kissy", new LvglRawImage((void*)happy.data, happy.data_size));
48-
otto_emoji_collection->AddEmoji("silly", new LvglRawImage((void*)happy.data, happy.data_size));
49-
50-
// 悲伤类表情 -> sad
51-
otto_emoji_collection->AddEmoji("sad", new LvglRawImage((void*)sad.data, sad.data_size));
52-
otto_emoji_collection->AddEmoji("crying", new LvglRawImage((void*)sad.data, sad.data_size));
53-
54-
// 愤怒类表情 -> anger
55-
otto_emoji_collection->AddEmoji("anger", new LvglRawImage((void*)anger.data, anger.data_size));
56-
otto_emoji_collection->AddEmoji("angry", new LvglRawImage((void*)anger.data, anger.data_size));
57-
58-
// 惊讶类表情 -> scare
59-
otto_emoji_collection->AddEmoji("scare", new LvglRawImage((void*)scare.data, scare.data_size));
60-
otto_emoji_collection->AddEmoji("surprised", new LvglRawImage((void*)scare.data, scare.data_size));
61-
otto_emoji_collection->AddEmoji("shocked", new LvglRawImage((void*)scare.data, scare.data_size));
62-
63-
// 思考/困惑类表情 -> buxue
64-
otto_emoji_collection->AddEmoji("buxue", new LvglRawImage((void*)buxue.data, buxue.data_size));
65-
otto_emoji_collection->AddEmoji("thinking", new LvglRawImage((void*)buxue.data, buxue.data_size));
66-
otto_emoji_collection->AddEmoji("confused", new LvglRawImage((void*)buxue.data, buxue.data_size));
67-
otto_emoji_collection->AddEmoji("embarrassed", new LvglRawImage((void*)buxue.data, buxue.data_size));
68-
69-
// 将表情集合添加到主题中
70-
auto& theme_manager = LvglThemeManager::GetInstance();
71-
auto light_theme = theme_manager.GetTheme("light");
72-
auto dark_theme = theme_manager.GetTheme("dark");
73-
74-
if (light_theme != nullptr) {
75-
light_theme->set_emoji_collection(otto_emoji_collection);
76-
}
77-
if (dark_theme != nullptr) {
78-
dark_theme->set_emoji_collection(otto_emoji_collection);
79-
}
28+
ESP_LOGI(TAG, "Otto表情初始化将由Assets系统处理");
29+
// 表情初始化已移至assets系统,通过DEFAULT_EMOJI_COLLECTION=otto-gif配置
30+
// assets.cc会从assets分区加载GIF表情并设置到theme
8031

8132
// 设置默认表情为staticstate
8233
SetEmotion("staticstate");
83-
84-
ESP_LOGI(TAG, "Otto GIF表情初始化完成");
8534
}
8635

8736
LV_FONT_DECLARE(OTTO_ICON_FONT);
@@ -148,7 +97,7 @@ void OttoEmojiDisplay::SetPreviewImage(std::unique_ptr<LvglImage> image) {
14897
auto img_dsc = preview_image_cached_->image_dsc();
14998
// 设置图片源并显示预览图片
15099
lv_image_set_src(preview_image_, img_dsc);
151-
lv_image_set_rotation(preview_image_, -900);
100+
lv_image_set_rotation(preview_image_, 900);
152101
if (img_dsc->header.w > 0 && img_dsc->header.h > 0) {
153102
// zoom factor 1.0
154103
lv_image_set_scale(preview_image_, 256 * width_ / img_dsc->header.w);

main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dependencies:
5858
espressif/adc_mic: ^0.2.1
5959
espressif/esp_mmap_assets: '>=1.2'
6060
txp666/otto-emoji-gif-component:
61-
version: ^1.0.3
61+
version: ^1.0.5
6262
rules:
6363
- if: target in [esp32s3]
6464
espressif/adc_battery_estimation: ^0.2.0

scripts/build_default_assets.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ def process_emoji_collection(emoji_collection_dir, assets_dir):
222222

223223
emoji_list = []
224224

225+
# Check if this is otto-gif collection
226+
is_otto_gif = 'otto-emoji-gif-component' in emoji_collection_dir or emoji_collection_dir.endswith('otto-gif')
227+
228+
# Otto GIF emoji aliases mapping
229+
otto_gif_aliases = {
230+
"staticstate": ["neutral", "relaxed", "sleepy", "idle"],
231+
"happy": ["laughing", "funny", "loving", "confident", "winking", "cool", "delicious", "kissy", "silly"],
232+
"sad": ["crying"],
233+
"anger": ["angry"],
234+
"scare": ["surprised", "shocked"],
235+
"buxue": ["thinking", "confused", "embarrassed"]
236+
}
237+
225238
# Copy each image from input directory to build/assets directory
226239
for root, dirs, files in os.walk(emoji_collection_dir):
227240
for file in files:
@@ -233,11 +246,19 @@ def process_emoji_collection(emoji_collection_dir, assets_dir):
233246
# Get filename without extension
234247
filename_without_ext = os.path.splitext(file)[0]
235248

236-
# Add to emoji list
249+
# Add main emoji entry
237250
emoji_list.append({
238251
"name": filename_without_ext,
239252
"file": file
240253
})
254+
255+
# Add aliases for otto-gif emojis
256+
if is_otto_gif and filename_without_ext in otto_gif_aliases:
257+
for alias in otto_gif_aliases[filename_without_ext]:
258+
emoji_list.append({
259+
"name": alias,
260+
"file": file
261+
})
241262

242263
return emoji_list
243264

@@ -682,14 +703,33 @@ def get_text_font_path(builtin_text_font, xiaozhi_fonts_path):
682703
return None
683704

684705

685-
def get_emoji_collection_path(default_emoji_collection, xiaozhi_fonts_path):
706+
def get_emoji_collection_path(default_emoji_collection, xiaozhi_fonts_path, project_root=None):
686707
"""
687708
Get the emoji collection path if needed
688709
Returns the emoji directory path or None if no emoji collection is needed
710+
711+
Supports:
712+
- PNG emoji collections from xiaozhi-fonts (e.g., emojis_32)
713+
- Otto GIF emoji collection (otto-gif)
689714
"""
690715
if not default_emoji_collection:
691716
return None
692717

718+
# Special handling for otto-gif collection
719+
if default_emoji_collection == 'otto-gif':
720+
if project_root:
721+
otto_gif_path = os.path.join(project_root, 'managed_components',
722+
'txp666__otto-emoji-gif-component', 'gifs')
723+
if os.path.exists(otto_gif_path):
724+
return otto_gif_path
725+
else:
726+
print(f"Warning: Otto GIF emoji collection directory not found: {otto_gif_path}")
727+
return None
728+
else:
729+
print("Warning: project_root not provided, cannot locate otto-gif collection")
730+
return None
731+
732+
# Default behavior for PNG emoji collections
693733
emoji_path = os.path.join(xiaozhi_fonts_path, 'png', default_emoji_collection)
694734
if os.path.exists(emoji_path):
695735
return emoji_path
@@ -828,7 +868,10 @@ def main():
828868
text_font_path = get_text_font_path(args.builtin_text_font, args.xiaozhi_fonts_path)
829869

830870
# Get emoji collection path if needed
831-
emoji_collection_path = get_emoji_collection_path(args.emoji_collection, args.xiaozhi_fonts_path)
871+
# Calculate project root from script location for otto-gif support
872+
script_dir = os.path.dirname(os.path.abspath(__file__))
873+
project_root = os.path.dirname(script_dir)
874+
emoji_collection_path = get_emoji_collection_path(args.emoji_collection, args.xiaozhi_fonts_path, project_root)
832875

833876
# Get extra files path if provided
834877
extra_files_path = args.extra_files

0 commit comments

Comments
 (0)