編集の要約なし |
編集の要約なし |
||
(同じ利用者による、間の4版が非表示) | |||
4行目: | 4行目: | ||
cookable = 'able', |
cookable = 'able', |
||
renewable = 'able', |
renewable = 'able', |
||
− | |||
canspawn = 'can', |
canspawn = 'can', |
||
gravity = 'can', |
gravity = 'can', |
||
transparent = 'can', |
transparent = 'can', |
||
− | |||
['end support'] = 'some', |
['end support'] = 'some', |
||
flammable = 'some', |
flammable = 'some', |
||
− | ['nether support'] = 'some' |
+ | ['nether support'] = 'some', |
+ | |||
+ | dirt = true, |
||
+ | light = true, |
||
+ | ['source available'] = true, |
||
+ | ['stackable'] = true, |
||
+ | type = true |
||
} |
} |
||
local i18n = { |
local i18n = { |
||
+ | na = '?', |
||
+ | |||
yesAble = '可', |
yesAble = '可', |
||
yesCan = 'する', |
yesCan = 'する', |
||
71行目: | 77行目: | ||
local args = require( 'Module:ProcessArgs' ).merge( true ) |
local args = require( 'Module:ProcessArgs' ).merge( true ) |
||
local param = args[ 1 ] |
local param = args[ 1 ] |
||
− | local |
+ | local origVal = args[ 2 ] |
+ | local val = origVal |
||
− | and args[ 2 ] or '?' |
||
local result |
local result |
||
− | if not param or |
+ | if not param or not origVal then |
+ | if param == 'flammable' then |
||
⚫ | |||
+ | return i18n.noSome |
||
+ | elseif param and paramsGrp[ param:lower() ] then |
||
⚫ | |||
+ | end |
||
+ | return origVal or '' |
||
end |
end |
||
param = param:lower() |
param = param:lower() |
||
val = val:lower() |
val = val:lower() |
||
+ | |||
+ | if i18n.type[ val ] then |
||
+ | return i18n.type[ val ] |
||
+ | end |
||
-- Normal yes/no check |
-- Normal yes/no check |
||
86行目: | 101行目: | ||
result = val == 'yes' |
result = val == 'yes' |
||
and i18n.yesAble or val == 'no' |
and i18n.yesAble or val == 'no' |
||
− | and i18n.noAble or |
+ | and i18n.noAble or origVal |
elseif paramsGrp[ param ] == 'can' then |
elseif paramsGrp[ param ] == 'can' then |
||
result = val == 'yes' |
result = val == 'yes' |
||
and i18n.yesCan or val == 'no' |
and i18n.yesCan or val == 'no' |
||
− | and i18n.noCan or |
+ | and i18n.noCan or origVal |
elseif paramsGrp[ param ] == 'some' then |
elseif paramsGrp[ param ] == 'some' then |
||
result = val == 'yes' |
result = val == 'yes' |
||
and i18n.yesSome or val == 'no' |
and i18n.yesSome or val == 'no' |
||
− | and i18n.noSome or |
+ | and i18n.noSome or origVal |
end |
end |
||
103行目: | 118行目: | ||
result = val == 'yes' |
result = val == 'yes' |
||
and i18n.yesDirt or val == 'no' |
and i18n.yesDirt or val == 'no' |
||
− | and i18n.noDirt or |
+ | and i18n.noDirt or origVal |
elseif param == 'light' then |
elseif param == 'light' then |
||
local lightLv = val:match( '^%d+$' ) or val:match( 'yes,?%s*%(?(%d+)%)?' ) |
local lightLv = val:match( '^%d+$' ) or val:match( 'yes,?%s*%(?(%d+)%)?' ) |
||
− | + | lightLv = tonumber( lightLv ) |
|
+ | result = ( 0 < lightLv and lightLv < 16 ) |
||
and i18n.yesLight:format( lightLv ) or val == 'yes' |
and i18n.yesLight:format( lightLv ) or val == 'yes' |
||
and i18n.yesLightP or ( val == 'no' or tonumber( val ) == 0 ) |
and i18n.yesLightP or ( val == 'no' or tonumber( val ) == 0 ) |
||
− | and i18n.noLight or |
+ | and i18n.noLight or origVal |
elseif param == 'source available' then |
elseif param == 'source available' then |
||
− | local link = val:match( '^[(%S+)%s' ) |
+ | local link = val:match( '^%[(%S+)%s' ) |
− | local text = val:match( '%s(.+)]$' ) |
+ | local text = val:match( '%s(.+)%]$' ) |
result = text == 'yes' |
result = text == 'yes' |
||
and i18n.yesSource:format( link ) or val == 'yes' |
and i18n.yesSource:format( link ) or val == 'yes' |
||
and i18n.yesSourceP or val == 'no' |
and i18n.yesSourceP or val == 'no' |
||
− | and i18n.noSource or |
+ | and i18n.noSource or origVal |
elseif param == 'stackable' then |
elseif param == 'stackable' then |
||
local stackSize = val:gsub( 'yes%s*%((%d+)%)', '%1' ) |
local stackSize = val:gsub( 'yes%s*%((%d+)%)', '%1' ) |
||
+ | |||
+ | if stackSize == val then |
||
⚫ | |||
+ | end |
||
+ | |||
result = ( 0 < tonumber( stackSize ) and tonumber( stackSize ) <= 64 ) |
result = ( 0 < tonumber( stackSize ) and tonumber( stackSize ) <= 64 ) |
||
and i18n.yesStackable:format( stackSize ) or val == 'yes' |
and i18n.yesStackable:format( stackSize ) or val == 'yes' |
||
and i18n.yesStackableP or val == 'no' |
and i18n.yesStackableP or val == 'no' |
||
− | and i18n.noStackable or |
+ | and i18n.noStackable or origVal |
end |
end |
||
− | + | return result or origVal |
|
− | |||
⚫ | |||
end |
end |
||
2019年7月14日 (日) 17:29時点における最新版
local p = {}
local paramsGrp = {
cookable = 'able',
renewable = 'able',
canspawn = 'can',
gravity = 'can',
transparent = 'can',
['end support'] = 'some',
flammable = 'some',
['nether support'] = 'some',
dirt = true,
light = true,
['source available'] = true,
['stackable'] = true,
type = true
}
local i18n = {
na = '?',
yesAble = '可',
yesCan = 'する',
yesSome = 'あり',
noAble = '不可',
noCan = 'しない',
noSome = 'なし',
yesDirt = '日光と土が必要',
yesLight = 'する(%s)',
yesLightP = 'する',
yesSource = '[%s 可]',
yesSourceP = '可',
yesStackable = '可(%s)',
yesStackableP = '可',
noDirt = '日光と砂が必要',
noLight = 'しない',
noSource = '不可',
noStackable = '不可',
type = {
armor = '防具',
block = 'ブロック',
['block entity'] = 'ブロックエンティティ',
['building block'] = '建築ブロック',
combat = '戦闘',
['decoration block'] = '装飾ブロック',
decorations = '装飾',
dyes = '染料',
entity = 'エンティティ',
fluid = '液体',
food = '食料',
foodstuff = '食料',
item = 'アイテム',
items = 'アイテム',
['non-solid block'] = '非個体ブロック',
plant = '植物',
plants = '植物',
potions = 'ポーション',
projectile = '発射物',
['raw materials'] = '原材料',
manufactured = '加工品',
['solid block'] = '個体ブロック',
['tile entity'] = 'タイルエンティティ',
tool = '道具',
tools = '道具',
transport = '運送',
unknown = '不明',
vehicles = '乗り物',
weapon = '武器',
['wearable items'] = '装備アイテム'
}
}
function p.conv( f )
local args = require( 'Module:ProcessArgs' ).merge( true )
local param = args[ 1 ]
local origVal = args[ 2 ]
local val = origVal
local result
if not param or not origVal then
if param == 'flammable' then
return i18n.noSome
elseif param and paramsGrp[ param:lower() ] then
return i18n.na
end
return origVal or ''
end
param = param:lower()
val = val:lower()
if i18n.type[ val ] then
return i18n.type[ val ]
end
-- Normal yes/no check
if paramsGrp[ param ] == 'able' then
result = val == 'yes'
and i18n.yesAble or val == 'no'
and i18n.noAble or origVal
elseif paramsGrp[ param ] == 'can' then
result = val == 'yes'
and i18n.yesCan or val == 'no'
and i18n.noCan or origVal
elseif paramsGrp[ param ] == 'some' then
result = val == 'yes'
and i18n.yesSome or val == 'no'
and i18n.noSome or origVal
end
if result then return result end
-- Special yes/no check
if param == 'dirt' then
result = val == 'yes'
and i18n.yesDirt or val == 'no'
and i18n.noDirt or origVal
elseif param == 'light' then
local lightLv = val:match( '^%d+$' ) or val:match( 'yes,?%s*%(?(%d+)%)?' )
lightLv = tonumber( lightLv )
result = ( 0 < lightLv and lightLv < 16 )
and i18n.yesLight:format( lightLv ) or val == 'yes'
and i18n.yesLightP or ( val == 'no' or tonumber( val ) == 0 )
and i18n.noLight or origVal
elseif param == 'source available' then
local link = val:match( '^%[(%S+)%s' )
local text = val:match( '%s(.+)%]$' )
result = text == 'yes'
and i18n.yesSource:format( link ) or val == 'yes'
and i18n.yesSourceP or val == 'no'
and i18n.noSource or origVal
elseif param == 'stackable' then
local stackSize = val:gsub( 'yes%s*%((%d+)%)', '%1' )
if stackSize == val then
return origVal
end
result = ( 0 < tonumber( stackSize ) and tonumber( stackSize ) <= 64 )
and i18n.yesStackable:format( stackSize ) or val == 'yes'
and i18n.yesStackableP or val == 'no'
and i18n.noStackable or origVal
end
return result or origVal
end
return p