打开/关闭菜单
切换首选项菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:GetGenres:修订间差异

来自此界与彼端
无编辑摘要
无编辑摘要
第12行: 第12行:
Platform = '平台',
Platform = '平台',
Puzzle = '解谜',
Puzzle = '解谜',
['Real Time Strategy (RTS)'] = '即时战略',
['Role-playing (RPG)'] = '角色扮演',
['Role-playing (RPG)'] = '角色扮演',
['Turn-based strategy (TBS)'] = '回合制策略'
['Turn-based strategy (TBS)'] = '回合制策略'

2025年3月26日 (三) 15:12的版本

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

local getArgs = require('Module:Arguments').getArgs

local p = {}

local types = {
	Arcade = '街机',
	Adventure = '冒险',
	Shooter = '射击',
	Simulator = '模拟',
	Strategy = '策略',
	Indie = '独立',
	Platform = '平台',
	Puzzle = '解谜',
	['Real Time Strategy (RTS)'] = '即时战略',
	['Role-playing (RPG)'] = '角色扮演',
	['Turn-based strategy (TBS)'] = '回合制策略'
}

function p.replace(str, target, result)
	local res = str:gsub(target, result)
	return res
end

function p.isKeyInTable(keyToCheck)
    for key in pairs(types) do
        if key == keyToCheck then
        	mw.log(key)
            return true
        end
    end
    return false
end

function p.split(str, separator)
    local fields = {}
    local temp = str:gsub(", ", ",")
    temp:gsub("[^"..separator.."]+", function(c) fields[#fields + 1] = c end)
    return fields
end

function p.exec(str)
	local arr = p.split(str, ",")
	local ret = ""
	for key, value in pairs(arr) do
	    if p.isKeyInTable(value) then
	        ret = ret.."[[:分类:类型/"..types[value].."|"..types[value].."]][[分类:类型/"..types[value].."]] "
	    else
	    	ret = ret..value.."[[分类:类型/缺少类型]] "
    	end
    end
	mw.logObject(ret)
	return ret
end

function p.getGenres(frame)
	local args = getArgs(frame)
	return p.exec(args[1])
end

return p