本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知)
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明)
全站通知:
模块:Version link
刷
历
编
跳到导航
跳到搜索
local p = {}
local mapPath = 'Module:Version link/map'
local function genNoCase( str )
local tbl = {}
local lowerStr = mw.ustring.lower( str )
local upperStr = mw.ustring.upper( str )
for i = 1, mw.ustring.len( str ) do
if mw.ustring.match( mw.ustring.sub( upperStr, i, i ), '^%a$' ) then
table.insert( tbl, table.concat( { '[', mw.ustring.sub( upperStr, i, i ), mw.ustring.sub( lowerStr, i, i ), ']' }, '' ) )
else
table.insert( tbl, mw.ustring.sub( upperStr, i, i ) )
end
end
return table.concat( tbl, '' )
end
local function removePrefix( s, prefixes )
local final = s
for _, p in ipairs( prefixes ) do
final = final:gsub( '^' .. p, '' )
end
return final
end
local function getLast( prefix )
return function( s )
local last = mw.ustring.match( s, '^.+%s+(%S+)$' )
if last then
return prefix .. last
else
return nil
end
end
end
local function getJava( s )
local prefix
if s:find( 'w' ) then
prefix = ''
else
prefix = 'Java版'
end
return prefix .. removePrefix( s, { genNoCase( 'java' ), genNoCase( ' edition' ), genNoCase( 'je' ), '%s+' } )
end
local function getBedrock( s )
local result = removePrefix( s, {
genNoCase( 'bedrock' ), genNoCase( ' edition' ), -- prefix "bedrock": Bedrock( Edition) ...
genNoCase( 'be' ), -- prefix "be": BE ...
'%s+'
} )
local newResult = mw.loadData(mapPath).bedrock[string.lower(result)]
if newResult then
result = newResult
end
return '基岩版' .. removePrefix( result, { genNoCase( 'beta' ), genNoCase( 'preview' ), '%s+' } )
end
local function getPocket( s )
local result = removePrefix( s, {
genNoCase( 'pocket' ), genNoCase( ' edition' ), -- prefix "pocket": Pocket( Edition) ...
genNoCase( 'pe' ), -- prefix "pe": PE ...
'%s+'
} )
local newResult = mw.loadData(mapPath).pocket[string.lower(result)]
if newResult then
result = newResult
end
return '携带版' .. string.gsub( removePrefix( result, { genNoCase( 'alpha' ), '%s+' } ), genNoCase( ' build ' ), '.b' )
end
local function getEducation( s )
return '教育版' .. removePrefix( s, {
genNoCase( 'edu' ), genNoCase( 'cation' ), genNoCase( ' edition' ), -- prefix "edu(cation)": Edu(cation)( Edition)
genNoCase( 'ee' ), -- prefix: ee "EE ..."
'%s+'
} )
end
local function getChinese()
return 'Minecraft:中国版#历史'
end
local function getLegacyConsole( s )
local verRegistry = {
['3ds'] = { 'New Nintendo 3DS版', { genNoCase( '3ds' ), '%s+' } }, -- Handled using the function for LCEs, but it is not a LCE.
ps = { 'PlayStation版', { genNoCase( 'ps' ), '%s+' } },
ps3 = { 'PlayStation 3版', { genNoCase( 'ps3' ), '%s+' } },
ps4 = { 'PlayStation 4版', { genNoCase( 'ps4' ), '%s+' } },
psv = { 'PlayStation Vita版', { genNoCase( 'psv' ), genNoCase( 'psvita' ), '%s+' } },
switch = { 'Nintendo Switch版', { genNoCase( 'switch' ), '%s+' } },
wiiu = { 'Wii U版', { genNoCase( 'wiiu' ), '%s+' } },
xb360 = { 'Xbox 360版', { genNoCase( 'xb360' ), '%s+' } },
xbone = { 'Xbox One版', { genNoCase( 'xbone' ), '%s+' } }
}
local verType = string.lower( mw.ustring.match( s, '^(%S+)%s+.+$' ) )
if verType == 'psvita' then
verType = 'psv'
end
local result
if verRegistry[verType][2] then
result = removePrefix( s, verRegistry[verType][2] )
end
local newResult = mw.loadData(mapPath)['lconsole'][verType][string.lower(result)]
if newResult then
return newResult
end
return verRegistry[verType][1] .. result
end
local prefixFunctions = {
['3ds'] = getLegacyConsole, -- Handled using the function for LCEs, but it is not a LCE.
alpha = getJava,
beta = getJava,
be = getBedrock,
bedrock = getBedrock,
ce = getLast( '原主机版版本记录#' ),
china = getChinese,
chinese = getChinese,
console = getLast( '原主机版版本记录#' ),
classic = getJava,
dungeons = getLast( 'MCD:' ),
earth = getLast( 'Minecraft Earth:' ),
edu = getEducation,
education = getEducation,
ee = getEducation,
indev = getJava,
infdev = getJava,
java = getJava,
je = getJava,
lce = getLast( '原主机版版本记录#' ),
legacy = getLast( '原主机版版本记录#' ),
pe = getPocket,
pocket = getPocket,
['pre-classic'] = getJava,
ps = getLegacyConsole,
ps3 = getLegacyConsole,
ps4 = getLegacyConsole,
psv = getLegacyConsole,
psvita = getLegacyConsole,
realms = getLast( 'Realms#' ),
switch = getLegacyConsole,
wiiu = getLegacyConsole,
xb360 = getLegacyConsole,
xbone = getLegacyConsole,
}
function p.version( s )
local v = removePrefix( s, { genNoCase( 'minecraft' ), '%s+' } )
local prefix = mw.text.split( v, '%s' )[1]:lower()
local func = prefixFunctions[prefix]
if func then
return func( v )
else
return s
end
end
function p.link( version, text )
return '[[' .. p.version( version ) ..
(text and ( '|' .. text ) or '') .. ']]'
end
function p.main( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( [[Module:ProcessArgs]] ).merge( true )
end
local text
if args[2] then
text = args[2]
else
text = getLast( '' )( args[1] ) or args[1]
end
return p.link( args[1], text )
end
return p