move retrieval of sprite url from svelte to rust

This commit is contained in:
2026-03-09 19:34:57 +08:00
parent 02f1119254
commit ceaa1257bf
11 changed files with 116 additions and 50 deletions

View File

@@ -0,0 +1,33 @@
use crate::{lock_r, models::dolls::DollDto, state::FDOLL};
const APPLY_TEXTURE: bool = true;
pub fn get_active_doll() -> Option<DollDto> {
let guard = lock_r!(FDOLL);
let active_doll_id = guard
.user_data
.user
.as_ref()
.and_then(|user| user.active_doll_id.as_deref())?;
guard
.user_data
.dolls
.as_ref()
.and_then(|dolls| dolls.iter().find(|doll| doll.id == active_doll_id))
.cloned()
}
pub fn get_active_doll_sprite_base64() -> Result<Option<String>, String> {
get_active_doll()
.map(|doll| {
let color_scheme = doll.configuration.color_scheme;
super::sprite_recolor::recolor_gif_base64(
&color_scheme.body,
&color_scheme.outline,
APPLY_TEXTURE,
)
.map_err(|err| err.to_string())
})
.transpose()
}