Skip to content

Commit

Permalink
Fix sprite preview in actor dropdown when using advanced values
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltby committed Apr 15, 2024
1 parent 3bfeaff commit f8d6039
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/components/script/ScriptEventFormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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}
/>
</OffscreenSkeletonInput>
Expand Down Expand Up @@ -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 (
<ValueSelect
name={id}
entityId={entityId}
value={
isValueScript ? value : isDefaultScript ? engineDefaultValue : undefined
isValueScript
? value
: isDefaultScript
? engineDefaultValue
: undefined
}
onChange={onChangeField}
min={clampToCType(
Expand All @@ -761,9 +765,7 @@ const ScriptEventFormInput = ({
engineField.cType
)}
step={field.step}
placeholder={String(
engineField.defaultValue ?? 0
)}
placeholder={String(engineField.defaultValue ?? 0)}
inputOverride={{
type: fieldType,
topLevelOnly: true,
Expand Down
3 changes: 3 additions & 0 deletions src/components/world/SpriteSheetCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const SpriteSheetCanvas = ({
if (flipX) {
animationIndex = 0;
}
if (animationIndex < 0) {
animationIndex = 3;
}

const animationId = animations[animationIndex] || "";

Expand Down

0 comments on commit f8d6039

Please sign in to comment.