打开/关闭搜索
搜索
打开/关闭菜单
1K
5.2K
4
8.2K
星砂岛百科
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
上传文件
打开/关闭外观设置菜单
通知
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
本站正在进行早期测试,目前仍存在许多内容的缺失。
查看“︁模块:Item”︁的源代码
来自星砂岛百科
查看
阅读
查看源代码
查看历史
associated-pages
模块
讨论
更多操作
←
模块:Item
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:已验证邮箱用户
您没有权限编辑
模块
命名空间内的页面。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
local common = require('Module:Common') local css = require('Module:CSS') local item_common = require('Module:ItemCommon') local p = {} local name_data local desc_data local mapping local LUACACHE_NAMESPACE = 'item:render' local LUACACHE_VERSION = '2026-03-12' local function normalize_key(value) return item_common.normalizeKey(value) end local function load_name_data() if name_data then return end name_data, mapping = item_common.loadDomainData('数据:Item/item_name_index.json', '数据:Item/item_mapping.json') end local function load_desc_data() if desc_data then return end desc_data = common.loadJsonData('数据:Item/item_desc_index.json') or {} end local function resolve_input_key(value) local resolved = common.trim(value) if resolved == '' then resolved = common.getCurrentTitleText() end return resolved end local function find_name_record(key) load_name_data() return item_common.findRecord(name_data, mapping, key) end local function find_desc_record(key) load_name_data() load_desc_data() local name_record = find_name_record(key) if name_record and name_record.id then local by_id = desc_data[normalize_key(name_record.id)] if by_id then return by_id end end return item_common.findRecord(desc_data, mapping, key) end local function resolve_item_meta(key) load_name_data() local record = find_name_record(key) if record then local id = record.id or '' local name = common.trim(record.name or '') if name ~= '' then return id, name end if id ~= '' then local mapped_name = mapping.id_to_name and mapping.id_to_name[normalize_key(id)] or '' if common.trim(mapped_name) ~= '' then return id, common.trim(mapped_name) end end end local resolved = resolve_input_key(key) local normalized = normalize_key(resolved) local mapped_id = mapping.name_to_id and mapping.name_to_id[normalized] local item_id = mapped_id or resolved local mapped_name = mapping.id_to_name and mapping.id_to_name[normalize_key(item_id)] or '' if common.trim(mapped_name) ~= '' then return item_id, common.trim(mapped_name) end return item_id, resolved end local function get_item_meta(key, size, suffix, custom_link, css_class) if common.trim(resolve_input_key(key)) == '' then return nil end local item_id, display_name = resolve_item_meta(key) local final_size = common.trim(size) if final_size == '' then final_size = '24' end local class_name = 'itemtemplate' if common.trim(css_class) == 'block' then class_name = class_name .. ' itemtemplateblock' end local file_name = item_id if file_name == '' then file_name = display_name end local link_text local link_target if common.trim(custom_link) ~= '' then link_target = custom_link link_text = ('[[%s|%s]]'):format(custom_link, display_name) else link_target = display_name link_text = ('[[%s]]'):format(display_name) end return { item_id = item_id, name = display_name, size = final_size, suffix = common.trim(suffix), link_target = link_target, link_text = link_text, class_name = class_name, file_name = file_name, key = normalize_key(resolve_input_key(key)), } end local function render_markup(meta) if not meta then return '' end local file_name = common.trim(meta.file_name or '') local image_name = '' local has_icon = false if file_name ~= '' then image_name = file_name .. '.png' has_icon = common.filePageExists(image_name) end local out = {} out[#out + 1] = ('<span class="%s">'):format(meta.class_name) if has_icon then out[#out + 1] = '<span class="item-icon-container">' out[#out + 1] = ('[[File:%s|%sx%spx|link=%s]]'):format(image_name, meta.size, meta.size, meta.link_target) out[#out + 1] = '</span>' end out[#out + 1] = '<span class="item-text">' out[#out + 1] = meta.link_text if meta.suffix ~= '' then out[#out + 1] = ('(%s)'):format(meta.suffix) end out[#out + 1] = '</span>' out[#out + 1] = '</span>' return table.concat(out) end function p.getNameByKey(key) local _, name = resolve_item_meta(key) return name end function p.getIdByKey(key) local id, _ = resolve_item_meta(key) return id end function p.getName(frame) local _, name = resolve_item_meta(common.getArg(frame, 1, '')) return name end function p.getId(frame) local id, _ = resolve_item_meta(common.getArg(frame, 1, '')) return id end function p.getDescription(frame) local record = find_desc_record(common.getArg(frame, 1, '')) if not record then return '' end return common.toText(record.description) end function p.renderItem(frame) local key = common.getArg(frame, 1, '') local size = common.getArg(frame, 'size', '') local suffix = common.getArg(frame, 2, '') local custom_link = common.getArg(frame, 'link', '') local css_class = common.getArg(frame, 'class', '') local meta = get_item_meta(key, size, suffix, custom_link, css_class) if not meta then return '' end local cache_parts = { meta.key, normalize_key(meta.item_id), normalize_key(meta.name), meta.size, meta.suffix, meta.link_target, meta.class_name, } local cache_key = common.buildLuaCacheKey( LUACACHE_NAMESPACE, LUACACHE_VERSION, table.concat(cache_parts, '|') ) local output = common.luaCacheGet(cache_key) if output == nil then output = render_markup(meta) common.luaCacheSet(cache_key, output) end local css_out = css.quickCall('Item') or '' return css_out .. output end function p.renderItemWithArgs(frame, args) if not args then return '' end local key = common.trim(args[1] or '') local size = common.trim(args.size or '') local suffix = common.trim(args[2] or '') local custom_link = common.trim(args.link or '') local css_class = common.trim(args.class or '') local meta = get_item_meta(key, size, suffix, custom_link, css_class) if not meta then return '' end return render_markup(meta) end function p.renderPureItem(frame, args) local params = args if not params then if frame == mw.getCurrentFrame() and frame:getParent() then params = require('Module:ProcessArgs').merge(true) else params = frame end end if not params then return '' end return p.renderItemWithArgs(nil, params) end return p
该页面嵌入的页面:
模块:Item/doc
(
查看源代码
)
返回
模块:Item
。
查看“︁模块:Item”︁的源代码
来自星砂岛百科