refactor(ui): cleanup + prepare inferium-gui final implementation
This commit is contained in:
parent
c0ea32bf17
commit
28ea977b86
@ -1,6 +1,6 @@
|
||||
local CountersSelector = require('libs/ui/CountersSelector')
|
||||
|
||||
local counterMax = 8
|
||||
local COUNTER_MAX = 8
|
||||
|
||||
local function centerString(str, width)
|
||||
width = width or term.getSize()
|
||||
@ -8,7 +8,29 @@ local function centerString(str, width)
|
||||
return string.rep(' ', padding) .. str
|
||||
end
|
||||
|
||||
local titleFn = function(countersMap, _, win)
|
||||
|
||||
local function formatSeedName(essenceName)
|
||||
return 'mysticalagriculture:' .. essenceName .. '_seeds'
|
||||
end
|
||||
|
||||
local function parseSeedName(seedName)
|
||||
local result, nbReplaced = string.gsub(seedName, 'mysticalagriculture:', '')
|
||||
|
||||
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
|
||||
@ -19,12 +41,15 @@ local titleFn = function(countersMap, _, win)
|
||||
|
||||
local width = win.getSize()
|
||||
return centerString("" .. total .. '/' .. counterMax .. ' used farmlands' .. "", width)
|
||||
end
|
||||
end
|
||||
|
||||
local config = {
|
||||
local config = {
|
||||
counterMax = counterMax,
|
||||
titleFn = titleFn
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
end
|
||||
|
||||
local countersMap = {
|
||||
{ name = "iron", count = 1 },
|
||||
@ -57,6 +82,10 @@ local countersMap = {
|
||||
{ name = "test_25", count = 0 },
|
||||
}
|
||||
|
||||
local result = CountersSelector(countersMap, config)
|
||||
-- term.clear()
|
||||
print(textutils.serialize(result))
|
||||
|
||||
local function main()
|
||||
local result = CountersSelector(countersMap, getCountersSelectorConfig(COUNTER_MAX))
|
||||
print(textutils.serialize(result))
|
||||
end
|
||||
|
||||
main()
|
||||
@ -206,7 +206,6 @@ local function CountersSelector(initialCountersMap, config)
|
||||
|
||||
local topHeight = 1
|
||||
|
||||
-- term.clear()
|
||||
local width, height = term.getSize()
|
||||
local mainHeight = height - topHeight
|
||||
local nbOfElemsPerPage = mainHeight
|
||||
|
||||
Loading…
Reference in New Issue
Block a user