本模块用于实现值提供器模板。
用法
此模块对外公开了以下方法:
p.value(f)
:模板使用的方法,会解析模板被传入的参数。p.getValue(argTargetNames, argType, argMode, argNocat)
:其他模块可以使用的易于调用的方法。p.getRawValue(targetName, valueType, onlyBE)
:直接返回原始数据类型、不进行转换为字符串的方法。每次调用只能处理单个目标名称。
名称 | p.value | p.getValue |
---|---|---|
目标名称 | 1 | argTargetNames |
目标类型 | type | argType |
数据模式 | mode | argMode |
停用分类 | nocat | argNocat |
目标名称
需要解析的一系列目标名称。
每一个目标名称应当是一个Reverselink的英文名称,之间使用;
作为分割,分隔符之间可以插入空格、制表符和换行符。模块会自动从Module:Autolink获取名称,但可以通过目标名称:可读名称
来覆盖。
{{Hardness values| Structure Void; Crafting Table; Beehive; Bee nest; Chest:大箱子; }}
目标类型
目标值的类型。
* 合适挖掘工具:{{#invoke: Autovalue | value | Crafting Table | type = breaking tool }} * 硬度:{{#invoke: Autovalue | value | Crafting Table | type = hardness }} * 爆炸抗性:{{#invoke: Autovalue | value | Crafting Table | type = blast resistance }}
数据模式
影响模块在数据于JE和BE有不同值时的输出方式。若没有JE和BE使用不同值的情况,模式对输出没有影响。
模式 | 输出 | 说明 |
---|---|---|
onlyJE | ? | 只输出JE值。 |
content | ? | 适用于文内插入的使用{{only}} 的叙述。
|
infobox | ? | 适用于插入信息框的纵列叙述。 |
onlyBE | ? | 只输出BE值。 |
停用分类
指定后不再添加缺失值的维护分类。
依赖项
另见
- 实现
- Module:Autovalue
- Module:Autovalue/types
{{Autovalue}}
- 主要用途
- 分类
- 数据
local p = {}
p.value = function( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
end
local block = mw.text.trim( args[1] or '' ):lower()
local type = args.type
-- Most of these transforms are unnecessary, but are kept for compatibility with original template
-- Strip trailing "s" on everything but these
if type == "blast resistance" then
block = block:gsub( "['%(%)%-%s]+", '' )
else
local keepS = {
glass = true,
steps = true, stairs = true,
bars = true,
cactus = true,
leaves = true,
grass = true,
potatoes = true,
planks = true,
seagrass = true
}
if not keepS[block:match( '%w+$' )] then
block = block:gsub( 's$', '' )
end
-- Other transforms
block = block
:gsub( 'wooden', 'wood' )
:gsub( 'mossy', 'moss' )
:gsub( 'steps', 'stairs' )
:gsub( "['%(%)%-%s]+", '' )
end
local value = mw.loadData( 'Module:' .. type .. ' values' )[block]
local category = ''
if not value then
value = '[[Template:' .. type .. ' values#缺失值|?]]'
local title = mw.title.getCurrentTitle()
if not args.nocat and title.namespace == 0 and not title.isSubpage then
category = '[[Category:缺失' .. type:lower() .. ']]'
end
end
return value .. category
end
return p