}>();
/** 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)}
{
+ vi.unstubAllEnvs();
+ vi.resetModules();
+});
+
+const load = async (dev: boolean) => {
+ vi.stubEnv("DEV", dev);
+ vi.resetModules();
+ return import("../src/lib/modules/editor/model/ui.model");
+};
+
+test("a development build opens the Animation tab", async () => {
+ const ui = await load(true);
+
+ expect(ui.ANIMATION_TAB).toBe(true);
+ ui.rightPanelSet("anim");
+ expect(ui.$rightPanel.getState()).toBe("anim");
+});
+
+test("a production build refuses it, and the other tabs still open", async () => {
+ const ui = await load(false);
+
+ expect(ui.ANIMATION_TAB).toBe(false);
+ ui.rightPanelSet("anim");
+ expect(ui.$rightPanel.getState()).toBe("props");
+ ui.rightPanelSet("sim");
+ expect(ui.$rightPanel.getState()).toBe("sim");
+ ui.rightPanelSet("anim");
+ expect(ui.$rightPanel.getState()).toBe("sim");
+});
diff --git a/tests/doc-anim.test.ts b/tests/doc-anim.test.ts
index 39d95cb..320b95f 100644
--- a/tests/doc-anim.test.ts
+++ b/tests/doc-anim.test.ts
@@ -16,7 +16,7 @@ import {
encodeAnim,
procOf,
} from "../src/lib/modules/editor/core/document/proc";
-import { withAnim } from "../src/lib/modules/editor/core/document/edits";
+import { withAnim, withAnimPreset } from "../src/lib/modules/editor/core/document/edits";
import {
animEndMs,
animPlace,
@@ -302,7 +302,7 @@ test("no animation edit can change the widget type, whatever the values", async
}
});
-import { animPath } from "../src/lib/modules/editor/core/render/anim";
+import { animPath, keepCentre } from "../src/lib/modules/editor/core/render/anim";
test("every preset is a valid, orbiting, type 2 body whose path the firmware math can draw", async () => {
const { doc } = fromLegacy(parseBin(readFileSync(FILE)));
@@ -312,7 +312,9 @@ test("every preset is a valid, orbiting, type 2 body whose path the firmware mat
const a = { ...STOCK_ANIM, ...p.patch };
expect(animIssues(a)).toEqual([]);
- expect(a.flags).toBe(0x88);
+ expect([0x88, 0x89]).toContain(a.flags);
+ // the repeat group, and only it, sets the loop bit
+ expect(animLoops(a)).toBe(p.group === "repeat");
expect(animPath(a).length).toBe(49);
// the install gate lets a face with that preset through, on every animated layer
let next = doc;
@@ -343,3 +345,78 @@ test("the stock slide and the arcs land where the firmware's formulas put them",
expect(at("quarterUp")[0]).toEqual({ dx: -200, dy: 0 });
expect(at("quarterUp").at(-1)).toEqual({ dx: 0, dy: -200 });
});
+
+test("side glides move sideways, and the layer shift round-trips exactly", () => {
+ const to = (id: string) => ({ ...STOCK_ANIM, ...ANIM_PRESETS.find((p) => p.id === id)!.patch });
+ const left = animPath(to("glideLeft"));
+ const right = animPath(to("glideRight"));
+ const far = animPath(to("glideLeftFar"));
+ const span = (pts: { dx: number; dy: number }[], k: "dx" | "dy") =>
+ Math.max(...pts.map((p) => p[k])) - Math.min(...pts.map((p) => p[k]));
+
+ // the angle growing from 180 moves the image left, the reverse moves it right
+ expect(left[0].dx).toBeGreaterThan(left.at(-1)!.dx);
+ expect(right[0].dx).toBeLessThan(right.at(-1)!.dx);
+ expect(span(left, "dx")).toBeGreaterThan(130);
+ // flat enough to read as sideways, and the long one flatter still
+ expect(span(left, "dy")).toBeLessThan(span(left, "dx") / 3);
+ expect(span(far, "dy") / span(far, "dx")).toBeLessThan(span(left, "dy") / span(left, "dx"));
+
+ // moving the layer by the shift puts the motion's middle back where it was, there and back
+ for (const a of ANIM_PRESETS)
+ for (const b of ANIM_PRESETS) {
+ const ab = keepCentre(to(a.id), to(b.id));
+ const ba = keepCentre(to(b.id), to(a.id));
+
+ expect(ab.dx + ba.dx).toBe(0);
+ expect(ab.dy + ba.dy).toBe(0);
+ }
+ // the two proven presets are the same motion reversed: no shift, so Sun Circle's layers stay put
+ expect(keepCentre(to("rise"), to("set"))).toEqual({ dx: 0, dy: 0 });
+});
+
+test("the straight slides are nearly flat, and flatter than the glides", () => {
+ const to = (id: string) => ({ ...STOCK_ANIM, ...ANIM_PRESETS.find((p) => p.id === id)!.patch });
+ const span = (pts: { dx: number; dy: number }[], k: "dx" | "dy") =>
+ Math.max(...pts.map((p) => p[k])) - Math.min(...pts.map((p) => p[k]));
+ const left = animPath(to("straightLeft"));
+ const right = animPath(to("straightRight"));
+
+ // right to left, then the reverse
+ expect(left[0].dx).toBeGreaterThan(left.at(-1)!.dx);
+ expect(right[0].dx).toBeLessThan(right.at(-1)!.dx);
+ expect(span(left, "dx")).toBeGreaterThan(250);
+ // a drop of a few pixels over the whole slide: as straight as a circle of radius 8000 gets
+ expect(span(left, "dy")).toBeLessThanOrEqual(6);
+ expect(span(left, "dy") / span(left, "dx")).toBeLessThan(
+ span(animPath(to("glideLeftFar")), "dy") / span(animPath(to("glideLeftFar")), "dx"),
+ );
+});
+
+test("withAnimPreset moves the layer to keep the motion centred, and back again", () => {
+ const { doc } = fromLegacy(parseBin(readFileSync(FILE)));
+ const sun = anims(doc).find((l) => bodyOf(l) === SUN)!;
+ const place = (d: Doc) => {
+ const l = anims(d).find((x) => x.id === sun.id) as unknown as { x: number; y: number };
+
+ return { x: l.x, y: l.y };
+ };
+ const glide = ANIM_PRESETS.find((p) => p.id === "glideLeft")!.patch;
+ const rise = ANIM_PRESETS.find((p) => p.id === "rise")!.patch;
+ const there = withAnimPreset(doc, sun.id, glide);
+
+ // a sideways glide rides about R px off the layer, so the layer moves to compensate
+ expect(place(there)).not.toEqual(place(doc));
+ expect(Math.abs(place(there).y - place(doc).y)).toBeGreaterThan(200);
+ // back to the stock motion: same bytes as the stock sun, and the layer is where it started
+ const back = withAnimPreset(there, sun.id, rise);
+
+ expect(place(back)).toEqual(place(doc));
+ expect(bodyOf(anims(back).find((l) => l.id === sun.id)!)).toBe(SUN);
+ // Rise and Set never move Sun Circle's layers
+ expect(
+ place(withAnimPreset(doc, sun.id, ANIM_PRESETS.find((p) => p.id === "set")!.patch)),
+ ).toEqual(place(doc));
+ // an effect that changes nothing hands back the same document (so it keeps its undo step)
+ expect(withAnimPreset(doc, sun.id, rise)).toBe(doc);
+});