-
Notifications
You must be signed in to change notification settings - Fork 812
/
drop-shadow-pixi-filter.ts
130 lines (130 loc) · 4.37 KB
/
drop-shadow-pixi-filter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
namespace gdjs {
interface DropShadowFilterNetworkSyncData {
b: number;
q: number;
a: number;
d: number;
r: number;
p: number;
c: number;
so: boolean;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'DropShadow',
new (class extends gdjs.PixiFiltersTools.PixiFilterCreator {
makePIXIFilter(target: EffectsTarget, effectData) {
const dropShadowFilter = new PIXI.filters.DropShadowFilter();
return dropShadowFilter;
}
updatePreRender(filter: PIXI.Filter, target: EffectsTarget) {}
updateDoubleParameter(
filter: PIXI.Filter,
parameterName: string,
value: number
) {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
if (parameterName === 'blur') {
dropShadowFilter.blur = value;
} else if (parameterName === 'quality') {
dropShadowFilter.quality = value;
} else if (parameterName === 'alpha') {
dropShadowFilter.alpha = value;
} else if (parameterName === 'distance') {
dropShadowFilter.distance = value;
} else if (parameterName === 'rotation') {
dropShadowFilter.rotation = value;
} else if (parameterName === 'padding') {
dropShadowFilter.padding = value;
}
}
getDoubleParameter(filter: PIXI.Filter, parameterName: string): number {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
if (parameterName === 'blur') {
return dropShadowFilter.blur;
}
if (parameterName === 'quality') {
return dropShadowFilter.quality;
}
if (parameterName === 'alpha') {
return dropShadowFilter.alpha;
}
if (parameterName === 'distance') {
return dropShadowFilter.distance;
}
if (parameterName === 'rotation') {
return dropShadowFilter.rotation;
}
if (parameterName === 'padding') {
return dropShadowFilter.padding;
}
return 0;
}
updateStringParameter(
filter: PIXI.Filter,
parameterName: string,
value: string
) {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
if (parameterName === 'color') {
dropShadowFilter.color = gdjs.PixiFiltersTools.rgbOrHexToHexNumber(
value
);
}
}
updateColorParameter(
filter: PIXI.Filter,
parameterName: string,
value: number
): void {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
if (parameterName === 'color') {
dropShadowFilter.color = value;
}
}
getColorParameter(filter: PIXI.Filter, parameterName: string): number {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
if (parameterName === 'color') {
return dropShadowFilter.color;
}
return 0;
}
updateBooleanParameter(
filter: PIXI.Filter,
parameterName: string,
value: boolean
) {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
if (parameterName === 'shadowOnly') {
dropShadowFilter.shadowOnly = value;
}
}
getNetworkSyncData(filter: PIXI.Filter): DropShadowFilterNetworkSyncData {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
return {
b: dropShadowFilter.blur,
q: dropShadowFilter.quality,
a: dropShadowFilter.alpha,
d: dropShadowFilter.distance,
r: dropShadowFilter.rotation,
p: dropShadowFilter.padding,
c: dropShadowFilter.color,
so: dropShadowFilter.shadowOnly,
};
}
updateFromNetworkSyncData(
filter: PIXI.Filter,
data: DropShadowFilterNetworkSyncData
) {
const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter;
dropShadowFilter.blur = data.b;
dropShadowFilter.quality = data.q;
dropShadowFilter.alpha = data.a;
dropShadowFilter.distance = data.d;
dropShadowFilter.rotation = data.r;
dropShadowFilter.padding = data.p;
dropShadowFilter.color = data.c;
dropShadowFilter.shadowOnly = data.so;
}
})()
);
}