Skip to content

Commit

Permalink
Add value support to Actor Set Direction and Actor Set Frame
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltby committed Apr 9, 2024
1 parent 3d3f10f commit 9e5d21f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 52 deletions.
11 changes: 11 additions & 0 deletions src/components/ui/form/InputGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import styled from "styled-components";
import { Button } from "ui/buttons/Button";
import { Input } from "./Input";
import { Select } from "ui/form/Select";
import { ToggleButtonGroupWrapper } from "ui/form/ToggleButtonGroup";

export const InputGroup = styled.div`
display: flex;
Expand All @@ -11,6 +12,11 @@ export const InputGroup = styled.div`
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
& > ${ToggleButtonGroupWrapper}:not(:first-child),
& > ${ToggleButtonGroupWrapper}:not(:first-child) > :first-child > label {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
& > div:not(:first-child) ${Select} .CustomSelect__control {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
Expand All @@ -24,6 +30,11 @@ export const InputGroup = styled.div`
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
& > ${ToggleButtonGroupWrapper}:not(:last-child),
& > ${ToggleButtonGroupWrapper}:not(:last-child) > :last-child > label {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
& > div:not(:last-child) ${Select} .CustomSelect__control {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/form/ToggleButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type ToggleButtonGroupProps<T> = {
}
);

const Wrapper = styled.div`
export const ToggleButtonGroupWrapper = styled.div`
display: flex;
position: relative;
background: ${(props) => props.theme.colors.input.background};
Expand Down Expand Up @@ -129,7 +129,7 @@ export const ToggleButtonGroup = <T,>({
[props]
);
return (
<Wrapper>
<ToggleButtonGroupWrapper>
{options.map((option) => (
<Option key={String(option.value)}>
<Input
Expand All @@ -148,6 +148,6 @@ export const ToggleButtonGroup = <T,>({
</Label>
</Option>
))}
</Wrapper>
</ToggleButtonGroupWrapper>
);
};
66 changes: 66 additions & 0 deletions src/lib/compiler/scriptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2822,6 +2822,53 @@ extern void __mute_mask_${symbol};
this._addNL();
};

actorSetDirectionToScriptValue = (actorId: string, value: ScriptValue) => {
const actorRef = this._declareLocal("actor", 4);
const leftLabel = this.getNextLabel();
const rightLabel = this.getNextLabel();
const upLabel = this.getNextLabel();
const endLabel = this.getNextLabel();

this._addComment("Actor Set Direction To");
const [rpnOps, fetchOps] = precompileScriptValue(
optimiseScriptValue(value)
);
if (rpnOps.length === 1 && rpnOps[0].type === "number") {
this.actorSetById(actorId);
this._actorSetDirection(actorRef, String(rpnOps[0].value || 0));
} else if (rpnOps.length === 1 && rpnOps[0].type === "direction") {
this.actorSetById(actorId);
this._actorSetDirection(actorRef, toASMDir(rpnOps[0].value));
} else {
const localsLookup = this._performFetchOperations(fetchOps);
this._addComment(`-- Calculate value`);
const rpn = this._rpn();
this._performValueRPN(rpn, rpnOps, localsLookup);
rpn.refSet(this._localRef(actorRef, 1)).stop();
this.actorSetById(actorId);
const newValueRef = this._localRef(actorRef, 1);
this._ifConst(".EQ", newValueRef, ".DIR_LEFT", leftLabel, 0);
this._ifConst(".EQ", newValueRef, ".DIR_RIGHT", rightLabel, 0);
this._ifConst(".EQ", newValueRef, ".DIR_UP", upLabel, 0);
// Down
this._actorSetDirection(actorRef, ".DIR_DOWN");
this._jump(endLabel);
// Left
this._label(leftLabel);
this._actorSetDirection(actorRef, ".DIR_LEFT");
this._jump(endLabel);
// Right
this._label(rightLabel);
this._actorSetDirection(actorRef, ".DIR_RIGHT");
this._jump(endLabel);
// Up
this._label(upLabel);
this._actorSetDirection(actorRef, ".DIR_UP");
this._label(endLabel);
}
this._addNL();
};

actorEmote = (emoteId: string) => {
const actorRef = this._declareLocal("actor", 4);
const { emotes } = this.options;
Expand Down Expand Up @@ -2907,6 +2954,25 @@ extern void __mute_mask_${symbol};
this._addNL();
};

actorSetFrameToScriptValue = (actorId: string, value: ScriptValue) => {
const actorRef = this._declareLocal("actor", 4);
this._addComment("Actor Set Animation Frame To");
const [rpnOps, fetchOps] = precompileScriptValue(
optimiseScriptValue(value)
);

const localsLookup = this._performFetchOperations(fetchOps);
this._addComment(`-- Calculate value`);
const rpn = this._rpn();
this._performValueRPN(rpn, rpnOps, localsLookup);
rpn.refSet(this._localRef(actorRef, 1));
rpn.stop();

this.actorSetById(actorId);
this._actorSetAnimFrame(actorRef);
this._addNL();
};

actorSetAnimate = (_enabled: boolean) => {
console.error("actorSetAnimate not implemented");
};
Expand Down
33 changes: 5 additions & 28 deletions src/lib/events/eventActorSetDirection.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,17 @@ const fields = [
key: "direction",
label: l10n("FIELD_DIRECTION"),
description: l10n("FIELD_DIRECTION_DESC"),
type: "union",
types: ["direction", "variable", "property"],
defaultType: "direction",
type: "value",
defaultValue: {
direction: "up",
variable: "LAST_VARIABLE",
property: "$self$:direction",
type: "direction",
value: "up",
},
},
];

const compile = (input, helpers) => {
const {
actorSetActive,
actorSetDirection,
actorSetDirectionToVariable,
variableFromUnion,
temporaryEntityVariable,
} = helpers;

if (input.direction.type === "direction") {
actorSetActive(input.actorId);
actorSetDirection(input.direction.value);
} else if (typeof input.direction === "string") {
actorSetActive(input.actorId);
actorSetDirection(input.direction);
} else {
const dirVar = variableFromUnion(
input.direction,
temporaryEntityVariable(0)
);
actorSetActive(input.actorId);
actorSetDirectionToVariable(dirVar);
}
const { actorSetDirectionToScriptValue } = helpers;
actorSetDirectionToScriptValue(input.actorId, input.direction);
};

module.exports = {
Expand Down
26 changes: 5 additions & 21 deletions src/lib/events/eventActorSetFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,19 @@ const fields = [
key: "frame",
label: l10n("FIELD_ANIMATION_FRAME"),
description: l10n("FIELD_ANIMATION_FRAME_DESC"),
type: "union",
types: ["number", "variable", "property"],
defaultType: "number",
type: "value",
min: 0,
max: 25,
defaultValue: {
number: 0,
variable: "LAST_VARIABLE",
property: "$self$:frame",
type: "number",
value: 0,
},
},
];

const compile = (input, helpers) => {
const {
actorSetActive,
actorSetFrame,
actorSetFrameToVariable,
variableFromUnion,
temporaryEntityVariable,
} = helpers;
if (input.frame.type === "number") {
actorSetActive(input.actorId);
actorSetFrame(input.frame.value);
} else {
const frameVar = variableFromUnion(input.frame, temporaryEntityVariable(0));
actorSetActive(input.actorId);
actorSetFrameToVariable(frameVar);
}
const { actorSetFrameToScriptValue } = helpers;
actorSetFrameToScriptValue(input.actorId, input.frame);
};

module.exports = {
Expand Down

0 comments on commit 9e5d21f

Please sign in to comment.