forked from 4ian/GDevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shockwave-pixi-filter.ts
101 lines (101 loc) · 3.37 KB
/
shockwave-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
namespace gdjs {
interface ShockwaveFilterExtra {
// extra properties are stored on the filter.
_centerX: number;
_centerY: number;
}
gdjs.PixiFiltersTools.registerFilterCreator(
'Shockwave',
new (class extends gdjs.PixiFiltersTools.PixiFilterCreator {
makePIXIFilter(target: EffectsTarget, effectData) {
const shockwaveFilter = new PIXI.filters.ShockwaveFilter([0.5, 0.5]);
return shockwaveFilter;
}
updatePreRender(filter: PIXI.Filter, target: EffectsTarget) {
const shockwaveFilter = (filter as unknown) as PIXI.filters.ShockwaveFilter &
ShockwaveFilterExtra;
if (shockwaveFilter.speed !== 0) {
shockwaveFilter.time += target.getElapsedTime() / 1000;
}
shockwaveFilter.center[0] = Math.round(
shockwaveFilter._centerX * target.getWidth()
);
shockwaveFilter.center[1] = Math.round(
shockwaveFilter._centerY * target.getHeight()
);
}
updateDoubleParameter(
filter: PIXI.Filter,
parameterName: string,
value: number
) {
const shockwaveFilter = filter as PIXI.filters.ShockwaveFilter &
ShockwaveFilterExtra;
if (parameterName === 'centerX') {
shockwaveFilter._centerX = value;
} else if (parameterName === 'centerY') {
shockwaveFilter._centerY = value;
} else if (parameterName === 'time') {
shockwaveFilter.time = value;
} else if (parameterName === 'speed') {
shockwaveFilter.speed = value;
} else if (parameterName === 'amplitude') {
shockwaveFilter.amplitude = value;
} else if (parameterName === 'wavelength') {
shockwaveFilter.wavelength = value;
} else if (parameterName === 'brightness') {
shockwaveFilter.brightness = value;
} else if (parameterName === 'radius') {
shockwaveFilter.radius = value;
}
}
getDoubleParameter(filter: PIXI.Filter, parameterName: string): number {
const shockwaveFilter = filter as PIXI.filters.ShockwaveFilter &
ShockwaveFilterExtra;
if (parameterName === 'centerX') {
return shockwaveFilter._centerX;
}
if (parameterName === 'centerY') {
return shockwaveFilter._centerY;
}
if (parameterName === 'time') {
return shockwaveFilter.time;
}
if (parameterName === 'speed') {
return shockwaveFilter.speed;
}
if (parameterName === 'amplitude') {
return shockwaveFilter.amplitude;
}
if (parameterName === 'wavelength') {
return shockwaveFilter.wavelength;
}
if (parameterName === 'brightness') {
return shockwaveFilter.brightness;
}
if (parameterName === 'radius') {
return shockwaveFilter.radius;
}
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
) {}
})()
);
}