全站通知:
模块:GiftsByItem
刷
历
编
跳到导航
跳到搜索
- 作用
用于物品人物喜好列表的生成,能够进行全自动的格式化和排序。
人物按照一定的逻辑排序,此外还对排版显示上进行了一定的优化。
如果该模块存在任何问题,请在 Template:GiftsByItem 的讨论页中反馈。
local p = {}
local predefinedOrder = {
"哈维", "山姆", "谢恩", "亚历克斯", "艾利欧特", "塞巴斯蒂安",
"海莉", "莉亚", "玛鲁", "潘妮", "艾米丽", "阿比盖尔",
"皮埃尔", "卡洛琳", "刘易斯", "玛妮", "罗宾", "德米特里厄斯",
"艾芙琳", "乔治", "贾斯", "文森特", "乔迪", "肯特",
"威利", "格斯", "潘姆", "莱纳斯", "克林特",
"法师", "矮人", "科罗布斯", "桑迪", "雷欧",
}
--ts = translate & sort
function p.ts(frame)
local villagerlist = frame.args[1]
if villagerlist ~= nil then
local vtable = {}
local villagers = mw.text.split(villagerlist, ",", true)
for i = 1, #villagers do
local v = mw.text.trim(villagers[i])
if v ~= "" then
table.insert(vtable, v)
end
end
--remove duplicate entries
local dupes = {}
local villagertable = {}
for i = 1, #vtable do
if not dupes[vtable[i]] then
table.insert(villagertable, vtable[i])
dupes[vtable[i]] = true
end
end
table.sort(villagertable)
for k,v in pairs(villagertable) do
if v == "Alex" then villagertable[k] = "亚历克斯" end
if v == "Elliott" then villagertable[k] = "艾利欧特" end
if v == "Harvey" then villagertable[k] = "哈维" end
if v == "Sam" then villagertable[k] = "山姆" end
if v == "Sebastian" then villagertable[k] = "塞巴斯蒂安" end
if v == "Shane" then villagertable[k] = "谢恩" end
if v == "Abigail" then villagertable[k] = "阿比盖尔" end
if v == "Emily" then villagertable[k] = "艾米丽" end
if v == "Haley" then villagertable[k] = "海莉" end
if v == "Leah" then villagertable[k] = "莉亚" end
if v == "Maru" then villagertable[k] = "玛鲁" end
if v == "Penny" then villagertable[k] = "潘妮" end
if v == "Caroline" then villagertable[k] = "卡洛琳" end
if v == "Clint" then villagertable[k] = "克林特" end
if v == "Demetrius" then villagertable[k] = "德米特里厄斯" end
if v == "Dwarf" then villagertable[k] = "矮人" end
if v == "Evelyn" then villagertable[k] = "艾芙琳" end
if v == "George" then villagertable[k] = "乔治" end
if v == "Gus" then villagertable[k] = "格斯" end
if v == "Jas" then villagertable[k] = "贾斯" end
if v == "Jodi" then villagertable[k] = "乔迪" end
if v == "Kent" then villagertable[k] = "肯特" end
if v == "Krobus" then villagertable[k] = "科罗布斯" end
if v == "Leo" then villagertable[k] = "雷欧" end
if v == "Lewis" then villagertable[k] = "刘易斯" end
if v == "Linus" then villagertable[k] = "莱纳斯" end
if v == "Marnie" then villagertable[k] = "玛妮" end
if v == "Pam" then villagertable[k] = "潘姆" end
if v == "Pierre" then villagertable[k] = "皮埃尔" end
if v == "Robin" then villagertable[k] = "罗宾" end
if v == "Sandy" then villagertable[k] = "桑迪" end
if v == "Vincent" then villagertable[k] = "文森特" end
if v == "Willy" then villagertable[k] = "威利" end
if v == "Wizard" then villagertable[k] = "法师" end
end
-- Custom sort
table.sort(villagertable, function(a, b)
local indexA = 0
local indexB = 0
for i, name in ipairs(predefinedOrder) do
if a == name then indexA = i end
if b == name then indexB = i end
end
return indexA < indexB
end)
--put the table "villagertable" back into a string blob
--table.concat( table, sep, i, j ) DOES NOT WORK
villagerlist = ""
for i = 1, (#villagertable-1) do
villagerlist = villagerlist .. '<span class="no-wrap">[[File:' .. villagertable[i] .. ' Icon.png|24px|link=' .. villagertable[i] .. ']] [[' .. villagertable[i] .. ']]</span> • '
end
--We don't want a trailing bullet at the end of the list
villagerlist = villagerlist .. '<span class="no-wrap">[[File:' .. villagertable[#villagertable] .. ' Icon.png|24px|link=' .. villagertable[#villagertable] .. ']] [[' .. villagertable[#villagertable] .. ']]</span>'
--Now that we've sorted by the native language,
--fix icons whose names are all in English
--Also add the é to Leo for French
--so I don't have to write an entire substitution table for accented chars
villagerlist = string.gsub(villagerlist, "亚历克斯 Icon", "Alex Icon")
villagerlist = string.gsub(villagerlist, "艾利欧特 Icon", "Elliott Icon")
villagerlist = string.gsub(villagerlist, "哈维 Icon", "Harvey Icon")
villagerlist = string.gsub(villagerlist, "山姆 Icon", "Sam Icon")
villagerlist = string.gsub(villagerlist, "塞巴斯蒂安 Icon", "Sebastian Icon")
villagerlist = string.gsub(villagerlist, "谢恩 Icon", " Shane Icon")
villagerlist = string.gsub(villagerlist, "阿比盖尔 Icon", "Abigail Icon")
villagerlist = string.gsub(villagerlist, "艾米丽 Icon", "Emily Icon")
villagerlist = string.gsub(villagerlist, "海莉 Icon", "Haley Icon")
villagerlist = string.gsub(villagerlist, "莉亚 Icon", "Leah Icon")
villagerlist = string.gsub(villagerlist, "玛鲁 Icon", "Maru Icon")
villagerlist = string.gsub(villagerlist, "潘妮 Icon", "Penny Icon")
villagerlist = string.gsub(villagerlist, "卡洛琳 Icon", "Caroline Icon")
villagerlist = string.gsub(villagerlist, "克林特 Icon", "Clint Icon")
villagerlist = string.gsub(villagerlist, "德米特里厄斯 Icon", "Demetrius Icon")
villagerlist = string.gsub(villagerlist, "矮人 Icon", "Dwarf Icon")
villagerlist = string.gsub(villagerlist, "艾芙琳 Icon", "Evelyn Icon")
villagerlist = string.gsub(villagerlist, "乔治 Icon", "George Icon")
villagerlist = string.gsub(villagerlist, "格斯 Icon", "Gus Icon")
villagerlist = string.gsub(villagerlist, "贾斯 Icon", "Jas Icon")
villagerlist = string.gsub(villagerlist, "乔迪 Icon", "Jodi Icon")
villagerlist = string.gsub(villagerlist, "肯特 Icon", "Kent Icon")
villagerlist = string.gsub(villagerlist, "科罗布斯 Icon", "Krobus Icon")
villagerlist = string.gsub(villagerlist, "雷欧 Icon", "Leo Icon")
villagerlist = string.gsub(villagerlist, "刘易斯 Icon", "Lewis Icon")
villagerlist = string.gsub(villagerlist, "莱纳斯 Icon", "Linus Icon")
villagerlist = string.gsub(villagerlist, "玛妮 Icon", "Marnie Icon")
villagerlist = string.gsub(villagerlist, "潘姆 Icon", "Pam Icon")
villagerlist = string.gsub(villagerlist, "皮埃尔 Icon", "Pierre Icon")
villagerlist = string.gsub(villagerlist, "罗宾 Icon", "Robin Icon")
villagerlist = string.gsub(villagerlist, "桑迪 Icon", "Sandy Icon")
villagerlist = string.gsub(villagerlist, "文森特 Icon", "Vincent Icon")
villagerlist = string.gsub(villagerlist, "威利 Icon", "Willy Icon")
villagerlist = string.gsub(villagerlist, "法师 Icon", "Wizard Icon")
return villagerlist
end --if villagerlist == nil, then do nothing but return p
end --end function p.ts()
return p