refactor(ui): cleanup + prepare inferium-gui final implementation

This commit is contained in:
Guillaume ARM 2024-05-23 23:34:36 +02:00
parent c0ea32bf17
commit 28ea977b86
2 changed files with 47 additions and 19 deletions

View File

@ -1,6 +1,6 @@
local CountersSelector = require('libs/ui/CountersSelector') local CountersSelector = require('libs/ui/CountersSelector')
local counterMax = 8 local COUNTER_MAX = 8
local function centerString(str, width) local function centerString(str, width)
width = width or term.getSize() width = width or term.getSize()
@ -8,23 +8,48 @@ local function centerString(str, width)
return string.rep(' ', padding) .. str return string.rep(' ', padding) .. str
end end
local titleFn = function(countersMap, _, win)
local total = 0;
for _, counterPayload in pairs(countersMap) do local function formatSeedName(essenceName)
if counterPayload and counterPayload.count then return 'mysticalagriculture:' .. essenceName .. '_seeds'
total = total + counterPayload.count
end
end
local width = win.getSize()
return centerString("" .. total .. '/' .. counterMax .. ' used farmlands' .. "", width)
end end
local config = { local function parseSeedName(seedName)
counterMax = counterMax, local result, nbReplaced = string.gsub(seedName, 'mysticalagriculture:', '')
titleFn = titleFn
} if nbReplaced == 0 then
return nil
end
local finalResult, nbFinalReplaced = string.gsub(result, '_seeds', '')
if nbFinalReplaced == 0 then
return nil
end
return finalResult
end
local function getCountersSelectorConfig(counterMax)
local titleFn = function(countersMap, _, win)
local total = 0;
for _, counterPayload in pairs(countersMap) do
if counterPayload and counterPayload.count then
total = total + counterPayload.count
end
end
local width = win.getSize()
return centerString("" .. total .. '/' .. counterMax .. ' used farmlands' .. "", width)
end
local config = {
counterMax = counterMax,
titleFn = titleFn
}
return config
end
local countersMap = { local countersMap = {
{ name = "iron", count = 1 }, { name = "iron", count = 1 },
@ -57,6 +82,10 @@ local countersMap = {
{ name = "test_25", count = 0 }, { name = "test_25", count = 0 },
} }
local result = CountersSelector(countersMap, config)
-- term.clear() local function main()
print(textutils.serialize(result)) local result = CountersSelector(countersMap, getCountersSelectorConfig(COUNTER_MAX))
print(textutils.serialize(result))
end
main()

View File

@ -206,7 +206,6 @@ local function CountersSelector(initialCountersMap, config)
local topHeight = 1 local topHeight = 1
-- term.clear()
local width, height = term.getSize() local width, height = term.getSize()
local mainHeight = height - topHeight local mainHeight = height - topHeight
local nbOfElemsPerPage = mainHeight local nbOfElemsPerPage = mainHeight