diff --git a/src/lib/modules/editor/components/props/animation.svelte b/src/lib/modules/editor/components/props/animation.svelte index 76c8e60..26a3f66 100644 --- a/src/lib/modules/editor/components/props/animation.svelte +++ b/src/lib/modules/editor/components/props/animation.svelte @@ -28,7 +28,7 @@ import { t } from "../../i18n-inspector"; import { num } from "./patch"; - const { animPatched } = editorModel; + const { animPatched, animPresetApplied } = editorModel; const { layer }: { layer: Layer } = $props(); const anim = $derived(animOf(layer)); @@ -54,7 +54,7 @@ }; }); - const GROUPS = ["slide", "arc"] as const; + const GROUPS = ["slide", "arc", "side", "repeat"] as const; // a card's picture: the preset's own motion, fitted into 0..40 keeping its proportions const thumb = (patch: Partial) => { const pts = animPath({ ...STOCK_ANIM, ...patch }, 24); @@ -73,6 +73,11 @@ let shown = $state(0); const put = (patch: Partial) => animPatched({ id: layer.id, patch }); + // An effect is a new geometry, and some ride far from where the layer sits (a sideways glide is + // R px off it): the edit moves the layer so the motion stays centred where it was (see + // withAnimPreset). ponytail: the simulator adds the layer's position to the motion; that the + // firmware does the same is not verified on a watch. + const apply = (patch: Partial) => animPresetApplied({ id: layer.id, patch }); // the simple controls go through safeAnim; the advanced fields write what they are given const putSafe = (patch: Partial) => put(safeAnim(patch)); // tenths of a degree on file, degrees on screen @@ -106,7 +111,7 @@ class="card type-caption" class:on={preset === p.id} aria-pressed={preset === p.id} - onclick={() => putSafe(p.patch)} + onclick={() => apply(p.patch)} >

{presetInfo.proven ? $t.animProven : $t.animUntested}

