Skip to content

Commit

Permalink
Add value support to Camera Shake
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltby committed Apr 9, 2024
1 parent ed03afb commit 9485de3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
30 changes: 30 additions & 0 deletions src/lib/compiler/scriptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3685,6 +3685,36 @@ extern void __mute_mask_${symbol};
this._addNL();
};

cameraShakeScriptValue = (
shouldShakeX: boolean,
shouldShakeY: boolean,
frames: number,
magnitude: ScriptValue
) => {
const [rpnOps, fetchOps] = precompileScriptValue(
optimiseScriptValue(magnitude)
);
const localsLookup = this._performFetchOperations(fetchOps);
const cameraShakeArgsRef = this._declareLocal("camera_shake_args", 3, true);
this._addComment("Camera Shake");
this._setConst(cameraShakeArgsRef, frames);
this._setConst(
this._localRef(cameraShakeArgsRef, 1),
unionFlags(
([] as string[]).concat(
shouldShakeX ? ".CAMERA_SHAKE_X" : [],
shouldShakeY ? ".CAMERA_SHAKE_Y" : []
)
)
);

const rpn = this._rpn();
this._performValueRPN(rpn, rpnOps, localsLookup);
rpn.refSet(this._localRef(cameraShakeArgsRef, 2)).stop();
this._invoke("camera_shake_frames", 0, cameraShakeArgsRef);
this._addNL();
};

// --------------------------------------------------------------------------
// Input

Expand Down
31 changes: 7 additions & 24 deletions src/lib/events/eventCameraShake.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,26 @@ const fields = [
defaultValue: "horizontal",
flexBasis: 30,
flexGrow: 0,
alignBottom: true,
},
],
},
{
key: "magnitude",
label: l10n("FIELD_MAGNITUDE"),
description: l10n("FIELD_MAGNITUDE_DESC"),
type: "union",
types: ["number", "variable", "property"],
defaultType: "number",
type: "value",
min: 1,
max: 255,
defaultValue: {
number: 5,
variable: "LAST_VARIABLE",
property: "$self$:xpos",
type: "number",
value: 5,
},
},
];

const compile = (input, helpers) => {
const {
cameraShake,
cameraShakeVariables,
variableFromUnion,
temporaryEntityVariable,
} = helpers;
const { cameraShakeScriptValue } = helpers;
let frames = 0;
if (input.units === "frames") {
frames = typeof input.frames === "number" ? input.frames : 30;
Expand Down Expand Up @@ -131,18 +124,8 @@ const compile = (input, helpers) => {
shouldShakeY = false;
}

if (input.magnitude.type === "number") {
if (frames > 0) {
cameraShake(shouldShakeX, shouldShakeY, frames, input.magnitude.value);
}
} else {
const magnitudeVar = variableFromUnion(
input.magnitude,
temporaryEntityVariable(0)
);
if (frames > 0) {
cameraShakeVariables(shouldShakeX, shouldShakeY, frames, magnitudeVar);
}
if (frames > 0) {
cameraShakeScriptValue(shouldShakeX, shouldShakeY, frames, input.magnitude);
}
};

Expand Down

0 comments on commit 9485de3

Please sign in to comment.