Module:少女前线装备
来自OGAS数据中枢
更多操作
此模块的文档可以在Module:少女前线装备/doc创建
local p = {}
function processGunTypes(guntypesParam)
local gunTypes = {"AR", "HG", "SMG", "RF", "MG", "SG"}
local availableGuns = {}
local gunDisplays = {}
-- 处理参数
if type(guntypesParam) == "table" then
for _, gun in ipairs(guntypesParam) do
local gunStr = tostring(gun):upper():gsub("%s+", "")
availableGuns[gunStr] = true
end
end
-- 生成显示代码
for _, gunType in ipairs(gunTypes) do
if availableGuns[gunType] then
gunDisplays[gunType] = [[
style="background:DarkCyan;" | {{color|#f7f3f7|]] .. gunType .. [[}}
]]
else
gunDisplays[gunType] =[[
style="background:Gray;" | {{color|#8c8e8c|]] .. gunType .. [[}}
]]
end
end
return gunDisplays
end
function setRarity(rarityLevel)
-- 生成对应数量的五角星
if rarityLevel == 2 then
return "★★", "#f7f3f7"
elseif rarityLevel == 3 then
return "★★★", "#5ab6de"
elseif rarityLevel == 4 then
return "★★★★", "#8cc321"
elseif rarityLevel == 5 then
return "★★★★★", "#ffd700"
else
return "★", "#8c8e8c" -- 默认
end
end
-- 专门处理可能包含模板的参数
local function processParamWithTemplates(frame, param)
if not param or param == "" then
return ""
end
-- 如果参数包含模板语法,使用预处理
if param:match("{{.*}}") then
return frame:preprocess(param)
else
return param
end
end
function p.main(frame)
-- 获取参数
local args = frame:getParent().args
local name = args['装备名称'] or '未知装备'
local etype = args['装备类型'] or '未知类型'
local rarity = args['稀有度'] or 2
local image = args['装备图片'] or ''
local attr = args['属性'] or ''
local source = args['获得途径'] or ''
local manpower = args['强化所需资源(人力)'] or ''
local ammunition = args['强化所需资源(弹药)'] or ''
local ration = args['强化所需资源(口粮)'] or ''
local sparepart = args['强化所需资源(零件)'] or ''
local intro = args['装备介绍'] or ''
local about = args['装备相关'] or ''
local doll = args['特别人形'] or ''
-- 预处理可能包含模板的参数
local processedSource = processParamWithTemplates(frame, source)
local processedDoll = processParamWithTemplates(frame, doll)
local processedAttr = processParamWithTemplates(frame, attr)
-- 收集匿名参数(适配枪种)
local eligibleClasses = {}
-- 遍历参数(包括命名和匿名)
for key, value in pairs(args) do
-- 关键逻辑:如果key是数字(说明是匿名参数)且value不为空字符串
if type(tonumber(key)) == 'number' and value ~= '' then
table.insert(eligibleClasses, value)
end
end
local gunDisplays = processGunTypes(eligibleClasses)
local stars, m_color = setRarity(tonumber(rarity))
-- 判断doll是否为空,为空则不显示
local dollCell = ""
if processedDoll and processedDoll ~= "" then
dollCell = [[
style="background:DarkCyan;" rowspan=2 | <span style="color:white;">]] .. processedDoll .. [[</span>
]]
else
dollCell = [[
style="background:Gray;" rowspan=2 | <span style="color:#8c8e8c;">/</span>
]]
end
-- 构建完整的wikitext
local wikitext = {[===[
{| class="wikitable" style="text-align:center"
|-
| style="background-color:#393431;width:128px;" | {{color|#ffba00|<big>]===] .. stars .. [===[</big>}}
| style="background-color:#101410;width:128px;" | {{color|#f7f3f7|属性(MAX+10)}}
| style="background-color:#101410;width:128px;" | {{color|#f7f3f7|获得途径}}
| style="background-color:#101410;width:128px;" colspan="2" | {{color|#f7f3f7|强化所需资源}}
| style="background-color:#101410;width:128px;" colspan="2" | {{color|#f7f3f7|适用单位}}
|-
| style="background-color:]===].. m_color .. [===[;width:128px;" rowspan="4" | ]===] .. image .. [===[
| style="background-color:#393431;" rowspan="4" | <span style="color:#8c8e8c;">]===] .. processedAttr .. [===[</span>
| style="background-color:#393431;" rowspan="4" | <span style="color:#8c8e8c;">]===] .. processedSource .. [===[</span>
| style="background-color:#393431;width:64px;" | {{color|#f7f3f7|人力}}
| style="background-color:#393431;width:64px;" | <span style="color:#8c8e8c;">]===] .. manpower .. [===[</span>
| ]===] .. gunDisplays.HG .. [===[
| ]===] .. gunDisplays.MG .. [===[
|-
| style="background-color:#393431;" | {{color|#f7f3f7|弹药}}
| style="background-color:#393431;" | <span style="color:#8c8e8c;">]===] .. ammunition .. [===[</span>
| ]===] .. gunDisplays.AR .. [===[
| ]===] .. gunDisplays.SG .. [===[
|-
| style="background-color:#393431;" | {{color|#f7f3f7|口粮}}
| style="background-color:#393431;" | <span style="color:#8c8e8c;">]===] .. ration .. [===[</span>
| ]===] .. gunDisplays.RF .. [===[
| ]===] .. dollCell .. [===[
|-
| style="background-color:#393431;" | {{color|#f7f3f7|零件}}
| style="background-color:#393431;" | <span style="color:#8c8e8c;">]===] .. sparepart .. [===[</span>
| ]===] .. gunDisplays.SMG .. [===[
|-
| style="background-color:#101410;" rowspan="2" | {{color|]===].. m_color .. [===[|]===] .. name .. [===[}}<br>{{color|#8c8e8c|]===] .. etype .. [===[}}
| style="background-color:#101410;width:512px;" colspan="6" | {{color|#f7f3f7|装备介绍}}
|-
| style="background-color:#393431;width:512px;" colspan="6" | <span style="color:#8c8e8c;">]===] .. intro .. [===[</span>
|-
| style="background-color:#101410;width:640px;" colspan="7" | {{color|#f7f3f7|装备相关}}
|-
| style="background-color:#393431;width:640px;" colspan="7" | <span style="color:#8c8e8c;">]===] .. about .. [===[</span>
|}
]===]}
local full_wikitext = table.concat(wikitext)
return frame:preprocess(full_wikitext)
end
return p