diff --git a/config.js b/config.js index 85fa927..0380c1e 100644 --- a/config.js +++ b/config.js @@ -66,6 +66,7 @@ export const config = { }, { label: 'Sala / Auditorium', + color: 'rgb(212, 96, 75)', children: [ { label: 'Peplano / Platea', @@ -108,6 +109,7 @@ export const config = { }, { label: 'Scena', + color: 'rgb(75, 100, 212)', children: [ { label: 'Palcoscenico', @@ -129,6 +131,7 @@ export const config = { }, { label: 'Spazi tecnici', + color: 'rgb(42, 139, 75)', children: [ { label: 'Spazio tecnico superiore', @@ -152,6 +155,7 @@ export const config = { }, { label: 'Orchestra', + color: 'rgb(187, 120, 218)', children: [ { label: 'Fossa orchestra', diff --git a/js/controllers/menu_controller.js b/js/controllers/menu_controller.js index 3ac3f0e..79b8344 100644 --- a/js/controllers/menu_controller.js +++ b/js/controllers/menu_controller.js @@ -34,8 +34,46 @@ export default class extends Controller { */ const id = event?.params.node; const status = event?.target?.checked; - ATON.getSceneNode(id).toggle(status); - AppState.normalizedNodes.find(n => n.id === id).active = status; + const node = AppState.normalizedNodes.find(n => n.id === id); + + if (node.children.length > 0) { + this.#toggleGroup(node, status); + this.#syncGroupCheckboxes(node, status, this.layersTarget); + } else { + ATON.getSceneNode(id).toggle(status); + node.active = status; + } + } + /** + * Recursively toggle children in a nodes group + * @param {Object} groupNode + * @param {Boolean} status + */ + #toggleGroup(groupNode, status) { + for (const child of groupNode.children) { + if (child.model) { + ATON.getSceneNode(child.id).toggle(status); + child.active = status; + } + if (child.children.length > 0) { + this.#toggleGroup(child, status); + } + } + } + #syncGroupCheckboxes(groupNode, status, container) { + for (const child of groupNode.children) { + const checkbox = container.querySelector( + `[data-menu-node-param="${child.id}"]` + ); + + console.debug(checkbox, child.id); + + if (checkbox) checkbox.checked = status; + + if (child.children.length > 0) { + this.#syncGroupCheckboxes(child, status, container); + } + } } /** * Clone a