本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明

全站通知:

模块:Version links

来自我的世界地下城WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块是模块:Editions的变种,用于生成附带版本号的游戏版本的链接,主要用于{{Upcoming}}{{Until}}

从其他模块调用时,请使用versions函数;从模板调用时,请使用wrapper函数。

函数接受一个Lua table作为参数。其中,数字索引的值用作附带版本号的版本名称,格式为版本类型 版本号cat索引的值指定要生成的分类名称,版本名称以$代替,版本号以#代替,默认为$nocat索引的值指定是否不生成分类,默认为生成。

local p = {}

local versionLink = require([[Module:Version link]]).link

local fullName = mw.loadData([[Module:Editions/FullName]])
local shortName = mw.loadData([[Module:Editions/ShortName]])

function p.versions(args)
	local tbl = {}
	local categories = {}
	local nocat = args.nocat
	local isShort = args.short
	local catPlaceholder = args.cat or '$'
	for _, v in ipairs(args) do
		if v ~= '' then
			local edition, number = mw.ustring.match(v, '^(%S+)%s+(.+)$')
			edition = fullName[mw.ustring.lower(edition)] or edition .. '版'
			local text
			if isShort then
				text = (shortName[edition] or edition) .. (number and ' ' .. number or '')
			else
				text = edition .. number
			end
			local link = versionLink(v, text)
			table.insert(tbl, link)
			if not nocat then
				local cat = mw.ustring.gsub(catPlaceholder, '%$', edition)
				if number then
					cat = mw.ustring.gsub(cat, '#', '/' .. number)
				else
					cat = mw.ustring.gsub(cat, '#', '')
				end
				table.insert(categories, '[[Category:' .. cat .. ']]')
			end
		end
	end
	return mw.text.listToText(tbl) .. table.concat(categories)
end

function p.wrapper()
	local args = require([[Module:ProcessArgs]]).merge(true)
	return p.versions(args)
end

return p