diff --git a/frontend/src/player/screens.ts b/frontend/src/player/screens.ts index ad99aec..0fd7d52 100644 --- a/frontend/src/player/screens.ts +++ b/frontend/src/player/screens.ts @@ -2046,7 +2046,12 @@ export class ScreenManager { Image: shape("image"), AlphaMask: shape("alphamask"), }; - out.If = (condition: any, yes: any = null, no: any = null) => (truthy(condition) ? yes : no); + out.If = (...a: any[]) => { + const kw = kwOf(a), args = a.filter((value) => !value?.__kw); + const condition = args.length ? args[0] : kw.expression; + return truthy(condition) ? (args.length > 1 ? args[1] : kw.true ?? null) + : (args.length > 2 ? args[2] : kw.false ?? null); + }; out.GetTooltip = () => this.tooltip; out.StaticValue = (value: number, range = 1) => new BarValue(() => value, () => range); out.AnimatedValue = out.StaticValue; diff --git a/frontend/tests/mist-runtime.test.mjs b/frontend/tests/mist-runtime.test.mjs index 78fdc3c..69b2e17 100644 --- a/frontend/tests/mist-runtime.test.mjs +++ b/frontend/tests/mist-runtime.test.mjs @@ -19,12 +19,14 @@ test("MIST's actual movie Skip survives a queued redraw and returns before its t engine.newStore(); Object.assign(engine.store, { movielength: 63, movieplaying: "images/animations/movies/Intro_Movie.webm" }); const completed = engine.exec({ op: "call_screen", name: "custommoviescreen", args: [], kw: {} }); + await until(() => root.querySelector(".pg-sadd")?.dataset.seen); const button = [...root.querySelectorAll(".pg-sbtn")].find((element) => element.textContent === "Skip"); assert.ok(button); assert.equal(button.classList.contains("pg-sdisabled"), false); engine.screens.refresh(); window.dispatchEvent(new window.Event("pointerdown")); - await until(() => engine.store.movielength < 63); + const remaining = engine.store.movielength; + await until(() => engine.store.movielength < remaining); assert.equal(button.isConnected, true); window.dispatchEvent(new window.Event("pointerup")); click(button); diff --git a/frontend/tests/screens.test.mjs b/frontend/tests/screens.test.mjs index 02b4f09..8f6b7c8 100644 --- a/frontend/tests/screens.test.mjs +++ b/frontend/tests/screens.test.mjs @@ -55,6 +55,22 @@ const buttons = (root) => [...root.querySelectorAll(".pg-sbtn")]; const click = (el) => el.onclick({ stopPropagation() {}, preventDefault() {} }); const settle = () => wait(15); +test("If accepts named true/false actions used by MIST's movie timer", () => { + const { manager, store } = setup(); + try { + const { If, SetVariable } = manager.builtins(); + const yes = SetVariable("branch", "yes"), no = SetVariable("branch", "no"); + manager.run(If(true, { __kw: { true: yes, false: no } }), null); + assert.equal(store.branch, "yes"); + manager.run(If(false, { __kw: { true: yes, false: no } }), null); + assert.equal(store.branch, "no"); + assert.equal(If(true, yes, no), yes); + assert.equal(If(false, yes, no), no); + assert.equal(If(true, null, { __kw: { false: no } }), null); + assert.equal(If({ __kw: { expression: false, true: yes, false: no } }), no); + } finally { manager.destroy(); } +}); + test("a screen renders its widgets, conditions, loops and interpolated text", () => { const { manager } = setup(); manager.show("hud", [2]);