Module:SkillTable: Difference between revisions
From Elwiki
Shironsaki (talk | contribs) No edit summary Tag: Reverted |
No edit summary |
||
(38 intermediate revisions by 2 users not shown) | |||
Line 15: | Line 15: | ||
end | end | ||
local mod_prefix = args.l_mod_prefix or '[Mod]' | |||
local | |||
local lang = args.lang and ('/' .. args.lang) or '' | local lang = args.lang and ('/' .. args.lang) or '' | ||
Line 53: | Line 52: | ||
local prefix = '' | local prefix = '' | ||
local suffix = '' | local suffix = '' | ||
local is_mod = false; | |||
-- Locked skills | -- Locked skills | ||
Line 58: | Line 58: | ||
local lock_arg = name:gsub('.*%sLocked%-', ''); | local lock_arg = name:gsub('.*%sLocked%-', ''); | ||
name = name:gsub('%sLocked%-.*', ''); | name = name:gsub('%sLocked%-.*', ''); | ||
lock = frame:expandTemplate{ | lock = frame:expandTemplate { | ||
title = 'Locked Skill', | title = 'Locked Skill', | ||
args = {lock_arg} | args = { lock_arg } | ||
} | } | ||
end | end | ||
Line 69: | Line 69: | ||
local cube_arg = string.sub(name, j); | local cube_arg = string.sub(name, j); | ||
name = name:gsub('%sModCube[0-9]', ''); | name = name:gsub('%sModCube[0-9]', ''); | ||
cube = frame:expandTemplate{ | cube = frame:expandTemplate { | ||
title = 'Mod Cube', | title = 'Mod Cube', | ||
args = {cube_arg} | args = { cube_arg } | ||
} | } | ||
end | end | ||
Line 84: | Line 84: | ||
-- Make chunks of skill boxes based on user preference (default 4). | -- Make chunks of skill boxes based on user preference (default 4). | ||
if ((i-1) % iterations == 0 or image_name_table[i-1] == nil) then | if ((i - 1) % iterations == 0 or image_name_table[i - 1] == nil) then | ||
row = skill_table:tag('div'):attr('data-type', 'table-row'); | row = skill_table:tag('div'):attr('data-type', 'table-row'); | ||
end | end | ||
Line 117: | Line 117: | ||
image[index] = trim(image[index]); | image[index] = trim(image[index]); | ||
name[index] = trim(name[index]); | name[index] = trim(name[index]); | ||
local mod_type; | |||
is_mod, name[index], mod_subpage, mod_type = get_mod_info(name[index]); | |||
-- Decide which icon to spawn based on being a [Mod] or not. | |||
if not (is_mod) then | |||
image_cell:wikitext('[[File:' .. image[index] .. '|link=' .. name[index] .. lang .. ']]') | |||
else | |||
image_cell:wikitext(frame:expandTemplate { | |||
title = 'Force', | |||
args = { | |||
image[index], | |||
language = args.lang, | |||
link = name[index], | |||
class = mod_type == '/ModE' and 'base' or nil | |||
} | |||
}); | |||
end | |||
index = index + 1 | |||
end | end | ||
is_mod, full_name, mod_subpage = get_mod_info(full_name); | |||
-- Prefixes and suffixes | -- Prefixes and suffixes | ||
Line 202: | Line 149: | ||
suffix = full_name:match('##(.*)$'); | suffix = full_name:match('##(.*)$'); | ||
full_name = trim(full_name:gsub('##.*$', '')); | full_name = trim(full_name:gsub('##.*$', '')); | ||
end | |||
local display_name = full_name; | |||
-- Display name for translations | |||
if (string.find(display_name, '\\')) then | |||
display_name = full_name:gsub('.*\\', '') | |||
full_name = full_name:gsub('\\.*', '') | |||
end | end | ||
Line 211: | Line 165: | ||
-- Remove (Elsword), (Elesis), etc. in display name | -- Remove (Elsword), (Elesis), etc. in display name | ||
display_name = display_name:gsub("%s%([%w%s%/]+%)", ""); | |||
if | |||
if (is_mod) then | |||
local modColor = frame:expandTemplate { | |||
title = 'ColorSel', | |||
args = { 'Skill', 'Mod' } | |||
} | |||
local modText = frame:expandTemplate { | |||
title = 'Color', | |||
args = { modColor, mod_prefix .. ' ' } | |||
} | |||
display_name = modText .. display_name; | |||
end | end | ||
Line 221: | Line 185: | ||
end | end | ||
suffix = suffix .. ((lock ~= '' or cube ~= '') and ' ' or ''); | |||
skill_wrap:tag('div'):addClass('skill-wrap-text'):wikitext('[[' .. | |||
link .. '|' .. prefix .. display_name .. ']] ' .. suffix .. lock .. cube); | |||
-- If a header is detected, it will not interrupt chunking. | -- If a header is detected, it will not interrupt chunking. | ||
i = i + 1 | i = i + 1 | ||
Line 243: | Line 197: | ||
-- Set color, either hardcoded or from the ColorSel template. | -- Set color, either hardcoded or from the ColorSel template. | ||
if not (string.find(image, "#") or string.find(image, "rgb(") or string.find(image, "rgba(")) then | if not (string.find(image, "#") or string.find(image, "rgb(") or string.find(image, "rgba(")) then | ||
color = frame:expandTemplate{ | color = frame:expandTemplate { | ||
title = 'ColorSel', | title = 'ColorSel', | ||
args = {'Character', color} | args = { 'Character', color } | ||
} | } | ||
end | end | ||
row = skill_table:tag('div'):attr('data-type', 'table-row'):attr('style', 'background-color: ' .. color):addClass('textfloat table-head'); | row = skill_table:tag('div'):attr('data-type', 'table-row'):attr('style', 'background-color: ' .. color) | ||
:addClass('textfloat table-head'); | |||
if (color == '#') then | if (color == '#') then | ||
row:addClass('related-title') | row:addClass('related-title') | ||
Line 258: | Line 213: | ||
-- Output point | -- Output point | ||
return tostring(skill_table); | return tostring(skill_table); | ||
end | |||
function get_mod_info(name) | |||
local is_mod = false; | |||
local name_resolved = name; | |||
local mod_subpage = ''; | |||
local mod_type = nil; | |||
local mod_types = { | |||
{ | |||
type = '/Mod', | |||
subpage = true | |||
}, | |||
{ | |||
type = '/ModE' | |||
} | |||
} | |||
for k, v in ipairs(mod_types) do | |||
if string.find(name, v.type) then | |||
is_mod = true; | |||
name_resolved = name:gsub('%' .. v.type, ''); | |||
mod_subpage = v.subpage and v.type or ''; | |||
mod_type = v.type; | |||
end | |||
end | |||
return is_mod, name_resolved, mod_subpage, mod_type; | |||
end | end | ||
return p | return p |
Latest revision as of 00:49, 8 March 2025
Documentation for this module may be created at Module:SkillTable/doc
require('Module:CommonFunctions')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Main process
function p.main(frame)
local args = getArgs(frame);
-- Main block
local skill_table = mw.html.create('div'):addClass('related-skills shown skill-table');
local iterations = args['i'];
if iterations == nil then
iterations = 4
end
local mod_prefix = args.l_mod_prefix or '[Mod]'
local lang = args.lang and ('/' .. args.lang) or ''
-- Split into two tables for easier maintenance of the code.
local skills = args.skills;
if (skills == nil) then
skills = args[1]
end
local skills = split(skills, ';')
local image_name_table = {}
local skill_name_table = {}
local index = 1
for k, v in ipairs(skills) do
v = trim(v);
if (index % 2 == 0) then
-- Skill names
table.insert(skill_name_table, v ~= '' and v or 'Unreleased');
else
-- Image names
table.insert(image_name_table, v);
end
index = index + 1
end
-- Iterate through rows
local i = 1;
-- Spawn a table row.
local row = skill_table:tag('div'):attr('data-type', 'table-row');
while i <= #skill_name_table do
local image = image_name_table[i];
local name = skill_name_table[i];
local lock = ''
local mod_subpage = ''
local cube = ''
local prefix = ''
local suffix = ''
local is_mod = false;
-- Locked skills
if (string.find(name, ' Locked-')) then
local lock_arg = name:gsub('.*%sLocked%-', '');
name = name:gsub('%sLocked%-.*', '');
lock = frame:expandTemplate {
title = 'Locked Skill',
args = { lock_arg }
}
end
-- Cube
if (string.find(name, 'ModCube')) then
local o, j = string.find(name, 'ModCube[0-9]');
local cube_arg = string.sub(name, j);
name = name:gsub('%sModCube[0-9]', '');
cube = frame:expandTemplate {
title = 'Mod Cube',
args = { cube_arg }
}
end
-- Check if the user wants to render a header or not.
local is_header = false;
if (string.starts(image, '--')) then
is_header = true;
table.remove(image_name_table, i);
table.remove(skill_name_table, i);
end
-- Make chunks of skill boxes based on user preference (default 4).
if ((i - 1) % iterations == 0 or image_name_table[i - 1] == nil) then
row = skill_table:tag('div'):attr('data-type', 'table-row');
end
-- Spawn regular cells
if not (is_header) then
-- Split images for situations with multiple icons.
local full_name = name;
image = split(image, '\\');
-- Remove prefix, suffix and full name syntax from the display name
name = split(name:gsub('%s?#%s?.*', ''):gsub('^.*%+%+', ''), '\\');
local index = 1;
local image_cell = row:tag('div'):attr('data-type', 'table-cell');
if (args.skill_columns ~= nil) then
image_cell:attr('style', 'grid-template-columns: repeat(' .. args.skill_columns .. ', auto)');
end
-- Set a display name if there is more than one image.
if (#image > 1 and #name > 1) then
image_cell:addClass('skill-columns');
local name_match = full_name:match('%s?#%s?(.*)');
if (name_match ~= nil) then
full_name = name_match;
else
full_name = name[1]
end
end
-- Iterate through split icons.
while index <= #image do
image[index] = trim(image[index]);
name[index] = trim(name[index]);
local mod_type;
is_mod, name[index], mod_subpage, mod_type = get_mod_info(name[index]);
-- Decide which icon to spawn based on being a [Mod] or not.
if not (is_mod) then
image_cell:wikitext('[[File:' .. image[index] .. '|link=' .. name[index] .. lang .. ']]')
else
image_cell:wikitext(frame:expandTemplate {
title = 'Force',
args = {
image[index],
language = args.lang,
link = name[index],
class = mod_type == '/ModE' and 'base' or nil
}
});
end
index = index + 1
end
is_mod, full_name, mod_subpage = get_mod_info(full_name);
-- Prefixes and suffixes
if (full_name:match('++')) then
prefix = full_name:match('^(.*)%+%+');
full_name = trim(full_name:gsub('^.*%+%+', ''));
end
if (full_name:match('##')) then
suffix = full_name:match('##(.*)$');
full_name = trim(full_name:gsub('##.*$', ''));
end
local display_name = full_name;
-- Display name for translations
if (string.find(display_name, '\\')) then
display_name = full_name:gsub('.*\\', '')
full_name = full_name:gsub('\\.*', '')
end
-- Spawn a name cell.
local link = full_name .. mod_subpage .. lang
local name_cell = row:tag('div'):attr('data-type', 'table-cell');
local skill_wrap = name_cell:tag('div'):addClass('skill-wrap');
skill_wrap:wikitext('[[' .. link .. '|.]]');
-- Remove (Elsword), (Elesis), etc. in display name
display_name = display_name:gsub("%s%([%w%s%/]+%)", "");
if (is_mod) then
local modColor = frame:expandTemplate {
title = 'ColorSel',
args = { 'Skill', 'Mod' }
}
local modText = frame:expandTemplate {
title = 'Color',
args = { modColor, mod_prefix .. ' ' }
}
display_name = modText .. display_name;
end
-- Remove the name of the Master Skill
if (args.no_mc_names == 'true') then
display_name = display_name:gsub('.*%/Stage%s([0-9])', 'Stage %1');
end
suffix = suffix .. ((lock ~= '' or cube ~= '') and ' ' or '');
skill_wrap:tag('div'):addClass('skill-wrap-text'):wikitext('[[' ..
link .. '|' .. prefix .. display_name .. ']] ' .. suffix .. lock .. cube);
-- If a header is detected, it will not interrupt chunking.
i = i + 1
else
-- Spawn a header
local color = image:gsub('%-%-', '');
-- Set color, either hardcoded or from the ColorSel template.
if not (string.find(image, "#") or string.find(image, "rgb(") or string.find(image, "rgba(")) then
color = frame:expandTemplate {
title = 'ColorSel',
args = { 'Character', color }
}
end
row = skill_table:tag('div'):attr('data-type', 'table-row'):attr('style', 'background-color: ' .. color)
:addClass('textfloat table-head');
if (color == '#') then
row:addClass('related-title')
end
row:tag('div'):attr('data-type', 'table-head'):wikitext(name);
end
end
-- Output point
return tostring(skill_table);
end
function get_mod_info(name)
local is_mod = false;
local name_resolved = name;
local mod_subpage = '';
local mod_type = nil;
local mod_types = {
{
type = '/Mod',
subpage = true
},
{
type = '/ModE'
}
}
for k, v in ipairs(mod_types) do
if string.find(name, v.type) then
is_mod = true;
name_resolved = name:gsub('%' .. v.type, '');
mod_subpage = v.subpage and v.type or '';
mod_type = v.type;
end
end
return is_mod, name_resolved, mod_subpage, mod_type;
end
return p