このモジュールについての説明文ページを モジュール:ServerRatesList/doc に作成できます
local p = {}
-- translate here:
local Strings = {
And = "and",
XP = "[[経験|XP]]", Harvesting = "[[家畜化|Harvesting]]", Taming = "[[テイム]]",
BabyMature = "[[Breeding|Maturation]]", MatingInterval = "[[Breeding#Mating Wait Interval|Mating Interval]]",
EggHatch = "[[Breeding|Hatch/Gestation]]", CuddleInterval = "[[刷り込み|Cuddle Interval]]",
ImprintAmount = "[[刷り込み|Imprint]]", Hexagon = "[[HLN-A (Genesis)|Hexagon Bonus]]",
}
-- inverse index hash table mainly to optimise for look-up frequency. this gives
-- us an O(1) time instead of worst case O(n); best to not prolong a potential
-- rail module request i think
local Order = {
XP = 1, Harvesting = 2, Taming = 3, BabyMature = 4, MatingInterval = 5,
EggHatch = 6, CuddleInterval = 7, ImprintAmount = 8, Hexagon = 9,
}
function p.main(frame)
local args = frame.args
local ratesArgs = {
XP = tonumber(args.xp or 1),
Harvesting = tonumber(args.harvesting or 1),
Taming = tonumber(args.taming or 1),
BabyMature = tonumber(args.babyMature or 1),
MatingInterval = tonumber(args.matingInterval or 1),
EggHatch = tonumber(args.eggHatch or 1),
CuddleInterval = tonumber(args.cuddleInterval or 1),
ImprintAmount = tonumber(args.imprintAmount or 1),
Hexagon = tonumber(args.hexagon or 1),
}
-- create a hash table where for each rate value there's a key
local rateMap = {}
local rates = {}
for setting, value in pairs(ratesArgs) do
if rateMap[value] == nil then
rateMap[value] = {}
rates[#rates+1] = value
end
rateMap[value][#rateMap[value]+1] = setting
end
-- sort rates
table.sort(rates, function (a,b)
return a>b
end)
-- generate lists
local out = {}
for _, rate in ipairs(rates) do
-- sort setting names
local settings = rateMap[rate]
table.sort(settings, function (a,b)
return Order[a] < Order[b]
end)
-- render
local list = {}
local maxIndex = #settings
for index, setting in ipairs(settings) do
if index == maxIndex and index ~= 1 then
list[#list+1] = string.format("%s %s", Strings.And, Strings[setting])
else
list[#list+1] = Strings[setting]
end
end
-- generate our own ul-li structure due to a parser bug with tabbers.
-- if lists are emitted using wikitext into tabs in a tabber, with nothing
-- in between, second and each subsequent tab will have only the items rendered
-- and no list containers, as if it was continuing the previous tab's list.
out[#out+1] = "<li>" .. rate .. "x " .. table.concat(list, ", ") .. ".</li>"
end
return "<ul>" .. table.concat(out, "\n") .. "</ul>"
end
return p