Cafeinlove (메시지 담벼락 | 기여) (Pokedex.main 함수를 통해 전체를 관리. 캐시를 적극적으로 활용.) 태그: sourceedit |
Cafeinlove (메시지 담벼락 | 기여) (author 코멘트 추가) 태그: sourceedit |
||
(같은 사용자의 중간 판 13개는 보이지 않습니다) | |||
1번째 줄: | 1번째 줄: | ||
+ | -- 포켓몬 도감 관련 모듈 |
||
− | local Pokedex = {} |
||
+ | -- @Author: [[User:Cafeinlove]] at ko.pokemon.wikia.com |
||
+ | -- @License: MIT License |
||
− | local |
+ | local pokedex = {} |
⚫ | |||
− | local forms |
||
+ | -- Dependencies |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
-- [[틀:번2포]] |
-- [[틀:번2포]] |
||
− | function |
+ | function pokedex.getName ( index ) |
+ | return dexData[index] or '없는 번호입니다.' |
||
− | local dexKey = args[1] |
||
− | return dexData[dexKey] |
||
end |
end |
||
+ | |||
− | |||
-- [[틀:포번앞]] |
-- [[틀:포번앞]] |
||
− | function |
+ | function pokedex.getPrevIndex ( index ) |
− | local currentIndex = tonumber( |
+ | local currentIndex = tonumber( index ) |
local prevIndex = ( currentIndex > 1 ) and ( currentIndex - 1 ) or dexSize |
local prevIndex = ( currentIndex > 1 ) and ( currentIndex - 1 ) or dexSize |
||
return string.format( '%03d', prevIndex ) |
return string.format( '%03d', prevIndex ) |
||
end |
end |
||
+ | |||
− | |||
-- [[틀:포번뒤]] |
-- [[틀:포번뒤]] |
||
− | function |
+ | function pokedex.getNextIndex ( index ) |
− | local currentIndex = tonumber( |
+ | local currentIndex = tonumber( index ) |
local nextIndex = ( currentIndex < dexSize ) and ( currentIndex + 1 ) or 1 |
local nextIndex = ( currentIndex < dexSize ) and ( currentIndex + 1 ) or 1 |
||
return string.format( '%03d', nextIndex ) |
return string.format( '%03d', nextIndex ) |
||
end |
end |
||
+ | |||
− | |||
-- [[틀:폼문자]] |
-- [[틀:폼문자]] |
||
− | function |
+ | function pokedex.getFormLetter ( name ) |
+ | local ret = forms[name] and forms[name][2] or '없는 폼입니다.' |
||
− | local formName = args[1] |
||
− | local ret = '' |
||
− | if not formName then return ret end |
||
− | |||
− | for key, value in pairs( forms ) do |
||
− | if formName == value[1] then |
||
− | ret = value[3] |
||
− | end |
||
− | end |
||
− | |||
return ret |
return ret |
||
end |
end |
||
+ | |||
− | |||
-- [[틀:폼이름]] |
-- [[틀:폼이름]] |
||
− | function |
+ | function pokedex.getFormName ( name ) |
− | local |
+ | local ret = forms[name] and forms[name][1] or '없는 폼입니다.' |
− | local ret = '' |
||
− | if not formName then return ret end |
||
− | |||
− | for key, value in pairs( forms ) do |
||
− | if formName == value[1] then |
||
− | ret = value[2] |
||
− | end |
||
− | end |
||
− | |||
return ret |
return ret |
||
end |
end |
||
− | |||
⚫ | |||
− | -- 인자 관리 모듈이 캐시되어 있지 않으면 정의 |
||
− | if not getArgs then |
||
⚫ | |||
− | end |
||
− | -- 도감 데이터가 캐시되어 있지 않으면 정의 |
||
− | if not dex then |
||
⚫ | |||
− | dexSize = dex.size |
||
⚫ | |||
− | end |
||
− | -- `다른 폼` 데이터가 캐시되어 있지 않으면 정의 |
||
− | if not forms then |
||
⚫ | |||
− | end |
||
⚫ | |||
local args = getArgs( frame ) |
local args = getArgs( frame ) |
||
local requested = args['request'] |
local requested = args['request'] |
||
− | local result = |
+ | local result = pokedex[requested] and pokedex[requested]( args[1] ) |
+ | |||
− | |||
return result |
return result |
||
end |
end |
||
+ | |||
− | |||
− | return |
+ | return pokedex |
2017년 2월 1일 (수) 09:18 판
이 모듈에 대한 설명문서는 모듈:Pokedex/설명문서에서 만들 수 있습니다
-- 포켓몬 도감 관련 모듈
-- @Author: [[User:Cafeinlove]] at ko.pokemon.wikia.com
-- @License: MIT License
local pokedex = {}
-- Dependencies
local getArgs = getArgs or require( 'Module:Arguments' ).getArgs
local dex = dex or mw.loadData( 'Module:Pokedex/Data' )
local dexSize = dexSize or dex.size
local dexData = dexData or dex.data
local forms = forms or mw.loadData( 'Module:Pokedex/Forms' )
-- [[틀:번2포]]
function pokedex.getName ( index )
return dexData[index] or '없는 번호입니다.'
end
-- [[틀:포번앞]]
function pokedex.getPrevIndex ( index )
local currentIndex = tonumber( index )
local prevIndex = ( currentIndex > 1 ) and ( currentIndex - 1 ) or dexSize
return string.format( '%03d', prevIndex )
end
-- [[틀:포번뒤]]
function pokedex.getNextIndex ( index )
local currentIndex = tonumber( index )
local nextIndex = ( currentIndex < dexSize ) and ( currentIndex + 1 ) or 1
return string.format( '%03d', nextIndex )
end
-- [[틀:폼문자]]
function pokedex.getFormLetter ( name )
local ret = forms[name] and forms[name][2] or '없는 폼입니다.'
return ret
end
-- [[틀:폼이름]]
function pokedex.getFormName ( name )
local ret = forms[name] and forms[name][1] or '없는 폼입니다.'
return ret
end
function pokedex.main( frame )
local args = getArgs( frame )
local requested = args['request']
local result = pokedex[requested] and pokedex[requested]( args[1] )
return result
end
return pokedex