Module:Infobox/Brand/Gear

From Inkipedia, the Splatoon wiki
Revision as of 13:38, 15 March 2024 by Exaskliri (talk | contribs) (UNFINISHED DO NOT USE)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Infobox/Brand/Gear/doc

--[[

UNFINISHED DO NOT USE

]]

local p = {}
local lib					= require("Module:MiscFunctions")
local favoredAbilityModule	= require("Module:AbilityFromBrand/new")
local abilityIconModule		= require("Module:Ability/new/2")

local function getAbilityFromBrand(game, brand)
    return favoredAbilityModule.requireFromModule{
    	game=string.upper(game),
    	brand=brand or mw.title.getCurrentTitle(),
    }
end

local function getAbilityIcon(game, ability)
    return abilityIconModule.requireFromModule{
    	game=string.upper(game),
    	name=ability,
    }
end

function p.invokeFromTemplate(frame)
	return p.repeatInfoboxes(
		string.upper(frame:getParent().args.game),
		frame:getParent().args.name or mw.title.getCurrentTitle(),
		frame:extensionTag('templatestyles', '', { src = "Infobox/common.css" } ),
		frame:getParent().args.game_delim or ";"
	)
end

function p.repeatInfoboxes(game, brand, templateStyles, gameDelim)
	local allInfoboxes = {}
	table.insert(allInfoboxes, templateStyles)
	local gameList = lib.split(game, gameDelim)
	for i, v in ipairs(gameList) do
		table.insert(allInfoboxes, p.buildInfobox(gameList[i], brand))
	end
	return table.concat(allInfoboxes, "\n")
end

function p.buildInfobox(game, brand)
	local title = mw.html.create("div")
	title
		:addClass("infobox-title")
		:wikitext(brand)
	title = tostring(title)
	
	local image = mw.html.create("div")
	image
		:addClass("infobox-image")
		:css("padding", "12px 0")
		:wikitext(string.format("[[File:%s Brand %s.png|64x64px|%s]]", game, brand, brand))
	image = tostring(image)
	
	local likelyLabel	=	mw.html.create('div')
	likelyLabel
		:addClass("infobox-label")
		:wikitext("Likely ability")
	likelyLabel = tostring(likelyLabel)
	
	local unlikelyLabel	=	mw.html.create('div')
	unlikelyLabel
		:addClass("infobox-label")
		:wikitext("Unlikely ability")
	unlikelyLabel = tostring(unlikelyLabel)
	
	local likelyAbilityList = {}
	local unlikelyAbilityList = {}
	if (getAbilityFromBrand(game, brand) ~= nil) then
		for i, v in ipairs(getAbilityFromBrand(game, brand)) do
			if v[1] > 1 then
				table.insert(likelyAbilityList, getAbilityIcon(game, v[2]))
			elseif v[1] < 1 then
				table.insert(unlikelyAbilityList, getAbilityIcon(game, v[2]))
			end
		end
	end
	
	likelyAbility = mw.html.create('div')
	if lib.isEmpty(likelyAbilityList) then
		likelyAbility:wikitext("Neutral")
	else
		likelyAbility:wikitext(table.concat(likelyAbilityList, "<br>"))
	end
	likelyAbility = tostring(likelyAbility)
	
	unlikelyAbility = mw.html.create('div')
	if lib.isEmpty(unlikelyAbilityList) then
		unlikelyAbility:wikitext("Neutral")
	else
		unlikelyAbility:wikitext(table.concat(unlikelyAbilityList, "<br>"))
	end
	unlikelyAbility = tostring(unlikelyAbility)
	
	local abilities = mw.html.create("div")
	abilities
		:addClass("infobox-table")
		:wikitext(likelyLabel, likelyAbility, unlikelyLabel, unlikelyAbility)
	abilities = tostring(abilities)
	
	local infobox = mw.html.create("div")
	infobox
		:addClass(string.format("infobox %s", game))
		:wikitext(title, image, abilities)
	
	return tostring(infobox)
end

return p