Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/lib/modules/editor/components/props/animation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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<Anim>) => {
const pts = animPath({ ...STOCK_ANIM, ...patch }, 24);
Expand All @@ -73,6 +73,11 @@
let shown = $state(0);

const put = (patch: Partial<Anim>) => 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<Anim>) => animPresetApplied({ id: layer.id, patch });
// the simple controls go through safeAnim; the advanced fields write what they are given
const putSafe = (patch: Partial<Anim>) => put(safeAnim(patch));
// tenths of a degree on file, degrees on screen
Expand Down Expand Up @@ -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)}
>
<svg viewBox="-2 -2 44 44" aria-hidden="true">
<polyline
Expand All @@ -126,6 +131,9 @@
<p class="type-caption hint-xs">{$t.animNoFade}</p>
{#if presetInfo}
<p class="type-caption hint-xs">{presetInfo.proven ? $t.animProven : $t.animUntested}</p>
{#if presetInfo.group === "side"}
<p class="type-caption hint-xs">{$t.animSideNote}</p>
{/if}
{/if}

{#if path.length > 1}
Expand Down
33 changes: 32 additions & 1 deletion src/lib/modules/editor/core/document/edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -399,3 +409,24 @@ export function withAnim(doc: Doc, id: NodeId, patch: Partial<Anim>): Doc {
? doc
: patchLayer(doc, id, { extra } as Partial<Layer>);
}

/** 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<Anim>): 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;
}
28 changes: 24 additions & 4 deletions src/lib/modules/editor/core/document/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = [
Expand All @@ -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<Anim>;
}[];
Expand Down
26 changes: 26 additions & 0 deletions src/lib/modules/editor/core/render/anim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
110 changes: 110 additions & 0 deletions src/lib/modules/editor/i18n-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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.",
Expand Down Expand Up @@ -375,9 +397,13 @@ export const t = dict(en, {
animGroup: {
slide: "Скольжение",
arc: "Дуга",
side: "В сторону",
repeat: "Повтор",
},
animNoFade:
"Этот виджет только перемещает изображение: затухание и другие эффекты на часах недоступны.",
animSideNote:
"Выбор эффекта сдвигает слой, чтобы движение осталось на прежнем месте; боковое скольжение начинается далеко от слоя. Прибавляет ли часы позицию слоя так же, как предпросмотр, не проверено.",
animPreset: {
rise: "Восход (солнце из Sun Circle)",
set: "Закат (луна из Sun Circle)",
Expand All @@ -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.",
Expand Down Expand Up @@ -649,9 +693,13 @@ export const t = dict(en, {
animGroup: {
slide: "Ковзання",
arc: "Дуга",
side: "Убік",
repeat: "Повтор",
},
animNoFade:
"Цей віджет лише переміщує зображення: згасання й інші ефекти на годиннику недоступні.",
animSideNote:
"Вибір ефекту зсуває шар, щоб рух залишився на колишньому місці; бічне ковзання починається далеко від шару. Чи додає годинник позицію шару так само, як попередній перегляд, не перевірено.",
animPreset: {
rise: "Схід (сонце з Sun Circle)",
set: "Захід (місяць з Sun Circle)",
Expand All @@ -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.",
Expand Down Expand Up @@ -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)",
Expand All @@ -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.",
Expand Down Expand Up @@ -1195,8 +1283,12 @@ export const t = dict(en, {
animGroup: {
slide: "स्लाइड",
arc: "चाप",
side: "बग़ल",
repeat: "दोहराव",
},
animNoFade: "यह विजेट केवल छवि को हिलाता है: फ़ेड और अन्य प्रभाव घड़ी पर उपलब्ध नहीं हैं।",
animSideNote:
"प्रभाव चुनने पर परत खिसकती है ताकि गति वहीं रहे जहाँ थी; बग़ल का सरकना परत से दूर शुरू होता है। घड़ी परत की स्थिति को पूर्वावलोकन की तरह जोड़ती है या नहीं, यह जाँचा नहीं गया।",
animPreset: {
rise: "उदय (Sun Circle का सूरज)",
set: "अस्त (Sun Circle का चाँद)",
Expand All @@ -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 पर चलकर देखा गया।",
Expand Down
Loading
Loading