diff --git a/lib/xtreme/assets.c b/lib/xtreme/assets.c index 6f4e80908..4f01eb358 100644 --- a/lib/xtreme/assets.c +++ b/lib/xtreme/assets.c @@ -9,7 +9,7 @@ #define ICONS_FMT XTREME_ASSETS_PATH "/%s/Icons/%s" -void ani(const Icon* replace, const char* name, FuriString* path, File* file) { +void swap_icon_animated(const Icon* replace, const char* name, FuriString* path, File* file) { const char* pack = XTREME_SETTINGS()->asset_pack; furi_string_printf(path, ICONS_FMT "/meta", pack, name); if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) { @@ -57,7 +57,7 @@ void ani(const Icon* replace, const char* name, FuriString* path, File* file) { storage_file_close(file); } -void ico(const Icon* replace, const char* name, FuriString* path, File* file) { +void swap_icon_static(const Icon* replace, const char* name, FuriString* path, File* file) { furi_string_printf(path, ICONS_FMT ".bmx", XTREME_SETTINGS()->asset_pack, name); if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) { uint64_t size = storage_file_size(file) - 8; @@ -94,32 +94,13 @@ void XTREME_ASSETS_LOAD() { info.flags & FSF_DIRECTORY) { File* f = storage_file_alloc(storage); - ani(&A_Levelup_128x64, "Animations/Levelup_128x64", p, f); - ico(&I_BLE_Pairing_128x64, "BLE/BLE_Pairing_128x64", p, f); - ico(&I_DolphinCommon_56x48, "Dolphin/DolphinCommon_56x48", p, f); - ico(&I_DolphinMafia_115x62, "iButton/DolphinMafia_115x62", p, f); - ico(&I_DolphinNice_96x59, "iButton/DolphinNice_96x59", p, f); - ico(&I_DolphinWait_61x59, "iButton/DolphinWait_61x59", p, f); - ico(&I_iButtonDolphinVerySuccess_108x52, "iButton/iButtonDolphinVerySuccess_108x52", p, f); - ico(&I_DolphinReadingSuccess_59x63, "Infrared/DolphinReadingSuccess_59x63", p, f); - ico(&I_Lockscreen, "Interface/Lockscreen", p, f); - ico(&I_WarningDolphin_45x42, "Interface/WarningDolphin_45x42", p, f); - ico(&I_NFC_dolphin_emulation_47x61, "NFC/NFC_dolphin_emulation_47x61", p, f); - ico(&I_passport_bad_46x49, "Passport/passport_bad_46x49", p, f); - ico(&I_passport_DB, "Passport/passport_DB", p, f); - ico(&I_passport_happy_46x49, "Passport/passport_happy_46x49", p, f); - ico(&I_passport_okay_46x49, "Passport/passport_okay_46x49", p, f); - ico(&I_RFIDDolphinReceive_97x61, "RFID/RFIDDolphinReceive_97x61", p, f); - ico(&I_RFIDDolphinSend_97x61, "RFID/RFIDDolphinSend_97x61", p, f); - ico(&I_RFIDDolphinSuccess_108x57, "RFID/RFIDDolphinSuccess_108x57", p, f); - ico(&I_Cry_dolph_55x52, "Settings/Cry_dolph_55x52", p, f); - ico(&I_Background_128x11, "StatusBar/Background_128x11", p, f); - ico(&I_Fishing_123x52, "SubGhz/Fishing_123x52", p, f); - ico(&I_Scanning_123x52, "SubGhz/Scanning_123x52", p, f); - ico(&I_Auth_62x31, "U2F/Auth_62x31", p, f); - ico(&I_Connect_me_62x31, "U2F/Connect_me_62x31", p, f); - ico(&I_Connected_62x31, "U2F/Connected_62x31", p, f); - ico(&I_Error_62x31, "U2F/Error_62x31", p, f); + for(size_t i = 0; i < ICON_PATHS_COUNT; i++) { + if(ICON_PATHS[i].animated) { + swap_icon_animated(ICON_PATHS[i].icon, ICON_PATHS[i].path, p, f); + } else { + swap_icon_static(ICON_PATHS[i].icon, ICON_PATHS[i].path, p, f); + } + } storage_file_free(f); } diff --git a/scripts/assets.py b/scripts/assets.py index 106cd56f5..f23ba5c3c 100755 --- a/scripts/assets.py +++ b/scripts/assets.py @@ -11,6 +11,7 @@ ICONS_SUPPORTED_FORMATS = ["png"] ICONS_TEMPLATE_H_HEADER = """#pragma once +#include #include """ @@ -120,6 +121,7 @@ class Main(App): ICONS_TEMPLATE_C_HEADER.format(assets_filename=self.args.filename) ) icons = [] + icon_paths = [] # Traverse icons tree, append image data to source file for dirpath, dirnames, filenames in os.walk(self.args.input_directory): self.logger.debug(f"Processing directory {dirpath}") @@ -164,6 +166,7 @@ class Main(App): ) icons_c.write("\n") icons.append((icon_name, width, height, frame_rate, frame_count)) + icon_paths.append((1, icon_name, dirpath.removeprefix(self.args.input_directory).replace("\\", "/")[1:])) else: # process icons for filename in filenames: @@ -186,6 +189,7 @@ class Main(App): ) icons_c.write("\n") icons.append((icon_name, width, height, 0, 1)) + icon_paths.append((0, icon_name, fullfilename[:fullfilename.rfind(".")].removeprefix(self.args.input_directory).replace("\\", "/")[1:])) # Create array of images: self.logger.debug("Finalizing source file") for name, width, height, frame_rate, frame_count in icons: @@ -198,7 +202,17 @@ class Main(App): frame_count=frame_count, ) ) - icons_c.write("\n") + if self.args.filename == "assets_icons": + icons_c.write(""" +const IconPath ICON_PATHS[] = { +#ifndef FURI_RAM_EXEC +""") + for animated, name, path in icon_paths: + icons_c.write(f' {{{animated}, &{name}, "{path}"}},\n') + icons_c.write("""#endif +}; +const size_t ICON_PATHS_COUNT = COUNT_OF(ICON_PATHS); +""") icons_c.close() # Create Public Header @@ -211,6 +225,17 @@ class Main(App): icons_h.write(ICONS_TEMPLATE_H_HEADER) for name, width, height, frame_rate, frame_count in icons: icons_h.write(ICONS_TEMPLATE_H_ICON_NAME.format(name=name)) + if self.args.filename == "assets_icons": + icons_h.write(""" +typedef struct { + bool animated; + const Icon* icon; + const char* path; +} IconPath; + +extern const IconPath ICON_PATHS[]; +extern const size_t ICON_PATHS_COUNT; +""") icons_h.close() self.logger.debug("Done") return 0