Skip to content

Commit 394fbd5

Browse files
committed
add deshake fromJson
1 parent 060932f commit 394fbd5

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

__TESTS__/unit/fromJson/effect.fromJson.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ describe('effect.fromJson', () => {
2727
{ actionType: 'gradientFade', strength: 5, horizontalStartPoint: 10, verticalStartPoint: 20 },
2828
{ actionType: 'assistColorblind', type: 'stripes', stripesStrength: 20 },
2929
{ actionType: 'assistColorblind', type: 'xray' },
30-
{ actionType: 'simulateColorblind', condition: 'rod_monochromacy' }
30+
{ actionType: 'simulateColorblind', condition: 'rod_monochromacy' },
31+
{ actionType: 'deshake', pixels: 16 }
3132
]);
3233

3334
expect(transformation.toString()).toStrictEqual([
@@ -55,7 +56,8 @@ describe('effect.fromJson', () => {
5556
'e_gradient_fade:5,x_10,y_20',
5657
'e_assist_colorblind:20',
5758
'e_assist_colorblind:xray',
58-
'e_simulate_colorblind:rod_monochromacy'
59+
'e_simulate_colorblind:rod_monochromacy',
60+
'e_deshake:16'
5961
].join('/'));
6062
});
6163
});

src/actions/effect/leveled/Deshake.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {LeveledEffectAction} from "../EffectActions/LeveledEffectAction.js";
22
import {ExpressionQualifier} from "../../../qualifiers/expression/ExpressionQualifier.js";
33
import {IDeshakeEffectModel} from "../../../internal/models/IEffectActionModel.js";
4+
import {IActionModel} from "../../../internal/models/IActionModel.js";
45

6+
type pixels = 16 | 32 | 48 | 64;
57
/**
68
* @description Removes small motion shifts from the video. with a maximum extent of movement in the horizontal and vertical direction of 32 pixels
79
* @extends LeveledEffectAction
@@ -14,12 +16,22 @@ class DeshakeEffectAction extends LeveledEffectAction {
1416
* The maximum number of pixels in the horizontal and vertical direction that will be addressed. (Possible values: 16, 32, 48, 64. Server default: 16)
1517
* @param value Possible values: 16, 32, 48, 64. Server default: 16.
1618
*/
17-
shakeStrength(value: 16 | 32 | 48 | 64 | string | ExpressionQualifier): this {
18-
this._actionModel.pixels = value as number;
19+
shakeStrength(value: pixels | string | ExpressionQualifier): this {
20+
this._actionModel.pixels = value as pixels;
1921
const qualifierEffect = this.createEffectQualifier(this.effectType, value);
2022
this.addQualifier(qualifierEffect);
2123
return this;
2224
}
25+
26+
static fromJson(actionModel: IActionModel): DeshakeEffectAction {
27+
const {actionType, pixels} = (actionModel as IDeshakeEffectModel);
28+
29+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
30+
// This allows the inheriting classes to determine the class to be created
31+
const result = new this(actionType, pixels);
32+
33+
return result;
34+
}
2335
}
2436

2537

src/internal/fromJson.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {VectorizeEffectAction} from "../actions/effect/Vectorize.js";
3535
import {GradientFadeEffectAction} from "../actions/effect/GradientFade.js";
3636
import {AssistColorBlindEffectAction} from "../actions/effect/AssistColorBlind.js";
3737
import {SimulateColorBlindEffectAction} from "../actions/effect/SimulateColorBlind.js";
38+
import {DeshakeEffectAction} from "../actions/effect/leveled/Deshake.js";
3839

3940
const ActionModelMap: Record<string, IHasFromJson> = {
4041
scale: ResizeScaleAction,
@@ -75,7 +76,8 @@ const ActionModelMap: Record<string, IHasFromJson> = {
7576
vectorize: VectorizeEffectAction,
7677
gradientFade: GradientFadeEffectAction,
7778
assistColorblind: AssistColorBlindEffectAction,
78-
simulateColorblind: SimulateColorBlindEffectAction
79+
simulateColorblind: SimulateColorBlindEffectAction,
80+
deshake: DeshakeEffectAction
7981
};
8082

8183
/**

src/internal/models/IEffectActionModel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {IActionModel} from "./IActionModel.js";
2+
import {ExpressionQualifier} from "../../qualifiers/expression/ExpressionQualifier.js";
23

34
interface IEffectActionWithLevelModel extends IActionModel{
45
level?: number;
@@ -65,7 +66,7 @@ interface ISimulateColorBlindEffectModel extends IActionModel{
6566
}
6667

6768
interface IDeshakeEffectModel extends IActionModel{
68-
pixels?: number;
69+
pixels?: 16 | 32 | 48 | 64;
6970
}
7071

7172
interface IPixelateModel extends IActionModel{

0 commit comments

Comments
 (0)