跳至內容

「Module:AnotherData」:修訂間差異

移除 2,107 位元組 、​ 2024年3月14日 (星期四)
放弃song的包装
(暂定Duration)
(放弃song的包装)
第1行: 第1行:
local checkType = require 'libraryUtil'.checkType
local p = {}
local p = {}


第11行: 第10行:
end
end
function p.listOfReserve()
function p.listOfReserve()
-- return mw.text.jsonDecode(mw.title.new('Reserved data.json', 'Template'):getContent()).songs
-- 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
local function chain(obj, expr)
function p.linkName(song)
for op, sKey in expr:gmatch '([.?])([^.?]+)' do
if op == '?' and obj == nil then break end
local key = tonumber(sKey) or sKey
obj = obj[key]
end
return obj
end
local commonExpr = {
title = '.title_localized.en',
pstChartDesigner = '.difficulties.1.chartDesigner',
pstJacketDesigner = '.difficulties.1.jacketDesigner',
pstRating = '.difficulties.1.rating',
prsChartDesigner = '.difficulties.2.chartDesigner',
prsJacketDesigner = '.difficulties.2.jacketDesigner',
prsRating = '.difficulties.2.rating',
ftrChartDesigner = '.difficulties.3.chartDesigner',
ftrJacketDesigner = '.difficulties.3.jacketDesigner',
-- ftrRating
bydChartDesigner = '.difficulties.4?chartDesigner',
bydJacketDesigner = '.difficulties.4?jacketDesigner',
-- bydRating
pstChange = '.difficulties.1.has_controller_alt_chart',
prsChange = '.difficulties.2.has_controller_alt_chart',
ftrChange = '.difficulties.3.has_controller_alt_chart',
bydAudioChange = '.difficulties.4?audioOverride',
bydBg = '.difficulties.4?bg',
bydBPM = '.difficulties.4?bpm',
bydArtist = '.difficulties.4?artist',
bydTitle = '.difficulties.4?title_localized?en',
bydDate = '.difficulties.4?date',
}
local songHandler = {}
function songHandler.ftrRating(obj)
local diff = obj.difficulties[3]
return diff.rating .. (diff.ratingPlus and '+' or '')
end
function songHandler.bydRating(obj)
local diff = obj.difficulties[4]
if not diff then return nil end
return diff.rating .. (diff.ratingPlus and '+' or '')
end
function songHandler.title(obj) return obj.title_localized.en end
function songHandler.linkTitle(obj)
local trans = mw.loadJsonData 'Template:Transition.json'
local trans = mw.loadJsonData 'Template:Transition.json'
local name = songHandler.title(obj)
local name = p.title(song)
local res = trans.songNameToDisplayName[name]
local res = trans.songNameToDisplayName[name]
if res then return res .. '|' .. name end
if res then return res end
res = trans.sameName[name]
res = trans.sameName[name]
if res then return res[obj.id] .. '|' end
if res then return res[song.id] end
return name
end
end
function songHandler.otherTitles(obj)
function p.linkTitle(song)
local res = {}
local name = p.title(song)
local titleJa = obj.title_localized.ja
local linkName = p.linkName(song)
if titleJa then table.insert(res, ('<span lang="ja">-{%s}-</span>'):format(titleJa)) end
return linkName and linkName .. '|' .. name or name
table.insert(res, obj.title_localized['zh-Hans'])
local titleByd = chain(obj, commonExpr.bydTitle)
if titleByd then table.insert(res, titleByd .. mw.getCurrentFrame():expandTemplate {title = '难度标签', args = {'Beyond'}}) end
return res
end
end
-- local chartHandler = {}
-- function p.ratingText(chart) return chart.rating .. (chart.ratingPlus and '+' or '') end
-- function chartHandler.ratingText(obj) return obj.rating .. (obj.ratingPlus and '+' or '') end
local RAW = '@raw'
local COMMON = '@common'
local function optQuery(t, prop)
local obj = rawget(t, RAW)
if not obj then return nil end
local res = obj[prop]
if res then return res end
checkType('optQuery', 2, prop, 'string')
local func = rawget(t, COMMON)[prop]
if func then return func(obj) end
local expr = commonExpr[prop]
if expr then return chain(obj, expr) end
return chain(obj, prop)
end
function p.songQueryWrap(song)
checkType('songQueryWrap', 1, song, 'table', true)
return setmetatable({[RAW] = song, [COMMON] = songHandler}, {__call = optQuery, __index = optQuery})
end
-- function p.chartQueryWrap(chart)
-- checkType('chartQueryWrap', 1, chart, 'table', true)
-- return setmetatable({[RAW] = chart, [COMMON] = chartHandler}, {__call = optQuery, __index = optQuery})
-- end


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
2,032

次編輯