2021-04-15 22:39:35 +02:00
|
|
|
import "jasmine";
|
2021-06-25 18:14:40 +02:00
|
|
|
import { Room } from "../../../src/Connexion/Room";
|
|
|
|
import { flattenGroupLayersMap } from "../../../src/Phaser/Map/LayersFlattener";
|
|
|
|
import type { 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-06-25 18:14:40 +02:00
|
|
|
let flatLayers: ITiledMapLayer[] = [];
|
2021-05-12 14:30:12 +02:00
|
|
|
flatLayers = flattenGroupLayersMap({
|
2021-06-25 18:14:40 +02:00
|
|
|
compressionlevel: -1,
|
|
|
|
height: 2,
|
|
|
|
infinite: false,
|
|
|
|
layers: [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-06-25 18:14:40 +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-06-25 18:14:40 +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,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
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);
|
|
|
|
}
|
2021-06-25 18:14:40 +02:00
|
|
|
expect(layers).toEqual(["Tile Layer 1", "Tile Layer 2"]);
|
2021-04-15 22:39:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should iterate maps with recursive groups", () => {
|
2021-06-25 18:14:40 +02:00
|
|
|
let flatLayers: ITiledMapLayer[] = [];
|
2021-05-12 14:30:12 +02:00
|
|
|
flatLayers = flattenGroupLayersMap({
|
2021-06-25 18:14:40 +02:00
|
|
|
compressionlevel: -1,
|
|
|
|
height: 2,
|
|
|
|
infinite: false,
|
|
|
|
layers: [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-06-25 18:14:40 +02:00
|
|
|
id: 6,
|
|
|
|
layers: [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-06-25 18:14:40 +02:00
|
|
|
id: 5,
|
|
|
|
layers: [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-06-25 18:14:40 +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-06-25 18:14:40 +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,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
name: "Group 3",
|
|
|
|
opacity: 1,
|
|
|
|
type: "group",
|
|
|
|
visible: true,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
2021-04-15 22:39:35 +02:00
|
|
|
},
|
|
|
|
{
|
2021-06-25 18:14:40 +02:00
|
|
|
id: 7,
|
|
|
|
layers: [
|
2021-04-15 22:39:35 +02:00
|
|
|
{
|
2021-06-25 18:14:40 +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,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
name: "Group 2",
|
|
|
|
opacity: 1,
|
|
|
|
type: "group",
|
|
|
|
visible: true,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
name: "Group 1",
|
|
|
|
opacity: 1,
|
|
|
|
type: "group",
|
|
|
|
visible: true,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
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);
|
|
|
|
}
|
2021-06-25 18:14:40 +02:00
|
|
|
expect(layers).toEqual(["Group 1/Group 3/Tile3", "Group 1/Group 3/Tile2", "Group 1/Group 2/Tile1"]);
|
2021-04-15 22:39:35 +02:00
|
|
|
});
|
|
|
|
});
|