Module:Fighter: Difference between revisions

From Wavu Wiki, the 🌊 wavy Tekken wiki
(wip punishers bar graph)
No edit summary
Line 39: Line 39:
p._punishers = function(name)
p._punishers = function(name)
data = mw.loadData('Module:Fighter/punishers')
data = mw.loadData('Module:Fighter/punishers')
subject = data.block[name]
local block = data.block[name]
if (subject == nil) then
if (block == nil) then
error("Punishers not defined in [[Module:Fighter/punishers]] for " .. name)
error("Punishers not defined in [[Module:Fighter/punishers]] for " .. name)
end
local span = 80
for _,t_group in pairs(block) do
for _,t_startup in pairs(t_group) do
for n,_ in pairs(t_startup) do
if n > span then
span = n
end
end
end
end
if span % 5 ~= 0 then
span = span + 5 - (span % 5)
end
end
local ret = ""
local scale = mw.html.create('div'):addClass('punishers-scale')
for pos,punishers in ipairs(subject) do
for i = 0,span,5 do
local root = mw.html.create('div'):attr('class', 'punishers')
local pip = mw.html.create('div'):addClass('punishers-scalepip')
root:node(mw.html.create("div")
:css("width", string.format("%.2f%%", 100 * i / span))
:attr('class', 'punishers-label')
if i % 50 == 0 then
pip:addClass('major')
elseif i % 25 == 0 then
pip:addClass('minor')
end
scale:node(pip)
end
local root = mw.html.create('div'):addClass('punishers')
for pos,punishers in pairs(block) do
local group = mw.html.create('div'):addClass('punishers-group')
root:node(group)
group:node(mw.html.create("div"):addClass('punishers-label')
:wikitext(pos:gsub("^%l", string.upper) .. "ing")
:wikitext(pos:gsub("^%l", string.upper) .. "ing")
)
)
local grid = mw.html.create('div'):attr('class', 'punishers-grid')
group:node(mw.clone(scale))
root:node(grid)
local grid = mw.html.create('div'):addClass('punishers-grid')
group:node(grid)
best = {}
best = {}
for i = 1,50 do
for i = 1,50 do
if punishers[i] ~= nil or (i >= 10 and i <= 15) then
if punishers[i] ~= nil then
local curr = punishers[i]
for k,v in pairs(punishers[i]) do
for k,v in ipairs(curr) do
if best[v] == nil or best[v] < k then
if best[v] == nil or best[v] < k then
best[v] = k
best[v] = k
end
end
end
end
bestInvert = {}
if best[true] then
for k,v in ipairs(best) do
for k,v in pairs(best) do
bestInvert[v] = k
if k ~= true and best[k] <= best[true] then
best[k] = nil
end
end
end
end
if bestInvert[true] ~= nil then
end
for k,v in ipairs(bestInvert) do
if k == true then break end
if punishers[i] ~= nil or (i >= 10 and i <= 15) then
bestInvert[k] = nil
bestSortedKeys = {}
end
for k,_ in pairs(best) do
table.insert(bestSortedKeys, k)
end
end
local row = mw.html.create('div'):attr('class', 'punishers-row')
table.sort(bestSortedKeys, function (a, b)
row:node(mw.html.create('div')
-- Larger bars first so that smaller bars are actually visible
:attr('class', 'punishers-startup')
return best[a] > best[b]
:wikitext("-" .. i)
end)
)
local bars = mw.html.create('punishers-bars')
local row = mw.html.create('div'):addClass('punishers-row')
:node(mw.html.create('div'):addClass('punishers-startup')
:wikitext("-" .. i)
)
grid:node(row)
local bars = mw.html.create('div'):addClass('punishers-bars')
row:node(bars)
for i,k in ipairs(bestSortedKeys) do
local class = k
if class == true then class = 'bg-blue' end
bars:node(
mw.html.create('div'):addClass('punishers-bar')
:addClass(class):addClass('pattern')
:css("width", string.format("%.2f%%", 100 * best[k] / span))
:wikitext(best[k])
)
end
local median = data.median[pos][i]
if median ~= nil then
bars:node(
mw.html.create('div'):addClass('punishers-median')
:css('width', string.format("%.2f%%", 100 * median / span))
)
end
end
end
end
end
ret = ret .. root
end
end
return root
end
end


return p
return p

Revision as of 11:20, 16 November 2021

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

