米斯特利亚Wiki正在建设中,本WIKI编辑权限开放!欢迎参与~!
全站通知:
模块:InfoBox
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:InfoBox/doc创建
local smw = require('模块:SMW')
local items = require('模块:items')
local custom = require('模块:custom')
local Get = require('模块:Get')
local Utils = require('模块:Utils')
local p = {}
p.pageCategory = mw.text.jsonDecode(smw.show({
args = {"Data", "PageCategoryJson"}
}))
local function getProperty(t, propertyName)
if type(t) == 'table' and t[propertyName] then
return t[propertyName]
elseif t then
return ""
else
return nil
end
end
local function mergeTable(arg1, ...)
local result = {}
local function mergeOne(t)
if type(t) ~= 'table' then return end
for k, v in pairs(t) do
result[k] = v
end
end
-- 情况A:以数组形式传入 {table1, table2, ...}
if select('#', ...) == 0 and type(arg1) == 'table' then
local n = #arg1
if n > 0 then
for i = 1, n do
mergeOne(arg1[i])
end
else
-- 兜底:非数组结构时,遍历值为 table 的条目
for _, t in pairs(arg1) do
mergeOne(t)
end
end
return result
end
-- 情况B:可变参数传入 mergeTable(t1, t2, ...)
mergeOne(arg1)
local n = select('#', ...)
for i = 1, n do
mergeOne(select(i, ...))
end
return result
end
local function transTableToString(t)
if type(t) ~= 'table' then return t end
local out = {}
local function toFlatString(val)
if type(val) ~= 'table' then
if type(val) == 'boolean' then
return val and 'true' or 'false'
elseif val == nil then
return ''
else
return tostring(val)
end
end
-- val is a table: 优先按数组处理,否则遍历所有值
local parts = {}
if #val > 0 then
for i = 1, #val do parts[#parts+1] = tostring(val[i]) end
else
for _, v in pairs(val) do parts[#parts+1] = tostring(v) end
end
return table.concat(parts, ',')
end
for k, v in pairs(t) do
out[k] = toFlatString(v)
end
return out
end
function p.itemsInfo(id)
local frame = mw.getCurrentFrame()
frame.args = {id}
-- 获取博物馆信息
local museum_wings = require('模块:museum_wings')
return {
["中文名"] = items._name(id),
["英文名"] = items._name_en(id),
["描述"] = items._desc(id),
["食用效果"] = items._restore(id),
["出售价格"] = items._bin(id),
["捐献声望"] = items._renown(id),
["商店价格"] = items._store(id),
["博物馆收集"] = museum_wings.findMuseumSetByItem(frame) or "",
-- 制作信息
["原料"] = items.recipes(frame),
["制作时间"] = items._recipes_Time(id),
["技能等级"] = items._crafting_level_requirement(id),
}
end
function p.dishInfo(id)
return {
["tags"] = items._tags(id),
["星级"] = items._stars(id),
["厨房等级"] = items._kitchen_tier_requirement(id),
["配方解锁"] = items._recipe_is_default(id)
}
end
function p.cropInfo(id)
return {
["种子"] = items._name(items._seed_name(id)),
["季节"] = items._season(id),
["成熟时间"] = items._grow_days(id),
["收获数量"] = items._currency(id)
}
end
function p.bugsInfo(id)
local bugs = require('模块:bugs')
return{
["类型"]=bugs._type(id),
["稀有度"]=bugs._rarity(id),
["季节"]= bugs._season(id),
["天气"]=bugs._weather(id),
["时间"]=bugs._hours(id),
["生成规则"]=bugs._spawn(id),
["生成位置"]=bugs._locations(id),
["是否水生"]=bugs._can_spawn_on_water(id),
["矿井生成"]=bugs._dungeon_biome(id),
["偏好环境"]=bugs._liked_object_categories(id),
["吸引机制"]=bugs._attraction(id),
}
end
function p.fishInfo(id)
local fish = require('模块:fish')
return{
["类型"]=fish._legendary(id),
["稀有度"]=fish._rarity(id),
["季节"]=fish._season(id),
["天气"]=fish._weather(id),
["时间"]=fish._hours(id),
["水流区域"]=fish._water_type(id),
["位置限制"]=fish._location(id),
["鱼影"]=fish._size(id),
["获取方式"]=fish._retrieval(id),
["文物技能需求"]=fish._perk_artifact(id),
["钓鱼技能需求"]=fish._has_perk(id),
}
end
function p.render(frame)
local pageName = frame.args[1]
local category = p.pageCategory[pageName]
local id = items._id(pageName)
local moduleName = frame.args[2]
if moduleName == '' then
moduleName = "InfoBox/" .. category
end
local mTable = {}
local itemTable = p.itemsInfo(id)
table.insert(mTable, itemTable)
if category == "作物" or category == "采集物" then
table.insert(mTable, p.cropInfo(id))
elseif category == "种子" then
table.insert(mTable, {["作物"] = items._name(items._crop_object(id))})
elseif category == "昆虫" then
table.insert(mTable, p.bugsInfo(id))
elseif category == "鱼类" then
table.insert(mTable, p.fishInfo(id))
elseif category == "料理" then
table.insert(mTable, p.dishInfo(id))
end
local allTable = mergeTable(mTable)
local tmplateArgs = transTableToString(allTable);
smw._set(tmplateArgs)
mw.logObject(tmplateArgs)
return frame:expandTemplate{
title = moduleName,
args = tmplateArgs
}
end
--[[
local frame = mw.getCurrentFrame()
frame.args={"兰花螳螂","InfoBox/昆虫"}
p.render(frame)
local frame = mw.getCurrentFrame()
frame.args={"鲳鱼","InfoBox/鱼类"}
p.render(frame)
local frame = mw.getCurrentFrame()
frame.args={"芜菁","InfoBox/作物"}
p.render(frame)
local frame = mw.getCurrentFrame()
frame.args={"芜菁种子","InfoBox/种子"}
p.render(frame)
local frame = mw.getCurrentFrame()
frame.args={"野莓果酱","InfoBox/料理"}
p.render(frame)
]]--
return p