diff --git a/src/lib/compiler/scriptBuilder.ts b/src/lib/compiler/scriptBuilder.ts index b1266a4ba..a271caf2d 100644 --- a/src/lib/compiler/scriptBuilder.ts +++ b/src/lib/compiler/scriptBuilder.ts @@ -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 diff --git a/src/lib/events/eventCameraShake.js b/src/lib/events/eventCameraShake.js index a5ed55730..0ad637570 100644 --- a/src/lib/events/eventCameraShake.js +++ b/src/lib/events/eventCameraShake.js @@ -75,6 +75,7 @@ const fields = [ defaultValue: "horizontal", flexBasis: 30, flexGrow: 0, + alignBottom: true, }, ], }, @@ -82,26 +83,18 @@ const fields = [ 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; @@ -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); } };