From a19f24433d4f968f4b6cb6b2bab299f93ec3ae13 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Thu, 19 Aug 2021 10:16:33 +0200 Subject: [PATCH] Add tests for effects in GDJS --- GDJS/tests/karma.conf.js | 2 + GDJS/tests/tests/effects.js | 163 ++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 GDJS/tests/tests/effects.js diff --git a/GDJS/tests/karma.conf.js b/GDJS/tests/karma.conf.js index e2305e4ebff4..9d6fd45ba626 100644 --- a/GDJS/tests/karma.conf.js +++ b/GDJS/tests/karma.conf.js @@ -76,6 +76,8 @@ module.exports = function (config) { '../../newIDE/app/resources/GDJS/Runtime/Extensions/TopDownMovementBehavior/topdownobstacleruntimebehavior.js', '../../newIDE/app/resources/GDJS/Runtime/Extensions/Firebase/A_firebasejs/*.js', '../../newIDE/app/resources/GDJS/Runtime/Extensions/Firebase/B_firebasetools/*.js', + '../../newIDE/app/resources/GDJS/Runtime/Extensions/Effects/kawase-blur-pixi-filter.js', + '../../newIDE/app/resources/GDJS/Runtime/Extensions/Effects/pixi-filters/filter-kawase-blur.js', // Test extensions: './tests/Extensions/**.js', diff --git a/GDJS/tests/tests/effects.js b/GDJS/tests/tests/effects.js new file mode 100644 index 000000000000..4deaa10bdeb0 --- /dev/null +++ b/GDJS/tests/tests/effects.js @@ -0,0 +1,163 @@ +// @ts-check + +describe('gdjs.EffectsManager', () => { + const runtimeGame = new gdjs.RuntimeGame({ + variables: [], + // @ts-ignore TODO: make a function to create an empty game and use it across tests. + properties: { windowWidth: 800, windowHeight: 600 }, + resources: { resources: [] }, + }); + + it('can add effects on a runtime object', () => { + const runtimeScene = new gdjs.RuntimeScene(runtimeGame); + const object = new gdjs.TestRuntimeObject(runtimeScene, { + name: 'obj1', + type: '', + variables: [], + behaviors: [], + effects: [ + { + name: 'InitialKawaseBlurEffect', + effectType: 'KawaseBlur', + stringParameters: {}, + booleanParameters: {}, + doubleParameters: { + pixelizeX: 1, + pixelizeY: 2, + blur: 3, + quality: 4, + }, + }, + ], + }); + expect(object.hasEffect('NonExistingEffect')).to.be(false); + expect(object.hasEffect('InitialKawaseBlurEffect')).to.be(true); + expect(object.isEffectEnabled('NonExistingEffect')).to.be(false); + expect(object.isEffectEnabled('InitialKawaseBlurEffect')).to.be(true); + + object.enableEffect('InitialKawaseBlurEffect', false); + expect(object.isEffectEnabled('InitialKawaseBlurEffect')).to.be(false); + object.enableEffect('InitialKawaseBlurEffect', true); + expect(object.isEffectEnabled('InitialKawaseBlurEffect')).to.be(true); + + object.setEffectDoubleParameter('InitialKawaseBlurEffect', 'pixelizeX', 10); + object.setEffectStringParameter( + 'InitialKawaseBlurEffect', + 'useless', + 'will-be-ignored' + ); + object.setEffectBooleanParameter( + 'InitialKawaseBlurEffect', + 'useless', + true + ); + + object.addEffect({ + name: 'AddedKawaseBlurEffect', + effectType: 'KawaseBlur', + stringParameters: {}, + booleanParameters: {}, + doubleParameters: { + pixelizeX: 1, + pixelizeY: 2, + blur: 3, + quality: 4, + }, + }); + expect(object.hasEffect('AddedKawaseBlurEffect')).to.be(true); + expect(object.hasEffect('InitialKawaseBlurEffect')).to.be(true); + expect(object.isEffectEnabled('AddedKawaseBlurEffect')).to.be(true); + expect(object.isEffectEnabled('InitialKawaseBlurEffect')).to.be(true); + }); + + it('can add effects on a runtime layer', () => { + const runtimeScene = new gdjs.RuntimeScene(runtimeGame); + runtimeScene.loadFromScene({ + layers: [ + { + name: '', + visibility: true, + effects: [ + { + name: 'InitialKawaseBlurEffect', + effectType: 'KawaseBlur', + stringParameters: {}, + booleanParameters: {}, + doubleParameters: { + pixelizeX: 1, + pixelizeY: 2, + blur: 3, + quality: 4, + }, + }, + ], + cameras: [], + + ambientLightColorR: 0, + ambientLightColorG: 0, + ambientLightColorB: 0, + isLightingLayer: false, + followBaseLayerCamera: true, + }, + ], + variables: [], + r: 0, + v: 0, + b: 0, + mangledName: 'Scene1', + name: 'Scene1', + stopSoundsOnStartup: false, + title: '', + behaviorsSharedData: [], + objects: [], + instances: [], + }); + + const runtimeLayer = runtimeScene.getLayer(''); + + expect(runtimeLayer.hasEffect('NonExistingEffect')).to.be(false); + expect(runtimeLayer.hasEffect('InitialKawaseBlurEffect')).to.be(true); + expect(runtimeLayer.isEffectEnabled('NonExistingEffect')).to.be(false); + expect(runtimeLayer.isEffectEnabled('InitialKawaseBlurEffect')).to.be(true); + + runtimeLayer.enableEffect('InitialKawaseBlurEffect', false); + expect(runtimeLayer.isEffectEnabled('InitialKawaseBlurEffect')).to.be( + false + ); + runtimeLayer.enableEffect('InitialKawaseBlurEffect', true); + expect(runtimeLayer.isEffectEnabled('InitialKawaseBlurEffect')).to.be(true); + + runtimeLayer.setEffectDoubleParameter( + 'InitialKawaseBlurEffect', + 'pixelizeX', + 10 + ); + runtimeLayer.setEffectStringParameter( + 'InitialKawaseBlurEffect', + 'useless', + 'will-be-ignored' + ); + runtimeLayer.setEffectBooleanParameter( + 'InitialKawaseBlurEffect', + 'useless', + true + ); + + runtimeLayer.addEffect({ + name: 'AddedKawaseBlurEffect', + effectType: 'KawaseBlur', + stringParameters: {}, + booleanParameters: {}, + doubleParameters: { + pixelizeX: 1, + pixelizeY: 2, + blur: 3, + quality: 4, + }, + }); + expect(runtimeLayer.hasEffect('AddedKawaseBlurEffect')).to.be(true); + expect(runtimeLayer.hasEffect('InitialKawaseBlurEffect')).to.be(true); + expect(runtimeLayer.isEffectEnabled('AddedKawaseBlurEffect')).to.be(true); + expect(runtimeLayer.isEffectEnabled('InitialKawaseBlurEffect')).to.be(true); + }); +});