fix(animation-manager): fix only 1 valid anim showing fallback (#455)

This commit is contained in:
WillyJL
2023-11-17 23:57:16 +00:00
committed by GitHub

View File

@@ -387,31 +387,22 @@ static StorageAnimation*
furi_record_close(RECORD_DOLPHIN);
uint32_t whole_weight = 0;
// Filter valid animations
bool fallback = xtreme_settings.fallback_anim;
if(StorageAnimationList_size(animation_list) == dolphin_internal_size + 1 && !fallback) {
// One ext anim and fallback disabled, dont skip current anim (current = only ext one)
avoid_animation = NULL;
}
StorageAnimationList_it_t it;
bool unlock = xtreme_settings.unlock_anims;
StorageAnimationList_it_t it;
for(StorageAnimationList_it(it, animation_list); !StorageAnimationList_end_p(it);) {
StorageAnimation* storage_animation = *StorageAnimationList_ref(it);
const StorageAnimationManifestInfo* manifest_info =
animation_storage_get_meta(storage_animation);
bool valid = animation_manager_is_valid_idle_animation(manifest_info, &stats, unlock);
if(avoid_animation != NULL && strcmp(manifest_info->name, avoid_animation) == 0) {
// Avoid repeating same animation twice
valid = false;
}
if(strcmp(manifest_info->name, HARDCODED_ANIMATION_NAME) == 0 && !fallback) {
// Skip fallback animation
valid = false;
}
if(valid) {
whole_weight += manifest_info->weight;
StorageAnimationList_next(it);
} else {
animation_storage_free_storage_animation(&storage_animation);
@@ -420,6 +411,28 @@ static StorageAnimation*
}
}
if(StorageAnimationList_size(animation_list) == 1) {
// One valid anim, dont skip current anim (current = only ext one)
avoid_animation = NULL;
}
// Avoid repeating current animation and calculate weights
for(StorageAnimationList_it(it, animation_list); !StorageAnimationList_end_p(it);) {
StorageAnimation* storage_animation = *StorageAnimationList_ref(it);
const StorageAnimationManifestInfo* manifest_info =
animation_storage_get_meta(storage_animation);
if(avoid_animation && strcmp(manifest_info->name, avoid_animation) == 0) {
// Avoid repeating same animation twice
animation_storage_free_storage_animation(&storage_animation);
/* remove and increase iterator */
StorageAnimationList_remove(animation_list, it);
} else {
whole_weight += manifest_info->weight;
StorageAnimationList_next(it);
}
}
uint32_t lucky_number = furi_hal_random_get() % whole_weight;
uint32_t weight = 0;