跳转到内容

模块:地点数据:修订间差异

来自Wymbot 共创站
NotBot​(留言 | 贡献)
建立模块化旅行介绍与地点收集度描述,条件可编辑,概况读取地点基础字段
 
NotBot​(留言 | 贡献)
地点解锁支持 unlock.text 自定义文本,更新全角与半角问号区域解锁方式
第17行: 第17行:
     if type(record) ~= 'table' or type(record.descriptions) ~= 'table' then
     if type(record) ~= 'table' or type(record.descriptions) ~= 'table' then
         return { status = 'error', code = 'invalid-place-record', page = page }
         return { status = 'error', code = 'invalid-place-record', page = page }
    end
    if record.unlock ~= nil and type(record.unlock) ~= 'table' then
        return { status = 'error', code = 'invalid-place-unlock', page = page }
    end
    if record.unlock and record.unlock.text ~= nil and type(record.unlock.text) ~= 'string' then
        return { status = 'error', code = 'invalid-place-unlock-text', page = page }
     end
     end
     for _, key in ipairs({ 'cost', 'hours', 'distance', 'experience' }) do
     for _, key in ipairs({ 'cost', 'hours', 'distance', 'experience' }) do

2026年10月24日 (六) 13:56的版本

此模块的文档可以在模块:地点数据/doc创建

local p = {}
local cached
local page = '模板:地点信息/json'

function p.get(name)
    if not cached then
        local ok, value = pcall(mw.loadJsonData, page)
        if not ok or type(value) ~= 'table' or value.schemaVersion ~= 1 or type(value.records) ~= 'table' then
            cached = { status = 'error', code = 'invalid-place-data', page = page }
        else
            cached = { status = 'known', records = value.records }
        end
    end
    if cached.status == 'error' then return cached end
    local record = cached.records[name]
    if record == nil then return { status = 'none' } end
    if type(record) ~= 'table' or type(record.descriptions) ~= 'table' then
        return { status = 'error', code = 'invalid-place-record', page = page }
    end
    if record.unlock ~= nil and type(record.unlock) ~= 'table' then
        return { status = 'error', code = 'invalid-place-unlock', page = page }
    end
    if record.unlock and record.unlock.text ~= nil and type(record.unlock.text) ~= 'string' then
        return { status = 'error', code = 'invalid-place-unlock-text', page = page }
    end
    for _, key in ipairs({ 'cost', 'hours', 'distance', 'experience' }) do
        if type(record[key]) ~= 'number' or record[key] < 0 or record[key] >= math.huge then
            return { status = 'error', code = 'invalid-place-' .. key, page = page }
        end
    end
    for level, text in pairs(record.descriptions) do
        local n = tonumber(level)
        if not n or n <= 0 or n % 1 ~= 0 or type(text) ~= 'string' then
            return { status = 'error', code = 'invalid-place-description', page = page }
        end
    end
    return { status = 'known', record = record }
end

return p