2021-05-18 11:50:03 +02:00
|
|
|
import type {ITiledMap, ITiledMapLayer} from "./ITiledMap";
|
2021-05-12 14:30:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flatten the grouped layers
|
|
|
|
*/
|
|
|
|
export function flattenGroupLayersMap(map: ITiledMap) {
|
2021-05-18 11:50:03 +02:00
|
|
|
const flatLayers: ITiledMapLayer[] = [];
|
2021-05-12 14:30:12 +02:00
|
|
|
flattenGroupLayers(map.layers, '', flatLayers);
|
|
|
|
return flatLayers;
|
|
|
|
}
|
|
|
|
|
|
|
|
function flattenGroupLayers(layers : ITiledMapLayer[], prefix : string, flatLayers: ITiledMapLayer[]) {
|
|
|
|
for (const layer of layers) {
|
|
|
|
if (layer.type === 'group') {
|
|
|
|
flattenGroupLayers(layer.layers, prefix + layer.name + '/', flatLayers);
|
|
|
|
} else {
|
|
|
|
const layerWithNewName = { ...layer };
|
|
|
|
layerWithNewName.name = prefix+layerWithNewName.name;
|
|
|
|
flatLayers.push(layerWithNewName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|