From 64176024f3ad95e68d5654137986d8211c529997 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Thu, 23 May 2024 22:38:29 +0200 Subject: [PATCH] feat(CountersSelectors): add 'delete' shortcut + change 'm' --- libs/ui/CountersSelector.lua | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/libs/ui/CountersSelector.lua b/libs/ui/CountersSelector.lua index 672cec4..a5c2ddf 100644 --- a/libs/ui/CountersSelector.lua +++ b/libs/ui/CountersSelector.lua @@ -161,21 +161,25 @@ local function decrementSelectedCounter(countersMap, selectedCounter) return false end -local function switchMinMaxSelectedCounter(countersMap, selectedCounter, maxPossibleCount) +local function switchToMaxSelectedCounter(countersMap, selectedCounter, maxPossibleCount) local counterPayload = countersMap[selectedCounter] if counterPayload and counterPayload.count then - if counterPayload.count > 0 then - countersMap[selectedCounter] = { - count = 0, - name = counterPayload.name - } - else - countersMap[selectedCounter] = { - count = maxPossibleCount, - name = counterPayload.name - } - end + countersMap[selectedCounter] = { + count = maxPossibleCount, + name = counterPayload.name + } + end +end + +local function switchToMinSelectedCounter(countersMap, selectedCounter) + local counterPayload = countersMap[selectedCounter] + + if counterPayload and counterPayload.count then + countersMap[selectedCounter] = { + count = 0, + name = counterPayload.name + } end end @@ -227,7 +231,10 @@ local function CountersSelector(initialCountersMap, config) globalCounter = globalCounter + 1 end elseif keyPressed == keys.m then - switchMinMaxSelectedCounter(countersMap, selectedCounter, counterMax - globalCounter) + switchToMaxSelectedCounter(countersMap, selectedCounter, counterMax - globalCounter) + globalCounter = getTotalCount(countersMap) + elseif keyPressed == keys.delete then + switchToMinSelectedCounter(countersMap, selectedCounter) globalCounter = getTotalCount(countersMap) elseif keyPressed == keys.r then countersMap = resetAllCounters(countersMap)