local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.main(frame)
local args = getArgs(frame, {wrappers = {"Template:沙盒", "Template:明日方舟模组"}})
return p._main(frame, args)
end
function p._main(frame, args)
local rootPageName = mw.title.getCurrentTitle().text
local operatorName = args['干员名'] or rootPageName:gsub("(明日方舟)", "")
-- 构建证章标签页
local badgeTab = p.createBadgeTab(args, operatorName)
-- 构建模组标签页
local moduleTabs = p.createModuleTabs(args)
-- 组合所有内容
local output = p.buildOutput(badgeTab, moduleTabs)
return frame:preprocess(output)
end
function p.createBadgeTab(args, operatorName)
local professionBranch = args['职业分支']
local badgeInfo = args['证章信息'] or "''暂无资料''"
local badgeImage = "{{#img:{{filepath:明日方舟模组_证章.png}}|width=100%|alt=明日方舟模组 证章}}{{链入文件|明日方舟模组_证章.png}}"
local overlayContent
if professionBranch then
overlayContent = string.format(
'{{mask|target=.akm-subprofession-overlay|image=明日方舟职业_分支_%s.png}}' ..
'<div class="akm-subprofession-overlay" style="position:absolute;left:35.5%%;top:38%%;width:22.5%%;height:22.5%%;background:#C2C3A5;-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center;"></div>',
professionBranch
)
else
overlayContent = '<div style="position:absolute;left:35.5%;top:48%;width:22.5%;height:22.5%;color:#C2C3A5;text-align:center;font-size:70px;line-height:0;font-weight:800">?</div>'
end
return string.format([[
<div class="Tab">
<div class="TabLabelText">%s证章</div>
<div class="TabContentText">
<div class="akm-unitcell">
<div class="module-img-div" style="position:relative;">
%s%s
</div>
<div class="module-info-div" style="margin-bottom:-25px;">
<div class="module-info-type" style="position:relative;top:-6.5px;">
<div>{{#img:{{filepath:AkModuleType_Original.png}}|height=30px|alt=ORIGINAL}}{{链入文件|AkModuleType_Original.png}}</div>
<div>ORIGINAL</div>
</div>
<div class="module-info-name" style="position:relative;top:-6.5px;">
<div>CUSTOMIZE MODULE AUTHORIZED</div>
<div>%s证章</div>
</div>
<div class="module-info-header">'''基础信息'''</div>
<div id="module-info-body-1" class="module-info-body">%s</div>
</div>
</div>
</div>
</div>]], operatorName, badgeImage, overlayContent, operatorName, badgeInfo)
end
-- 辅助函数:获取参数值,支持无数字后缀和有数字后缀两种形式
function p.getModuleArg(args, baseName, index, defaultValue)
-- 优先使用带数字后缀的参数
local value = args[baseName .. index]
if value then
return value
end
-- 如果没有数字后缀且是第一个模块,尝试使用无数字后缀的参数
if index == 1 then
value = args[baseName]
if value then
return value
end
end
return defaultValue
end
function p.createModuleTabs(args)
local tabs = {}
local index = 1
-- 检查是否有模块参数(支持无数字后缀和有数字后缀两种形式)
while p.getModuleArg(args, '模组名', index, nil) do
local moduleName = p.getModuleArg(args, '模组名', index, "''UNKNOWN MODULE''")
local moduleType = p.getModuleArg(args, '模组类型', index, "UNKNOWN")
local moduleInfo = p.getModuleArg(args, '模组信息', index, "''暂无资料''")
local unlockReq = p.getModuleArg(args, '解锁需求', index, "")
local unlockCost = p.getModuleArg(args, '解锁消耗', index, "")
-- 构建模组图片部分
local moduleImage
if moduleName ~= "''UNKNOWN MODULE''" then
moduleImage = string.format([=[
<div style="position:absolute;left:0;top:0;width:300px;text-align:center;z-index:2;">
{{HighBrightnessMod|selector=.module-img-background, .ak-module .HighBrightnessMod input|minimumBrightness=0}}
</div>
<div class="module-img-background" style="background-color:#FFF;position:absolute;left:0;bottom:0;width:300px;height:300px;"></div>
{{#img:{{filepath:明日方舟模组_%s.png}}|width=100%%|alt="%s"}}{{链入文件|明日方舟模组_%s.png}}]=],
moduleName, moduleName, moduleName
)
else
moduleImage = '<div style="color:#0004;font-weight:800;font-size:200px;text-align:center">?</div>'
end
-- 构建模组任务部分
local moduleTasks = p.buildModuleTasks(args, index)
-- 构建升级消耗部分
local upgradeCosts = p.buildUpgradeCosts(args, index)
-- 构建数值变化部分
local statChanges = p.buildStatChanges(args, index)
-- 组合所有内容
local tabContent = string.format([=[
<div class="Tab">
<div class="TabLabelText">%s</div>
<div class="TabContentText">
<div class="akm-unitcell">
<div class="module-img-div">%s</div>
<div class="module-info-div" style="margin-bottom:-25px;">
<div class="module-info-type" style="position:relative;top:-6.5px;">
%s
<div>%s</div>
</div>
<div class="module-info-name" style="position:relative;top:-6.5px;">
<div>CUSTOMIZE MODULE AUTHORIZED</div>
<div>%s</div>
</div>
<div class="module-info-header">'''基础信息'''</div>
<div class="module-info-body">%s</div>
</div>
%s
</div>
</div>
</div>]=], moduleName, moduleImage,
p.buildModuleTypeIcon(moduleType), moduleType, moduleName, moduleInfo,
p.buildModuleTable(moduleTasks, unlockReq, unlockCost, upgradeCosts, statChanges, index))
table.insert(tabs, tabContent)
index = index + 1
end
return table.concat(tabs, "\n")
end
function p.buildModuleTypeIcon(moduleType)
if moduleType ~= "UNKNOWN" then
return string.format([=[
<div>{{#img:{{filepath:AkModuleType_%s.png}}|height:30px|alt=%s}}{{链入文件|AkModuleType_%s.png}}</div>]=],
moduleType, moduleType, moduleType
)
else
return '<div style="color:#fff;font-weight:800;font-size:35px;line-height:40px;text-align:center">?</div>'
end
end
function p.buildModuleTasks(args, index)
local tasks = {}
local taskIndex = 1
-- 检查任务参数(支持无数字后缀和有数字后缀两种形式)
while args['模组任务' .. index .. '-' .. taskIndex] or (index == 1 and args['模组任务-' .. taskIndex]) do
local task = args['模组任务' .. index .. '-' .. taskIndex] or (index == 1 and args['模组任务-' .. taskIndex])
table.insert(tasks, task)
taskIndex = taskIndex + 1
end
return tasks
end
function p.buildUpgradeCosts(args, index)
local costs = {}
local costIndex = 1
-- 检查升级消耗参数(支持无数字后缀和有数字后缀两种形式)
while args['升级消耗' .. index .. '-' .. costIndex] or (index == 1 and args['升级消耗-' .. costIndex]) do
local cost = args['升级消耗' .. index .. '-' .. costIndex] or (index == 1 and args['升级消耗-' .. costIndex])
table.insert(costs, cost)
costIndex = costIndex + 1
end
return costs
end
function p.buildStatChanges(args, index)
local changes = {}
local changeIndex = 1
-- 检查数值变化参数(支持无数字后缀和有数字后缀两种形式)
while args['基础数值变化' .. index .. '-' .. changeIndex] or (index == 1 and args['基础数值变化-' .. changeIndex]) do
local statChange = args['基础数值变化' .. index .. '-' .. changeIndex] or (index == 1 and args['基础数值变化-' .. changeIndex]) or ""
local traitUpdate = args['分支特性更新' .. index .. '-' .. changeIndex] or (index == 1 and args['分支特性更新-' .. changeIndex]) or ""
table.insert(changes, {stat = statChange, trait = traitUpdate})
changeIndex = changeIndex + 1
end
return changes
end
function p.buildModuleTable(tasks, unlockReq, unlockCost, upgradeCosts, statChanges, index)
if #tasks == 0 then
return ""
end
local taskRows = {}
for i, task in ipairs(tasks) do
if i == 1 then
table.insert(taskRows, string.format([=[
<tr>
<th style="min-width:5em;" rowspan="%d">模组任务</th>
<td colspan="2">%s</td>
</tr>]=], #tasks, task))
else
table.insert(taskRows, string.format([=[
<tr>
<td colspan="2">%s</td>
</tr>]=], task))
end
end
local costRows = {}
for i, cost in ipairs(upgradeCosts) do
if i == 1 then
table.insert(costRows, string.format([=[
<tr>
<th style="min-width:5em;" rowspan="%d">升级消耗</th>
<td colspan="2">[[File:明日方舟模组阶段_1.png|50px|link=|阶段1]]<div style="background-color:#3B3B3B;height:7px;width:10px;display:inline-block;margin-left:10px;"></div><div style="width: 0;height: 0; border-left: 7px solid #3B3B3B; border-top: 7px solid transparent; border-bottom: 7px solid transparent;display:inline-block;padding-right:10px;position:relative;top:3.8px;"></div>[[File:明日方舟模组阶段_2.png|50px|link=|阶段2]]%s</td>
</tr>]=], #upgradeCosts, cost))
else
table.insert(costRows, string.format([=[
<tr>
<td colspan="2">[[File:明日方舟模组阶段_%d.png|50px|link=|阶段%d]]<div style="background-color:#3B3B3B;height:7px;width:10px;display:inline-block;margin-left:10px;"></div><div style="width: 0;height: 0; border-left: 7px solid #3B3B3B; border-top: 7px solid transparent; border-bottom: 7px solid transparent;display:inline-block;padding-right:10px;position:relative;top:3.8px;"></div>[[File:明日方舟模组阶段_%d.png|50px|link=|阶段%d]]%s</td>
</tr>]=], i, i, i+1, i+1, cost))
end
end
local statRows = {}
for i, change in ipairs(statChanges) do
if i == 1 then
table.insert(statRows, string.format([=[
<tr>
<td style="vertical-align:middle;text-align:center">[[File:明日方舟模组阶段_1.png|50px|link=|阶段1]]</td>
<td>%s</td>
<td>%s</td>
</tr>]=], change.stat, change.trait))
else
table.insert(statRows, string.format([=[
<tr>
<td style="vertical-align:middle;text-align:center">[[File:明日方舟模组阶段_%d.png|50px|link=|阶段%d]]</td>
<td>%s</td>
<td>%s</td>
</tr>]=], i, i, change.stat, change.trait))
end
end
return string.format([=[
<table class="wikitable" style="width:100%%;margin:0;background-color:#FFF;">
%s
<tr>
<th style="min-width:5em;">解锁需求</th>
<td colspan="2">%s</td>
</tr>
<tr>
<th style="min-width:5em;">解锁消耗</th>
<td colspan="2">%s</td>
</tr>
%s
<tr>
<th style="min-width:3em;">阶段</th>
<th style="min-width:7em;">基础数值变化</th>
<th style="min-width:7em;">分支特性更新</th>
</tr>
%s
</table>]=], table.concat(taskRows, "\n"), unlockReq, unlockCost,
table.concat(costRows, "\n"), table.concat(statRows, "\n"))
end
function p.buildOutput(badgeTab, moduleTabs)
return string.format([=[
{| class="wikitable mw-collapsible ak-module"
! style="background-color:#000;border-bottom:2px solid #2BF;-webkit-text-fill-color:#FFF;"|'''{{color|white;-webkit-text-fill-color:#FFF;|模组}}'''
|-
|style="padding:0;"|
<div class="Tabs" data-label-side="top" data-label-padding="0.5em" data-label-border-color="transparent" data-label-color="transparent" data-text-border-color="transparent" data-text-padding="0" data-label-background-color="#000">
%s
%s
</div>
|}
]=], badgeTab, moduleTabs)
end
return p