Files
GDevelop/GDJS/tests/tests/layer.js
T
AlexandreS cf374737fc Add support for built-in 3D games (#5285)
* This provides new 3D objects: 3D Box (perfect to create walls, floors, or billboards) and 3D Model (to import objects created in a 3D modeling app).
* 2D and 3D can be mixed in a same game. Each layer of a game can contain 2D objects, 3D objects or a mix of both.
* This allows to build 2D games, 2.5D games and full 3D games: platformers, racing games, FPS, hyper casual games. It's easy to start adding 3D objects to an existing 2D game.
* You can set up a light by adding an ambient light and/or directional light in the effects of a 3D layer. 3D objects can be configured to react to light or ignore it.
* In the future, support for 3D objects will be improved: light objects, animations, etc...
2023-05-16 17:37:49 +02:00

64 lines
2.4 KiB
JavaScript

/**
* Common tests for gdjs game engine.
* See README.md for more information.
*/
describe('gdjs.Layer', () => {
const runtimeGame = gdjs.getPixiRuntimeGame();
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
it('can convert coordinates', () => {
const layer = new gdjs.Layer({name: 'My layer', visibility: true, effects:[]}, runtimeScene)
layer.setCameraX(100, 0);
layer.setCameraY(200, 0);
layer.setCameraRotation(90, 0);
expect(layer.convertCoords(350, 450, 0)[0]).to.be.within(-50.001, -49.99999);
expect(layer.convertCoords(350, 450, 0)[1]).to.be.within(149.9999, 150.001);
});
it('can convert inverse coordinates', () => {
const layer = new gdjs.Layer({name: 'My layer', visibility: true, effects:[]}, runtimeScene)
layer.setCameraX(100, 0);
layer.setCameraY(200, 0);
layer.setCameraRotation(90, 0);
expect(layer.convertInverseCoords(350, 450, 0)[0]).to.be.within(649.999, 650.001);
expect(layer.convertInverseCoords(350, 450, 0)[1]).to.be.within(49.9999, 50.001);
});
it('can get the camera Z position', () => {
const layer = new gdjs.Layer({name: 'My layer', visibility: true, effects:[]}, runtimeScene)
expect(layer.getCameraZoom()).to.be(1);
expect(layer.getWidth()).to.be(800);
expect(layer.getHeight()).to.be(600);
expect(layer.getCameraZ(45)).to.be.within(724.264, 724.265);
});
it('can update the camera Z position', () => {
const layer = new gdjs.Layer({name: 'My layer', visibility: true, effects:[]}, runtimeScene)
layer.setCameraZ(400, 45);
expect(layer.getCameraZ(45)).to.be(400);
expect(layer.getCameraZoom()).to.be.within(1.81066, 1.81067);
});
it('can get the camera Z position after a zoom update', () => {
const layer = new gdjs.Layer({name: 'My layer', visibility: true, effects:[]}, runtimeScene)
layer.setCameraZoom(2);
expect(layer.getCameraZoom()).to.be(2);
expect(layer.getCameraZ(45)).to.be.within(362.132, 362.133);
});
it('can set the camera Z position to 0', () => {
const layer = new gdjs.Layer({name: 'My layer', visibility: true, effects:[]}, runtimeScene)
expect(layer.getCameraZoom()).to.be(1);
expect(layer.getCameraZ(45)).to.be.within(724.264, 724.265);
layer.setCameraZ(0, 45);
// The zoom factor is capped to avoid infinity.
expect(layer.getCameraZoom()).to.be(Number.MAX_SAFE_INTEGER);
// The camera Z is still 0, it's not evaluated from the zoom factor.
expect(layer.getCameraZ(45)).to.be(0);
});
});