![]() |
VOOZH | about |
This module implements {{Experience}}. It accepts no directly passed arguments, only parent arguments and is therefore recommended to not be invoked directly from templates.
localp={} locali18n={ error_exp_arg_not_a_number="Module:Experience: %s is not a number",-- %1 = the description of the parameter error_exp_arg_too_small="Module:Experience: %s is less than -32,768 (int16 lower limit)",-- %1 = the description of the parameter error_exp_arg_too_large="Module:Experience: %s is greater than 32,767 (int16 upper limit)",-- %1 = the description of the parameter arg_desc_min_exp="minimum experience",-- %1 = the description of the parameter arg_desc_max_exp="maximum experience",-- %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 } localEXP_VALUES={ {"xp-2",-32768,2}, {"xp-6",3,6}, {"xp-16",7,16}, {"xp-36",17,36}, {"xp-72",37,72}, {"xp-148",73,148}, {"xp-306",149,306}, {"xp-616",307,616}, {"xp-1236",617,1236}, {"xp-2476",1237,2476}, {"xp-32767",2477,32767} } localfunctionvalidate_xp_arg(arg,desc) localarg_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)) returnarg_n end localfunctionproduce_exp_sprite(class,is_first) localsprite=mw.html.create('span'):addClass("pixel-image") ifis_firstthen sprite:addClass("animated-active") end sprite:css({ ["padding-left"]="19px", ["background-size"]="16px 16px", ["background-position"]="left center", ["background-repeat"]="no-repeat", }):addClass(class) returnsprite end localfunctionproduce_exp_anim(exp_min,exp_max) localwrap=mw.html.create("span"):addClass("animated") locallower_bound=1 localupper_bound=#EXP_VALUES fori,vinipairs(EXP_VALUES)do ifexp_min>=v[2]andexp_min<=v[3]then lower_bound=i end ifexp_max>=v[2]andexp_max<=v[3]then upper_bound=i end end --mw.log(lower_bound) --mw.log(upper_bound) localfirst=true fori=lower_bound,upper_bounddo iffirstthen wrap:node(produce_exp_sprite(EXP_VALUES[i][1],true)) first=false else wrap:node(produce_exp_sprite(EXP_VALUES[i][1])) end end returntostring(wrap) end functionp.main(exp_min,exp_max) localanim=produce_exp_anim(exp_min,exp_max) ifexp_min==exp_maxthen returnanim..exp_min end returnanim..exp_min.."–"..exp_max end functionp.exp_range(f) localargs=require("Module:ProcessArgs").merge(true) localexp_min=validate_xp_arg(args[1],i18n.arg_desc_min_exp) localexp_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 )) returnp.main(exp_min,exp_max) end returnp