模块:CharHeart
来自星砂岛百科
更多操作
概述
CharHeart 提供角色心级节点与触发模板的独立展示能力。
用法
{{#invoke:CharHeart|heartTable|枫汐}}
数据来源
local common = require('Module:Common')
local character_common = require('Module:CharacterCommon')
local p = {}
local data_cache
local mapping_cache
local function load_data()
if data_cache then
return
end
data_cache, mapping_cache = character_common.loadDomainData({
'数据:Character/character_heart_index.json',
'数据:Character/character heart index.json',
})
end
local function find_record(key)
load_data()
return character_common.findRecord(data_cache, mapping_cache, key)
end
local function render_count(values)
local ordered = character_common.orderedNumericValues(values)
if #ordered == 0 then
return '—'
end
return tostring(#ordered) .. ' 项'
end
local function build_note(entry)
local notes = {}
if common.trim(common.toText(entry.template or '')) ~= '' then
notes[#notes + 1] = '存在心级触发'
end
if entry.unlock_date then
notes[#notes + 1] = '记录解锁日期'
end
if #notes == 0 then
return '—'
end
return mw.text.encode(table.concat(notes, ';'))
end
function p.heartTable(frame)
local record = find_record(common.getArg(frame, 1, ''))
if not record then
return '<div class="char-empty char-heart-empty">未找到角色好感节点数据</div>'
end
local heart = record.heart
local entries = character_common.orderedNumericValues(heart)
if #entries == 0 then
return '<div class="char-empty char-heart-empty">该角色当前未发现好感节点数据</div>'
end
local out = {}
out[#out + 1] = '<div class="char-table-wrap">'
out[#out + 1] = '{| class="wikitable sortable char-data-table char-heart-table"'
out[#out + 1] = '! 心级'
out[#out + 1] = '! 赠礼邮件'
out[#out + 1] = '! 好感对话'
out[#out + 1] = '! 相关任务'
out[#out + 1] = '! 说明'
for _, entry in ipairs(entries) do
out[#out + 1] = '|-'
out[#out + 1] = '| ' .. mw.text.encode(common.trim(common.toText(entry.level or '')))
out[#out + 1] = '| ' .. render_count(entry.mail_templates)
out[#out + 1] = '| ' .. render_count(entry.dialog_templates)
out[#out + 1] = '| ' .. render_count(entry.mission_templates)
out[#out + 1] = '| ' .. build_note(entry)
end
out[#out + 1] = '|}'
out[#out + 1] = '</div>'
return table.concat(out, '\n')
end
return p