Please note that some information on this wiki is still based on the demo version.
If you notice any errors, feel free to correct them.

Module:Stats: Difference between revisions

From Super Fantasy Kingdom Official Wiki
wgg>Cadaei
moved statNames to subModule
m syntax fix
 
(5 intermediate revisions by 3 users not shown)
Line 4: Line 4:


function p.stats(f)
function p.stats(f)
return create(f:getParent().args)
return p.create(f:getParent().args)
end
end


local function create(args)
function p.create(args)
local usedStats = {}
local usedStats = {}
local useInline = args.inline ~= nil
local useInline = args.inline ~= nil
local align = args.align -- if not empty use simple vertical layout
local useInlineBlock = args.inlineBlock ~= nil
local useGain = args.first ~= nil and args.second ~= nil
local useGain = args.first ~= nil and args.second ~= nil
if align ~= nil then
if align == 'left' or align == 'center' or align == 'right' then
useInline = true
else
align = nil
end
end
for _, statNames in ipairs(statNames) do
for _, statNames in ipairs(statNames) do
Line 22: Line 32:
secondValue = args[statAbbreviation..'2']
secondValue = args[statAbbreviation..'2']
gain = args[statAbbreviation..'Gain']
gain = args[statAbbreviation..'Gain']
table.insert(usedStats, statEntryFormatGain(statName, statValue, secondValue, gain))
table.insert(usedStats, p.statEntryFormatGain(statName, statValue, secondValue, gain))
else
else
table.insert(usedStats, statEntryFormat(statName, statValue, useInline, true))
table.insert(usedStats, p.statEntryFormat(statName, statValue, useInline, true))
end
end
end
end
Line 34: Line 44:
if useInline then
if useInline then
  -- one line, separated by bullet points
if align ~= nil then
  return table.concat(usedStats, ' • ')
return '<div style="display: inline-block; text-align: '..align..';">'..table.concat(usedStats, '<br>')..'</div>'
end
-- one line, separated by bullet points
return table.concat(usedStats, ' &bull; ')
end
end
-- table format
-- table format
if useGain then
if useGain then
return '<table class="plainTable" style="text-align:left; display:inline-block; border-spacing: 0; border: 2px solid gray; padding: 1em">'..
return '<table class="plain-table" style="text-align:left; display:inline-block; border-spacing: 0; border: 2px solid gray; padding: 1em">'..
'<tr><td></td><td colspan=3 style="text-align: center; font-weight: bold">'..args.first..'</td><td></td><td colspan=3 style="text-align: center; font-weight: bold">'..args.second..'</td></tr>'..
'<tr><td></td><td colspan=3 style="text-align: center; font-weight: bold">'..args.first..'</td><td></td><td colspan=3 style="text-align: center; font-weight: bold">'..args.second..'</td></tr>'..
'<tr>'..table.concat(usedStats, '</tr><tr>')..'</tr></table>'
'<tr>'..table.concat(usedStats, '</tr><tr>')..'</tr></table>'
end
end
return '<table class="plainTable" style="text-align:left; display:inline-block; border-spacing: 0"><tr>'..table.concat(usedStats, '</tr><tr>')..'</tr></table>'
local inlineBlockStyle = ''
if useInlineBlock then inlineBlockStyle = ' display:inline-block;' end
return '<table class="plain-table" style="text-align:left; border-spacing: 0;'..inlineBlockStyle..'"><tr>'..
table.concat(usedStats, '</tr><tr>')..'</tr></table>'
end
end


local function statEntryFormat(name, val, inline, withIcon)
function p.statEntryFormat(name, val, inline, withIcon)
if inline then
if inline then
return '[[File:'..name..'.png|link='..name..'|16x16px]]&nbsp;'..val
return '[[File:'..name..'.png|link='..name..'|16x16px]]&nbsp;'..val
Line 61: Line 79:
end
end


local function statEntryFormatGain(name, val, secondVal, gain)
function p.statEntryFormatGain(name, val, secondVal, gain)
local gainCell = ''
local gainCell = ''
gain = tonumber(gain)
gain = tonumber(gain)
Line 67: Line 85:
gainCell = '<td style="padding: 0 1em;">[[File:StatGain'..gain..'.png|12px]]</td>'
gainCell = '<td style="padding: 0 1em;">[[File:StatGain'..gain..'.png|12px]]</td>'
end
end
return statEntryFormat(name, val, false, true)..
return p.statEntryFormat(name, val, false, true)..
gainCell..
gainCell..
statEntryFormat('', secondVal, false, false)
p.statEntryFormat('', secondVal, false, false)
end
end


return p
return p

Latest revision as of 17:15, 25 November 2025

Displays stats for units. Call with Template:Stats, code is in Module:Stats.

