block tales
Lua Logo
"Just as important as CSS, you know.."
This template uses Lua as its script language. (Module:StatTemplate)


Description

Module:StatTemplate is invoked and implemented by {{Status}}, {{Stat}} and {{Itemicon}}.

This template displays a attribute with an icon. Usually use for various stat and status templates.

Syntax

{{Status|<1>|<name>|<image>|<size>|<link>|<color>|<class>}}

Template Data

Displays a stat attribute with an optional icon

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Display Name1

Alternate display name

Stringrequired
Display Namename

The name of the stat or status

Default
Untitled
Stringsuggested
Icon Filenameimage

Custom icon filename

Filesuggested
Icon Sizesize

Icon size in pixels

Default
20x20
Stringoptional
Page Linklink

Page to link to

Page namesuggested
Text Colorcolor

Color code for the text

Default
#aaa
Stringoptional
Classclass

Extra CSS class for custom styling

Stringsuggested

Examples

Stat

{{Stat|{{{1|}}}|name=Example Stat|image=hp.png|color=#aaa|link=HP}}
HP Example Stat
{{Stat|25|name=Example Stat|image=hp.png|color=#aaa|link=HP}}
{{Stat|hello|name=Example Stat|image=hp.png|color=#aaa|link=HP}}
{{Stat|Where is the heart go?|name=Example Stat|color=#aaa|link=HP}}

Status

{{Status|{{{1|}}}|name=Example Status|image=Aware status.gif|color=#aaa|link=Status_Effects}}
Status_Effects EXAMPLE STATUS
{{Status|8|name=Example Status|image=Aware status.gif|color=#aaa|link=Status_Effects}}
{{Status|hey bro you got any eye drops|name=Example Status|image=Aware status.gif|color=#aaa|link=Status_Effects}}
{{Status|hey bro you got any eye drops|name=Example Status|image=Aware status.gif|color=#aaa|link=Status_Effects}}
{{Status| |name=Example Status|image=Aware status.gif|color=#aaa|link=Status_Effects}}
{{Status||name=Stop|image=Stop status.gif|class=yellow|link=Status Effects}}
{{Status||name=Angry|image=Angry status.gif|class=red|link=Status Effects}}
ViewEditBlock Tales LogoWiki Templates NavigationWiki Templates Navigation
ViewEditTemplates
NoticesMainBigDataDeleteDisambiguationFanmadeInternalNavMaintenancePlagiarismRemovedRightTOCStubUnreleasedBestWrittenArticle
OtherLuaCSS
Infomation BoxesCardCard2CardSummonEnemyEnemy3EnemyDuoEnemyTrioGameCharacterItemLocationStatisticsStatisticsBP
Navigation BoxesCardsNavCardsNav/ActiveCardsNav/PassiveEnemiesNavEnemiesNav/BossesEnemiesNav/EnemiesItemsNavNavigationBoxMechanicsNavMiscNavModulesNavStoryProgressionNavWeaponsNav
InfoiconsStatusAnkhATK DownATK UpBigBigheadBurnChargeConfusionDEF DownDEF UpDetachmentDizzyDodgyEnchant BurnEnchant IceEnchant PoisonExhaustedFastFineFirst StrikeFocusedFrozenGuardedHalved DamageHP RegenInvisibleNRG RegenPeeling OrangePiercingPoisonSilencedSleepSlowSmallSP RegenSpikyStinkyStretchy
AttributesBall WeaknessBurn WeaknessChanges StanceDisables NRGDouble TurnsExplosiveFlamingFlyingInvincibility In NumbersItem-ResistantMelee DeflectingMobileProjectile DeflectingSpiky
StatArmorAttackBPDefenseHPNRGSPXP
OtherBroken ArmorBroken DefenseBUXFlavorItemsProjectileRobuxTIX
OtherAchievementTableCharacter NavbarCodeCombat LogHieroglyphQuote
ViewEditModules
ModulesNavboxTemplateStatTemplate

-- This module is created by @IxGamerXL (https://block-tales.fandom.com/wiki/User:IxGamerXL)
-- Do not attempt to edit this module unless you are well aware of how to use Lua programming,
-- as many templates will be using this module for the sake of convenience.
-- If there's a problem or missing feature here and you cannot edit it, message me about it.

-- Fun fact: You can use this module OUTSIDE of templates, which basically means you get to create and use your own stats and status effects in your user page, all without having to create templates that would be dead weight to the rest of the wiki!

local warpStyles = require("Module:TemplateStyles").wrap

-- These variables are treated as feature flags. These are extremely easy to modify without error.
FFLAG_BOOL_TEXTLINKS = true -- Text Links (left 'false' due to hyperlink underlines appearing under most stat/status templates)
FFLAG_PERCENT_TAG = "_PS_" -- The phrase all % characters are temporarily turned into to prevent parse errors.
-- All functions being delared in 't' is the front-end work. These are much easier to understand.
-- Don't be mistaken though, you might still trip up here if you aren't well educated in Lua.
local t = {}

-- Helper function to get Argument for the template
local function getArgs(frame, wrappers)
	return require('Dev:Arguments').getArgs(frame, {
		trim = false,
		removeBlanks = false,
		parentFirst = true,
		wrapper = wrappers
	}) or frame.args
end

-- Generates a Status Template's Template
-- Templates using this function will have a "LV." indicator next to the status name IF {{{1}}} is a number.
-- If {{{1}}} isn't a number, this will use a similar format to Stat's custom text format.\
function t.Status(frame)
	local args = getArgs(frame, { 'Template:Status' })
	return t.status(args)
end

function t.status(args)
	local x = (args[1] or "")
	local content
	if x and x~="" then
		local customLv = string.sub(x, 1, 3) == 'Lv '
		if tonumber(x) then content = 'Lv ' .. x .. ' ' .. string.upper(args.name~="" and args.name or '') --(args.name~="" and args.name or '') .. ' (LV ' .. x .. ')' <-- old
		elseif customLv then content = x .. ' ' .. string.upper(args.name~="" and args.name or '')
		else content = x
		end
	else content = args.name~="" and string.upper(args.name) or ''
	end
	
	local parsed = render(content, args, "status")
	local final = warpStyles(mw.getCurrentFrame(), "Template:Status/styles.css", parsed)
	return final
end

-- Generates a Stat Template's Template
-- Templates using this function will have the stat name replaced with {{{1}}} if it isn't omitted.
function t.Stat(frame)
	local args = getArgs(frame, { 'Template:Stat' })
	return t.stat(args)
end

function t.stat(args)
	local x = (args[1] or "")
	local content
	if x and x~="" then content = x
	else content = args.name~="" and args.name or ''
	end
	
	local parsed = render(content, args, "stat")
	local final = warpStyles(mw.getCurrentFrame(), "Template:Stat/styles.css", parsed)
	return final
end

-- Generates a Itemicon Template's Template
-- This template also used for display cards.
function t.Icon(frame)
	local args = getArgs(frame, { 'Template:Itemicon' })
	return t.icon(args)
end

function t.icon(args)
	local x = (args[1] or "")
	args.name = (args.name or args[2] or x)
	if string.find(args.name, "^[e']?s$") then
		args.name = x .. args.name
	end
	local content = args.name~="" and args.name or ""
	local success, categories = pcall(require('Module:Transcluder').get, x, { only = 'categories' })
	local ext = '.png'
	if success and (string.find(categories, '%[%[Category:Enemies%]%]') or string.find(categories, '%[%[Category:Bosses%]%]') or string.find(categories, '%[%[Category:Superbosses%]%]')) then
		ext = ' Icon.png'
	end
	args.image = args.image or x and (x..ext):gsub(':', ""):gsub('/', "-")
	args.link = args.link or x
	
	local parsed = render(content, args, "item")
	local final = warpStyles(mw.getCurrentFrame(), "Template:Itemicon/styles.css", parsed)
	return final
end


__is = { -- The icon size for template formats.
	["stat"] = '20x20',
	["status"] = '20x20',
	["enemy"] = '20x20',
	["item"] = '20x20'
}

function render(content, args, tt)
	local sortkey = mw.html.create("span"):addClass("sortkey"):wikitext(args.link and ("[["..args.link.."]]") or "")
	local span = mw.html.create("span"):addClass("info-"..tt):addClass(args.class)
	if args.image and args.image~="" then
		span:wikitext(("[[File:%s|%spx|link=%s|alt=]] "):format( args.image~="" and args.image or "Status Placeholder.gif", args.size or __is[tt] or "20x20", args.link or ""))
	end
	if content and content ~= "" then
		if args.color and args.color~="" then
			content = tostring(mw.html.create("span"):css("color", args.color):wikitext(content))
		end
		if args.link and args.link~="" then
			if content == args.link then
				span:wikitext(("[[%s]]"):format(args.link))
			else
				span:wikitext(("[[%s|%s]]"):format(args.link, content))
			end
		else
			span:attr("title", args.name or ""):wikitext(content)
		end
	end
	return tostring(sortkey) .. tostring(span) 
end

-- Everything past this point is unused, but kept for the sake of archiving purposes. It is also very technical and not so user friendly.-- 

-- Fragments of HTML (so that it's easier to understand)
start = '<span style="display:none;" class="sortkey"></span><span class="info-__TT__ $class|$" title="$name|Untitled$">'
icon = '[[File:$image|Status Placeholder.gif$|__SIZE__px|link=$link|$]] '
wlink = '[[$link|$|<span style="color:$color|#aaa$;">&TEXT&</span>]]'
nolink = '<span style="color:$color|#aaa$">&TEXT&</span>'
finish = '</span>'

-- Unused, but kept for the sake of archiving purposes.
excl_status = '$name|Untitled$ {{#ifeq: $1|$||| (LV. $1|$)}}'
excl_stat = '{{#ifeq: $1|$||$name|Untitled$|$1|$}}'

-- Grab any variable the string is trying to grab.
function parse(str, args)
	return str:gsub('%$([a-zA-Z]+)(|[^$]*)%$', function(varname, default)
		return args[varname] or default or "$"..varname.."$"
	end)
end

function fullparse(content, args, tt)
	return ({parse(
		(start:gsub('__TT__', tt)
			.. (args.image and args.image~="" and icon:gsub('__SIZE__', args.size or __is[tt] or '20x20') or "")
			.. (args.link and args.link~="" and FFLAG_BOOL_TEXTLINKS and wlink or nolink)
			.. finish
		):gsub('&TEXT&', content), args)
	})[1]:gsub(FFLAG_PERCENT_TAG, '%%')
end

return t