Module:Songtable
可在Module:Songtable/doc创建此模块的帮助文档
local p = {} local data = require("模块:Rotaeno Data") local getArgs = require('Module:Arguments').getArgs function toInteger(num) return num - num % 0.1 ^ 0 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.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 = data.singleSongInformation(songName, "name") -- 如果没有来源一栏的话,图片合并行的数量减少 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") box:tag("tr"):tag("th"):wikitext(query("title")):attr("colspan", "6") if query("title-list") then box:tag("tr"):tag("th"):wikitext(query("title-list")):attr("colspan", "6") end box:tag("tr"):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") -- 接下来就是ctrl-c ctrl-v了 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("artist")):attr("colspan", "4") end 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("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"):tag("th"):wikitext("谱面信息"):attr("colspan", "5") 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("ChartDesigner")):attr("colspan", "4") end 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["等级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"]) else 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"))) end box:tag("tr"):tag("td"):wikitext("Note数量"):done() :tag("td"):wikitext(args["等级INote数量"]):done() :tag("td"):wikitext(args["等级IINote数量"]):done() :tag("td"):wikitext(args["等级IIINote数量"]):done() :tag("td"):wikitext(args["等级IVNote数量"]) box:tag("tr"):tag("td"):wikitext("更新时间"):done():tag("td"):wikitext(args["更新时间"]):attr("colspan", "4") box:tag("tr"):tag("td"):wikitext("更新版本"):done():tag("td"):wikitext(args["更新版本"]):attr("colspan", "4") return box end return p