move retrieval of sprite url from svelte to rust
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
lock_r,
|
||||
models::{app_data::UserData, dolls::DollColorSchemeDto},
|
||||
services::presence_modules::models::ModuleMetadata,
|
||||
models::app_data::UserData,
|
||||
services::{presence_modules::models::ModuleMetadata, sprite},
|
||||
state::{init_app_data_scoped, AppDataRefreshScope, FDOLL},
|
||||
};
|
||||
|
||||
@@ -29,24 +29,6 @@ pub fn get_modules() -> Result<Vec<ModuleMetadata>, String> {
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub fn get_active_doll_color_scheme() -> Result<Option<DollColorSchemeDto>, String> {
|
||||
let guard = lock_r!(FDOLL);
|
||||
let active_doll_id = guard
|
||||
.user_data
|
||||
.user
|
||||
.as_ref()
|
||||
.and_then(|u| u.active_doll_id.as_deref());
|
||||
|
||||
match active_doll_id {
|
||||
Some(active_doll_id) => {
|
||||
let color_scheme = guard
|
||||
.user_data
|
||||
.dolls
|
||||
.as_ref()
|
||||
.and_then(|dolls| dolls.iter().find(|d| d.id == active_doll_id))
|
||||
.map(|d| d.configuration.color_scheme.clone());
|
||||
Ok(color_scheme)
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
pub fn get_active_doll_sprite_base64() -> Result<Option<String>, String> {
|
||||
sprite::get_active_doll_sprite_base64()
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ pub mod config;
|
||||
pub mod dolls;
|
||||
pub mod friends;
|
||||
pub mod interaction;
|
||||
pub mod sprite;
|
||||
pub mod petpet;
|
||||
pub mod sprite;
|
||||
|
||||
use crate::lock_r;
|
||||
use crate::state::{init_app_data_scoped, AppDataRefreshScope, FDOLL};
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
},
|
||||
};
|
||||
use commands::app::{quit_app, restart_app, retry_connection};
|
||||
use commands::app_state::{get_app_data, get_active_doll_color_scheme, refresh_app_data};
|
||||
use commands::app_state::{get_active_doll_sprite_base64, get_app_data, refresh_app_data};
|
||||
use commands::auth::{change_password, login, logout_and_restart, register, reset_password};
|
||||
use commands::config::{get_client_config, open_client_config_manager, save_client_config};
|
||||
use commands::dolls::{
|
||||
@@ -17,18 +17,18 @@ use commands::friends::{
|
||||
search_users, send_friend_request, sent_friend_requests, unfriend,
|
||||
};
|
||||
use commands::interaction::send_interaction_cmd;
|
||||
use commands::sprite::recolor_gif_base64;
|
||||
use commands::petpet::encode_pet_doll_gif_base64;
|
||||
use commands::sprite::recolor_gif_base64;
|
||||
use specta_typescript::Typescript;
|
||||
use tauri::async_runtime;
|
||||
use tauri_specta::{Builder as SpectaBuilder, ErrorHandlingMode, collect_commands, collect_events};
|
||||
use tauri_specta::{collect_commands, collect_events, Builder as SpectaBuilder, ErrorHandlingMode};
|
||||
|
||||
use crate::services::app_events::{
|
||||
AppDataRefreshed, CreateDoll, CursorMoved, EditDoll, FriendActiveDollChanged,
|
||||
FriendCursorPositionsUpdated, FriendDisconnected,
|
||||
FriendRequestAccepted, FriendRequestDenied, FriendRequestReceived,
|
||||
FriendUserStatusChanged, InteractionDeliveryFailed, InteractionReceived,
|
||||
SceneInteractiveChanged, SetInteractionOverlay, Unfriended, UserStatusChanged,
|
||||
ActiveDollSpriteChanged, AppDataRefreshed, CreateDoll, CursorMoved, EditDoll,
|
||||
FriendActiveDollChanged, FriendCursorPositionsUpdated, FriendDisconnected,
|
||||
FriendRequestAccepted, FriendRequestDenied, FriendRequestReceived, FriendUserStatusChanged,
|
||||
InteractionDeliveryFailed, InteractionReceived, SceneInteractiveChanged, SetInteractionOverlay,
|
||||
Unfriended, UserStatusChanged,
|
||||
};
|
||||
|
||||
static APP_HANDLE: std::sync::OnceLock<tauri::AppHandle<tauri::Wry>> = std::sync::OnceLock::new();
|
||||
@@ -65,7 +65,7 @@ pub fn run() {
|
||||
.error_handling(ErrorHandlingMode::Throw)
|
||||
.commands(collect_commands![
|
||||
get_app_data,
|
||||
get_active_doll_color_scheme,
|
||||
get_active_doll_sprite_base64,
|
||||
refresh_app_data,
|
||||
list_friends,
|
||||
search_users,
|
||||
@@ -106,6 +106,7 @@ pub fn run() {
|
||||
CursorMoved,
|
||||
SceneInteractiveChanged,
|
||||
AppDataRefreshed,
|
||||
ActiveDollSpriteChanged,
|
||||
SetInteractionOverlay,
|
||||
EditDoll,
|
||||
CreateDoll,
|
||||
|
||||
@@ -30,6 +30,10 @@ pub struct SceneInteractiveChanged(pub bool);
|
||||
#[tauri_specta(event_name = "app-data-refreshed")]
|
||||
pub struct AppDataRefreshed(pub UserData);
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Type, Event)]
|
||||
#[tauri_specta(event_name = "active-doll-sprite-changed")]
|
||||
pub struct ActiveDollSpriteChanged(pub Option<String>);
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Type, Event)]
|
||||
#[tauri_specta(event_name = "set-interaction-overlay")]
|
||||
pub struct SetInteractionOverlay(pub bool);
|
||||
|
||||
@@ -15,6 +15,7 @@ pub mod interaction;
|
||||
pub mod petpet;
|
||||
pub mod presence_modules;
|
||||
pub mod scene;
|
||||
pub mod sprite;
|
||||
pub mod sprite_recolor;
|
||||
pub mod welcome;
|
||||
pub mod ws;
|
||||
|
||||
33
src-tauri/src/services/sprite.rs
Normal file
33
src-tauri/src/services/sprite.rs
Normal 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()
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
use crate::{
|
||||
get_app_handle, lock_r, lock_w,
|
||||
remotes::{dolls::DollsRemote, friends::FriendRemote, user::UserRemote},
|
||||
services::{app_events::AppDataRefreshed, friend_cursor},
|
||||
services::{
|
||||
app_events::{ActiveDollSpriteChanged, AppDataRefreshed},
|
||||
friend_cursor, sprite,
|
||||
},
|
||||
state::FDOLL,
|
||||
};
|
||||
use std::{collections::HashSet, sync::LazyLock};
|
||||
use tokio::sync::Mutex;
|
||||
use tauri_specta::Event as _;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::{info, warn};
|
||||
|
||||
pub fn update_display_dimensions_for_scene_state() {
|
||||
@@ -227,6 +230,26 @@ pub async fn init_app_data_scoped(scope: AppDataRefreshScope) {
|
||||
.kind(MessageDialogKind::Error)
|
||||
.show(|_| {});
|
||||
}
|
||||
|
||||
if matches!(
|
||||
scope,
|
||||
AppDataRefreshScope::All
|
||||
| AppDataRefreshScope::User
|
||||
| AppDataRefreshScope::Dolls
|
||||
) {
|
||||
match sprite::get_active_doll_sprite_base64() {
|
||||
Ok(sprite_b64) => {
|
||||
if let Err(e) =
|
||||
ActiveDollSpriteChanged(sprite_b64).emit(get_app_handle())
|
||||
{
|
||||
warn!("Failed to emit active-doll-sprite-changed event: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to generate active doll sprite: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user