Module:CharStats: Difference between revisions
From Elwiki
Shironsaki (talk | contribs) No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
local stats = {}; | local stats = {}; | ||
function readStats(stat, value1, value2, value3 | function readStats(stat, value1, value2, value3) | ||
stats[stat] = args[value1] | stats[stat] = args[value1] | ||
if args[stat] == '2' then | if args[stat] == '2' then | ||
Line 15: | Line 15: | ||
stats[stat] = args[value3] | stats[stat] = args[value3] | ||
elseif args[stat] == '0' or args[stat] == nil then | elseif args[stat] == '0' or args[stat] == nil then | ||
stats[stat] = args[ | stats[stat] = args['l_unk'] | ||
end | end | ||
end | end | ||
readStats('Speed', 'l_slow', 'l_average', 'l_fast | readStats('Speed', 'l_slow', 'l_average', 'l_fast'); | ||
readStats('Range', 'l_short', 'l_medium', 'l_long | readStats('Range', 'l_short', 'l_medium', 'l_long'); | ||
readStats('Difficulty', 'l_easy', 'l_normal', 'l_hard | readStats('Difficulty', 'l_easy', 'l_normal', 'l_hard'); | ||
local type = args.l_magical; | local type = args.l_magical; |
Latest revision as of 14:39, 7 July 2022
Documentation for this module may be created at Module:CharStats/doc
require('Module:CommonFunctions')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Main process
function p.main(frame, title)
local args = getArgs(frame);
local stats = {};
function readStats(stat, value1, value2, value3)
stats[stat] = args[value1]
if args[stat] == '2' then
stats[stat] = args[value2]
elseif args[stat] == '3' then
stats[stat] = args[value3]
elseif args[stat] == '0' or args[stat] == nil then
stats[stat] = args['l_unk']
end
end
readStats('Speed', 'l_slow', 'l_average', 'l_fast');
readStats('Range', 'l_short', 'l_medium', 'l_long');
readStats('Difficulty', 'l_easy', 'l_normal', 'l_hard');
local type = args.l_magical;
local type_img = '[[File:UI - Magical Class.png]]';
if args['Damage'] == 'P' then
type = args.l_physical;
type_img = '[[File:UI - Physical Class.png]]';
end
local char_stats = mw.html.create('div'):addClass('char-stats');
function addCell(cell_class, wikitext, has_span)
local cell = char_stats:tag('div'):addClass(cell_class);
if (has_span) then
cell:tag('span'):wikitext(wikitext);
else
cell:wikitext(wikitext);
end
end
addCell('char-stats-cat', args.l_speed, true);
addCell('char-stats-active', stats['Speed']);
addCell('char-stats-attack', type_img);
addCell('char-stats-cat', args.l_range, true);
addCell('char-stats-active', stats['Range']);
addCell('char-stats-cat', args.l_difficulty, true);
addCell('char-stats-active', stats['Difficulty']);
addCell('char-stats-attack-caption', type, true);
return char_stats;
end
return p