forked from 4ian/GDevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflection-pixi-filter.ts
126 lines (126 loc) · 4.2 KB
/
reflection-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
namespace gdjs {
interface ReflectionFilterExtra {
_animationTimer: number;
animationSpeed: number;
animationFrequency: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Reflection',
new (class extends gdjs.PixiFiltersTools.PixiFilterCreator {
makePIXIFilter(layer, effectData) {
let time = 0;
const reflectionFilter = new PIXI.filters.ReflectionFilter({
mirror: effectData.booleanParameters.mirror,
boundary: effectData.doubleParameters.boundary,
amplitude: [
effectData.doubleParameters.amplitudeStart,
effectData.doubleParameters.amplitudeEnding,
],
waveLength: [
effectData.doubleParameters.waveLengthStart,
effectData.doubleParameters.waveLengthEnding,
],
alpha: [
effectData.doubleParameters.alphaStart,
effectData.doubleParameters.alphaEnding,
],
time,
});
return reflectionFilter;
}
updatePreRender(filter: PIXI.Filter, target: EffectsTarget) {
const reflectionFilter = (filter as unknown) as PIXI.filters.ReflectionFilter &
ReflectionFilterExtra;
if (reflectionFilter.animationSpeed !== 0) {
reflectionFilter.time +=
(target.getElapsedTime() / 1000) * reflectionFilter.animationSpeed;
}
}
updateDoubleParameter(
filter: PIXI.Filter,
parameterName: string,
value: number
) {
const reflectionFilter = (filter as unknown) as PIXI.filters.ReflectionFilter &
ReflectionFilterExtra;
if (parameterName === 'boundary') {
reflectionFilter.boundary = value;
}
if (parameterName === 'amplitudeStart') {
reflectionFilter.amplitude[0] = value;
}
if (parameterName === 'amplitudeEnding') {
reflectionFilter.amplitude[1] = value;
}
if (parameterName === 'waveLengthStart') {
reflectionFilter.waveLength[0] = value;
}
if (parameterName === 'waveLengthEnding') {
reflectionFilter.waveLength[1] = value;
}
if (parameterName === 'alphaStart') {
reflectionFilter.alpha[0] = value;
}
if (parameterName === 'alphaEnding') {
reflectionFilter.alpha[1] = value;
}
if (parameterName === 'animationSpeed') {
reflectionFilter.animationSpeed = value;
}
}
getDoubleParameter(filter: PIXI.Filter, parameterName: string): number {
const reflectionFilter = (filter as unknown) as PIXI.filters.ReflectionFilter &
ReflectionFilterExtra;
if (parameterName === 'boundary') {
return reflectionFilter.boundary;
}
if (parameterName === 'amplitudeStart') {
return reflectionFilter.amplitude[0];
}
if (parameterName === 'amplitudeEnding') {
return reflectionFilter.amplitude[1];
}
if (parameterName === 'waveLengthStart') {
return reflectionFilter.waveLength[0];
}
if (parameterName === 'waveLengthEnding') {
return reflectionFilter.waveLength[1];
}
if (parameterName === 'alphaStart') {
return reflectionFilter.alpha[0];
}
if (parameterName === 'alphaEnding') {
return reflectionFilter.alpha[1];
}
if (parameterName === 'animationSpeed') {
return reflectionFilter.animationSpeed;
}
return 0;
}
updateStringParameter(
filter: PIXI.Filter,
parameterName: string,
value: string
) {}
updateColorParameter(
filter: PIXI.Filter,
parameterName: string,
value: number
): void {}
getColorParameter(filter: PIXI.Filter, parameterName: string): number {
return 0;
}
updateBooleanParameter(
filter: PIXI.Filter,
parameterName: string,
value: boolean
) {
const reflectionFilter = (filter as unknown) as PIXI.filters.ReflectionFilter &
ReflectionFilterExtra;
if (parameterName === 'mirror') {
reflectionFilter.mirror = value;
}
}
})()
);
}