2021-04-15 22:39:35 +02:00
|
|
|
import "jasmine";
|
|
|
|
import {Room} from "../../../src/Connexion/Room";
|
2021-05-12 14:30:12 +02:00
|
|
|
import {flattenGroupLayersMap} from "../../../src/Phaser/Map/LayersFlattener";
|
|
|
|
import {ITiledMapLayer} from "../../../src/Phaser/Map/ITiledMap";
|
2021-04-15 22:39:35 +02:00
|
|
|
|
2021-05-12 14:30:12 +02:00
|
|
|
describe("Layers flattener", () => {
|
2021-04-15 22:39:35 +02:00
|
|
|
it("should iterate maps with no group", () => {
|
2021-05-12 14:30:12 +02:00
|
|
|
let flatLayers:ITiledMapLayer[] = [];
|
|
|
|
flatLayers = flattenGroupLayersMap({
|
|
|
|
"compressionlevel": -1,
|
|
|
|
"height": 2,
|
|
|
|
"infinite": false,
|
|
|
|
"layers": [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-05-12 14:30:12 +02:00
|
|
|
"data": [0, 0, 0, 0],
|
|
|
|
"height": 2,
|
|
|
|
"id": 1,
|
|
|
|
"name": "Tile Layer 1",
|
|
|
|
"opacity": 1,
|
|
|
|
"type": "tilelayer",
|
|
|
|
"visible": true,
|
|
|
|
"width": 2,
|
|
|
|
"x": 0,
|
|
|
|
"y": 0
|
2021-04-15 22:39:35 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-12 14:30:12 +02:00
|
|
|
"data": [0, 0, 0, 0],
|
|
|
|
"height": 2,
|
|
|
|
"id": 1,
|
|
|
|
"name": "Tile Layer 2",
|
|
|
|
"opacity": 1,
|
|
|
|
"type": "tilelayer",
|
|
|
|
"visible": true,
|
|
|
|
"width": 2,
|
|
|
|
"x": 0,
|
|
|
|
"y": 0
|
2021-04-15 22:39:35 +02:00
|
|
|
}],
|
2021-05-12 14:30:12 +02:00
|
|
|
"nextlayerid": 2,
|
|
|
|
"nextobjectid": 1,
|
|
|
|
"orientation": "orthogonal",
|
|
|
|
"renderorder": "right-down",
|
|
|
|
"tiledversion": "2021.03.23",
|
|
|
|
"tileheight": 32,
|
|
|
|
"tilesets": [],
|
|
|
|
"tilewidth": 32,
|
|
|
|
"type": "map",
|
|
|
|
"version": 1.5,
|
|
|
|
"width": 2
|
2021-04-15 22:39:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const layers = [];
|
2021-05-12 14:30:12 +02:00
|
|
|
for (const layer of flatLayers) {
|
2021-04-15 22:39:35 +02:00
|
|
|
layers.push(layer.name);
|
|
|
|
}
|
|
|
|
expect(layers).toEqual(['Tile Layer 1', 'Tile Layer 2']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should iterate maps with recursive groups", () => {
|
2021-05-12 14:30:12 +02:00
|
|
|
let flatLayers:ITiledMapLayer[] = [];
|
|
|
|
flatLayers = flattenGroupLayersMap({
|
|
|
|
"compressionlevel": -1,
|
|
|
|
"height": 2,
|
|
|
|
"infinite": false,
|
|
|
|
"layers": [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-05-12 14:30:12 +02:00
|
|
|
"id": 6,
|
|
|
|
"layers": [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-05-12 14:30:12 +02:00
|
|
|
"id": 5,
|
|
|
|
"layers": [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-05-12 14:30:12 +02:00
|
|
|
"data": [0, 0, 0, 0],
|
|
|
|
"height": 2,
|
|
|
|
"id": 10,
|
|
|
|
"name": "Tile3",
|
|
|
|
"opacity": 1,
|
|
|
|
"type": "tilelayer",
|
|
|
|
"visible": true,
|
|
|
|
"width": 2,
|
|
|
|
"x": 0,
|
|
|
|
"y": 0
|
2021-04-15 22:39:35 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-12 14:30:12 +02:00
|
|
|
"data": [0, 0, 0, 0],
|
|
|
|
"height": 2,
|
|
|
|
"id": 9,
|
|
|
|
"name": "Tile2",
|
|
|
|
"opacity": 1,
|
|
|
|
"type": "tilelayer",
|
|
|
|
"visible": true,
|
|
|
|
"width": 2,
|
|
|
|
"x": 0,
|
|
|
|
"y": 0
|
2021-04-15 22:39:35 +02:00
|
|
|
}],
|
2021-05-12 14:30:12 +02:00
|
|
|
"name": "Group 3",
|
|
|
|
"opacity": 1,
|
|
|
|
"type": "group",
|
|
|
|
"visible": true,
|
|
|
|
"x": 0,
|
|
|
|
"y": 0
|
2021-04-15 22:39:35 +02:00
|
|
|
},
|
|
|
|
{
|
2021-05-12 14:30:12 +02:00
|
|
|
"id": 7,
|
|
|
|
"layers": [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-05-12 14:30:12 +02:00
|
|
|
"data": [0, 0, 0, 0],
|
|
|
|
"height": 2,
|
|
|
|
"id": 8,
|
|
|
|
"name": "Tile1",
|
|
|
|
"opacity": 1,
|
|
|
|
"type": "tilelayer",
|
|
|
|
"visible": true,
|
|
|
|
"width": 2,
|
|
|
|
"x": 0,
|
|
|
|
"y": 0
|
2021-04-15 22:39:35 +02:00
|
|
|
}],
|
2021-05-12 14:30:12 +02:00
|
|
|
"name": "Group 2",
|
|
|
|
"opacity": 1,
|
|
|
|
"type": "group",
|
|
|
|
"visible": true,
|
|
|
|
"x": 0,
|
|
|
|
"y": 0
|
2021-04-15 22:39:35 +02:00
|
|
|
}],
|
2021-05-12 14:30:12 +02:00
|
|
|
"name": "Group 1",
|
|
|
|
"opacity": 1,
|
|
|
|
"type": "group",
|
|
|
|
"visible": true,
|
|
|
|
"x": 0,
|
|
|
|
"y": 0
|
2021-04-15 22:39:35 +02:00
|
|
|
}],
|
2021-05-12 14:30:12 +02:00
|
|
|
"nextlayerid": 11,
|
|
|
|
"nextobjectid": 1,
|
|
|
|
"orientation": "orthogonal",
|
|
|
|
"renderorder": "right-down",
|
|
|
|
"tiledversion": "2021.03.23",
|
|
|
|
"tileheight": 32,
|
|
|
|
"tilesets": [],
|
|
|
|
"tilewidth": 32,
|
|
|
|
"type": "map",
|
|
|
|
"version": 1.5,
|
|
|
|
"width": 2
|
2021-04-15 22:39:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const layers = [];
|
2021-05-12 14:30:12 +02:00
|
|
|
for (const layer of flatLayers) {
|
2021-04-15 22:39:35 +02:00
|
|
|
layers.push(layer.name);
|
|
|
|
}
|
|
|
|
expect(layers).toEqual(['Group 1/Group 3/Tile3', 'Group 1/Group 3/Tile2', 'Group 1/Group 2/Tile1']);
|
|
|
|
});
|
|
|
|
});
|