fix(ui): CountersSelectors add 'name' and 'count' in countersMap payload
This commit is contained in:
parent
b1c24ee6a2
commit
be9e57ebd7
@ -25,7 +25,7 @@ local function getTotalCount(countersMap)
|
|||||||
return total
|
return total
|
||||||
end
|
end
|
||||||
|
|
||||||
local function omitN(t, n)
|
local function dropN(t, n)
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
@ -39,7 +39,7 @@ local function omitN(t, n)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
local function pickN(t, n)
|
local function takeN(t, n)
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
@ -59,7 +59,6 @@ local function renderCountersMap(countersMap, selectedCounter, titleFn)
|
|||||||
term.setCursorPos(1, 1)
|
term.setCursorPos(1, 1)
|
||||||
local _, height = term.getSize()
|
local _, height = term.getSize()
|
||||||
-- local nbCounters = utils.sizeof(countersMap)
|
-- local nbCounters = utils.sizeof(countersMap)
|
||||||
local selectedCounterKey = countersMap[selectedCounter]
|
|
||||||
-- local totalCount = getTotalCount(countersMap)
|
-- local totalCount = getTotalCount(countersMap)
|
||||||
|
|
||||||
local topMargin = 0
|
local topMargin = 0
|
||||||
@ -77,14 +76,14 @@ local function renderCountersMap(countersMap, selectedCounter, titleFn)
|
|||||||
-- local totalPages = (nbCounters % availableHeight) + 1
|
-- local totalPages = (nbCounters % availableHeight) + 1
|
||||||
|
|
||||||
local nbElementsToOmit = (selectedPage - 1) * availableHeight
|
local nbElementsToOmit = (selectedPage - 1) * availableHeight
|
||||||
local displayedCounters = pickN(omitN(countersMap, nbElementsToOmit), availableHeight)
|
local displayedCounters = takeN(dropN(countersMap, nbElementsToOmit), availableHeight)
|
||||||
|
|
||||||
local cursorYIndex = 1 + topMargin
|
local cursorYIndex = 1 + topMargin
|
||||||
for k,v in pairs(displayedCounters) do
|
for k,v in pairs(displayedCounters) do
|
||||||
term.clearLine()
|
|
||||||
term.setCursorPos(1, cursorYIndex)
|
term.setCursorPos(1, cursorYIndex)
|
||||||
|
term.clearLine()
|
||||||
|
|
||||||
if k == selectedCounterKey then
|
if k == selectedCounter then
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
else
|
else
|
||||||
@ -92,7 +91,7 @@ local function renderCountersMap(countersMap, selectedCounter, titleFn)
|
|||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
end
|
end
|
||||||
|
|
||||||
term.write(tostring(k) .. ' ' .. tostring(v))
|
term.write(tostring(v.name) .. ' ' .. tostring(v.count))
|
||||||
cursorYIndex = cursorYIndex + 1
|
cursorYIndex = cursorYIndex + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -124,7 +123,6 @@ local function CountersSelector(initialCountersMap, config)
|
|||||||
local shouldContinue = true
|
local shouldContinue = true
|
||||||
while shouldContinue do
|
while shouldContinue do
|
||||||
renderCountersMap(countersMap, selectedCounter, titleFn)
|
renderCountersMap(countersMap, selectedCounter, titleFn)
|
||||||
|
|
||||||
local _, keyPressed, isHeld = os.pullEvent('key')
|
local _, keyPressed, isHeld = os.pullEvent('key')
|
||||||
|
|
||||||
if keyPressed == keys.up then
|
if keyPressed == keys.up then
|
||||||
@ -132,15 +130,21 @@ local function CountersSelector(initialCountersMap, config)
|
|||||||
elseif keyPressed == keys.down then
|
elseif keyPressed == keys.down then
|
||||||
selectedCounter = math.min(nbCounters, selectedCounter + 1)
|
selectedCounter = math.min(nbCounters, selectedCounter + 1)
|
||||||
elseif keyPressed == keys.left and globalCounter > 0 then
|
elseif keyPressed == keys.left and globalCounter > 0 then
|
||||||
local currentCount = countersMap[selectedCounter]
|
local counterPayload = countersMap[selectedCounter]
|
||||||
if currentCount and currentCount > 0 then
|
if counterPayload and counterPayload.count and counterPayload.count > 0 then
|
||||||
countersMap[selectedCounter] = currentCount - 1
|
countersMap[selectedCounter] = {
|
||||||
|
count = counterPayload.count - 1,
|
||||||
|
name = counterPayload.name
|
||||||
|
}
|
||||||
globalCounter = globalCounter - 1
|
globalCounter = globalCounter - 1
|
||||||
end
|
end
|
||||||
elseif keyPressed == keys.right and globalCounter < counterMax then
|
elseif keyPressed == keys.right and globalCounter < counterMax then
|
||||||
local currentCount = countersMap[selectedCounter]
|
local counterPayload = countersMap[selectedCounter]
|
||||||
if currentCount then
|
if counterPayload and counterPayload.count then
|
||||||
countersMap[selectedCounter] = currentCount + 1
|
countersMap[selectedCounter] = {
|
||||||
|
count = counterPayload.count + 1,
|
||||||
|
name = counterPayload.name
|
||||||
|
}
|
||||||
globalCounter = globalCounter + 1
|
globalCounter = globalCounter + 1
|
||||||
end
|
end
|
||||||
elseif keyPressed == keys.enter then
|
elseif keyPressed == keys.enter then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user