- 致编者:请牢记我们的域名wiki.mcbe-dev.net!
- 致编者:欢迎加入本Wiki的官方交流QQ群或Discord服务器!
- 基岩版1.19.31现已发布!(了解更多)
- Inner Core现已支持Xbox模组联机!(了解更多)
- 如果您是第一次来到本Wiki,欢迎注册一个账户
- 点击顶部的“编辑”或“编辑源代码”按钮即可编辑当前页面
- 请知悉:在不登录时也可以编辑和新建页面,但是您当前的IP地址会记录在编辑历史中
Module:Experience
来自Minecraft基岩版开发Wiki
local p = {}
local i18n = {
error_exp_arg_not_a_number = "模块:Experience: %s不是一个数字", -- %1 = the description of the parameter
error_exp_arg_too_small = "模块:Experience: %s小于-32768(int16的最小值)", -- %1 = the description of the parameter
error_exp_arg_too_large = "模块:Experience: %s大于32767(int16的最大值)", -- %1 = the description of the parameter
arg_desc_min_exp = "最小经验值", -- %1 = the description of the parameter
arg_desc_max_exp = "最大经验值", -- %1 = the description of the parameter
error_exp_min_gt_exp_max = "Module:Experience: %s (%d) > %s (%d)", -- %1 = min exp description, %2 = min exp, %3 = max exp description, %4 = max exp
link = "经验#经验球"
}
local EXP_VALUES = {
{"Experience Orb Value -32768-2.png", 2},
{"Experience Orb Value 3-6.png", 6},
{"Experience Orb Value 7-16.png", 16},
{"Experience Orb Value 17-36.png", 36},
{"Experience Orb Value 37-72.png", 72},
{"Experience Orb Value 73-148.png", 148},
{"Experience Orb Value 149-306.png", 306},
{"Experience Orb Value 307-616.png", 616},
{"Experience Orb Value 617-1236.png", 1236},
{"Experience Orb Value 1237-2476.png", 2476},
{"Experience Orb Value 2477-32767.png", 32767}
}
local function validate_xp_arg(arg, desc)
local arg_n = assert(tonumber(arg), i18n.error_exp_arg_not_a_number:format(desc))
assert(arg_n >= -32768, i18n.error_exp_arg_too_small:format(desc))
assert(arg_n <= 32767, i18n.error_exp_arg_too_large:format(desc))
return arg_n
end
local function produce_exp_sprite(image, is_first)
local sprite = mw.html.create('span')
if is_first then
sprite:addClass("animated-active")
end
sprite:css({
["padding-left"] = "19px",
["background-size"] = "16px 16px",
["background-position"] = "left center",
["background-repeat"] = "no-repeat",
["background-image"] = mw.getCurrentFrame():expandTemplate({title="Template:FileUrl", args = {image}})
})
return sprite
end
local function produce_exp_anim(exp_min, exp_max)
local wrap = mw.html.create("span"):addClass("animated")
local lower_bound = 1
local upper_bound = #EXP_VALUES
for i, v in ipairs(EXP_VALUES) do
if v[2] <= exp_min then
lower_bound = i
end
if v[2] <= exp_max then
upper_bound = i
end
end
local first = true
for i = lower_bound, upper_bound do
if first then
wrap:node(produce_exp_sprite(EXP_VALUES[i][1], true))
first = false
else
wrap:node(produce_exp_sprite(EXP_VALUES[i][1]))
end
end
return '[[' .. i18n.link .. '|' .. tostring(wrap) .. ']]'
end
function p.main(exp_min, exp_max)
local anim = produce_exp_anim(exp_min, exp_max)
if exp_min == exp_max then
return anim .. exp_min
end
return anim .. exp_min .. "-" .. exp_max
end
function p.exp_range(f)
local args = require("Module:ProcessArgs").merge(true)
local exp_min = validate_xp_arg(args[1], i18n.arg_desc_min_exp)
local exp_max = validate_xp_arg(args[2], i18n.arg_desc_max_exp)
assert(exp_max >= exp_min, i18n.error_exp_min_gt_exp_max:format(
i18n.arg_desc_min_exp,
exp_min,
i18n.arg_desc_max_exp,
exp_max
))
return p.main(exp_min, exp_max)
end
return p