模块:RhodesFashion
使用方式:
{{#invoke:RhodesFashion|list|no=<开启次数>}}
- 模块引用模板:RhodesFashion/data作为查询数据源。
- 本模块也包含其它使用方法,但不适合普遍使用,仅用于特定用途。
--====数据区====
local rf_data = mw.loadJsonData("Template:RhodesFashion/data")
--由于mw.loadJsonData导致长度丢失,因此必须手动重新计算
local _getLength = function(t)
local no = 0
for _ in ipairs(t) do
no = no + 1
end
return no
end
local length_event = _getLength(rf_data.event)
--===内部处理区===
local newSkinTemp = '<span style="position:relative"><span style="position: absolute; background: #334ACC; color:white; font-size: small; font-family: monospace; box-shadow: 0 0 4px 1px black; padding: 0px 5px;">\'\'\'NEW!\'\'\'</span>%s</span>'
local brandTemp = '<span class="brandlogo">[[文件:Skin_brand_%s.png|50px|link=]]%s</span>'
local subBrandTemp = '<div class="brandlogo" style="display: inline-table; text-align: center;">[[文件:Skin_logo_%s.png|50px|link=]]%s</div>'
local newBrandTag = '<br/><span style=\"background: #FFD800; font-size: small; font-family: monospace; box-shadow: 0 0 4px 1px black; padding: 0px 5px;">\'\'\'NEW!\'\'\'</span>'
local genSkinIcon = function(skinExp, brand, isNew)
local skinInfo = mw.text.split(skinExp, '|', true)
local icon = string.format("[[文件:头像 %s skin%s.png|x50px|link=时装回廊/%s#%s]]", skinInfo[1], skinInfo[2], brand, skinInfo[3])
if isNew then
return string.format(newSkinTemp, icon)
else
return icon
end
end
local getBrandIcon = function(brandName, isNew)
return string.format(brandTemp, brandName, isNew and newBrandTag or "")
end
local getSubBrandIcon = function(subBrandName, isNew)
return string.format(subBrandTemp, subBrandName, isNew and newBrandTag or "")
end
local findIsNewBrand = function(brandId, eventNo)
if rf_data.event[eventNo] then
if rf_data.event[eventNo].newBrand then
for _,id in ipairs(rf_data.event[eventNo].newBrand) do
if id == brandId then return true end
end
end
end
return false
end
local findIsNewSubBrand = function(subBrandId, eventNo)
if rf_data.event[eventNo] then
if rf_data.event[eventNo].newSubBrand then
for _,id in ipairs(rf_data.event[eventNo].newSubBrand) do
if id == subBrandId then return true end
end
end
end
return false
end
local output_head = '{| class="wikitable mw-collapsible mw-collapsed" style="white-space:normal"\n! colspan=2 | 详细时装列表'
local output_compareInfo = function(eventNo)
local link = string.format("%s#%s", rf_data.event[eventNo].pageLink or rf_data.event[eventNo].name.."/活动公告", rf_data.event[eventNo].announceSection)
return string.format("|-\n| colspan=2 | ※标注为“NEW!”的时装为相较于上次[[%s|【罗德岛风尚回顾】]]新增复刻贩售的时装。", link)
end
--====输出====
local p = {}
function p.list(frame)
mw.addWarning("{{Cbox2|mdi=true|lv=2|icon=information-variant-circle|title=本页面引用了[[模块:RhodesFashion|【罗德岛风尚回顾】模块]]以显示相关内容。|text=请在保存时查看数据是否正确,若有误请确认[[Template:RhodesFashion/data|数据源]]是否有对应数据。}}")
local stylePredifine = frame:callParserFunction{name = '#Widget:style', args = {style = ".brandlogo{filter:invert(.8)}"}}
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
--const
local maxEventCnt = length_event
local curEventCnt = mw.text.trim(args["no"] or "")
--mw.log(maxEventCnt)
--mw.log(curEventCnt)
local triggerNew = true
if curEventCnt=="" then
curEventCnt = maxEventCnt
triggerNew = false
else
curEventCnt = tonumber(curEventCnt)
if curEventCnt<=1 then triggerNew = false end
end
local res_table = {}
table.insert(res_table, stylePredifine.."\n")
table.insert(res_table, output_head.."\n")
if triggerNew then
table.insert(res_table, output_compareInfo(curEventCnt-1).."\n" )
end
for _,id in ipairs(rf_data.brandSort) do
local timeline = rf_data.retroSkin[id]
local skin_table = {}
if id ~= "crossover" then
for eventNo = curEventCnt, 1, -1 do
local timepoint = timeline["e"..eventNo]
if timepoint then
local tp_table = {}
for i=1, _getLength(timepoint) do
table.insert(tp_table, genSkinIcon(timepoint[i], rf_data.brand[id], triggerNew and (findIsNewBrand(id, curEventCnt)==false) and eventNo==curEventCnt).."\n")
end
for i=1, #tp_table do
table.insert(skin_table, i, tp_table[i])
end
end
end
if #skin_table>0 then
table.insert(res_table, string.format("|-\n!%s\n", getBrandIcon(rf_data.brand[id], triggerNew and findIsNewBrand(id, curEventCnt))))
local lineSkin = 0
local skin_str = ""
for i=1, #skin_table do
skin_str = skin_str..skin_table[i]
lineSkin = lineSkin + 1
if lineSkin == 15 then
skin_str = skin_str.."<br>\n"
lineSkin = 0
end
end
table.insert(res_table, string.format("|\n%s",skin_str)) --不需要再换行
end
else
local crossover_table = {}
local enableCrossover = false
for __,subId in ipairs(rf_data.subBrandSort) do
local timeline = timeline[subId]
local skin_table = {}
for eventNo = curEventCnt, 1, -1 do
local timepoint = timeline["e"..eventNo]
if timepoint then
local tp_table = {}
for i=1, _getLength(timepoint) do
table.insert(tp_table, genSkinIcon(timepoint[i], rf_data.brand[id], triggerNew and (findIsNewSubBrand(subId, curEventCnt)==false) and eventNo==curEventCnt))
end
table.insert(skin_table, 1, table.concat(tp_table))
end
end
if #skin_table>0 then
enableCrossover = true
table.insert(crossover_table, string.format("%s", getSubBrandIcon(rf_data.subBrand[subId], triggerNew and findIsNewSubBrand(subId, curEventCnt))))
table.insert(crossover_table, string.format("%s", table.concat(skin_table))) --不需要再换行
end
end
if enableCrossover then
table.insert(res_table, string.format("|-\n!%s\n", getBrandIcon(rf_data.brand[id], triggerNew and findIsNewBrand(id, curEventCnt))))
table.insert(res_table, string.format("|\n%s\n",table.concat(crossover_table)))
end
end
end
--
table.insert(res_table, "|}")
return table.concat(res_table)
end
function p.timeline(frame)
--debug mode
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local debug = args["debug"] and true or false
local debugrec = ""
local debugrectotal = 0
local debugout = ""
local maxEventCnt = length_event
local res_table = {}
table.insert(res_table, output_head.."\n")
for eventNo, event in ipairs(rf_data.event) do
table.insert(res_table, "|-\n")
local link = string.format("%s#%s", event.pageLink or event.name.."/活动公告", event.announceSection)
local linkname = event.timelineAlias or event.name
table.insert(res_table, string.format("! [[%s|%s]]\n", link, linkname))
local skin_table = {}
for _,id in ipairs(rf_data.brandSort) do
if id ~= "crossover" then
local timepoint = rf_data.retroSkin[id]["e"..eventNo]
if timepoint then
for i=1, _getLength(timepoint) do
table.insert(skin_table, genSkinIcon(timepoint[i], rf_data.brand[id], false).."\n")
end
end
else
for __,subId in ipairs(rf_data.subBrandSort) do
local timepoint = rf_data.retroSkin[id][subId]["e"..eventNo]
if timepoint then
for i=1, _getLength(timepoint) do
table.insert(skin_table, genSkinIcon(timepoint[i], rf_data.brand[id], false).."\n")
end
end
end
end
end
local lineSkin = 0
local skin_str = ""
local debugreccounter = 0
if debug then debugrec = debugrec .. string.gsub(linkname, "<br>", "") .. ":" end
for i=1, #skin_table do
skin_str = skin_str..skin_table[i]
lineSkin = lineSkin + 1
if lineSkin == 15 then
skin_str = skin_str.."<br>\n"
lineSkin = 0
end
debugreccounter = debugreccounter + 1
end
table.insert(res_table, string.format("|\n%s",skin_str)) --不需要再换行
if debug then
debugrectotal = debugrectotal + debugreccounter
debugrec = debugrec .. string.format("%d (+%d)<br>", debugrectotal, debugreccounter)
end
end
table.insert(res_table, "|}")
if debug then
debugout = debugout .. debugrec
end
return table.concat(res_table) .. debugout
end
function p.debug()
--[[
for _,id in ipairs(rf_data.brandSort) do
mw.log(id)
end
]]
mw.log(length_event)
end
return p