Module:AnotherData:修订间差异
小 (暂定Duration) |
小 (放弃song的包装) |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
第11行: | 第10行: | ||
end | end | ||
function p.listOfReserve() | function p.listOfReserve() | ||
-- | -- Reserved data.json | ||
return mw.text.jsonDecode(mw.title.new('Duration.json', 'Template'):getContent()).songs | return mw.text.jsonDecode(mw.title.new('Duration.json', 'Template'):getContent()).songs | ||
end | end | ||
function p.title(obj) return (obj.title_localized or {}).en end | |||
function p.linkName(song) | |||
function | |||
local trans = mw.loadJsonData 'Template:Transition.json' | local trans = mw.loadJsonData 'Template:Transition.json' | ||
local name = | local name = p.title(song) | ||
local res = trans.songNameToDisplayName[name] | local res = trans.songNameToDisplayName[name] | ||
if res then return res | if res then return res end | ||
res = trans.sameName[name] | res = trans.sameName[name] | ||
if res then return res[ | if res then return res[song.id] end | ||
end | end | ||
function | function p.linkTitle(song) | ||
local | local name = p.title(song) | ||
local | local linkName = p.linkName(song) | ||
return linkName and linkName .. '|' .. name or name | |||
end | end | ||
-- function p.ratingText(chart) return chart.rating .. (chart.ratingPlus and '+' or '') end | |||
-- function | |||
local mPlatFormPackData = {} | local mPlatFormPackData = {} | ||
第141行: | 第69行: | ||
-- return id and packData[id] or packData | -- return id and packData[id] or packData | ||
return packData[id] or {name = '请更新plst', section = 'unknown'} | return packData[id] or {name = '请更新plst', section = 'unknown'} | ||
end | |||
function p.color(t) | |||
if t.args then t = t.args end | |||
-- | |||
local rc = tonumber(t.rc) or t.rc | |||
local n = mw.html.create(t.tag or 'span') | |||
if t.inline then | |||
local colorCode = ({'#0a82be', '#648c3c', '#50194b', '#822328', '#5d4e76'})[rc] | |||
if colorCode then | |||
n:css {color = colorCode} | |||
if t.bright ~= false then n:css {filter = 'brightness(1.2)'} end | |||
else | |||
n:css {color = tostring(rc)} | |||
end | |||
else | |||
local colorClass = ({'pst', 'prs', 'ftr', 'byd', 'etr'})[rc] | |||
if colorClass then | |||
n:addClass('text-' .. colorClass) | |||
else | |||
n:addClass(tostring(rc)) | |||
end | |||
end | |||
return tostring(n:wikitext(t.txt)) | |||
end | |||
function p.nullGuard(f) | |||
return function(o) | |||
if o == nil then return nil end | |||
return f(o) | |||
end | |||
end | end | ||
return p | return p |
2024年3月14日 (四) 12:49的版本
可在Module:AnotherData/doc创建此模块的帮助文档
local p = {}
local srcFileName = {
['songs'] = {'Songlist.json', 'Songlist NS.json'},
['packs'] = {'Packlist.json', 'Packlist NS'},
['unlocks'] = {'Unlocks.json', 'Unlocks NS'},
}
function p.listOf(type, platform)
return mw.text.jsonDecode(mw.title.new(srcFileName[type][platform == 'ns' and 2 or 1], 'Template'):getContent())[type]
end
function p.listOfReserve()
-- Reserved data.json
return mw.text.jsonDecode(mw.title.new('Duration.json', 'Template'):getContent()).songs
end
function p.title(obj) return (obj.title_localized or {}).en end
function p.linkName(song)
local trans = mw.loadJsonData 'Template:Transition.json'
local name = p.title(song)
local res = trans.songNameToDisplayName[name]
if res then return res end
res = trans.sameName[name]
if res then return res[song.id] end
end
function p.linkTitle(song)
local name = p.title(song)
local linkName = p.linkName(song)
return linkName and linkName .. '|' .. name or name
end
-- function p.ratingText(chart) return chart.rating .. (chart.ratingPlus and '+' or '') end
local mPlatFormPackData = {}
local function mobileSection(pack)
return pack.section
end
local function nsSection(pack)
if pack.pack_parent then return nil end
if mw.loadJsonData 'Template:Transition.json'.packName[pack.id] then return 'collab' end
return ({'free', 'mainstory', 'sidestory'})[pack.section]
end
local function factPackData(platform)
local sectionOf = platform == 'ns' and nsSection or mobileSection
local res = {single = {name = 'Memory Archive', section = 'single', numero = 0}}
for idx, pack in ipairs(p.listOf('packs', platform)) do
--- 单个曲包查询的数据结构
local item = {_parentId_ = pack.pack_parent, name = pack.name_localized.en, section = sectionOf(pack), numero = idx}
res[pack.id] = item
end
for _, item in pairs(res) do
local parentId = item._parentId_
local parent
if parentId then
parent = res[parentId]
if item.name:match 'Collaboration Chapter' then
item.name = parent.name .. ' ' .. item.name
end
end
item.section = item.section or parent.section
end
return res
end
function p.packQueryWrap(id, platform)
platform = platform or 'mobile'
local packData = mPlatFormPackData[platform]
if not packData then
packData = factPackData(platform)
mPlatFormPackData[platform] = packData
end
-- return id and packData[id] or packData
return packData[id] or {name = '请更新plst', section = 'unknown'}
end
function p.color(t)
if t.args then t = t.args end
--
local rc = tonumber(t.rc) or t.rc
local n = mw.html.create(t.tag or 'span')
if t.inline then
local colorCode = ({'#0a82be', '#648c3c', '#50194b', '#822328', '#5d4e76'})[rc]
if colorCode then
n:css {color = colorCode}
if t.bright ~= false then n:css {filter = 'brightness(1.2)'} end
else
n:css {color = tostring(rc)}
end
else
local colorClass = ({'pst', 'prs', 'ftr', 'byd', 'etr'})[rc]
if colorClass then
n:addClass('text-' .. colorClass)
else
n:addClass(tostring(rc))
end
end
return tostring(n:wikitext(t.txt))
end
function p.nullGuard(f)
return function(o)
if o == nil then return nil end
return f(o)
end
end
return p