該模塊作為碧藍航線系列條目的重要模塊,編輯請儘量使用,並且保存前請務必預覽Template:碧藍航線的顯示情況。
邏輯代碼位於模塊:碧藍航線Ships。
數據位於模塊:碧藍航線Ships/Data。
目前數據由腳本自動更新,有編輯組專人負責。
local module = {} local translist_favor = { [0] = { ["好感度1"] = "好感度-失望", ["好感度2"] = "好感度-陌生", ["好感度3"] = "好感度-友好", ["好感度4"] = "好感度-喜歡", ["好感度5"] = "好感度-愛" }, [97] = { ["好感度1"] = "好感度-未知", ["好感度2"] = "好感度-調率", ["好感度3"] = "好感度-理解", ["好感度4"] = "好感度-同步", ["好感度5"] = "好感度-共鳴" }, [107] = { ["好感度1"] = "好感度-失望", ["好感度2"] = "好感度-普通", ["好感度3"] = "好感度-友好", ["好感度4"] = "好感度-協作", ["好感度5"] = "好感度-應援" }, } local tranform_favor = function (ship_info, arg_name) return (translist_favor[ship_info.nation] or translist_favor[0])[arg_name] end local arglist = { {"獲得", "登錄", "查看詳情", { "主界面[1-9][0-9]?", list = true, display = "主界面" }, "觸摸", "摸頭", "特殊觸摸", "任務提醒", "任務完成", "郵件提醒", "回港", "委託完成", "強化成功", "旗艦開戰", "勝利MVP", "失敗", "技能", "HP告急", "彩蛋", { "彩蛋[1-9][0-9]?", list = true, display = "彩蛋" }, { "20%d%d情人節禮物", noaudio = true } }, {"簡介", { "好感度[1-5]", ["display"] = tranform_favor }, "好感度-失望", "好感度-陌生", "好感度-友好", "好感度-喜歡", "好感度-愛", "誓約", "掉落描述" }, {"獲得", "登錄", "查看詳情", { "主界面[1-9][0-9]?" }, "觸摸", "摸頭", "特殊觸摸", "任務提醒", "任務完成", "郵件提醒", "回港", "委託完成", "簡介", "好感度-失望", "好感度-陌生", "好感度-友好", "好感度-喜歡", "好感度-愛", "誓約", "強化成功", "旗艦開戰", "勝利MVP", "失敗", "技能", "HP告急", "彩蛋", { "彩蛋[1-9]", list = true, display = "彩蛋" } } } local hidelist = { ["禮物-喜歡"] = true, ["禮物-不喜歡"] = true, ["禮物-喜歡語音"] = true, ["禮物-不喜歡語音"] = true } local g_frame = nil function get_arg(name) return g_frame.args[name] and mw.text.trim(g_frame.args[name]) or '' end function bkcolor(level) if level == 1 then return "#d0d0d0" elseif level == 2 then return"#aae6fd" elseif level == 3 then return"#b9a7db" elseif level == 4 then return"#f9f593" elseif level == 5 then return"rgba(162, 214, 245,0.8)" elseif level == 6 then return"#d3aa4f" elseif level == 7 then return"#dcceff" elseif level == 14 then return"#9e5c22" elseif level == 13 then return"#a676fc" else return"#d0d0d0" end end shipmodule = nil function shipModule() if not shipmodule then shipmodule = require("Module:碧藍航線Ships") end return shipmodule end function module.LinesUnit(frame) local parent = frame:getParent() local index = nil if parent then index = mw.ustring.match(parent:getTitle(), "^Template:碧藍航線台詞([1-3])$") if index then frame = parent end else index = frame.args["index"] end g_frame = frame if index then index = tonumber(index) else return end local num_level = frame:callParserFunction("#var", "levelnum", "") if num_level == "" then local obj_title = mw.title.getCurrentTitle() if obj_title.namespace == 0 then local name = mw.ustring.match(obj_title.text,"^碧藍航線:(.+)") num_level = shipModule().innerlevel(name) end else num_level = tonumber(num_level) end if index == 3 and get_arg('改造') ~= '' then num_level = num_level + 1 end local color_bkg = bkcolor(num_level) local hasAudio, hasDouble = false, false local used = { } local incorrect = { } local Incorrect_Add = function(key, group) if mw.title.getCurrentTitle().namespace ~= 0 then return end group = group or "模板參數不正確" if not incorrect[1] then table.insert(incorrect, "[[Category:碧藍航線:" .. group .. "]]") end table.insert(incorrect, "[[Category:碧藍航線:" .. group .. "/" .. key .. "]]") end local html = mw.html.create() local box = html:tag("table"):addClass("customers"):attr("width", "100%"):css("border-collapse", "separate"):css("border-spacing", "0 0.3em"):css("background-color", "rgba(235,248,255,0.5)"):css("border-radius", "0.3em") local Work_Audio = function(arg_name) local arg_audio = mw.text.trim(frame.args[arg_name]) if arg_audio == "" then return "" end local arg_split = mw.text.split(arg_audio, ";", true) for index, file_audio in ipairs(arg_split) do local file_path = frame:callParserFunction("filepath", file_audio) if file_path == "" then Incorrect_Add(arg_name, "語音文件不存在") arg_split[index] = '<div class="error">語音文件不存在:' .. file_audio .. '</div>' else arg_split[index] = frame:extensionTag("sm2", file_audio) end end arg_audio = table.concat(arg_split) return arg_audio end local InsertItem = function(item, title, noaudio) local tr_item = box:tag("tr") tr_item:tag("td"):css("background", color_bkg):css("text-align", "center"):css("width", "110px"):css("border-top-left-radius","0.2em"):css("border-bottom-left-radius","0.2em"):tag("b"):wikitext(title or item) if mw.ustring.find(frame.args[item], "<u>") then hasDouble = true end local text = mw.ustring.gsub(frame.args[item], "(.+)\n\n+", "<p>%1</p>") tr_item:tag("td"):wikitext(text) local arg_audio = item .. "語音" if frame.args[arg_audio] and not noaudio then local text_audio = Work_Audio(arg_audio) if text_audio then hasAudio = true tr_item:tag("td"):attr("width", "40px"):wikitext(text_audio) elseif hasAudio then tr_item:tag("td") end used[arg_audio] = true elseif hasAudio then tr_item:tag("td") end used[item] = true end local InsertSubItems = function(itemlist, title, noaudio) local tr_item = box:tag("tr") tr_item:tag("td"):attr("rowspan", #itemlist):css("background", color_bkg):css("text-align", "center"):css("width", "110px"):css("border-top-left-radius","0.2em"):css("border-bottom-left-radius","0.2em"):tag("b"):wikitext(title or "") for idx, item in ipairs(itemlist) do if mw.ustring.find(frame.args[item], "<u>") then hasDouble = true end local text = mw.ustring.gsub(frame.args[item], "(.+)\n\n+", "<p>%1</p>") tr_item:tag("td"):wikitext(text) local arg_audio = item .. "語音" if frame.args[arg_audio] and not noaudio then local text_audio = Work_Audio(arg_audio) if text_audio then hasAudio = true tr_item:tag("td"):attr("width", "40px"):wikitext(text_audio) elseif hasAudio then tr_item:tag("td") end used[arg_audio] = true elseif hasAudio then tr_item:tag("td") end if itemlist[idx + 1] then tr_item = box:tag("tr") end used[item] = true end end if index == 1 and get_arg('登錄歡迎語音') ~= '' then frame.args["登錄歡迎"] = "碧藍航線!" InsertItem("登錄歡迎") end for _, item in ipairs(arglist[index]) do if type(item) == "table" then local pattern = item[1] local itemlist = { } for key, value in pairs(frame.args) do if mw.ustring.match(key, "^" ..pattern .. "$") and mw.text.trim(value) ~= "" then table.insert(itemlist, key) end end table.sort(itemlist) if item.list and itemlist[1] then InsertSubItems(itemlist, item.display, item.noaudio) elseif itemlist[1] then for _, name in ipairs(itemlist) do if type(item.display) == "table" then InsertItem(name, item.display[name] or name, item.noaudio) elseif type(item.display) == "function" then local ship_name = mw.ustring.match(mw.title.getCurrentTitle().text,"^碧藍航線:(.+)") local ship_info = shipModule().get_data(ship_name or 'null') InsertItem(name, item.display(ship_info, name), item.noaudio) else InsertItem(name, name, item.noaudio) end end end else if frame.args[item] then if mw.text.trim(frame.args[item]) ~= "" then InsertItem(item) else used[item] = true if frame.args[item .. "語音"] then used[item .. "語音"] = true end end end end end local retn = tostring(html) if hasDouble then retn = '<ul class="margin-left-set" style="margin-left: 1.2em;"><li>下方有底線為誓約新增額外台詞</li></ul>' .. retn end for key, value in pairs(frame.args) do if (not used[key] and (index ~= 3 or key ~= "改造") and not hidelist[key]) or (key == "登錄歡迎") then Incorrect_Add(key) elseif mw.ustring.match(value, "[暫暫][無無]") then Incorrect_Add("暫無") elseif key == "彩蛋" and mw.ustring.match(value, "\n\n") then Incorrect_Add("彩蛋") end end if incorrect[1] then retn = retn .. table.concat(incorrect) end return retn end -- 陣營名稱相關([[Template:碧藍航線陣營]]) local translist = { ["Eagle"] = "白[鷹鷹]", ["Royal"] = "皇家", ["Sakura"] = "重[櫻櫻]", ["Metalblood"] = "[鐵鐵]血", ["Eastern"] = "[東東]煌", ["North"] = "北方[聯聯]合", ["Iris"] = "自由[鳶鳶]尾", ["Vichya"] = "[維維]希教廷", ["Sardinia"] = "撒丁", ["Neptunia"] = { "海王星", "hyperdimension" }, ["Utawarerumono"] = { "傳頌", "傳頌" }, ["Kizuna"] = "絆愛", ["Hololive"] = 0, ["DOAXVV"] = { "維納斯假期", "維納斯假期" },["META"] = 0, ["Bilibili"] = "嗶哩嗶哩", ["None"] = { "無陣營", "無陣營", "布里神教" } , ["iM@S"] = "偶像大師", ["SSSS"] = "SSSS", ["Tempesta"] = { "颶風", "颶風" }, ["Atelier Ryza"] = { "Atelier Ryza" }, ["閃亂神樂"] = { "閃亂神樂" }} local mapslist = { ["Eagle"] = "碧藍航線-白鷹", ["Royal"] = "碧藍航線-皇家", ["Sakura"] = "赤色中軸-重櫻", ["Metalblood"] = "赤色中軸-鐵血", ["Eastern"] = "碧藍航線-東煌", ["North"] = "碧藍航線-北方聯合", ["Iris"] = "碧藍航線-自由鳶尾", ["Vichya"] = "赤色中軸-維希教廷", ["Neptunia"] = "????-海王星", ["Utawarerumono"] = "????-傳頌之物", ["Kizuna"] = "????-KizunaAI", ["Hololive"] = "????-hololive", ["DOAXVV"] = "????-維納斯假期", ["Sardinia"] = "赤色中軸-撒丁帝國", ["Bilibili"] = "????-嗶哩嗶哩", ["None"] = "????-其他",["META"] = "META-???" , ["iM@S"] = "????-偶像大師", ["SSSS"] = "????-SSSS", ["Tempesta"] = "????-颶風", ["Atelier Ryza"] = "????-Atelier Ryza", ["閃亂神樂"] = "????-閃亂神樂"} function module.team_getcode(frame) local arg_input = mw.ustring.lower(frame.args[1]) for key, value in pairs(translist) do if mw.ustring.find(arg_input, mw.ustring.lower(key)) then return key end if type(value) == "string" then if mw.ustring.find(arg_input, value) then return key end elseif type(value) == "table" then for _, item in pairs(value) do if mw.ustring.find(arg_input, item) then return key end end end end return "Unknow" end function module.team_normalize(frame) local code = module.team_getcode(frame) return mapslist[code] or "陣營信息" end local alphabet = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N" } function module.MapsGen(frame) local parent = frame:getParent() if parent and parent:getTitle() == "Template:碧藍航線地圖" then frame = parent end g_frame = frame local rows = frame.args["行數"] rows = rows and tonumber(rows) or 1 local cols = frame.args["列數"] cols = cols and tonumber(cols) or 1 local html = mw.html.create() local box = html:tag("table"):addClass("Azur_Maps"):css( { ["position"] = "relative", ["z-index"] = "2", ["margin"] = "0", ["border-collapse"] = "collapse", ["text-align"] = "center", ["color"] = "white", ["font-weight"] = "bold", } ) local tr_line = box:tag("tr"):tag("td"):done() for col = 1, cols do tr_line:tag("td"):wikitext(alphabet[col]) end local arg_list = { '起點', '敵人', '塞壬', 'BOSS', '潛艇' } local objects = {} for _, arg in ipairs(arg_list) do value = get_arg(arg) mw.log(arg, value) if (value ~= '') then objects[arg] = frame:expandTemplate{ title = '碧藍航線地圖/Item', args = { arg } } list_pos = mw.text.split(value, ',') for _, pos in ipairs(list_pos) do objects[pos] = objects[arg] end end end local arg_name = "" for row = 1, rows do tr_line = box:tag("tr") tr_line:tag("td"):wikitext(tostring(row)) for col = 1, cols do arg_name = tostring(row) .. alphabet[col] tr_line:tag("td"):wikitext(objects[arg_name] or frame.args[arg_name]) end end return html end return module