mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-08-25 12:23:58 -04:00
364ec2ecfb
- Make color parsing from string more robust (issues when setting colors in Sprite, BBText, Particle emitter and effects with colors) - Allow use of hex strings and shorthand hex strings in color fields - Remove UI glitch when switching effect type and both effects have parameters with identical names
106 lines
3.4 KiB
TypeScript
106 lines
3.4 KiB
TypeScript
namespace gdjs {
|
|
interface AmbientLightFilterNetworkSyncData {
|
|
i: number;
|
|
c: number;
|
|
}
|
|
gdjs.PixiFiltersTools.registerFilterCreator(
|
|
'Scene3D::AmbientLight',
|
|
new (class implements gdjs.PixiFiltersTools.FilterCreator {
|
|
makeFilter(
|
|
target: EffectsTarget,
|
|
effectData: EffectData
|
|
): gdjs.PixiFiltersTools.Filter {
|
|
if (typeof THREE === 'undefined') {
|
|
return new gdjs.PixiFiltersTools.EmptyFilter();
|
|
}
|
|
return new (class implements gdjs.PixiFiltersTools.Filter {
|
|
light: THREE.AmbientLight;
|
|
_isEnabled: boolean;
|
|
|
|
constructor() {
|
|
this.light = new THREE.AmbientLight();
|
|
this._isEnabled = false;
|
|
}
|
|
|
|
isEnabled(target: EffectsTarget): boolean {
|
|
return this._isEnabled;
|
|
}
|
|
setEnabled(target: EffectsTarget, enabled: boolean): boolean {
|
|
if (this._isEnabled === enabled) {
|
|
return true;
|
|
}
|
|
if (enabled) {
|
|
return this.applyEffect(target);
|
|
} else {
|
|
return this.removeEffect(target);
|
|
}
|
|
}
|
|
applyEffect(target: EffectsTarget): boolean {
|
|
const scene = target.get3DRendererObject() as
|
|
| THREE.Scene
|
|
| null
|
|
| undefined;
|
|
if (!scene) {
|
|
return false;
|
|
}
|
|
scene.add(this.light);
|
|
this._isEnabled = true;
|
|
return true;
|
|
}
|
|
removeEffect(target: EffectsTarget): boolean {
|
|
const scene = target.get3DRendererObject() as
|
|
| THREE.Scene
|
|
| null
|
|
| undefined;
|
|
if (!scene) {
|
|
return false;
|
|
}
|
|
scene.remove(this.light);
|
|
this._isEnabled = false;
|
|
return true;
|
|
}
|
|
updatePreRender(target: gdjs.EffectsTarget): any {}
|
|
updateDoubleParameter(parameterName: string, value: number): void {
|
|
if (parameterName === 'intensity') {
|
|
this.light.intensity = value;
|
|
}
|
|
}
|
|
getDoubleParameter(parameterName: string): number {
|
|
if (parameterName === 'intensity') {
|
|
return this.light.intensity;
|
|
}
|
|
return 0;
|
|
}
|
|
updateStringParameter(parameterName: string, value: string): void {
|
|
if (parameterName === 'color') {
|
|
this.light.color.setHex(gdjs.rgbOrHexStringToNumber(value));
|
|
}
|
|
}
|
|
updateColorParameter(parameterName: string, value: number): void {
|
|
if (parameterName === 'color') {
|
|
this.light.color.setHex(value);
|
|
}
|
|
}
|
|
getColorParameter(parameterName: string): number {
|
|
if (parameterName === 'color') {
|
|
return this.light.color.getHex();
|
|
}
|
|
return 0;
|
|
}
|
|
updateBooleanParameter(parameterName: string, value: boolean): void {}
|
|
getNetworkSyncData(): AmbientLightFilterNetworkSyncData {
|
|
return {
|
|
i: this.light.intensity,
|
|
c: this.light.color.getHex(),
|
|
};
|
|
}
|
|
updateFromNetworkSyncData(data: AmbientLightFilterNetworkSyncData) {
|
|
this.light.intensity = data.i;
|
|
this.light.color.setHex(data.c);
|
|
}
|
|
})();
|
|
}
|
|
})()
|
|
);
|
|
}
|