更多操作
小 (拆分) |
小 (fix) |
||
第11行: | 第11行: | ||
return meta, true |
return meta, true |
||
elseif meta == nil then |
elseif meta == nil then |
||
return |
return 'emoji遗失, 名称: ' .. name, false |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
elseif type(meta) ~= 'string' then |
elseif type(meta) ~= 'string' then |
||
return |
return 'emoji配置不正确, 类型: ' .. type(meta), false |
||
⚫ | |||
⚫ | |||
⚫ | |||
'emoji配置不正确, 类型: ' .. type(meta), |
|||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |
||
第35行: | 第23行: | ||
meta = (meta.aliases or {})[varietyName] |
meta = (meta.aliases or {})[varietyName] |
||
if meta == nil then |
if meta == nil then |
||
⚫ | |||
return frame:expandTemplate { |
|||
⚫ | |||
args = { |
|||
⚫ | |||
'emoji变种遗失, 变种名称: ' .. varietyName, |
|||
}, |
|||
}, false |
|||
elseif type(meta) == 'string' then |
elseif type(meta) == 'string' then |
||
return |
return 'emoji变种暂未支持别名', false |
||
title = '?', |
|||
args = { |
|||
'[[help:emoji|❓]]', |
|||
'emoji变种暂未支持别名', |
|||
}, |
|||
}, false |
|||
elseif type(meta) ~= 'table' then |
elseif type(meta) ~= 'table' then |
||
return |
return 'emoji变种配置不正确, 类型:' .. type(meta), false |
||
title = '?', |
|||
args = { |
|||
'[[help:emoji|❓]]', |
|||
'emoji变种配置不正确, 类型:' .. type(meta), |
|||
}, |
|||
}, false |
|||
end |
end |
||
return meta, true |
return meta, true |
||
第80行: | 第50行: | ||
local metaOrError, succ = getEmojiMeta(data, name) |
local metaOrError, succ = getEmojiMeta(data, name) |
||
if not succ then |
if not succ then |
||
return |
return frame:expandTemplate { |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
local meta = metaOrError |
local meta = metaOrError |
||
第87行: | 第63行: | ||
local metaOrError, succ = resolveVariety(meta, var) |
local metaOrError, succ = resolveVariety(meta, var) |
||
if not succ then |
if not succ then |
||
return |
return frame:expandTemplate { |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
meta = metaOrError |
meta = metaOrError |
2019年4月17日 (三) 03:27的版本
此模块的文档可以在模块:Emoji/doc创建
local p = {}
local data = require('Module:emoji/data')
local function getEmojiMeta(data, name)
-- 获取该名称 emoji 的元数据, 处理别名
local meta = name
while true do
meta = data.emojis[meta]
if type(meta) == 'table' then
return meta, true
elseif meta == nil then
return 'emoji遗失, 名称: ' .. name, false
elseif type(meta) ~= 'string' then
return 'emoji配置不正确, 类型: ' .. type(meta), false
end
end
end
local function resolveVariety(meta, varietyName)
-- 处理变种 (如果指定了)
-- 变种暂时不支持别名 (懒)
meta = (meta.aliases or {})[varietyName]
if meta == nil then
return 'emoji变种遗失, 变种名称: ' .. varietyName, false
elseif type(meta) == 'string' then
return 'emoji变种暂未支持别名', false
elseif type(meta) ~= 'table' then
return 'emoji变种配置不正确, 类型:' .. type(meta), false
end
return meta, true
end
function p.emoji()
local frame = mw.getCurrentFrame():getParent()
local name = frame.args[1]
local var = nil
-- 接受两种格式来指定变种:
-- {{e|名称/变种名}}
-- {{e|名称|变种名}}
local varSepPosi = string.find(name, '/')
if varSepPosi ~= nil then
var = string.sub(name, varSepPosi + 1)
name = string.sub(name, 1, varSepPosi - 1)
else
var = frame.args[2]
end
local metaOrError, succ = getEmojiMeta(data, name)
if not succ then
return frame:expandTemplate {
title = '?',
args = {
'[[help:emoji|❓]]',
metaOrError,
},
}
end
local meta = metaOrError
if var ~= nil then
local metaOrError, succ = resolveVariety(meta, var)
if not succ then
return frame:expandTemplate {
title = '?',
args = {
'[[help:emoji|❓]]',
metaOrError,
},
}
end
meta = metaOrError
end
if type(meta.position) ~= 'table'
or type(meta.position[1]) ~= 'number'
or type(meta.position[2]) ~= 'number'
then
return frame:expandTemplate {
title = '?',
args = {
'[[help:emoji|❓]]',
'emoji位置配置不正确',
},
}
end
local image = data.texture.image
local row = meta.position[1]
local col = meta.position[2]
local width = data.texture.unitSize[1]
local height = data.texture.unitSize[2]
local y = row * height
local x = col * width
return frame:expandTemplate {
title = 'image crop',
width = width,
height = height,
y = y,
x = x,
image = '[[File:' .. image .. '|link=help:emoji]]',
}
end
return p