Difference between revisions of "Module:Character/Skills"

From Granblue Fantasy Wiki
Jump to navigation Jump to search
m
Line 42: Line 42:
  
 
local o = {}
 
local o = {}
o[#o+1] = ('<div class="table-container character character__details character--element-%s"><table class="wikitable" style="width:100%%; text-align:center; text-size-adjust: none;"><tr><th colspan="6">%s %s</th></tr>'):format(
+
o[#o+1] = ([[<div class="table-container character character__details character--element-%s">
 +
  <table class="wikitable" style="width:100%%; text-align:center; text-size-adjust: none;">
 +
  <tr><th colspan="6">%s %s</th></tr>
 +
  <tr style="font-weight:bold;">
 +
    <th style="background:#FFF;">Icon</th>
 +
    <th style="background:#FFF;">Name</th>
 +
    <th style="background:#FFF; width:35px;">Cooldown</th>
 +
    <th style="background:#FFF; width:35px;">Duration</th>
 +
    <th style="background:#FFF; width:35px;">Obtained</th>
 +
    <th style="background:#FFF;">Effect</th>
 +
  </tr>]]):format(
 
(args.element or 'unknown'):lower(),
 
(args.element or 'unknown'):lower(),
 
args['abilitytitle' .. _idSuffix] or 'Skills',
 
args['abilitytitle' .. _idSuffix] or 'Skills',

Revision as of 21:41, 13 January 2020

Documentation for this module may be created at Module:Character/Skills/doc

local p = {}
local MAX_SKILLS = 4
local SKILL_ROW_HTML = [[<tr>
  <td class="skill-icon"> {icons} </td>
  <td class="skill-name"> {display_name|???} </td>
  <td> {cd|???} </td>
  <td> {dur|???} </td>
  <td> {oblevel|???} </td>
  <td style="text-align:left;"> {effdesc|???} </td>
</tr>]]

local function notEmpty(s)
	return s ~= nil and s:match('%S') ~= nil and s
end
local function formatIconList(icons)
	local n, r = 0
	if icons then
		for p in icons:gmatch('[^%s,][^,]*[^%s,]') do
			n, r = n+1, (r or '') .. ('[[File:%s|40px|link=]]'):format(p)
		end
	end
	return (r or '[[File:40ph.png|40px|center|link=Ability Icon List]]')
	       .. (n > 1 and '[[Category:2 or more skill icons]]' or '')
end
local function formatTemplate(text, args)
	return (text:gsub('{([^|}]+)(|?)([^}]*)}', function(k, pipe, phv)
		return args[k] or (pipe == '|' and phv) or nil
	end))
end
local function renderSkillTemplate(frame, template, argsTable)
	if template then
		return frame:expandTemplate({title=template, args=argsTable})
	end
	return formatTemplate(SKILL_ROW_HTML, argsTable)
end

function p.renderSkillTable(frame, args, idSuffix)
	local iargs = args or frame.args
	args = args or frame:getParent().args
	local idSuffix = (idSuffix or iargs.idsuffix or ''):match('%a+') or ''
	local _idSuffix = idSuffix ~= '' and '_' .. idSuffix or ''

	local o = {}
	o[#o+1] = ([[<div class="table-container character character__details character--element-%s">
  <table class="wikitable" style="width:100%%; text-align:center; text-size-adjust: none;">
  <tr><th colspan="6">%s %s</th></tr>
  <tr style="font-weight:bold;">
    <th style="background:#FFF;">Icon</th>
    <th style="background:#FFF;">Name</th>
    <th style="background:#FFF; width:35px;">Cooldown</th>
    <th style="background:#FFF; width:35px;">Duration</th>
    <th style="background:#FFF; width:35px;">Obtained</th>
    <th style="background:#FFF;">Effect</th>
  </tr>]]):format(
		(args.element or 'unknown'):lower(),
		args['abilitytitle' .. _idSuffix] or 'Skills',
		args['abilitysubtitle' .. _idSuffix] or ''
	)

	local sa = {}
	local template = iargs.template or nil
	for i=1,MAX_SKILLS do
		local p = 'a' .. i .. idSuffix .. '_'
		if notEmpty(args[p .. 'name']) or notEmpty(args[p .. 'name_custom']) then
			sa.name = args[p .. 'name']
			sa.name_custom = args[p .. 'name_custom']
			sa.display_name = notEmpty(sa.name_custom) or sa.name
			sa.icon = args[p .. 'icon']
			sa.cd = args[p .. 'cd']
			sa.dur = args[p .. 'dur']
			sa.oblevel = args[p .. 'oblevel']
			sa.effdesc = args[p .. 'effdesc']
			sa.icons = formatIconList(sa.icon)
			sa.skill_id = i .. idSuffix
			o[#o+1] = renderSkillTemplate(frame, template, sa)
		end
	end

	o[#o+1] = '</table></div>'
	return #o > 2 and table.concat(o, '\n') or nil
end
function p.renderSkillTables(frame, args)
	local o = {p.renderSkillTable(frame, args, '')}
	for s in ('abcd'):gmatch('.') do
		o[#o+1] = p.renderSkillTable(frame, args, s)
	end
	return table.concat(o, '\n')
end

return p