91 lines
2.3 KiB
Lua
91 lines
2.3 KiB
Lua
local CountersSelector = require('libs/ui/CountersSelector')
|
|
|
|
local COUNTER_MAX = 8
|
|
|
|
local function centerString(str, width)
|
|
width = width or term.getSize()
|
|
local padding = (width / 2) - (#str / 2)
|
|
return string.rep(' ', padding) .. str
|
|
end
|
|
|
|
|
|
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
|
|
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 = {
|
|
{ name = "iron", count = 1 },
|
|
{ name = "dye", count = 2 },
|
|
{ name = "experience", count = 3 },
|
|
{ name = "test_1", count = 0 },
|
|
{ name = "test_2", count = 0 },
|
|
{ name = "test_3", count = 0 },
|
|
{ name = "test_4", count = 0 },
|
|
{ name = "test_5", count = 0 },
|
|
{ name = "test_6", count = 0 },
|
|
{ name = "test_7", count = 0 },
|
|
{ name = "test_8", count = 0 },
|
|
{ name = "test_9", count = 0 },
|
|
{ name = "test_10", count = 0 },
|
|
{ name = "test_11", count = 0 },
|
|
{ name = "test_12", count = 0 },
|
|
{ name = "test_13", count = 0 },
|
|
{ name = "test_14", count = 0 },
|
|
{ name = "test_15", count = 0 },
|
|
{ name = "test_16", count = 0 },
|
|
{ name = "test_17", count = 0 },
|
|
{ name = "test_18", count = 0 },
|
|
{ name = "test_19", count = 0 },
|
|
{ name = "test_20", count = 0 },
|
|
{ name = "test_21", count = 0 },
|
|
{ name = "test_22", count = 0 },
|
|
{ name = "test_23", count = 0 },
|
|
{ name = "test_24", count = 0 },
|
|
{ name = "test_25", count = 0 },
|
|
}
|
|
|
|
|
|
local function main()
|
|
local result = CountersSelector(countersMap, getCountersSelectorConfig(COUNTER_MAX))
|
|
print(textutils.serialize(result))
|
|
end
|
|
|
|
main() |