From adb4f7fe360fa664a7333b8e1f7b305b82064631 Mon Sep 17 00:00:00 2001 From: Wind-Explorer Date: Sat, 5 Sep 2026 02:54:45 +0800 Subject: [PATCH] option to hide own puppet when no friends are online --- messages/en.json | 1 + messages/zh-CN.json | 1 + ...00000_add_hide_local_puppet_when_alone.sql | 2 + src-tauri/src/scene_configuration/mod.rs | 11 ++- src/lib/bindings.ts | 2 +- .../control-panel/scene-panel.svelte | 88 +++++++++++-------- src/lib/listeners/scene-configuration.ts | 1 + src/routes/onboarding/+page.svelte | 1 + src/routes/scene/+page.svelte | 25 +++++- 9 files changed, 91 insertions(+), 41 deletions(-) create mode 100644 src-tauri/migrations/20260905000000_add_hide_local_puppet_when_alone.sql diff --git a/messages/en.json b/messages/en.json index 6098668..4b621d1 100644 --- a/messages/en.json +++ b/messages/en.json @@ -158,6 +158,7 @@ "scene_all_puppets": "All puppets", "scene_scale": "Scale", "scene_opacity": "Opacity", + "scene_hide_local_puppet_when_alone": "Hide my puppet when no friends are online", "scene_choose_skin": "Choose a skin", "scene_loading_preview": "Loading puppet preview", "action_add_friend_title": "Add Friend", diff --git a/messages/zh-CN.json b/messages/zh-CN.json index 109b504..58b1937 100644 --- a/messages/zh-CN.json +++ b/messages/zh-CN.json @@ -158,6 +158,7 @@ "scene_all_puppets": "所有玩偶", "scene_scale": "缩放", "scene_opacity": "不透明度", + "scene_hide_local_puppet_when_alone": "没有好友在线时隐藏我的玩偶", "scene_choose_skin": "选择皮肤", "scene_loading_preview": "正在加载玩偶预览", "action_add_friend_title": "添加好友", diff --git a/src-tauri/migrations/20260905000000_add_hide_local_puppet_when_alone.sql b/src-tauri/migrations/20260905000000_add_hide_local_puppet_when_alone.sql new file mode 100644 index 0000000..dbc830f --- /dev/null +++ b/src-tauri/migrations/20260905000000_add_hide_local_puppet_when_alone.sql @@ -0,0 +1,2 @@ +ALTER TABLE scene_configuration +ADD COLUMN hide_local_puppet_when_alone BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/src-tauri/src/scene_configuration/mod.rs b/src-tauri/src/scene_configuration/mod.rs index 203bcb5..4d0b824 100644 --- a/src-tauri/src/scene_configuration/mod.rs +++ b/src-tauri/src/scene_configuration/mod.rs @@ -26,6 +26,7 @@ pub struct SceneConfiguration { pub puppet_scale: f64, pub puppet_opacity: f64, pub puppet_movement_mode: PuppetMovementMode, + pub hide_local_puppet_when_alone: bool, } pub struct SceneConfigurationState(RwLock); @@ -56,7 +57,7 @@ pub struct SceneConfigurationChanged { async fn get(database: &AppDatabase) -> Result { sqlx::query_as::<_, SceneConfiguration>( - "SELECT puppet_scale, puppet_opacity, puppet_movement_mode FROM scene_configuration WHERE id = ?1", + "SELECT puppet_scale, puppet_opacity, puppet_movement_mode, hide_local_puppet_when_alone FROM scene_configuration WHERE id = ?1", ) .bind(SCENE_CONFIGURATION_ID) .fetch_one(database.pool()) @@ -83,11 +84,12 @@ async fn update( } sqlx::query( - "UPDATE scene_configuration SET puppet_scale = ?1, puppet_opacity = ?2, puppet_movement_mode = ?3 WHERE id = ?4", + "UPDATE scene_configuration SET puppet_scale = ?1, puppet_opacity = ?2, puppet_movement_mode = ?3, hide_local_puppet_when_alone = ?4 WHERE id = ?5", ) .bind(configuration.puppet_scale) .bind(configuration.puppet_opacity) .bind(configuration.puppet_movement_mode) + .bind(configuration.hide_local_puppet_when_alone) .bind(SCENE_CONFIGURATION_ID) .execute(database.pool()) .await @@ -164,6 +166,7 @@ mod tests { puppet_scale: 1.0, puppet_opacity: 1.0, puppet_movement_mode: PuppetMovementMode::Free, + hide_local_puppet_when_alone: false, } ); } @@ -178,6 +181,7 @@ mod tests { puppet_scale: 1.5, puppet_opacity: 0.4, puppet_movement_mode: PuppetMovementMode::Bottom, + hide_local_puppet_when_alone: true, }, ) .await @@ -188,6 +192,7 @@ mod tests { configuration.puppet_movement_mode, PuppetMovementMode::Bottom ); + assert!(configuration.hide_local_puppet_when_alone); assert_eq!(get(&database).await.unwrap(), configuration); let error = update( @@ -196,6 +201,7 @@ mod tests { puppet_scale: 2.1, puppet_opacity: 0.4, puppet_movement_mode: PuppetMovementMode::Bottom, + hide_local_puppet_when_alone: true, }, ) .await @@ -209,6 +215,7 @@ mod tests { puppet_scale: 1.5, puppet_opacity: 0.05, puppet_movement_mode: PuppetMovementMode::Bottom, + hide_local_puppet_when_alone: true, }, ) .await diff --git a/src/lib/bindings.ts b/src/lib/bindings.ts index d58c05f..ca8780b 100644 --- a/src/lib/bindings.ts +++ b/src/lib/bindings.ts @@ -187,7 +187,7 @@ export type PuppetStatesChanged = { puppets: PuppetState[] } export type Remote = { id: string; address: string; name: string | null; port: number | null; priority: number } export type RemoteInput = { address: string; name: string | null; port: number | null } export type RemotesChanged = { remotes: Remote[] } -export type SceneConfiguration = { puppetScale: number; puppetOpacity: number; puppetMovementMode: PuppetMovementMode } +export type SceneConfiguration = { puppetScale: number; puppetOpacity: number; puppetMovementMode: PuppetMovementMode; hideLocalPuppetWhenAlone: boolean } export type SceneConfigurationChanged = { configuration: SceneConfiguration } export type SceneHitbox = { x: number; y: number; width: number; height: number } /** diff --git a/src/lib/components/control-panel/scene-panel.svelte b/src/lib/components/control-panel/scene-panel.svelte index 5c72b1d..05d034a 100644 --- a/src/lib/components/control-panel/scene-panel.svelte +++ b/src/lib/components/control-panel/scene-panel.svelte @@ -1,5 +1,5 @@