Module:Songtable
可在Module:Songtable/doc创建此模块的帮助文档
local p = {} local data = require("模块:Rotaeno Data") local getArgs = require('Module:Arguments').getArgs function toInteger(num) local a, b = math.modf(num) if b > 0.6 and num >= 10 then return tostring(a).."+" else return tostring(a) end end function packName(name) if string.find(name, "%[") then return name else return "[["..name.."]]" end end function createTable(tab,list) local max = #list; local cur = 1; local col = 1; local curCell = tab:tag("td"):wikitext(list[1]); for i=2, max do if list[i] == list[i-1] then col = col + 1; curCell:attr("colspan", tostring(col)) else curCell = tab:tag("td"):wikitext(list[i]); col = 1; end end end function nonI18n(txt) return '-{' .. txt .. '}-' end function makeInvokeFunc(funcName) return function(frame) local args = getArgs(frame) return p[funcName](args) end end p.main = makeInvokeFunc('_main') function p._main(args) --生成HTML的主函数 -- 从参数或者页面名称读取曲目名称 local songName if args['曲名'] then songName = args['曲名'] else songName = mw.text.decode(mw.getCurrentFrame():preprocess("{{FULLPAGENAME}}")) end -- 如果是从页面名读取的,那可能因为mediawiki限制导致页面名和曲名不符。如果有这个转换规则的话,使用转换JSON进行转换。 local covList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Transition.json' })["displayNameToSongName"] if covList[songName] then songName = covList[songName] end -- 生成查找函数。 local query if args['id'] then query = data.singleSongInformation(args['id'], "id") else query = data.singleSongInformation(songName, "name") end if not(args["曲名"] or query("title"))then error('Songlist中无法找到该歌曲信息,请检查Songlist模板是否更新,若更新后仍出现该错误请尝试手动填写id字段。如上述方案均无法解决请联系管理员进行处理。');end -- 防止不明不白的报错 -- 如果没有来源一栏的话,图片合并行的数量减少 local imageRowspan; if query("source") then imageRowspan = 13 else imageRowspan = 12 end -- 分类表 local cat = {} -- 拼html,因为内容比较简单,就不像arcaeawiki一样写数据table了。 local box = mw.html.create("table"):addClass("rotable") if args["曲名"] then box:tag("tr"):tag("th"):wikitext(nonI18n(args["曲名"])):attr("colspan", "6") else box:tag("tr"):tag("th"):wikitext(nonI18n(query("title"))):attr("colspan", "6") end if args["曲名语言表"] then box:tag("tr"):tag("th"):wikitext(nonI18n(args["曲名语言表"])):attr("colspan", "6") elseif query("title-list") then box:tag("tr"):tag("th"):wikitext(nonI18n(query("title-list"))):attr("colspan", "6") end if args["id"] then box:tag("tr"):addClass("rotable-title"):tag("th"):wikitext("曲目信息"):attr("colspan", "5") :done():tag("td"):wikitext("[[File:Songs_"..args["id"]..".png|256px]]"):attr("rowspan", imageRowspan) :css("height", "256px"):css("width", "256px") elseif query("id") then box:tag("tr"):addClass("rotable-title"):tag("th"):wikitext("曲目信息"):attr("colspan", "5") :done():tag("td"):wikitext("[[File:Songs_"..query("id")..".png|256px]]"):attr("rowspan", imageRowspan) :css("height", "256px"):css("width", "256px") else box:tag("tr"):addClass("rotable-title"):tag("th"):wikitext("曲目信息"):attr("colspan", "5") :done():tag("td"):wikitext("未指定图片"):attr("rowspan", imageRowspan) :css("height", "256px"):css("width", "256px") end if args["曲包"] then box:tag("tr"):tag("td"):wikitext("曲包"):done():tag("td"):wikitext(packName(args["曲包"])):attr("colspan", "4") table.insert(cat, "[[分类:"..args["曲包"].."曲包曲目]]") else box:tag("tr"):tag("td"):wikitext("曲包"):done():tag("td"):attr("colspan", "4") end if args["曲师"] then box:tag("tr"):tag("td"):wikitext("曲师"):done():tag("td"):wikitext(nonI18n(args["曲师"])):attr("colspan", "4") else box:tag("tr"):tag("td"):wikitext("曲师"):done():tag("td"):wikitext(nonI18n(query("artist"))):attr("colspan", "4") end if args["画师"] then box:tag("tr"):tag("td"):wikitext("画师"):done():tag("td"):wikitext(nonI18n(args["画师"])):attr("colspan", "4") else box:tag("tr"):tag("td"):wikitext("画师"):done():tag("td"):wikitext(nonI18n(query("JacketDesigner"))):attr("colspan", "4") end -- 来源有可能没有 if args["来源"] or query("source") then if args["来源"] then box:tag("tr"):tag("td"):wikitext("来源"):done():tag("td"):wikitext(args["来源"]):attr("colspan", "4") else box:tag("tr"):tag("td"):wikitext("来源"):done():tag("td"):wikitext(query("source")):attr("colspan", "4") end end box:tag("tr"):tag("td"):wikitext("时长"):done():tag("td"):wikitext(args["时长"]):attr("colspan", "4") box:tag("tr"):addClass("rotable-title"):tag("th"):wikitext("谱面信息"):attr("colspan", "5") box:tag("tr"):tag("td"):wikitext("难度"):done() :tag("td"):wikitext("难度I"):css("color", "#43a047"):done() :tag("td"):wikitext("难度Ⅱ"):css("color", "#1565c0"):done() :tag("td"):wikitext("难度Ⅲ"):css("color", "#e65100"):done() :tag("td"):wikitext("难度Ⅳ"):css("color", "#ab47bc") if args["谱师"] then box:tag("tr"):tag("td"):wikitext("谱师"):done():tag("td"):wikitext(args["谱师"]):attr("colspan", "4") elseif args["难度I谱师"] and args["难度II谱师"] and args["难度III谱师"]and args["难度IV谱师"] then box:tag("tr"):tag("td"):wikitext("谱师"):done() :tag("td"):wikitext(args["难度I谱师"]):done() :tag("td"):wikitext(args["难度II谱师"]):done() :tag("td"):wikitext(args["难度III谱师"]):done() :tag("td"):wikitext(args["难度IV谱师"]):done() else createTable( box:tag("tr"):tag("td"):wikitext("谱师"):done(), {query("ChartDesigner1"),query("ChartDesigner2"),query("ChartDesigner3"),query("ChartDesigner4"),} ) end if args["难度I等级"] and args["难度I等级"] and args["难度III等级"] and args["难度IV等级"] then box:tag("tr"):tag("td"):wikitext("等级"):done() -- 删除小数 :tag("td"):wikitext(args["难度I等级"]):done() :tag("td"):wikitext(args["难度II等级"]):done() :tag("td"):wikitext(args["难度III等级"]):done() :tag("td"):wikitext(args["难度IV等级"]) table.insert(cat, "[[分类:难度I中"..args["难度I等级"].."级曲目]]") table.insert(cat, "[[分类:难度II中"..args["难度II等级"].."级曲目]]") table.insert(cat, "[[分类:难度III中"..args["难度III等级"].."级曲目]]") table.insert(cat, "[[分类:难度IV中"..args["难度IV等级"].."级曲目]]") else if query("rating1") then box:tag("tr"):tag("td"):wikitext("等级"):done() -- 删除小数 :tag("td"):wikitext(toInteger(query("rating1"))):done() :tag("td"):wikitext(toInteger(query("rating2"))):done() :tag("td"):wikitext(toInteger(query("rating3"))):done() :tag("td"):wikitext(toInteger(query("rating4"))) if query("title") then table.insert(cat, "[[分类:难度I中"..toInteger(query("rating1")).."级曲目]]") table.insert(cat, "[[分类:难度II中"..toInteger(query("rating2")).."级曲目]]") table.insert(cat, "[[分类:难度III中"..toInteger(query("rating3")).."级曲目]]") table.insert(cat, "[[分类:难度IV中"..toInteger(query("rating4")).."级曲目]]") end end end box:tag("tr"):tag("td"):wikitext("Note数量"):done() :tag("td"):wikitext(args["难度I物量"]):done() :tag("td"):wikitext(args["难度II物量"]):done() :tag("td"):wikitext(args["难度III物量"]):done() :tag("td"):wikitext(args["难度IV物量"]) box:tag("tr"):tag("td"):wikitext("更新时间"):done():tag("td"):wikitext(args["更新时间"]):attr("colspan", "4") if args["更新时间"] then table.insert(cat, "[[分类:时间"..args["更新时间"].."更新的曲目]]") end box:tag("tr"):tag("td"):wikitext("更新版本"):done():tag("td"):wikitext(args["更新版本"]):attr("colspan", "4") if args["更新版本"] then table.insert(cat, "[[分类:版本"..args["更新版本"].."更新的曲目]]") end return tostring(box)..table.concat(cat) end return p