From 66faf94f77266f4451c4781a599299c7a4b72bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Clet?= Date: Sat, 17 Aug 2024 12:46:23 +0200 Subject: [PATCH] autowriteagain at preset color change --- code/tc.preset.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/code/tc.preset.js b/code/tc.preset.js index b4256c1..aab38e3 100644 --- a/code/tc.preset.js +++ b/code/tc.preset.js @@ -570,25 +570,28 @@ function setcolor() { var args = arrayfromargs(arguments); var nb_args = args.length; var slot_nb = selected_slot; - if (nb_args == 1) { - // Set the color index of the currently selected slot (for when color_mode is 2) - slots[selected_slot].color_index = Math.floor(args); - } else if (nb_args == 2) { - // Set the color index to the 2nd argument for the slot number defined by the 1st argument - slot_nb = Math.floor(args[0]); - slots[slot_nb].color_index = Math.floor(args[1]); - } else if (nb_args == 4) { - // Set the custom color of the currently selected slot (for when color_mode is 3) - slots[selected_slot].color_custom = [args[0], args[1], args[2], args[3]]; - } else if (nb_args == 5) { - // Set the custom color for the slot number defined by the 1st argument to the color defined by following arguments in rgba format. - slot_nb = Math.floor(args[0]); - slots[slot_nb].color_custom = [args[1], args[2], args[3], args[4]]; - } else { + if (nb_args < 1 && nb_args > 5) { error("color: wrong number of arguments."); + } else { + if (nb_args == 1) { + // Set the color index of the currently selected slot (for when color_mode is 2) + slots[selected_slot].color_index = Math.floor(args); + } else if (nb_args == 2) { + // Set the color index to the 2nd argument for the slot number defined by the 1st argument + slot_nb = Math.floor(args[0]); + slots[slot_nb].color_index = Math.floor(args[1]); + } else if (nb_args == 4) { + // Set the custom color of the currently selected slot (for when color_mode is 3) + slots[selected_slot].color_custom = [args[0], args[1], args[2], args[3]]; + } else if (nb_args == 5) { + // Set the custom color for the slot number defined by the 1st argument to the color defined by following arguments in rgba format. + slot_nb = Math.floor(args[0]); + slots[slot_nb].color_custom = [args[1], args[2], args[3], args[4]]; + } + update_preset_color_pattr(slot_nb); + paint_base(); + trigger_writeagain(); } - update_preset_color_pattr(slot_nb); - paint_base(); } } @@ -886,6 +889,7 @@ function store(v) { outlet(0, "store", v); if (v) { + // We writagain only if stored preset is > 0 trigger_writeagain(); } }