缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!

该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!

全站通知:

模块:成就

来自缺氧WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:成就/doc创建

-- Module:成就
local achievements = require("Module:Data/Achievements")
local po = require("Module:Po").po
local getArgs = require("Module:Dev/Arguments").getArgs
local codesPattern = '(%S-),'
local p = {}

-- test by: =p.formatAchievement({name = "COMPLETED_RESEARCH",args = {}})
-- test by: =p.formatAchievement({name = "BUILD_NATURE_RESERVES",  args = {['$0'] = require("Module:Po").po("STRINGS.DUPLICANTS.MODIFIERS.ROOMNATURERESERVE.NAME"), ['$1'] = "4"}})
function p.formatAchievement(achievement)
	local prefix = "STRINGS.COLONY_ACHIEVEMENTS.MISC_REQUIREMENTS."
	local name = po(prefix..achievement.name)
	local args = achievement.args
	args.format = #args > 0
	args[1] = prefix..achievement.name.."_DESCRIPTION"
	local desc = po(args)
	return mw.getCurrentFrame():expandTemplate({title = "成就/内容", args = {name, desc}})
end

--test by: =p._main({})
--test by: =p._main({code = "BUILD_NATURE_RESERVES"})
--test by: =p._main({code = "TWENTY_DUPES, TAME_GASSYMOO"})
function p._main(args)
	local out = {}
	local codes = {}
	if args.code then
		args.code = args.code .. ','
		args.code = mw.ustring.gsub(args.code, ' ', '')
		for code in mw.ustring.gmatch(args.code, codesPattern) do
			table.insert(codes, code)
		end
	end
	local flag = #codes == 0
	for _, achievement in ipairs(achievements) do
		local found = false
		for _, code in ipairs(codes) do
			if code and code == achievement.name then
				found = true
				break
			end
		end
		if flag or found then
			table.insert(out, p.formatAchievement(achievement))
		end
	end
	return table.concat(out, '')
end

function p.main(frame) return p._main(getArgs(frame)) end

return p