Skip to content

Commit

Permalink
Add tests for effects in GDJS
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian committed Aug 19, 2021
1 parent cbc0252 commit a19f244
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
2 changes: 2 additions & 0 deletions GDJS/tests/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
163 changes: 163 additions & 0 deletions GDJS/tests/tests/effects.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit a19f244

Please sign in to comment.