Module:ChartConstant/dev:修订间差异
小无编辑摘要 |
小 (w+: override) |
||
第49行: | 第49行: | ||
table.insert(rowData, { | table.insert(rowData, { | ||
-- TODO: 难度不同曲绘不同 | -- TODO: 难度不同曲绘不同 | ||
data = { title.en, id, ({ 'pst', 'prs', 'ftr', 'byd', 'etr' })[rc], link = link, override = chart.jacketOverride }, | data = { title.en, id, ({ 'pst', 'prs', 'ftr', 'byd', 'etr' })[rc], link = link, override = chart.jacketOverride and '1' or '0' }, | ||
sort = { nCc, rc, date } | sort = { nCc, rc, date } | ||
}) | }) |
2024年11月28日 (四) 02:28的最新版本
可在Module:ChartConstant/dev/doc创建此模块的帮助文档
local mad = require 'Module:AnotherData'
local p = {}
-- ns待补充(ns也不需要这个)
-- 需要输出详表(如存档旧ptt数据)的话控制台直接print(p.detail())就行了
-- 分界参数
local ccmax = 13 --容纳的最大定数,一般为最高定级+1
local divide = 11.4 --分界定数,低于此定数按0.1划分(值需≤间断定数,当前为11.8)
-- local divide = 11.4
local maxCut = 11.4 -- 定数大于maxCut不显示
local function itData(datas, cc)
cc = cc or maxCut
cc = cc - .1
local id = ('%.1f'):format(cc)
local data = datas[id]
if not data then return nil end
return cc, id, data
end
function p.main()
local datas = {}
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
local divide_str = ('%.1f'):format(divide)
for _, song in ipairs(mad.listOf 'songs') do
if not song.deleted then
local id, titleBase, dateBase = song.id, song.title_localized, song.date
local songCc = songCcs[id] or {}
local link = mad.linkName(song) or titleBase.en
for _, chart in ipairs {}, song.difficulties, 1 do
local rc = chart.ratingClass + 1
local chartCc = songCc[rc]
-- fk lua donot support continue. use single-loop & break for subst
repeat
if not chartCc or chartCc.old ~= false then break end
local nCc = chartCc.constant
if nCc < 8 or nCc >= maxCut then break end
local title, date = chart.title_localized or titleBase, chart.date or dateBase
local rowId = ('%.1f'):format(nCc)
local rowData = datas[rowId]
if not rowData then
rowData = {}
datas[rowId] = rowData
end
if true then
table.insert(rowData, {
-- TODO: 难度不同曲绘不同
data = { title.en, id, ({ 'pst', 'prs', 'ftr', 'byd', 'etr' })[rc], link = link, override = chart.jacketOverride and '1' or '0' },
sort = { nCc, rc, date }
})
end
until (true)
end
end
end
local frame = mw.getCurrentFrame()
local text = mw.html.create 'div':addClass 'notaninfobox dstable'
for _, rowId, rowData in itData, datas do
-- 不显示最高位
if rowId ~= divide_str
then
-- if rowId==divide_str then rowId=('%s+'):format(divide_str) end
text = text
-- :tag 'div':addClass 'ds':wikitext(rowId):done()
-- :tag 'div':addClass 'number'
:wikitext(frame:expandTemplate { title = '定数表组排列', args = { math.floor(rowId) } })
:wikitext(frame:expandTemplate { title = '定数表组排-first', args = { math.floor(rowId), (rowId - math.floor(rowId)) * 10 } })
table.sort(rowData, function(a, b)
a, b = a.sort, b.sort
if a[1] ~= b[1] then return a[1] > b[1] end
if a[2] ~= b[2] then return a[2] > b[2] end
return a[3] < b[3]
end)
for _, rowItem in ipairs(rowData) do
text:wikitext(frame:expandTemplate { title = '定数表组排单元', args = rowItem.data })
end
text = text:wikitext(frame:expandTemplate { title = '定数表组排列-end' }):done()
end
end
return tostring(text)
end
function p.detail()
local datas = {}
local songCcs = mw.text.jsonDecode(mw.title.new('ChartConstant.json', 'Template'):getContent())
for _, song in ipairs(mad.listOf 'songs') do
if not song.deleted then
local id = song.id
local songCc = songCcs[id] or {}
--
local data = { mad.linkTitle(song) }
local sort = { 0, song.date }
table.insert(datas, { data = data, sort = sort })
for _, chart in ipairs(song.difficulties) do
local rc = chart.ratingClass + 1
local chartCc = songCc[rc]
repeat
if not chartCc then break end
local nCc = chartCc.constant
if not chart.date then sort[1] = nCc end
local sCc = ('%.1f'):format(nCc)
data[rc + 1] = chartCc.old ~= false and
tostring(mw.html.create 'span':addClass 'old-constant':wikitext(sCc)) or sCc
until (true)
end
for i = 2, 6 do
data[i] = data[i] or ' '
end
end
end
table.sort(datas, function(a, b)
a, b = a.sort, b.sort
if a[1] == b[1] then return a[2] < b[2] end
return a[1] > b[1]
end)
local texts = {}
local template = '|-\n|[[%s]]' .. ('||%s'):rep(5)
for _, value in ipairs(datas) do
table.insert(texts, template:format(unpack(value.data)))
end
return table.concat(texts, '\n')
end
return p