puppet scale

This commit is contained in:
2026-08-29 17:13:40 +08:00
parent 9615fe870f
commit 55ed1f9d32
11 changed files with 307 additions and 31 deletions
+12 -2
View File
@@ -65,6 +65,12 @@ async sendInteraction(recipientId: string, content: InteractionContent) : Promis
async listPuppetStates() : Promise<PuppetState[]> {
return await TAURI_INVOKE("list_puppet_states");
},
async getSceneConfiguration() : Promise<SceneConfiguration> {
return await TAURI_INVOKE("get_scene_configuration");
},
async updateSceneConfiguration(configuration: SceneConfiguration) : Promise<SceneConfiguration> {
return await TAURI_INVOKE("update_scene_configuration", { configuration });
},
async openActionWindow(name: string, title: string, pageUrl: string) : Promise<null> {
return await TAURI_INVOKE("open_action_window", { name, title, pageUrl });
},
@@ -86,7 +92,8 @@ friendsChanged: FriendsChanged,
networkStatusChanged: NetworkStatusChanged,
profileChanged: ProfileChanged,
puppetStatesChanged: PuppetStatesChanged,
remotesChanged: RemotesChanged
remotesChanged: RemotesChanged,
sceneConfigurationChanged: SceneConfigurationChanged
}>({
cursorPositionChanged: "cursor-position-changed",
foregroundAppChanged: "foreground-app-changed",
@@ -97,7 +104,8 @@ friendsChanged: "friends-changed",
networkStatusChanged: "network-status-changed",
profileChanged: "profile-changed",
puppetStatesChanged: "puppet-states-changed",
remotesChanged: "remotes-changed"
remotesChanged: "remotes-changed",
sceneConfigurationChanged: "scene-configuration-changed"
})
/** user-defined constants **/
@@ -141,6 +149,8 @@ export type PuppetStatesChanged = { puppets: PuppetState[] }
export type Remote = { id: string; address: string; name: string | null; port: number | null }
export type RemoteInput = { address: string; name: string | null; port: number | null }
export type RemotesChanged = { remotes: Remote[] }
export type SceneConfiguration = { puppetScale: number }
export type SceneConfigurationChanged = { configuration: SceneConfiguration }
export type SceneHitbox = { x: number; y: number; width: number; height: number }
/**
* Public user identity exchanged with peers and remote servers. `id` is the
@@ -0,0 +1,86 @@
<script lang="ts">
import { commands } from "$lib/bindings";
import {
sceneConfiguration,
sceneConfigurationListenerError,
} from "$lib/listeners/scene-configuration";
import { onMount } from "svelte";
import PanelMessage from "./panel-message.svelte";
import type { RegisterPanel } from "./types";
let { register }: { register: RegisterPanel } = $props();
let puppetScale = $state(1);
let dirty = $state(false);
let busy = $state(false);
let error = $state("");
$effect(() => {
if (!dirty) puppetScale = $sceneConfiguration.puppetScale;
register("scene", { apply, reset }, { dirty, busy });
});
onMount(() => register("scene", { apply, reset }, { dirty, busy }));
function updateDirty() {
dirty = puppetScale !== $sceneConfiguration.puppetScale;
error = "";
}
function reset() {
puppetScale = $sceneConfiguration.puppetScale;
dirty = false;
error = "";
}
async function apply() {
if (!dirty) return true;
busy = true;
error = "";
try {
const configuration = await commands.updateSceneConfiguration({
puppetScale,
});
puppetScale = configuration.puppetScale;
dirty = false;
return true;
} catch (cause) {
error = String(cause);
return false;
} finally {
busy = false;
}
}
</script>
<div class="space-y-3">
{#if error || $sceneConfigurationListenerError}
<PanelMessage kind="error">
{error || $sceneConfigurationListenerError}
</PanelMessage>
{/if}
<fieldset class="fieldset border border-base-300 bg-base-100 p-3">
<legend class="fieldset-legend px-1">Puppets</legend>
<div class="flex items-center justify-between gap-3">
<label class="fieldset-label" for="puppet-scale">Scale</label>
<output class="badge badge-outline tabular-nums" for="puppet-scale">
{puppetScale.toFixed(2)}×
</output>
</div>
<input
id="puppet-scale"
class="range range-sm"
type="range"
min="0.5"
max="2"
step="0.05"
bind:value={puppetScale}
oninput={updateDirty}
disabled={busy}
aria-describedby="puppet-scale-help"
/>
</fieldset>
</div>
+2
View File
@@ -6,6 +6,7 @@ import { initLiveMetadataListeners } from "./live-metadata";
import { initProfileListener } from "./profile";
import { initPuppetStatesListener } from "./puppets";
import { initRemotesListener } from "./remotes";
import { initSceneConfigurationListener } from "./scene-configuration";
type Unlisten = () => void;
@@ -22,6 +23,7 @@ export function initAppListeners(): Unlisten {
initLiveMetadataListeners(),
initInteractionListener(),
initPuppetStatesListener(),
initSceneConfigurationListener(),
])
.then((results) => {
const listeners = results.flatMap((result) =>
+25
View File
@@ -0,0 +1,25 @@
import { writable } from "svelte/store";
import {
commands,
events,
type SceneConfiguration,
} from "$lib/bindings";
export const sceneConfiguration = writable<SceneConfiguration>({
puppetScale: 1,
});
export const sceneConfigurationListenerError = writable("");
export async function initSceneConfigurationListener() {
const unlisten = await events.sceneConfigurationChanged.listen((event) => {
sceneConfiguration.set(event.payload.configuration);
});
try {
sceneConfiguration.set(await commands.getSceneConfiguration());
} catch (error) {
sceneConfigurationListenerError.set(String(error));
}
return unlisten;
}