Parameters

  • inline: If not empty stats will be shown in one line, else in a table format
  • align: Optional, valid values are left, center or right. It will display the stats in a simple column with the stated alignment.
  • hp: Health
  • ma: Mana
  • sh: Shield
  • pd: Physical Defense
  • md: Magical Defense
  • dm: Damage
  • cr: Critical Chance
  • ra: Range
  • cd: Cooldown
  • ar: Area
  • kb: Knockback
  • sp: Speed
  • du: Duration
  • rg: Rage
  • gr: Greed
  • rr: Reroll
  • ba: Banish
  • cu: Curse

Examples

{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%}}
33
4
2%
20%
10%
8
{{stats|hp=20.5|ra=8.33 m|cd=1.2 s|cr=2%}}
20.5
2%
1.2s
8.33m
{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%|inline=1}}

 33 •  4 •  2% •  20% •  10% •  8

{{stats|hp=33|dm=8|sh=4|cr=2%|pd=20%|md=10%|align=center}}
 33
 4
 2%
 20%
 10%
 8
{{stats
| first = Base stats
| second = Maxed<br/>Base stats
| dm = 5
| dm2 = 6.25
| dmGain = 1
| hp = 11
| hp2 = 14.3
| hpGain = 1
| sh = 13 m
| sh2 = 16.9 m
| shGain = 2
| cr = 5%
| cr2 = 5.63%
| crGain = 1
| pd = 0%
| pd2 = 15%
| pdGain = 3
| md = 0%
| md2 = 15%
| mdGain = 3
}}
Base statsMaxed
Base stats
1114.3
13m16.9m
5%5.63%
0%15%
0%15%
56.25

local p = {}

local statNames = require ('Module:Stats/StatNames')

function p.stats(f)
	return p.create(f:getParent().args)
end

function p.create(args)	
	local usedStats = {}
	local useInline = args.inline ~= nil
	local align = args.align -- if not empty use simple vertical layout
	local useInlineBlock = args.inlineBlock ~= nil
	local useGain = args.first ~= nil and args.second ~= nil
	
	if align ~= nil then
		if align == 'left' or align == 'center' or align == 'right' then
			useInline = true
		else
			align = nil
		end
	end
	
	for _, statNames in ipairs(statNames) do
		local statAbbreviation = statNames[1]
		local statValue = args[statAbbreviation]
		if statValue ~= nil and statValue ~= '' then
			local statName = statNames[2]
			local secondValue = ''
			local gain = ''
			if useGain then
				secondValue = args[statAbbreviation..'2']
				gain = args[statAbbreviation..'Gain']
				table.insert(usedStats, p.statEntryFormatGain(statName, statValue, secondValue, gain))
			else
				table.insert(usedStats, p.statEntryFormat(statName, statValue, useInline, true))
			end
		end
	end
	
	if #usedStats == 0 then
	  return ''
	end
	
	if useInline then
		if align ~= nil then
			return '<div style="display: inline-block; text-align: '..align..';">'..table.concat(usedStats, '<br>')..'</div>'
		end
		-- one line, separated by bullet points
		return table.concat(usedStats, ' &bull; ')
	end
		
	-- table format
	if useGain then
		return '<table class="plain-table" style="text-align:left; display:inline-block; border-spacing: 0; border: 2px solid gray; padding: 1em">'..
			'<tr><td></td><td colspan=3 style="text-align: center; font-weight: bold">'..args.first..'</td><td></td><td colspan=3 style="text-align: center; font-weight: bold">'..args.second..'</td></tr>'..
			'<tr>'..table.concat(usedStats, '</tr><tr>')..'</tr></table>'
	end
	
	local inlineBlockStyle = ''
	if useInlineBlock then inlineBlockStyle = ' display:inline-block;' end
	
	return '<table class="plain-table" style="text-align:left; border-spacing: 0;'..inlineBlockStyle..'"><tr>'..
		table.concat(usedStats, '</tr><tr>')..'</tr></table>'
end

function p.statEntryFormat(name, val, inline, withIcon)
	if inline then
		return '[[File:'..name..'.png|link='..name..'|16x16px]]&nbsp;'..val
	else
		local wholeNumberPart, decimalPart, unit  = string.match(val, '^(%d*)(%.?%d*) ?(.*)$')
		local iconColumn = ''
		if withIcon then
			iconColumn = '<td style="padding-right: 0.3em;">[[File:'..name..'.png|link='..name..'|16x16px]]</td>'
		end
		return iconColumn..'<td style="text-align: right; padding: 0">'..
			wholeNumberPart..'</td><td style="padding: 0">'..decimalPart..'</td><td style="padding-left: 0.2em">'..unit..'</td>'
	end
end

function p.statEntryFormatGain(name, val, secondVal, gain)
	local gainCell = ''
	gain = tonumber(gain)
	if gain ~= nil and gain >= 0 then
		gainCell = '<td style="padding: 0 1em;">[[File:StatGain'..gain..'.png|12px]]</td>'
	end
	return p.statEntryFormat(name, val, false, true)..
		gainCell..
		p.statEntryFormat('', secondVal, false, false)
end

return p