模組:ACGaward/nominee check new
外观

模组采用子頁面来定義標籤,字页面名称和{{ACG提名}}
等模板的|ver=
字段搭配。
子页面設計旨在避免做出破坏性调整時,影響過往的存檔。当刪除标签、調整既有定义時,请新建子頁面重写所有定义。
例如原版本中2d
指典特内容:
local rules = {
["2-c"] = { "丙級", 1, aliases = { 'c', '2a' } },
["2-b"] = { "乙級", 3, aliases = { 'b', '2b' } },
["2-ga"] = { "優良", 5, aliases = { 'ga', '2c' } },
["2-fa"] = { "典特", 10, aliases = { 'fa', '2d' } },
}
现插入甲级,并将2d
让给此新等级:
local rules = {
["2-c"] = { "丙級", 1, aliases = { 'c', '2a' } },
["2-b"] = { "乙級", 3, aliases = { 'b', '2b' } },
["2-ga"] = { "優良", 5, aliases = { 'ga', '2c' } },
["2-a"] = { "甲級", 7, aliases = { 'a', '2d' } },
["2-fa"] = { "典特", 10, aliases = { 'fa', '2e' } },
}
為避免影响以往存檔中的记录2d
,请启用新子页面等级该定义。
若单纯添加定义,则直接在当前子页面中修改,无需新增页面。
子頁面列表
require('strict')
local str = mw.text
local getArgs = require("Module:Arguments").getArgs
---@alias Criteria table<string, any>
local criteria = {
-- 1. 新建與擴充
["1a"] = { "短新增", 1 },
["1b"] = { "中新增", 2 },
["1c"] = { "長新增", 3 },
-- 2. 品質提升 // 怕哪天真的插個甲級,所以沒按abcd排下來
["2-c"] = { "丙級", 1 },
["2-b"] = { "乙級", 3 },
["2-ga"] = { "優良", 5 },
["2-fa"] = { "典特", 10 },
-- 3. 格式
["3"] = { "格式", 1 },
-- 4. 活動 // DC什麼的可以自己加
["4"] = { "活動", 1 },
["4-dyk"] = { "DYK", 1 },
["4-req-game"] = { "請求·遊戲", 1 },
["4-req-ac"] = { "請求·動漫", 1 },
-- 5. 評審
["5"] = { "評審", 1 },
["5-half"] = { "快評", 0.5 },
--- 5.1 典優評審相關
["5x-fac"] = { "完整典特評審", 6 },
["5a-fac"] = { "典特文筆評審", 2 },
["5a-fac-half"] = { "典特文筆快評", 1 },
["5b-fac"] = { "典特覆蓋面評審", 2 },
["5b-fac-half"] = { "典特覆蓋面快評", 1 },
["5c-fac"] = { "典特來源格式評審", 2 },
["5c-fac-half"] = { "典特來源格式快評", 1 },
["5-fac"] = { "典特單項評審", 2 },
["5-fac-half"] = { "典特單項快評", 1 },
--- 5.2 甲級評審相關
["5x-acr"] = { "完整甲級評審", 6 },
["5a-acr"] = { "甲級文筆評審", 2 },
["5a-acr-half"] = { "甲級文筆快評", 1 },
["5b-acr"] = { "甲級覆蓋面評審", 2 },
["5b-acr-half"] = { "甲級覆蓋面快評", 1 },
["5c-acr"] = { "甲級來源格式評審", 2 },
["5c-acr-half"] = { "甲級來源格式快評", 1 },
["5-acr"] = { "甲級單項評審", 2 },
["5-acr-half"] = { "甲級單項快評", 1 },
--- 5.3 優良評審相關
["5x-gan"] = { "完整優良評審", 3 },
["5a-gan"] = { "優良文筆評審", 1 },
["5a-gan-half"] = { "優良文筆快評", 0.5 },
["5b-gan"] = { "優良覆蓋面評審", 1 },
["5b-gan-half"] = { "優良覆蓋面快評", 0.5 },
["5c-gan"] = { "優良來源格式評審", 1 },
["5c-gan-half"] = { "優良來源格式快評", 0.5 },
["5-gan"] = { "優良單項評審", 1 },
["5-gan-half"] = { "優良單項快評", 0.5 },
--- 5.4 乙級評審相關
["5x-bcr"] = { "完整乙級評審", 3 },
["5a-bcr"] = { "乙級文筆評審", 1 },
["5a-bcr-half"] = { "乙級文筆快評", 0.5 },
["5b-bcr"] = { "乙級覆蓋面評審", 1 },
["5b-bcr-half"] = { "乙級覆蓋面快評", 0.5 },
["5c-bcr"] = { "乙級來源格式評審", 1 },
["5c-bcr-half"] = { "乙級來源格式快評", 0.5 },
["5-bcr"] = { "乙級單項評審", 1 },
["5-bcr-half"] = { "乙級單項快評", 0.5 },
-- 6. 媒體檔案
["6"] = { "媒体", 3 },
["6-fp"] = { "特色圖片", 3 },
-- 7. 他薦
["7"] = { "他薦", 0.5 },
-- 8. 其他
["8"] = { "其他", 0 }
}
---@param text string
---@param status string
---@return string
local function with_icon(text, status)
local icon_table = {
["yes"] = "[[File:Green check.svg|13px|alt=✓|link=]]",
["partly"] = "[[File:Yellow check.svg|13px|alt=✓|link=]]",
["no"] = "[[File:Red x.svg|13px|alt=✗|link=]]"
}
return icon_table[status] .. ' ' .. text
end
---@param text string
---@param criteria_table Criteria
---@return string | nil
---@return string | nil
---@return number | nil
local function parse_item(criteria_table, text)
local _, _, code = str.find(text, "^([0-9a-z-]+)")
local rule = criteria_table[code]
if rule == nil then
return
end
local annotation, score = rule[1], rule[2]
local _, _, _annotation = str.find(text, "%((.-)%)")
if _annotation then
annotation = _annotation
end
local _, _, _score = str.find(text, "%[([%d+%.%d-)%]")
if _score then
score = tonumber(_score)
end
return code, annotation, score
end
---@param code string
---@param annotation string
---@return string
local function item_string(code, annotation)
local template = '<span style="margin-right: 0.2em; font-weight: bold;">%s</span><small>%s</small>'
return str.format(template, code, annotation)
end
---@param num number
---@return string
local function frac_format(num)
local integer, decimal = math.modf(num)
if decimal == 0.5 then
return tostring(integer) .. '½'
end
return tostring(num)
end
---@param config_table Criteria
---@param text string
---@return string
---@return number
local function generate_result(config_table, text)
local items = {}
local string_fragments = str.split(text, "%s+")
for _, string_fragment in ipairs(string_fragments) do
local code, annotation, score = parse_item(config_table, string_fragment)
if code then
table.insert(items, { code, annotation, score })
end
end
local result_string_fragments, total_score = {}, 0
for _, v in ipairs(items) do
table.insert(result_string_fragments, item_string(v[1], v[2]))
total_score = total_score + v[3]
end
return table.concat(result_string_fragments, '、'), total_score
end
local p = {}
local function makeInvokeFunc(funcName)
return function(frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
p.main = makeInvokeFunc("_main")
function p._main(args)
if args[1] == nil then
return
end
if args[1] == "0" then
return with_icon("'''不得分'''。", "no")
end
local _result, _score = generate_result(criteria, args[1])
local yes_result = str.format("符合%s,得%s分", _result, frac_format(_score))
if args.no == nil then
return with_icon(yes_result .. '。', 'yes')
end
_result = generate_result(criteria, args.no)
local no_result = str.format("不符合%s", _result)
return with_icon(yes_result .. ";" .. no_result .. "。", 'partly')
end
return p