+ {#if presetInfo.group === "side"} +

{$t.animSideNote}

+ {/if} {/if} {#if path.length > 1} diff --git a/src/lib/modules/editor/core/document/edits.ts b/src/lib/modules/editor/core/document/edits.ts index e0faee4..8a9b896 100644 --- a/src/lib/modules/editor/core/document/edits.ts +++ b/src/lib/modules/editor/core/document/edits.ts @@ -5,7 +5,17 @@ // here is keyed by NodeId, which is what makes the layer identity survive an immutable update: // the old code compared node objects, so any rebuilt parent silently invalidated `sel`. import { hex, TAG, unhex } from "../format"; -import { PANELS, procOf, RINGS, withAnimBody, animOf, type Anim, type Proc } from "./proc"; +import { + PANELS, + procOf, + RINGS, + safeAnim, + withAnimBody, + animOf, + type Anim, + type Proc, +} from "./proc"; +import { keepCentre } from "../render/anim"; import { framesOf, isPlaced, @@ -399,3 +409,24 @@ export function withAnim(doc: Doc, id: NodeId, patch: Partial): Doc { ? doc : patchLayer(doc, id, { extra } as Partial); } + +/** An effect for a type 2 layer: its fields (kept inside ANIM_LIMITS) and, in the same edit, the + * layer's position moved so the motion stays centred where it was. Going from one effect to + * another and back leaves the layer where it started, and Rise <-> Set never moves it. A position + * outside an int16 is left alone, not wrapped. */ +export function withAnimPreset(doc: Doc, id: NodeId, patch: Partial): Doc { + const l = findLayer(doc, id); + const a = l && animOf(l); + + if (!l || !a) return doc; + const safe = safeAnim(patch); + const next = withAnim(doc, id, safe); + const now = findLayer(next, id); + + if (next === doc || !now || !("x" in now) || !("y" in now)) return next; + const shift = keepCentre(a, { ...a, ...safe }); + const x = now.x + shift.dx; + const y = now.y + shift.dy; + + return Math.abs(x) <= 32767 && Math.abs(y) <= 32767 ? patchLayer(next, id, { x, y }) : next; +} diff --git a/src/lib/modules/editor/core/document/proc.ts b/src/lib/modules/editor/core/document/proc.ts index ef17f45..475af71 100644 --- a/src/lib/modules/editor/core/document/proc.ts +++ b/src/lib/modules/editor/core/document/proc.ts @@ -202,9 +202,11 @@ export const animRises = (a: Anim) => a.start <= a.end; * unproven until the watch tests are back. The arcs use a small radius: from 180 to 360 degrees * the image goes round half a circle of that radius, bulging left by R, (0, R) -> (-R, 0) -> * (0, -R) relative to where it is placed; Sun Circle's radius of 3817 makes the same path a - * nearly straight vertical slide. + * nearly straight vertical slide. Near 180 degrees the path runs mostly sideways (the angle + * growing moves the image left), but it rides R px below where the layer is placed, so the "side" + * group is applied together with a layer shift that keeps the motion where it was. * ponytail: grow this list from tests on a watch, not from the firmware reading alone. */ -const geo = (R: number, start: number, end: number, duration = 2000) => ({ +const geo = (R: number, start: number, end: number, duration = 2000, flags = 0x88) => ({ duration, start, end, @@ -214,7 +216,7 @@ const geo = (R: number, start: number, end: number, duration = 2000) => ({ raw10: 0, raw16: R, raw18: R, - flags: 0x88, + flags, }); export const ANIM_PRESETS = [ @@ -228,9 +230,27 @@ export const ANIM_PRESETS = [ { id: "quarterUp", group: "arc", proven: false, patch: geo(200, 2700, 3600) }, { id: "quarterDown", group: "arc", proven: false, patch: geo(200, 3600, 2700) }, { id: "dropLong", group: "slide", proven: false, patch: geo(3817, 2600, 2800, 3000) }, + { id: "quickRise", group: "slide", proven: false, patch: geo(3817, 2645, 2754, 800) }, + { id: "quickSet", group: "slide", proven: false, patch: geo(3817, 2754, 2645, 800) }, + { id: "nudgeUp", group: "slide", proven: false, patch: geo(3817, 2680, 2720, 800) }, + { id: "nudgeDown", group: "slide", proven: false, patch: geo(3817, 2720, 2680, 800) }, + { id: "arcBig", group: "arc", proven: false, patch: geo(233, 1801, 3600, 2500) }, + { id: "arcBigBack", group: "arc", proven: false, patch: geo(233, 3600, 1801, 2500) }, + { id: "quarterTop", group: "arc", proven: false, patch: geo(200, 1801, 2700) }, + { id: "quarterTopBack", group: "arc", proven: false, patch: geo(200, 2700, 1801) }, + { id: "glideLeft", group: "side", proven: false, patch: geo(300, 1801, 2100, 1500) }, + { id: "glideRight", group: "side", proven: false, patch: geo(300, 2100, 1801, 1500) }, + { id: "glideLeftFar", group: "side", proven: false, patch: geo(600, 1801, 2000, 1800) }, + { id: "glideRightFar", group: "side", proven: false, patch: geo(600, 2000, 1801, 1800) }, + { id: "straightLeft", group: "side", proven: false, patch: geo(8000, 1801, 1822, 1500) }, + { id: "straightRight", group: "side", proven: false, patch: geo(8000, 1822, 1801, 1500) }, + { id: "loopRise", group: "repeat", proven: false, patch: geo(3817, 2645, 2754, 2000, 0x89) }, + { id: "loopSet", group: "repeat", proven: false, patch: geo(3817, 2754, 2645, 2000, 0x89) }, + { id: "loopArc", group: "repeat", proven: false, patch: geo(150, 1801, 3600, 3000, 0x89) }, + { id: "pulse", group: "repeat", proven: false, patch: geo(3817, 2680, 2720, 600, 0x89) }, ] as const satisfies readonly { id: string; - group: "slide" | "arc"; + group: "slide" | "arc" | "side" | "repeat"; proven: boolean; patch: Partial; }[]; diff --git a/src/lib/modules/editor/core/render/anim.ts b/src/lib/modules/editor/core/render/anim.ts index 5e7c616..2123d88 100644 --- a/src/lib/modules/editor/core/render/anim.ts +++ b/src/lib/modules/editor/core/render/anim.ts @@ -139,3 +139,29 @@ export function animPath(a: Anim, steps = 48): AnimPlace[] { } return out; } + +/** The middle of a motion's bounding box, rounded to whole pixels; the origin when it has none. */ +function centreOf(a: Anim): AnimPlace { + // sampled low angle to high, so a motion and its reverse have the same middle + const lo = Math.min(wrap(a.start), wrap(a.end)); + const hi = Math.max(wrap(a.start), wrap(a.end)); + const pts = animPath({ ...a, start: lo, end: hi }, 24); + + if (!pts.length) return { dx: 0, dy: 0 }; + const xs = pts.map((p) => p.dx); + const ys = pts.map((p) => p.dy); + + return { + dx: Math.round((Math.min(...xs) + Math.max(...xs)) / 2), + dy: Math.round((Math.min(...ys) + Math.max(...ys)) / 2), + }; +} + +/** How far to move a layer so that swapping its motion `from` -> `to` keeps the motion centred + * where it was. Whole pixels, so going there and back lands exactly where it started. */ +export function keepCentre(from: Anim, to: Anim): AnimPlace { + const was = centreOf(from); + const now = centreOf(to); + + return { dx: was.dx - now.dx, dy: was.dy - now.dy }; +} diff --git a/src/lib/modules/editor/i18n-inspector.ts b/src/lib/modules/editor/i18n-inspector.ts index 4c88ea5..8c2a81d 100644 --- a/src/lib/modules/editor/i18n-inspector.ts +++ b/src/lib/modules/editor/i18n-inspector.ts @@ -96,9 +96,13 @@ const en = { animGroup: { slide: "Slide", arc: "Arc", + side: "Side", + repeat: "Repeat", }, animNoFade: "This widget only moves the image: fades and other effects are not available on the watch.", + animSideNote: + "Choosing an effect moves the layer so its motion stays where it was; a sideways glide starts far from the layer. Whether the watch adds the layer position the way the preview does is not verified.", animPreset: { rise: "Rise (stock sun)", set: "Set (stock moon)", @@ -110,6 +114,24 @@ const en = { quarterUp: "Quarter arc up", quarterDown: "Quarter arc down", dropLong: "Long drop", + quickRise: "Quick rise", + quickSet: "Quick set", + nudgeUp: "Nudge up", + nudgeDown: "Nudge down", + arcBig: "Big arc", + arcBigBack: "Big arc back", + quarterTop: "Top quarter", + quarterTopBack: "Top quarter back", + glideLeft: "Glide left", + glideRight: "Glide right", + glideLeftFar: "Long glide left", + glideRightFar: "Long glide right", + straightLeft: "Straight, right to left", + straightRight: "Straight, left to right", + loopRise: "Repeat rise", + loopSet: "Repeat set", + loopArc: "Repeat arc", + pulse: "Pulse", }, animUntested: "Not yet tried on a Watch Pro 2.", animProven: "Played on a Watch Pro 2.", @@ -375,9 +397,13 @@ export const t = dict(en, { animGroup: { slide: "Скольжение", arc: "Дуга", + side: "В сторону", + repeat: "Повтор", }, animNoFade: "Этот виджет только перемещает изображение: затухание и другие эффекты на часах недоступны.", + animSideNote: + "Выбор эффекта сдвигает слой, чтобы движение осталось на прежнем месте; боковое скольжение начинается далеко от слоя. Прибавляет ли часы позицию слоя так же, как предпросмотр, не проверено.", animPreset: { rise: "Восход (солнце из Sun Circle)", set: "Закат (луна из Sun Circle)", @@ -389,6 +415,24 @@ export const t = dict(en, { quarterUp: "Четверть дуги вверх", quarterDown: "Четверть дуги вниз", dropLong: "Длинный спуск", + quickRise: "Быстрый восход", + quickSet: "Быстрый закат", + nudgeUp: "Толчок вверх", + nudgeDown: "Толчок вниз", + arcBig: "Большая дуга", + arcBigBack: "Большая дуга назад", + quarterTop: "Верхняя четверть", + quarterTopBack: "Верхняя четверть назад", + glideLeft: "Скольжение влево", + glideRight: "Скольжение вправо", + glideLeftFar: "Длинное скольжение влево", + glideRightFar: "Длинное скольжение вправо", + straightLeft: "Прямо, справа налево", + straightRight: "Прямо, слева направо", + loopRise: "Восход по кругу", + loopSet: "Закат по кругу", + loopArc: "Дуга по кругу", + pulse: "Пульс", }, animUntested: "Ещё не проверено на Watch Pro 2.", animProven: "Проверено на Watch Pro 2.", @@ -649,9 +693,13 @@ export const t = dict(en, { animGroup: { slide: "Ковзання", arc: "Дуга", + side: "Убік", + repeat: "Повтор", }, animNoFade: "Цей віджет лише переміщує зображення: згасання й інші ефекти на годиннику недоступні.", + animSideNote: + "Вибір ефекту зсуває шар, щоб рух залишився на колишньому місці; бічне ковзання починається далеко від шару. Чи додає годинник позицію шару так само, як попередній перегляд, не перевірено.", animPreset: { rise: "Схід (сонце з Sun Circle)", set: "Захід (місяць з Sun Circle)", @@ -663,6 +711,24 @@ export const t = dict(en, { quarterUp: "Чверть дуги вгору", quarterDown: "Чверть дуги вниз", dropLong: "Довгий спуск", + quickRise: "Швидкий схід", + quickSet: "Швидкий захід", + nudgeUp: "Поштовх вгору", + nudgeDown: "Поштовх вниз", + arcBig: "Велика дуга", + arcBigBack: "Велика дуга назад", + quarterTop: "Верхня чверть", + quarterTopBack: "Верхня чверть назад", + glideLeft: "Ковзання вліво", + glideRight: "Ковзання вправо", + glideLeftFar: "Довге ковзання вліво", + glideRightFar: "Довге ковзання вправо", + straightLeft: "Прямо, справа наліво", + straightRight: "Прямо, зліва направо", + loopRise: "Схід по колу", + loopSet: "Захід по колу", + loopArc: "Дуга по колу", + pulse: "Пульс", }, animUntested: "Ще не перевірено на Watch Pro 2.", animProven: "Перевірено на Watch Pro 2.", @@ -923,9 +989,13 @@ export const t = dict(en, { animGroup: { slide: "Deslizamiento", arc: "Arco", + side: "Lateral", + repeat: "Repetir", }, animNoFade: "Este widget solo mueve la imagen: los fundidos y otros efectos no están disponibles en el reloj.", + animSideNote: + "Elegir un efecto mueve la capa para que su movimiento siga donde estaba; un deslizamiento lateral empieza lejos de la capa. No está verificado que el reloj sume la posición de la capa como la vista previa.", animPreset: { rise: "Salida (sol de Sun Circle)", set: "Puesta (luna de Sun Circle)", @@ -937,6 +1007,24 @@ export const t = dict(en, { quarterUp: "Cuarto de arco arriba", quarterDown: "Cuarto de arco abajo", dropLong: "Caída larga", + quickRise: "Salida rápida", + quickSet: "Puesta rápida", + nudgeUp: "Empujón arriba", + nudgeDown: "Empujón abajo", + arcBig: "Arco grande", + arcBigBack: "Arco grande inverso", + quarterTop: "Cuarto superior", + quarterTopBack: "Cuarto superior inverso", + glideLeft: "Deslizar a la izquierda", + glideRight: "Deslizar a la derecha", + glideLeftFar: "Deslizamiento largo a la izquierda", + glideRightFar: "Deslizamiento largo a la derecha", + straightLeft: "Recto, de derecha a izquierda", + straightRight: "Recto, de izquierda a derecha", + loopRise: "Salida repetida", + loopSet: "Puesta repetida", + loopArc: "Arco repetido", + pulse: "Pulso", }, animUntested: "Aún no probado en un Watch Pro 2.", animProven: "Probado en un Watch Pro 2.", @@ -1195,8 +1283,12 @@ export const t = dict(en, { animGroup: { slide: "स्लाइड", arc: "चाप", + side: "बग़ल", + repeat: "दोहराव", }, animNoFade: "यह विजेट केवल छवि को हिलाता है: फ़ेड और अन्य प्रभाव घड़ी पर उपलब्ध नहीं हैं।", + animSideNote: + "प्रभाव चुनने पर परत खिसकती है ताकि गति वहीं रहे जहाँ थी; बग़ल का सरकना परत से दूर शुरू होता है। घड़ी परत की स्थिति को पूर्वावलोकन की तरह जोड़ती है या नहीं, यह जाँचा नहीं गया।", animPreset: { rise: "उदय (Sun Circle का सूरज)", set: "अस्त (Sun Circle का चाँद)", @@ -1208,6 +1300,24 @@ export const t = dict(en, { quarterUp: "चौथाई चाप ऊपर", quarterDown: "चौथाई चाप नीचे", dropLong: "लंबी गिरावट", + quickRise: "तेज़ उदय", + quickSet: "तेज़ अस्त", + nudgeUp: "हल्का ऊपर", + nudgeDown: "हल्का नीचे", + arcBig: "बड़ा चाप", + arcBigBack: "बड़ा चाप उलटा", + quarterTop: "ऊपरी चौथाई", + quarterTopBack: "ऊपरी चौथाई उलटा", + glideLeft: "बाएँ सरकना", + glideRight: "दाएँ सरकना", + glideLeftFar: "लंबा बाएँ सरकना", + glideRightFar: "लंबा दाएँ सरकना", + straightLeft: "सीधा, दाएँ से बाएँ", + straightRight: "सीधा, बाएँ से दाएँ", + loopRise: "दोहराता उदय", + loopSet: "दोहराता अस्त", + loopArc: "दोहराता चाप", + pulse: "स्पंदन", }, animUntested: "Watch Pro 2 पर अभी आज़माया नहीं गया।", animProven: "Watch Pro 2 पर चलकर देखा गया।", diff --git a/src/lib/modules/editor/model/edit.model.ts b/src/lib/modules/editor/model/edit.model.ts index f0de155..1bdc0b3 100644 --- a/src/lib/modules/editor/model/edit.model.ts +++ b/src/lib/modules/editor/model/edit.model.ts @@ -25,6 +25,7 @@ import { siblingsOf, ungroup, withAnim, + withAnimPreset, withPanel, wrapInGroup, } from "../core/document/edits"; @@ -113,6 +114,8 @@ export const panelSet = createEvent<{ id: NodeId; panel: number }>(); export const sourceIdSet = createEvent<{ id: NodeId; source: number }>(); /** The Watch Pro 2 animated image's fields. Through `committed`, so a no-op keeps the undo step. */ export const animPatched = createEvent<{ id: NodeId; patch: Partial }>(); +/** An effect from the gallery: the fields and the layer shift that keeps its motion centred. */ +export const animPresetApplied = createEvent<{ id: NodeId; patch: Partial }>(); /** A layer that was just created and should become the selection. Shared with create.model. */ export const selectAdded = createEvent<{ added: NodeId }>(); @@ -296,6 +299,14 @@ sample({ target: committed, }); +sample({ + clock: animPresetApplied, + fn: ({ id, patch }) => ({ + edit: (doc: Doc) => (findLayer(doc, id)?.locked ? doc : withAnimPreset(doc, id, patch)), + }), + target: committed, +}); + sample({ clock: layerFlagsSet, filter: ({ ids }) => ids.length > 0, diff --git a/src/lib/modules/editor/model/ui.model.ts b/src/lib/modules/editor/model/ui.model.ts index c9906e2..55289c2 100644 --- a/src/lib/modules/editor/model/ui.model.ts +++ b/src/lib/modules/editor/model/ui.model.ts @@ -3,6 +3,12 @@ import { createEvent, createStore, sample } from "effector"; // ---- stores ---- +/** The Animation tab is for development builds only, for now: the effects move the layer, and an + * object that is moved afterwards does not play as the preview shows it. Production builds + * leave the tab out, and `rightPanelSet` refuses it there too. + * ponytail: turn it on again (drop this flag) once a watch agrees with the preview. */ +export const ANIMATION_TAB: boolean = import.meta.env.DEV; + /** Right-side panel tab. Driven by the `select` event rather than derived from the selection: * the selection store also changes when a simulator tweak re-selects the same layer, and * deriving would flip the tab back to Properties on every input. */ @@ -20,6 +26,7 @@ export const lockAspectToggled = createEvent(); // ---- business logic ---- sample({ clock: rightPanelSet, + filter: (tab) => tab !== "anim" || ANIMATION_TAB, target: $rightPanel, }); sample({ diff --git a/src/lib/modules/editor/pages/editor.svelte b/src/lib/modules/editor/pages/editor.svelte index 45d1714..51d6235 100644 --- a/src/lib/modules/editor/pages/editor.svelte +++ b/src/lib/modules/editor/pages/editor.svelte @@ -129,6 +129,7 @@ watchFrameToggled, $rightPanel: rightPanel, rightPanelSet, + ANIMATION_TAB, $loading: loading, } = editorModel; @@ -541,7 +542,7 @@ ]); const panelItems = $derived([ { value: "props", label: $t.properties }, - { value: "anim", label: $t.animTab, disabled: !$doc }, + ...(ANIMATION_TAB ? [{ value: "anim", label: $t.animTab, disabled: !$doc }] : []), { value: "sim", label: $t.simulator, disabled: !$doc }, ]); const mobileTitle = $derived( @@ -880,7 +881,7 @@ {#if $doc}
- {#each [["tree", "account_tree", $t.tree], ["props", "tune", $t.propsShort], ["anim", "wb_twilight", $t.animTab], ["sim", "play_arrow", $t.simShort]] as [id, icon, label] (id)} + {#each [["tree", "account_tree", $t.tree], ["props", "tune", $t.propsShort], ...(ANIMATION_TAB ? [["anim", "wb_twilight", $t.animTab]] : []), ["sim", "play_arrow", $t.simShort]] as [id, icon, label] (id)}