米斯特利亚Wiki正在建设中,本WIKI编辑权限开放!欢迎参与~!
全站通知:
模块:Custom
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:Custom/doc创建
-- 模块:cunstom
-- 说明:通过中文名或ID查询对应的icon名。
-- 数据结构参考 ./data_lua/custom.lua:
-- { key(id) = { name = '中文名', icon = 'icon_sprite' }, ... }
local Utils = require('模块:Utils')
local Data = require('模块:custom/Data')
local MapData = require('模块:custom/MapData')
local p = {}
-- 内部函数:通过中文名查找ID
local function findIdByName(name)
if type(Data) ~= 'table' then return nil end
for id, item in pairs(Data) do
if type(item) == 'table' and item.name == name then
return id
end
end
return nil
end
-- p.id(frame): 如果传入的是中文名,则返回其ID;否则原样返回。
function p.id(frame)
local arg = frame and frame.args and frame.args[1]
if not arg or arg == '' then
return '<!-- 参数为空 -->'
end
if Utils.hasChinese(arg) then
local id = findIdByName(arg)
return id or '<!-- 未找到中文名对应的ID -->'
else
return arg
end
end
function p._name(arg)
if Utils.hasChinese(arg) then
return arg
end
if Data[arg] then
return Data[arg]["name"]
end
return nil
end
function p.name(frame)
local arg = frame.args[1]
p._name(arg)
end
-- 传入id table,返回name table
function p._nameTable(arr)
if type(arr) ~= 'table' then return {} end
local rArr = {}
for _,id in pairs(arr) do
table.insert(rArr,p._name(id))
end
return rArr
end
-- 传入id table,返回name组成的字符串
function p._nameTable2Str(arr)
local rArr = p._nameTable(arr)
return table.concat(rArr,",")
end
-- 传入id组成的字符串,返回name组成的字符串
function p._nameStr(str)
if type(str) ~= 'string' then return '' end
local arr = Utils.split(str)
local rArr = p._nameTable(arr)
return table.concat(rArr,",")
end
-- 传入id组成的字符串,返回name组成的table
function p._nameStr2Table(str)
if type(str) ~= 'string' then return {} end
local arr = Utils.split(str)
local rArr = p._nameTable(arr)
return rArr
end
-- p.icon(frame): 根据传入的中文名或ID,返回icon名。
function p._icon(id)
if Utils.hasChinese(id) then
id = findIdByName(id)
end
if type(id) ~= "string" then return id end
if Data and Data[id] and Data[id].icon then
return Data[id].icon
end
return id
end
function p.icon(frame)
local id = frame.args[1]
return p._icon(id)
end
-- 获取稀有度
function p._rarity(id)
if type(id) ~= "string" then return id end
if MapData and MapData.rarity[id] then
return MapData.rarity[id]
end
return id
end
-- 获取地图
function p._location(id)
if type(id) ~= "string" then return id end
if MapData and MapData.location[id] then
return MapData.location[id]
end
return id
end
function p._locationByTable(arg)
if arg ~= "" and type(arg) == "string" then
return t[arg] or arg
end
if type(arg) == 'table' then
local out = {}
for i, v in ipairs(arg) do
out[i] = MapData.location[v] or v
end
return table.concat(out, ",")
end
return nil
end
-- mw.log(p.id({args={"春天"}}))
-- mw.log(p.icon({args={"春天"}}))
return p