Skip to content

Commit 9388edf

Browse files
committed
add loop fromJson
1 parent 27cae03 commit 9388edf

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ describe('effect.fromJson', () => {
1717
{ actionType: 'cartoonify', colorReductionLevel: 80, lineStrength: 70 },
1818
{ actionType: 'outline', width: 100, color: 'lightblue' },
1919
{ actionType: 'blackwhite', level: 40 },
20-
{ actionType: 'accelerate'}
20+
{ actionType: 'accelerate' },
21+
{ actionType: 'loop', iterations: 5 }
2122

2223
]);
2324

@@ -36,7 +37,8 @@ describe('effect.fromJson', () => {
3637
'e_cartoonify:70:80',
3738
'co_lightblue,e_outline:100',
3839
'e_blackwhite:40',
39-
'e_accelerate'
40+
'e_accelerate',
41+
'e_loop:5'
4042
].join('/'));
4143
});
4244
});

src/actions/effect/leveled/Loop.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {LeveledEffectAction} from "../EffectActions/LeveledEffectAction.js";
2+
import {IActionModel} from "../../../internal/models/IActionModel.js";
23

34
/**
45
* @description Delivers a video or animated GIF that contains additional loops of the video/GIF.
@@ -13,6 +14,16 @@ class LoopEffectAction extends LeveledEffectAction {
1314
this.addQualifier(qualifierEffect);
1415
return this;
1516
}
17+
18+
static fromJson(actionModel: IActionModel): LoopEffectAction {
19+
const {actionType, iterations } = (actionModel);
20+
21+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
22+
// This allows the inheriting classes to determine the class to be created
23+
const result = new this(actionType, iterations as number);
24+
25+
return result;
26+
}
1627
}
1728

1829

src/internal/fromJson.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {CartoonifyEffect} from "../actions/effect/Cartoonify.js";
2828
import {EffectOutline} from "../actions/effect/Outline.js";
2929
import {BlackwhiteEffectAction} from "../actions/effect/leveled/Blackwhite.js";
3030
import {AccelerationEffectAction} from "../actions/effect/leveled/Accelerate.js";
31+
import {LoopEffectAction} from "../actions/effect/leveled/Loop.js";
3132

3233
const ActionModelMap: Record<string, IHasFromJson> = {
3334
scale: ResizeScaleAction,
@@ -59,7 +60,8 @@ const ActionModelMap: Record<string, IHasFromJson> = {
5960
cartoonify: CartoonifyEffect,
6061
outline: EffectOutline,
6162
blackwhite: BlackwhiteEffectAction,
62-
accelerate: AccelerationEffectAction
63+
accelerate: AccelerationEffectAction,
64+
loop: LoopEffectAction
6365
};
6466

6567
/**

0 commit comments

Comments
 (0)