local function makeReverseMap(objs)
local map = {}
for key, obj in pairs(objs) do
obj.id = key
map[key] = key
for _, alias in ipairs(obj.alias or {}) do
map[mw.ustring.lower(alias)] = key
end
end
return map
end
local function makeGetFunc(objs, map)
return function(name)
if not name then return nil end
local id = map[mw.ustring.lower(name)]
return id and objs[id] or nil
end
end
local attrData = {
smile = {
alias = { '粉', '桃红', '桃' },
fileName = '桃红',
text = '桃',
picture = '[[File:AS_Smile.png|24px|link=|Smile]]',
color = '#df49a6',
bgColor = '#eb90c8',
sortOrder = 1
},
pure = {
alias = { '绿' },
picture = '[[File:AS_Pure.png|24px|link=|Pure]]',
color = '#37a75c',
bgColor = '#9ddeb2',
sortOrder = 2
},
cool = {
alias = { '蓝' },
picture = '[[File:AS_Cool.png|24px|link=|Cool]]',
color = '#0099ee',
bgColor = '#7dcfff',
sortOrder = 3
},
active = {
alias = { '红' },
picture = '[[File:AS_Active.png|24px|link=|Active]]',
color = '#da3e3f',
bgColor = '#e99292',
sortOrder = 4
},
natural = {
alias = { '黄' },
picture = '[[File:AS_Natural.png|24px|link=|Natural]]',
color = '#edbb3e',
bgColor = '#f3d488',
sortOrder = 5
},
elegant = {
alias = { '紫' },
picture = '[[File:AS_Elegant.png|24px|link=|Elegant]]',
color = '#86509c',
bgColor = '#c6a9d2',
sortOrder = 6
},
none = {
alias = {},
picture = '[[File:AS_None.png|24px|link=|None]]',
color = '#666666',
bgColor = '#d8d9da',
sortOrder = 7
}
}
local allAttrs = { attrData.active, attrData.cool, attrData.pure, attrData.natural, attrData.elegant, attrData.smile }
local attrMap = makeReverseMap(attrData)
local getAttr = makeGetFunc(attrData, attrMap)
local kindData = {
vo = {
alias = { '张力', '热度' },
text = {
zhHans = '热度',
zhHant = '張力'
}
},
sk = {
alias = { '技能' },
text = {
zhHans = '技能',
zhHant = '技能'
}
},
sp = {
alias = { '组合技' },
text = {
zhHans = 'SP',
zhHant = '組合技'
}
},
gd = {
alias = { '强化', '防御' },
text = {
zhHans = '防御',
zhHant = '強化'
}
}
}
local allKinds = { kindData.vo, kindData.sp, kindData.gd, kindData.sk }
local kindMap = makeReverseMap(kindData)
local getKind = makeGetFunc(kindData, kindMap)
local itemData = {
g = {
alias = { '金币' },
fileName = 'AS金币',
text = '金币',
defaultNum = 10000,
measure = ''
},
sblg = {
alias = { 'sblm', 'sbl奖牌' },
fileName = {
'22001',
['无底'] = 'SBLcoin',
['无框'] = 'SBLcoin',
['白'] = 'SBLcoin',
},
text = '大型合作演唱会奖章',
defaultNum = 250,
measure = '枚'
},
dlpg = {
alias = { 'dlpm', 'dlp奖牌' },
fileName = 'AS_DLP币',
text = '巡演奖章',
defaultNum = 250,
measure = '枚'
},
star = {
alias = { '星', '星石', '虹彩星石', '爱星' },
fileName = '虹彩星石',
text = '虹彩星石',
defaultNum = 10,
measure = '个'
},
exp = {
alias = { '经验', '经验值' },
fileName = 'AS经验值',
text = '经验值',
defaultNum = 10000,
measure = ''
},
skip = {
alias = { '跳略券', '跳过券' },
fileName = '跳略券',
text = '跳过券',
defaultNum = 5,
measure = '张'
},
lp50 = {
alias = { '糖50' },
fileName = '演唱会糖果50%%',
text = '演唱会糖果(50%s)',
defaultNum = 1,
measure = '个'
},
lp100 = {
alias = { '糖100' },
fileName = '演唱会糖果100%%',
text = '演唱会糖果(100%s)',
defaultNum = 1,
measure = '个'
},
['羽毛'] = {
alias = { '光石', '学园偶像光石', '光辉', '学园偶像的光辉' },
fileName = '学园偶像光石',
text = '学园偶像的光辉',
defaultNum = 1,
measure = '个'
},
['大羽毛'] = {
alias = { '心愿', '学园偶像心愿' },
fileName = '学园偶像的心愿',
text = '学园偶像的心愿',
defaultNum = 1,
measure = '个'
},
['大人头交换券'] = {
alias = { '高级记忆碎片交换券' },
fileName = '高级记忆碎片交换券',
text = '高级记忆碎片交换券',
defaultNum = 1,
measure = '张'
},
['勋章'] = {
alias = { '学园偶像勋章', '凭证', '学园偶像的凭证' },
fileName = '学园偶像勋章',
text = '学园偶像的凭证',
defaultNum = 1,
measure = '个'
},
['集训票'] = {
alias = { '集训票券', '合宿券' },
fileName = '集训票券',
text = '合宿券',
defaultNum = 1,
measure = '张'
},
['灯泡'] = {
alias = { '胸章', '经验技能胸章', '徽章', '灵感徽章' },
fileName = '经验技能胸章',
text = '灵感徽章★1',
defaultNum = 1,
measure = '个'
},
['护身符'] = {
alias = { '幸运护身符' },
fileName = '幸运护身符',
text = '幸运护身符★1',
defaultNum = 1,
measure = '个'
},
['马卡龙'] ={
alias = { '马' },
fileName = '%s星%s色马卡龙',
text = '马卡龙★%s',
defaultNum = 100,
measure = '个',
numParam = 4
},
['晶球'] ={
alias = { '珠子' },
fileName = '%s晶球',
text = '珠子',
defaultNum = 10,
measure = '个',
numParam = 3
},
ur = {
alias = {},
fileName = 'LLAS Icon UR'
},
sr = {
alias = {},
fileName = 'LLAS Icon SR'
},
['书'] ={
alias = {},
fileName = '%s%s手册',
text = '%s书',
defaultNum = 10,
measure = '本',
numParam = 4
},
['植物'] ={
alias = {},
fileName = '%s%s',
text = '%s',
defaultNum = 10,
measure = '个',
numParam = 4
}
}
local itemMap = makeReverseMap(itemData)
local getItem = makeGetFunc(itemData, itemMap)
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
local args = getArgs(frame)
return p._main(frame, args)
end
function p._main(frame, args)
local function writeImg(...)
local fileName = mw.ustring.format(...) .. '.png'
local filePath = frame:callParserFunction('filepath', fileName)
return frame:callParserFunction('#img', { filePath, style = 'width:24px' })
end
local function writeColor(color, text)
return frame:expandTemplate{ title = 'color', args = { color, text } }
end
if not args[1] then
return ''
end
local arg1 = mw.ustring.lower(args[1])
if not arg1 or arg1 == '' then
return ''
elseif mw.ustring.find(arg1, '^pic') then
-- 属性图标
local attr = getAttr(mw.ustring.sub(arg1, 4))
return attr and attr.picture or ''
elseif mw.ustring.find(arg1, '^tx') then
-- 属性颜色代码
local attr = getAttr(mw.ustring.sub(arg1, 3))
return attr and attr.color or ''
elseif mw.ustring.find(arg1, '^t') then
-- 带排序参数的属性图标
local attr = getAttr(mw.ustring.sub(arg1, 2))
return attr and mw.ustring.format('data-sort-value="%d"|%s', attr.sortOrder, attr.picture) or ''
elseif mw.ustring.find(arg1, '^bg') then
-- 属性背景颜色
local attr = getAttr(mw.ustring.sub(arg1, 3))
return attr and mw.ustring.format('style="background: %s;"', attr.bgColor) or ''
end
local item = getItem(arg1)
if not item then
return ''
elseif item.id == 'ur' or item.id == 'sr' then
-- UR / SR
local attr = getAttr(args[2])
if not attr then return '' end
local img = writeImg(item.fileName)
local span = mw.html.create('span')
:addClass('nomobile')
:wikitext(attr.picture)
:done()
local colorText = writeColor(attr.color, mw.ustring.format("'''%s'''", args[3] or ''))
return img .. ' ' .. tostring(span) .. ' ' .. colorText
end
local img = ''
local kindOrColorText = ''
local itemText = item.text
if item.id == '书' or item.id == '植物' then
-- 书 / 植物
if not args[2] or not args[3] then return '' end
local kinds
if args[2] == 'all' then
kinds = allKinds
kindOrColorText = '各类'
else
local kind = getKind(args[2])
if not kind then return '' end
kinds = { kind }
kindOrColorText = mw.ustring.format('-{zh-hant:《%s》;zh-hans:%s类型}-', kind.text.zhHant, kind.text.zhHans)
end
for _, k in ipairs(kinds) do
img = img .. writeImg(item.fileName, k.alias[1], args[3]) -- 书: '%s%s手册'; 植物: '%s%s'
end
itemText = mw.ustring.format(item.text, args[3]) -- 书: '%s书'; 植物: '%s'
elseif item.id == '马卡龙' then
-- 马卡龙
if not args[2] or not args[3] then return '' end
local attrs
if args[3] == 'all' then
attrs = allAttrs
kindOrColorText = '各色'
else
local attr = getAttr(args[3]) or { alias = {args[3]} }
attrs = { attr }
local textToColor = (attr.text or attr.alias[1]) .. '色'
kindOrColorText = attr.color and writeColor(attr.color, textToColor) or textToColor
end
for _, a in ipairs(attrs) do
img = img .. writeImg(item.fileName, args[2], a.fileName or a.alias[1]) -- '%s星%s色马卡龙'
end
itemText = mw.ustring.format(item.text, args[2]) -- '马卡龙★%s'
elseif item.id == '晶球' then
-- 晶球
if not args[2] then return '' end
local attr = getAttr(args[2]) or { alias = {args[3]} }
if not attr then return '' end
img = writeImg(item.fileName, attr.id) -- '%s晶球'
local lang = mw.language.getContentLanguage()
kindOrColorText = writeColor(attr.color, lang:ucfirst(attr.id))
elseif item.id == 'lp50' or item.id == 'lp100' then
-- 演唱会糖果
img = writeImg(item.fileName)
itemText = mw.ustring.format(item.text, args[3] or '') -- '演唱会糖果(50%s)' / '演唱会糖果(100%s)'
elseif item.id == 'sblg' then
-- SBL奖牌
img = writeImg(item.fileName[args[3]] or item.fileName[1])
else
img = writeImg(item.fileName)
end
local result = img .. ' ' .. kindOrColorText .. itemText
local num = args[item.numParam or 2]
if num ~= 'none' and num ~= '0' and num ~= 0 then
num = num or item.defaultNum
if item.id == 'g' or item.id == 'exp' then
-- 金币 / 经验值
local lang = mw.language.getContentLanguage()
num = lang:formatNum(tonumber(num))
end
result = result .. ' ' .. tostring(num) .. (item.measure or '')
end
return result
end
return p