local p = {};

p.fighters = {
	"Akuma", "Alisa", "Anna", "Armor King", "Asuka",
	"Bob", "Bryan", "Claudio", "Devil Jin", "Dragunov",
	"Eddy", "Eliza", "Fahkumram", "Feng", "Ganryu",
	"Geese", "Gigas", "Heihachi", "Hwoarang", "Jack-7",
	"Jin", "Josie", "Julia", "Katarina", "Kazumi",
	"Kazuya", "King", "Kuma", "Kunimitsu", "Lars",
	"Law", "Lee", "Lei", "Leo", "Leroy",
	"Lidia", "Lili", "Lucky Chloe", "Marduk", "Master Raven",
	"Miguel", "Negan", "Nina", "Noctis", "Paul",
	"Shaheen", "Steve", "Xiaoyu", "Yoshimitsu", "Zafina"
}

p.list = function()
	local r = ''
	for _, f in ipairs(p.fighters) do
		r = r .. "* [[" .. f .. "]]\n"
	end
	return r
end

p.class = function(frame)
	local name = frame.args[1]
	return p._class(name)
end

p._class = function(name)
	local r = name:lower():gsub("%s+","-")
	return r
end

p.punishers = function(frame)
	local name = frame.args[1]
	return p._punishers(name)
end

p._punishers = function(name)
	data = mw.loadData('Module:Fighter/punishers')
	local block = data.block[name]
	if (block == nil) then
		error("Punishers not defined in [[Module:Fighter/punishers]] for " .. name)
	end

	local span = 80
	for _,t_group in pairs(block) do
		for _,t_startup in pairs(t_group) do
			for n,_ in pairs(t_startup) do
				if n > span then
					span = n
				end
			end
		end
	end
	if span % 5 ~= 0 then
		span = span + 5 - (span % 5)
	end
	
	local scale = mw.html.create('div'):addClass('punishers-scale')
	for i = 0,span,5 do
		local pip = mw.html.create('div'):addClass('punishers-scalepip')
			:css("width", string.format("%.2f%%", 100 * i / span))
		if i % 50 == 0 then
			pip:addClass('major')
		elseif i % 25 == 0 then
			pip:addClass('minor')
		end
		scale:node(pip)
	end
	
	local root = mw.html.create('div'):addClass('punishers')
	for pos,punishers in pairs(block) do
		local group = mw.html.create('div'):addClass('punishers-group')
		root:node(group)
		group:node(mw.html.create("div"):addClass('punishers-label')
			:wikitext(pos:gsub("^%l", string.upper) .. "ing")
		)
		group:node(mw.clone(scale))
		local grid = mw.html.create('div'):addClass('punishers-grid')
		group:node(grid)
		
		best = {}
		for i = 1,50 do
			if punishers[i] ~= nil then
				for k,v in pairs(punishers[i]) do
					if best[v] == nil or best[v] < k then
						best[v] = k
					end
				end
				if best[true] then
					for k,v in pairs(best) do
						if k ~= true and best[k] <= best[true] then
							best[k] = nil
						end
					end
				end
			end
			
			if punishers[i] ~= nil or (i >= 10 and i <= 15) then
				bestSortedKeys = {}
				for k,_ in pairs(best) do
					table.insert(bestSortedKeys, k)
				end
				table.sort(bestSortedKeys, function (a, b)
					-- Larger bars first so that smaller bars are actually visible
					return best[a] > best[b]
				end)
				
				local row = mw.html.create('div'):addClass('punishers-row')
					:node(mw.html.create('div'):addClass('punishers-startup')
						:wikitext("-" .. i)
					)
				grid:node(row)
				local bars = mw.html.create('div'):addClass('punishers-bars')
				row:node(bars)
				for i,k in ipairs(bestSortedKeys) do
					local class = k
					if class == true then class = 'bg-blue' end
					bars:node(
						mw.html.create('div'):addClass('punishers-bar')
							:addClass(class):addClass('pattern')
							:css("width", string.format("%.2f%%", 100 * best[k] / span))
							:wikitext(best[k])
					)
				end
				local median = data.median[pos][i]
				if median ~= nil then
					bars:node(
						mw.html.create('div'):addClass('punishers-median')
							:css('width', string.format("%.2f%%", 100 * median / span))
					)
				end
			end
		end
	end
	
	return root
end

return p