From 4afc8bc94a98639f48134e821796634bdae3c1e7 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Sun, 10 Sep 2023 21:38:30 +0200 Subject: [PATCH] Option to layout by entertainment area center --- assets/webconfig/i18n/en.json | 1 + assets/webconfig/js/wizard.js | 38 +++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 8b75d8e9..d8518fd2 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -87,6 +87,7 @@ "conf_leds_layout_cl_cornergap": "Corner Gap", "conf_leds_layout_cl_edgegap": "Edge Gap", "conf_leds_layout_cl_entertainment": "Entertainment Area", + "conf_leds_layout_cl_entertainment_center": "Entertainment Area Center", "conf_leds_layout_cl_gaglength": "Gap length", "conf_leds_layout_cl_gappos": "gap position", "conf_leds_layout_cl_hleddepth": "Horizontal LED depth", diff --git a/assets/webconfig/js/wizard.js b/assets/webconfig/js/wizard.js index 6312b97c..9c7534a4 100755 --- a/assets/webconfig/js/wizard.js +++ b/assets/webconfig/js/wizard.js @@ -1152,12 +1152,31 @@ function beginWizardHue() { createHueUser(); }); - function assignLightEntertainmentPos(position, name, id) { + function assignLightEntertainmentPos(isFocusCenter, position, name, id) { var x = position.x; var z = position.z; - var h = (x + 1) / 2; - var v = (-z + 1) / 2; + + if (isFocusCenter) { + // Map lights as in centered range -0.5 to 0.5 + if (x < -0.5) { + x = -0.5; + } else if (x > 0.5) { + x = 0.5; + } + if (z < -0.5) { + z = -0.5; + } else if (z > 0.5) { + z = 0.5; + } + } else { + // Map lights as in full range -1 to 1 + x /= 2; + z /= 2; + } + + var h = x + 0.5; + var v = -z + 0.5; var hmin = h - 0.05; var hmax = h + 0.05; @@ -1256,19 +1275,25 @@ function beginWizardHue() { serviceID = lightLocation.service.rid; } - if (position === "entertainment") { + if (position.startsWith("entertainment")) { + // Layout per entertainment area definition at bridge + var isFocusCenter = false; + if (position === "entertainment_center") { + isFocusCenter = true; + } + if (isAPIv2Ready) { groupChannels.forEach((channel) => { if (channel.members[0].service.rid === serviceID) { - var layoutObject = assignLightEntertainmentPos(channel.position, lightName, channel.channel_id); + var layoutObject = assignLightEntertainmentPos(isFocusCenter, channel.position, lightName, channel.channel_id); hueLedConfig.push(JSON.parse(JSON.stringify(layoutObject))); ++channelNumber; } }); } else { - var layoutObject = assignLightEntertainmentPos(lightLocation.position, lightName); + var layoutObject = assignLightEntertainmentPos(isFocusCenter, lightLocation.position, lightName); hueLedConfig.push(JSON.parse(JSON.stringify(layoutObject))); } } @@ -1529,6 +1554,7 @@ function get_hue_lights(username) { ]; if (isEntertainmentReady) { + lightOptions.unshift("entertainment_center"); lightOptions.unshift("entertainment"); } else { lightOptions.unshift("disabled");