Skip to content

Commit 4a087d9

Browse files
committed
add pixelate fromJson
1 parent 394fbd5 commit 4a087d9

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ describe('effect.fromJson', () => {
2828
{ actionType: 'assistColorblind', type: 'stripes', stripesStrength: 20 },
2929
{ actionType: 'assistColorblind', type: 'xray' },
3030
{ actionType: 'simulateColorblind', condition: 'rod_monochromacy' },
31-
{ actionType: 'deshake', pixels: 16 }
31+
{ actionType: 'deshake', pixels: 16 },
32+
{ actionType: 'pixelate', squareSize: 15, region: { RegionType: 'faces' }}
3233
]);
3334

3435
expect(transformation.toString()).toStrictEqual([
@@ -57,7 +58,8 @@ describe('effect.fromJson', () => {
5758
'e_assist_colorblind:20',
5859
'e_assist_colorblind:xray',
5960
'e_simulate_colorblind:rod_monochromacy',
60-
'e_deshake:16'
61+
'e_deshake:16',
62+
'e_pixelate_faces:15'
6163
].join('/'));
6264
});
6365
});

src/actions/effect/pixelate/Pixelate.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {NamedRegion} from "../../../qualifiers/region/NamedRegion.js";
22
import {Qualifier} from "../../../internal/qualifier/Qualifier.js";
33
import {Action} from "../../../internal/Action.js";
44
import {IPixelateModel} from "../../../internal/models/IEffectActionModel.js";
5+
import {IActionModel} from "../../../internal/models/IActionModel.js";
6+
import {custom, faces} from "../../../qualifiers/region.js";
57

68
/**
79
* @description The Action class of the pixelate Builder
@@ -83,6 +85,25 @@ class Pixelate extends Action {
8385
this.addQualifier(new Qualifier('e', `pixelate${str}`));
8486
}
8587
}
88+
89+
static fromJson(actionModel: IActionModel): Pixelate {
90+
const {actionType, region, squareSize } = (actionModel as IPixelateModel);
91+
92+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
93+
// This allows the inheriting classes to determine the class to be created
94+
const result = new this(squareSize);
95+
squareSize && result.squareSize(squareSize);
96+
97+
if(region.RegionType === 'faces'){
98+
result.region(faces());
99+
}
100+
101+
if(region.RegionType === 'custom'){
102+
result.region(custom());
103+
}
104+
105+
return result;
106+
}
86107
}
87108

88109

src/internal/fromJson.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {GradientFadeEffectAction} from "../actions/effect/GradientFade.js";
3636
import {AssistColorBlindEffectAction} from "../actions/effect/AssistColorBlind.js";
3737
import {SimulateColorBlindEffectAction} from "../actions/effect/SimulateColorBlind.js";
3838
import {DeshakeEffectAction} from "../actions/effect/leveled/Deshake.js";
39+
import {Pixelate} from "../actions/effect/pixelate/Pixelate.js";
3940

4041
const ActionModelMap: Record<string, IHasFromJson> = {
4142
scale: ResizeScaleAction,
@@ -77,7 +78,8 @@ const ActionModelMap: Record<string, IHasFromJson> = {
7778
gradientFade: GradientFadeEffectAction,
7879
assistColorblind: AssistColorBlindEffectAction,
7980
simulateColorblind: SimulateColorBlindEffectAction,
80-
deshake: DeshakeEffectAction
81+
deshake: DeshakeEffectAction,
82+
pixelate: Pixelate
8183
};
8284

8385
/**

0 commit comments

Comments
 (0)