缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!
该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!
全站通知:
模块:图库/蓝图
刷
历
编
< 模块:图库
跳到导航
跳到搜索
此模块的文档可以在模块:图库/蓝图/doc创建
local p = {}
local getArgs = require('Module:Dev/Arguments').getArgs
local po = require('Module:Po').po
local dlcs = require('Module:Utils').DLC_ICONS
local outfits = mw.loadData('Module:Data/ClothingOutfits')
local permits = mw.loadData('Module:Data/PermitResources')
-- 常量定义
local EQUALS_SIGN = '='
local OUTFIT_CATEGORIES = {
Clothing = {
title = '衣服套装',
defaults = {'DupeTops', 'DupeBottoms', 'DupeGloves', 'DupeShoes'}
},
AtmoSuit = {
title = '太空服套装',
defaults = {'AtmoSuitHelmet', 'AtmoSuitBody', 'AtmoSuitGloves', 'AtmoSuitBelt', 'AtmoSuitShoes'}
},
JetSuit = {
title = '喷气服套装',
defaults = {'JetSuitHelmet', 'JetSuitBody', 'JetSuitGloves', 'JetSuitShoes'}
}
}
-- 工具函数
local function formatTitle(level, text)
return string.format('%s %s %s', EQUALS_SIGN:rep(level), text, EQUALS_SIGN:rep(level))
end
local function getItemDisplayInfo(item, displayDlc)
if not item then return nil end
local out = {
name = po(item.Name),
desc = string.format('<small>%s</small>', po(item.Description)),
suffix = ""
}
if item.Rarity then
if item.Rarity and item.Rarity ~= "Universal" then
out.suffix = "<br>" .. po('STRINGS.UI.PERMIT_RARITY.' .. item.Rarity:upper())
end
if displayDlc and item.requiredDlcIds then
out.suffix = out.suffix .. "<br>" .. dlcs[item.requiredDlcIds[1]]
end
end
return out
end
-- 按照默认顺序排序套装物品
local function sortOutfitItems(outfitSet, categoryId)
local defaultOrder = OUTFIT_CATEGORIES[categoryId] and OUTFIT_CATEGORIES[categoryId].defaults or {}
-- 创建物品ID到物品对象的映射
local itemMap = {}
for _, item in ipairs(outfitSet) do
itemMap[item.Category] = item
end
-- 按照默认顺序重新排列
local sortedSet = {}
for _, defaultId in ipairs(defaultOrder) do
if itemMap[defaultId] then
table.insert(sortedSet, itemMap[defaultId])
itemMap[defaultId] = nil -- 从映射中移除已添加的
end
end
-- 添加剩余不在默认顺序中的物品
for _, item in pairs(itemMap) do
table.insert(sortedSet, item)
end
return sortedSet
end
-- 核心功能函数
function p._set(args)
args = args or {}
local set = args.set or {}
local displayDlc = args.displayDlc ~= false -- 默认为true
local items = {}
for _, item in ipairs(set) do
local itemInfo = getItemDisplayInfo(item, displayDlc)
if itemInfo then
table.insert(items, itemInfo)
end
end
local galleryOutput = require('Module:图库').gallery(items)
return galleryOutput -- 返回原始字符串,由调用者预处理
end
function p._dlc(args)
if not args or not args.dlc then return '' end
local set = {}
for _, cat in ipairs(permits.displayedPermits or {}) do
for _, subcat in ipairs(cat.subcategoryIds or {}) do
for _, id in ipairs(cat[subcat] or {}) do
local item = permits.allPermits and permits.allPermits[id]
if item and item.requiredDlcIds and item.requiredDlcIds[1] == args.dlc then
table.insert(set, item)
end
end
end
end
local setOutput = p._set({set = set})
-- 在函数内部预处理输出
return mw.getCurrentFrame():preprocess(setOutput)
end
function p._id(args)
local titleLevel = tonumber(args.titleLevel) or 2
local out = {}
local set = {}
table.insert(out, formatTitle(titleLevel, "蓝图"))
for _, permitId in ipairs(permits.permitSortedByPrefabs[args.id] or {}) do
local item = permits.allPermits[permitId]
table.insert(set, item)
end
if #set < 1 then return "" end
table.insert(out, p._set({set = set}))
return table.concat(out, "\n")
end
function p._outfit(args)
local titleLevel = tonumber(args.titleLevel) or 2
local sequence = {"Clothing", "AtmoSuit", "JetSuit"}
local outputParts = {}
for _, categoryId in ipairs(sequence) do
table.insert(outputParts, formatTitle(titleLevel, OUTFIT_CATEGORIES[categoryId].title))
local categoryOutfits = {}
for _, outfitId in ipairs(outfits.displayedOutfits or {}) do
local outfit = outfits.allOutfits[outfitId]
if outfit.outfitType == categoryId then
local outfitSet = {}
for _, itemId in ipairs(outfit.itemsInOutfit or {}) do
local item = permits.allPermits and permits.allPermits[itemId]
if item then
table.insert(outfitSet, item)
end
end
if #outfitSet > 0 then
-- 按照默认顺序排序套装物品
local sortedOutfitSet = sortOutfitItems(outfitSet, categoryId)
mw.logObject(sortedOutfitSet)
local outfitContent = p._set({set = sortedOutfitSet})
table.insert(categoryOutfits,
formatTitle(titleLevel + 1, po(outfit.Name or '')) ..
'\n' .. outfitContent
)
end
end
end
table.insert(outputParts, table.concat(categoryOutfits, '\n'))
end
local combinedOutput = table.concat(outputParts, '\n')
return mw.getCurrentFrame():preprocess(combinedOutput)
end
function p._category(args)
local titleLevel = tonumber(args.titleLevel) or 2
local out = mw.html.create()
for _, cat in ipairs(permits.displayedPermits or {}) do
local categoryTitle = po('STRINGS.UI.KLEI_INVENTORY_SCREEN.TOP_LEVEL_CATEGORIES.' .. (cat.categoryId or ''))
local outCategory = out:tag('details'):tag('summary')
:wikitext(categoryTitle):attr('id', categoryTitle):done()
for _, subcat in ipairs(cat.subcategoryIds or {}) do
local subcatTitle = po('STRINGS.UI.KLEI_INVENTORY_SCREEN.SUBCATEGORIES.' .. subcat)
local set = {}
for _, id in ipairs(cat[subcat] or {}) do
local item = permits.allPermits and permits.allPermits[id]
if item then
table.insert(set, item)
end
end
if #set > 0 then
outCategory:tag('details'):tag('summary')
:wikitext(subcatTitle):attr('id', subcatTitle):done()
:wikitext(p._set({set = set})):done()
end
end
outCategory:done()
end
return tostring(out:allDone())
end
-- 主入口函数
function p._main(args)
if not args then return '' end
if args[1] == 'Outfits' then
return p._outfit(args)
elseif args.dlc then
return p._dlc(args)
elseif args.id then
return p._id(args)
else
return p._category(args)
end
end
function p.main(frame)
local args = getArgs(frame)
local output = p._main(args)
return mw.getCurrentFrame():preprocess(output)
end
return p

沪公网安备 31011002002714 号