I have the following type:
mutable struct JSButtonState
btn1::Observable{Bool}
btn2::Observable{Bool}
btn3::Observable{Bool}
btn4::Observable{Bool}
btn5::Observable{Bool}
btn6::Observable{Bool}
btn7::Observable{Bool}
btn8::Observable{Bool}
btn9::Observable{Bool}
btn10::Observable{Bool}
btn11::Observable{Bool}
btn12::Observable{Bool}
end
And use the following code to set the Observables from the array buttons
, which is an array of UInt8 values that are zero or one:
if ! isnothing(jsbuttons)
buttons = GLFW.GetJoystickButtons(js.device)
if js.button_count >= 1
if jsbuttons.btn1[] != (buttons[1] != 0)
jsbuttons.btn1[] = (buttons[1] != 0)
end
end
if js.button_count >= 2
if jsbuttons.btn2[] != (buttons[2] != 0)
jsbuttons.btn2[] = (buttons[2] != 0)
end
end
if js.button_count >= 3
if jsbuttons.btn3[] != (buttons[3] != 0)
jsbuttons.btn3[] = (buttons[3] != 0)
end
end
if js.button_count >= 4
if jsbuttons.btn4[] != (buttons[4] != 0)
jsbuttons.btn4[] = (buttons[4] != 0)
end
end
... # there are 12 buttons or more
end
This are lots of lines of code…
Any idea how to simplify the code without changing the type JSButtonState ?