模块:地点数据:修订间差异
外观
地点hours/distance/experience改为可选,空值不显示对应概况;cost仍必填,同步使用文档 |
VisualJSON:地点解锁迁移为 and/or 条件树,支持 use;校正太阳持有条件 |
||
| 第1行: | 第1行: | ||
local U = require('模块:地点解锁') | |||
local p = {} | local p = {} | ||
local cached | local cached | ||
| 第6行: | 第7行: | ||
if not cached then | if not cached then | ||
local ok, value = pcall(mw.loadJsonData, page) | local ok, value = pcall(mw.loadJsonData, page) | ||
if not ok or type(value) ~= 'table' or value.schemaVersion ~= | if not ok or type(value) ~= 'table' or value.schemaVersion ~= 2 or type(value.records) ~= 'table' then | ||
cached = { status = 'error', code = 'invalid-place-data', page = page } | cached = { status = 'error', code = 'invalid-place-data', page = page } | ||
else | else | ||
| 第17行: | 第18行: | ||
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 | end | ||
for _, key in ipairs({ 'cost', 'hours', 'distance', 'experience' }) do | for _, key in ipairs({ 'cost', 'hours', 'distance', 'experience' }) do | ||
| 第28行: | 第23行: | ||
local empty = key ~= 'cost' and (value == nil or | local empty = key ~= 'cost' and (value == nil or | ||
(type(value) == 'string' and mw.text.trim(value) == '')) | (type(value) == 'string' and mw.text.trim(value) == '')) | ||
if not empty and (type(value) ~= 'number' or value < 0 or value >= math.huge) then | if not empty and (type(value) ~= 'number' or value ~= value or value < 0 or value >= math.huge) then | ||
return { status = 'error', code = 'invalid-place-' .. key, page = page } | return { status = 'error', code = 'invalid-place-' .. key, page = page } | ||
end | end | ||
| 第38行: | 第33行: | ||
end | end | ||
end | end | ||
return { status = 'known', record = record } | local unlock = U.describe(record, 2) | ||
if unlock.status == 'error' then | |||
unlock.page = page | |||
return unlock | |||
end | |||
return { status = 'known', record = record, unlock = unlock } | |||
end | end | ||
return p | return p | ||
2026年11月12日 (四) 09:59的最新版本
此模块的文档可以在模块:地点数据/doc创建
local U = require('模块:地点解锁')
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 ~= 2 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
for _, key in ipairs({ 'cost', 'hours', 'distance', 'experience' }) do
local value = record[key]
local empty = key ~= 'cost' and (value == nil or
(type(value) == 'string' and mw.text.trim(value) == ''))
if not empty and (type(value) ~= 'number' or value ~= value or value < 0 or value >= 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
local unlock = U.describe(record, 2)
if unlock.status == 'error' then
unlock.page = page
return unlock
end
return { status = 'known', record = record, unlock = unlock }
end
return p