So I had a quick look at that and changed a few things.
First I have put the images in persistent Symbols. This allows us to easily keep the changes if we go back and forth on scenes.
I have given the day, night buttons ids. of day and night
Both buttons call a single function. The id is used to determine which mode we want.
This function not only changes the images but also changes the button colour by also using css in the head and toggling the buttons class names.
The day and night image names from what I tell will match each other apart from the first word. day or night.
So the simple idea is to use the button id to work out which image mode we need and replace the first word of the image name to that. Then set the background image to correct image.
The day button is preset with the class so it shows as the active button when you first go to settings.
head
<style>
.buttonOn{
background-color: #5AB52C !important;
pointer-events: none !important;
}
</style>
mode()
element.classList.add("buttonOn"); //-- set button class to change css background colour
hypeDocument.setElementProperty(element, 'opacity', 1, 0.4, 'easeinout')
var mode =element.id;//-- get the mode from the id of the button
var mode1,mode2 = "";
//-- set the mode
mode == 'day' ? (
mode1 = 'night',
mode2 = 'day'
) : (
mode1 = 'day',
mode2 = 'night'
);
var otherButton = hypeDocument.getElementById( mode1)
otherButton.classList.remove("buttonOn");
hypeDocument.setElementProperty(otherButton, 'opacity', 0.5, 0.4, 'easeinout')
var images = document.querySelectorAll('.image_'); //-- get all images
for (i = 0; i < images.length; i++) {
var imagePath = hypeDocument.getElementProperty(images[i], 'background-image') //-- get image path
var name_ = imagePath.split('/') //-- split image path components
name_ = name_[name_.length-1]
if ( name_.includes(mode1)) {
name_ = name_.replace(mode1,mode2);//-- switch out the first word
hypeDocument.setElementProperty(images[i], 'background-image', '${resourcesFolderName}/' + name_)
}
}
Slight updated version.
Added single click (pointerEvents toggle ) and colour persistence to buttons. The buttons are now also persistence symbols.
day_night_mode_MHv2.hypetemplate.zip (85.6 KB)
Version with settings slide out…
nIghtDay_MHv2.hypetemplate.zip (77.9 KB)