From f8d60394c9cb46102edbe6b1ba380b3c4e1f7e74 Mon Sep 17 00:00:00 2001 From: Chris Maltby Date: Mon, 15 Apr 2024 17:28:09 +0100 Subject: [PATCH] Fix sprite preview in actor dropdown when using advanced values --- .../script/ScriptEventFormInput.tsx | 26 ++++++++++--------- src/components/world/SpriteSheetCanvas.tsx | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/components/script/ScriptEventFormInput.tsx b/src/components/script/ScriptEventFormInput.tsx index bee92352f..dcc222959 100644 --- a/src/components/script/ScriptEventFormInput.tsx +++ b/src/components/script/ScriptEventFormInput.tsx @@ -56,7 +56,7 @@ import { defaultVariableForContext } from "shared/lib/scripts/context"; import ScriptEventFormMathArea from "./ScriptEventFormMatharea"; import ScriptEventFormTextArea from "./ScriptEventFormTextarea"; import { AngleInput } from "ui/form/AngleInput"; -import { isStringArray } from "shared/types"; +import { ensureMaybeNumber, isStringArray } from "shared/types"; import { clampToCType } from "shared/lib/engineFields/engineFieldToCType"; import { setDefault } from "shared/lib/helpers/setDefault"; import { TilesetSelect } from "components/forms/TilesetSelect"; @@ -88,10 +88,10 @@ const ConnectButton = styled.div` const argValue = (arg: unknown): unknown => { const unionArg = arg as { value: unknown; type: unknown }; if (unionArg && unionArg.value !== undefined) { - if (unionArg.type === "variable" || unionArg.type === "property") { - return undefined; + if (unionArg.type === "number" || unionArg.type === "direction") { + return unionArg.value; } - return unionArg.value; + return undefined; } return arg; }; @@ -617,7 +617,7 @@ const ScriptEventFormInput = ({ name={id} value={String(value ?? "")} direction={argValue(args.direction) as ActorDirection} - frame={argValue(args.frame) as number | undefined} + frame={ensureMaybeNumber(argValue(args.frame), undefined)} onChange={onChangeField} /> @@ -739,17 +739,21 @@ const ScriptEventFormInput = ({ const fieldType = engineField.type || "number"; const engineDefaultValue = { type: "number", - value: engineField.defaultValue - } + value: engineField.defaultValue, + }; const isValueScript = isScriptValue(value); const isDefaultScript = isScriptValue(engineDefaultValue); - + return (