local p = {}
local args = {}
local parentarg = {}
local mw = mw
local data = mw.loadData("模块:战舰少女:特殊数据")
local ships = data.ships
local fr = {}
local function getShipname() return mw.text.trim(args[1]) end
--- 图鉴编号
local function getShipnum(sname)
if sname ~= nil and ships[sname] ~= nil then
return ships[sname].index
end
local ship = ships[getShipname()]
return ship and ship.index or 0
end
local function isFileExsist(fname)
local title = mw.title.new('File:' .. fname)
return title and title.fileExists
end
--- 中文语音文件名
local function cfn(shipname, stageKey, stage)
if args['prefix'] ~= nil and stage ~= nil then
local ship = ships[shipname]
return ship[args['prefix'] .. '-' .. stage .. "(中)"]
end
return string.format("舰R中文-%d_%s.mp3", getShipnum(shipname),
stageKey)
end
--- 日文语音文件名
local function jfn(shipname, stageKey, stage)
if args['prefix'] ~= nil and stage ~= nil then
local ship = ships[shipname]
return ship[args['prefix'] .. '-' .. stage .. "(日)"]
end
return string.format("舰R日文-%d_%s.mp3", getShipnum(shipname),
stageKey)
end
local function hasCNVoice(shipname)
local fn = cfn(shipname, "get")
return parentarg['语音(中)'] or isFileExsist(fn)
end
local function hasJPVoice(shipname)
local fn = jfn(shipname, "get")
return parentarg['语音(日)'] or isFileExsist(fn)
end
--- 改装名
-- local function shipmod() return ships[getShipname()]['mod'] end
local stages = {
{'获得', 'get'},
{'白天1', 'main_01'},
{'白天2', 'main_02'},
{'白天3', 'main_03'},
{'誓约-白天1', 'main_13'},
{'誓约-白天2', 'main_14'},
{'誓约-白天3', 'main_15'},
{'夜间1', 'main_07'},
{'夜间2', 'main_08'},
{'夜间3', 'main_09'},
{'誓约-夜间1', 'main_16'},
{'誓约-夜间2', 'main_17'},
{'誓约-夜间3', 'main_18'},
{'拜访好友', 'friend_room'},
{'提督室', 'my_room'},
{'阵型', 'formation'},
{'攻击', 'atk'},
{'夜战', 'night_atk'},
{'中破', 'break'},
{'沉没', 'sink'},
{'MVP', 'mvp'},
{'誓约', 'vow'},
}
--- 表头
local function createTableHead(shipname)
local css1 =
'background:#3A7194;color:white;padding:0px 10px;text-align:center;width:5em;'
local css2 =
'background:#3A7194;color:white;padding:0px 10px;text-align:center;'
local css3 =
'background:#3A7194;color:white;padding:0px 10px;text-align:center;width:40px;'
local heads = mw.html.create('tr')
heads:tag('th'):cssText(css1):wikitext('场合'):done()
heads:tag('th'):cssText(css2):wikitext("'''内容'''"):done()
if args['hasCNVoice'] then
heads:tag('th'):wikitext("'''语音(中)'''"):cssText(css3)
end
if args['hasJPVoice'] then
heads:tag('th'):wikitext("'''语音(日)'''"):cssText(css3)
end
return tostring(heads)
end
--- 台词行
local function createTableline(stage, stageKey, shipname)
local special = stage:sub(-2) == "誓约"
local color = '#CCE9FD' --- 非第一列的背景颜色
if special then
color = "#FFD2D2"
end
local line = mw.html.create('tr')
--- 第一列有颜色
local css1 = {
background = special and "#FF9C9C" or "#4682B4",
color = "white",
}
css1["text-align"] = "center"
line:tag("td"):css(css1):wikitext(stage):done()
local css2 = {
background = color,
color = "black",
padding = "0px 10px",
}
local ship = ships[shipname]
if ship == nil then
return
end
local paramname = stage
if args['param-prefix'] ~= nil then
paramname = args['param-prefix'] .. paramname
end
local raw = parentarg[paramname] or ship[stage]
if args['prefix'] ~= nil then
paramname = args['prefix'] .. '-' .. stage
raw = ship[paramname]
end
if raw == nil then
return ""
end
if stage == "沉没" then
txt = fr:preprocess(string.format("{{黑幕|%s}}", raw))
else
txt = raw
end
line:tag("td"):css(css2):wikitext(txt):done()
local css3 = {color = "black", background = color}
local cssdil = "display:inline-block;"
local function voices(vtype)
local div = line:tag('td'):css(css3):tag('div')
:cssText(cssdil)
local fname = vtype(shipname, stageKey, stage)
if fname == nil then
return
end
local s = string.format("[[File:%s|30px]]", fname)
-- if not isFileExsist(fname) then
-- return
-- end
div:wikitext(s)
end
if args['hasCNVoice'] then
voices(cfn)
end
if args['hasJPVoice'] then
voices(jfn)
end
return tostring(line)
end
--- 构造表格
local function createTable(shipname)
local css1 =
'text-align:left;border:solid #aaa 1px;padding:0.1em;max-width:1000em;'
local full = mw.html.create('table'):cssText(css1)
full:node(createTableHead(shipname))
for i = 1, #stages do
full:node(
createTableline(stages[i][1], stages[i][2], shipname))
end
return full
end
function p.main(frame)
fr = frame
args = frame.args
parentarg = frame:getParent().args
args['hasCNVoice'] = hasCNVoice(getShipname())
args['hasJPVoice'] = hasJPVoice(getShipname())
-- 台词key加前缀,用于换装
if args['prefix'] ~= nil then
args['prefix'] = mw.text.trim(args['prefix'])
end
if args['param-prefix'] ~= nil then
args['param-prefix'] = mw.text.trim(args['param-prefix'])
args['param-prefix'] = args['param-prefix'] .. '-'
end
return createTable(getShipname())
end
--- 当前页面名字语法糖,不加糖真吃不下去这史山
function p.shipname(frame)
local title = frame:getParent().args["战舰名"] or
mw.title.getCurrentTitle().text:gsub("^.*:", "")
return mw.text.trim(title)
end
function p.modname(frame)
local ship = ships[p.shipname(frame)]
return ship and ship['mod'] or ""
end
function p.dressname(frame)
local ship = ships[p.shipname(frame)]
local num = mw.text.trim(frame.args[1])
return ship and ship["dress" .. (num ~= "1" and num or "")] or ""
end
return p