打开/关闭搜索
搜索
打开/关闭菜单
1K
5.2K
4
8.2K
星砂岛百科
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
上传文件
打开/关闭外观设置菜单
通知
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
本站正在进行早期测试,目前仍存在许多内容的缺失。
查看“︁模块:ItemCommon”︁的源代码
来自星砂岛百科
查看
阅读
查看源代码
查看历史
associated-pages
模块
讨论
更多操作
←
模块:ItemCommon
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:已验证邮箱用户
您没有权限编辑
模块
命名空间内的页面。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
local common = require('Module:Common') local p = {} function p.normalizeKey(value) return common.normalizeKey(value) end function p.loadDomainData(data_page, mapping_page) local data = common.readJsonPage(data_page) or {} local mapping = common.readJsonPage(mapping_page) or { name_to_id = {}, id_to_name = {}, aliases = {}, overrides = { name_to_id = {}, aliases = {}, }, } return data, mapping end function p.findRecord(data, mapping, key) local resolved = common.trim(key) if resolved == '' then resolved = common.getCurrentTitleText() end local normalized = p.normalizeKey(resolved) if data[normalized] then return data[normalized] end local override_id = mapping.overrides and mapping.overrides.name_to_id and mapping.overrides.name_to_id[normalized] if override_id and data[p.normalizeKey(override_id)] then return data[p.normalizeKey(override_id)] end local override_alias = mapping.overrides and mapping.overrides.aliases and mapping.overrides.aliases[normalized] if override_alias and data[p.normalizeKey(override_alias)] then return data[p.normalizeKey(override_alias)] end local mapped_id = mapping.name_to_id and mapping.name_to_id[normalized] if mapped_id and data[p.normalizeKey(mapped_id)] then return data[p.normalizeKey(mapped_id)] end local alias_id = mapping.aliases and mapping.aliases[normalized] if alias_id and data[p.normalizeKey(alias_id)] then return data[p.normalizeKey(alias_id)] end return nil end function p.getField(record, field) if type(record) ~= 'table' then return '' end return record[field] end function p.itemLink(frame, item_name, count) if common.trim(item_name) == '' then return '' end local args = { item_name } if count and tonumber(count) and tonumber(count) ~= 1 then args[2] = tostring(count) end return frame:expandTemplate{ title = 'Item', args = args, } end function p.machineLinks(machine_names) if type(machine_names) ~= 'table' or #machine_names == 0 then return '' end local parts = {} for _, machine_name in ipairs(machine_names) do if common.trim(machine_name) ~= '' then parts[#parts + 1] = '[[' .. machine_name .. ']]' end end return table.concat(parts, '、') end function p.renderRecipeList(frame, recipes) if type(recipes) ~= 'table' or #recipes == 0 then return '' end local out = {} for _, recipe in ipairs(recipes) do if type(recipe) == 'table' then local row = {} local machine_name = common.trim(recipe.machine) if machine_name ~= '' then row[#row + 1] = ('[[%s]]'):format(machine_name) end local material_parts = {} if type(recipe.materials) == 'table' then for material_name, count in pairs(recipe.materials) do material_parts[#material_parts + 1] = p.itemLink(frame, material_name, count) end end if #material_parts > 0 then row[#row + 1] = table.concat(material_parts, '') end if #row > 0 then out[#out + 1] = table.concat(row, ':') end end end return table.concat(out, '<br>') end function p.buildRecipeDomain(module_table, data_page, mapping_page) local data_cache local mapping_cache local function load_data() if data_cache then return end data_cache, mapping_cache = p.loadDomainData(data_page, mapping_page) end local function find_record(key) load_data() return p.findRecord(data_cache, mapping_cache, key) end function module_table.getField(frame) local key = common.getArg(frame, 1, '') local field = common.getArg(frame, 2, '') if field == '' then return '' end local record = find_record(key) if not record then return '' end if field == 'production_machines_display' then return p.machineLinks(record.production_machines) end if field == 'process_machines_display' then return p.machineLinks(record.process_machines) end return common.toText(p.getField(record, field)) end function module_table.productionRecipeList(frame) local record = find_record(common.getArg(frame, 1, '')) if not record then return '' end return p.renderRecipeList(frame, record.production_recipes) end function module_table.processRecipeList(frame) local record = find_record(common.getArg(frame, 1, '')) if not record then return '' end return p.renderRecipeList(frame, record.process_recipes) end function module_table.machineList(frame) local record = find_record(common.getArg(frame, 1, '')) if not record then return '' end if common.getArg(frame, 2, 'process') == 'production' then return p.machineLinks(record.production_machines) end return p.machineLinks(record.process_machines) end end return p
该页面嵌入的页面:
模块:ItemCommon/doc
(
查看源代码
)
返回
模块:ItemCommon
。
查看“︁模块:ItemCommon”︁的源代码
来自星砂岛百科