Module:Fighter: Difference between revisions

From Wavu Wiki, the 🌊 wavy Tekken wiki
(Created page with "local p = {}; p.class = function(frame) local name = frame.args[1] return p._class(name) end p._class = function(name) return name:lower():gsub("%s+","-") end return p")
 
No edit summary
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local game = require("Module:Game");
local p = {};
local p = {};
p.fighters = game.Tekken7.fighters
p.fighters8 = game.Tekken8.fighters
p.shortcuts = {
["ak"] = "armor-king",
["dj"] = "devil-jin",
["drag"] = "dragunov",
["fahk"] = "fahkumram",
["gan"] = "ganryu",
["hei"] = "heihachi",
["hwo"] = "hwoarang",
["jack"] = "jack-7",
["kat"] = "katarina",
["kuni"] = "kunimitsu",
["lc"] = "lucky-chloe",
["chloe"] = "lucky-chloe",
["maven"] = "master-raven",
["raven"] = "master-raven",
["ling"] = "xiaoyu",
["yoshi"] = "yoshimitsu",
["zaf"] = "zafina"
}
p.list = function()
local r = ''
for _, f in ipairs(p.fighters) do
r = r .. "* [[" .. game.Tekken7.fighterPage(f) .. "|" .. f .. "]]\n"
end
return r
end
p.list8 = function(frame)
local subpage = frame.args[1]
return p._list8(subpage)
end
p._list8 = function(subpage)
subpage = subpage and " " .. subpage or ""
local r = ""
for _, f in ipairs(p.fighters8) do
r = r .. "* [[" .. f .. subpage  .. "|" .. f .. "]]\n"
end
return r
end


p.class = function(frame)
p.class = function(frame)
Line 7: Line 55:


p._class = function(name)
p._class = function(name)
return name:lower():gsub("%s+","-")
local r = name:lower():gsub("%s+","-")
return r
end
 
p.bodysize = function(frame)
local label = frame.args[1] or ""
local yes = frame.args["yes"] or frame.args[2] or ""
local no = frame.args["no"] or frame.args[3] or ""
return p._bodysize(label, yes, no)
end
 
p._bodysize = function(label, yes, no)
local function parse_arg(arg)
local hash = {}
for str in string.gmatch(arg, "([^,]+)") do
local strip = str:gsub("^%s+", ""):gsub("%s+$", "")
local class = p._class(strip)
if p.shortcuts[class] ~= nil then
hash[ p.shortcuts[class] ] = true
else
hash[ class ] = true
end
end
return hash
end
local yes_hash = parse_arg(yes)
local no_hash = parse_arg(no)
local ordered_bodysize_keys = {}
for k,v in pairs(p.fighters) do ordered_bodysize_keys[k] = p._class(v) end
 
-- If "bears" have been mentioned, then only list bears icon
-- Otherwise, list kuma and panda
if yes_hash["bears"] or no_hash["bears"] then
table.insert(ordered_bodysize_keys, "bears")
local k = 1
while k <= #ordered_bodysize_keys and ordered_bodysize_keys[k] ~= "kuma" do
k = k+1
end
table.remove(ordered_bodysize_keys, k)
else
table.insert(ordered_bodysize_keys, "panda")
end
table.sort(ordered_bodysize_keys)
local yes_wikitext = ' '
local no_wikitext = ''
local untested_wikitext = ''
for k,v in pairs(ordered_bodysize_keys) do
local wt = "{{Fi|" .. v .. "}}"
if yes_hash[v] ~= nil then
yes_wikitext = yes_wikitext .. wt
yes_hash[v] = nil
elseif no_hash[v] ~= nil then
no_wikitext = no_wikitext .. wt
no_hash[v] = nil
else
untested_wikitext = untested_wikitext .. wt
end
end
-- We removed the keys earlier to check for errors
-- Any remaining keys in yes_hash or no_hash are invalid keys
for k,v in pairs(yes_hash) do error("Unknown Fighter: " .. k) end
for k,v in pairs(no_hash) do error("Unknown Fighter: " .. k) end
local content = mw.html.create('span'):addClass("mw-collapsible-content")
:node(mw.html.create('span'):addClass('bodysize-yes'):wikitext(yes_wikitext))
:wikitext(" ")
:node(mw.html.create('span'):addClass('bodysize-no'):wikitext(no_wikitext))
:wikitext(" ")
:node(mw.html.create('span'):addClass('bodysize-untested'):wikitext(untested_wikitext))
content = mw.getCurrentFrame():preprocess( tostring(content) )
-- Evil hack so that we get commas if we select the icons and copy+paste
-- Maybe better to just not use {{Fi}} at all so it's decoupled from this?
-- Matching: aria-hidden="true">jin</span>
content = content:gsub('(aria%-hidden="true">[^<]-)(</span>)', '%1,%2')
local ctn = mw.html.create('span'):addClass("bodysize mw-collapsible mw-collapsed")
ctn:wikitext("【")
ctn:node(mw.html.create('span'):addClass("bodysize-label"):wikitext(label))
ctn:wikitext(" ")
ctn:node(
mw.html.create('span'):addClass("mw-collapsible-toggle")
:node(mw.html.create('span'):addClass("mw-collapsible-text fg-link"))
)
ctn:wikitext(content)
ctn:wikitext("】")
return ctn
end
 
p.punishment = function(frame)
local name = frame.args[1]
return p._punishment(name)
end
 
p._punishment = function(name)
data = mw.loadData('Module:Fighter/punishment')
local block = data.block[name]
if (block == nil) then
error("Punishers not defined in [[Module:Fighter/punishment]] 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('punishment-scale')
for i = 0,span,5 do
local pip = mw.html.create('div'):addClass('punishment-scalepip')
:css("width", string.format("%.2f%%", 100 * i / span))
:node(mw.html.create('div'):addClass('punishment-piplabel'):wikitext(i))
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('punishment')
for pos,punishment in pairs(block) do
local group = mw.html.create('div'):addClass('punishment-group')
root:node(group)
group:node(mw.html.create("div"):addClass('punishment-label')
:wikitext(pos:gsub("^%l", string.upper) .. "ing punishment")
)
local grid = mw.html.create('div'):addClass('punishment-grid')
group:node(grid)
best = {}
for i = 1,50 do
-- don't carry rage/meter punishment, makes viz. look funky
best[data.P_METER] = nil
if punishment[i] ~= nil then
for k,v in pairs(punishment[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 punishment[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)
grid:node(mw.html.create('div'):addClass('punishment-startup')
:wikitext("-" .. i)
)
local bars = mw.html.create('div'):addClass('punishment-bars')
grid: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('punishment-bar')
:addClass(class)
: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('punishment-median')
:css('width', string.format("%.2f%%", 100 * median / span))
)
end
end
end
grid:node(mw.clone(scale))
end
return root
end
end


return p
return p

Latest revision as of 17:20, 25 January 2024

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

local game = require("Module:Game");

local p = {};

p.fighters = game.Tekken7.fighters

p.fighters8 = game.Tekken8.fighters

p.shortcuts = {
	["ak"] = "armor-king",
	["dj"] = "devil-jin",
	["drag"] = "dragunov",
	["fahk"] = "fahkumram",
	["gan"] = "ganryu",
	["hei"] = "heihachi",
	["hwo"] = "hwoarang",
	["jack"] = "jack-7",
	["kat"] = "katarina",
	["kuni"] = "kunimitsu",
	["lc"] = "lucky-chloe",
	["chloe"] = "lucky-chloe",
	["maven"] = "master-raven",
	["raven"] = "master-raven",
	["ling"] = "xiaoyu",
	["yoshi"] = "yoshimitsu",
	["zaf"] = "zafina"
}

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

p.list8 = function(frame)
	local subpage = frame.args[1]
	return p._list8(subpage)
end

p._list8 = function(subpage)
	subpage = subpage and " " .. subpage or ""
	local r = ""
	for _, f in ipairs(p.fighters8) do
		r = r .. "* [[" .. f .. subpage  .. "|" .. 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.bodysize = function(frame)
	local label = frame.args[1] or ""
	local yes = frame.args["yes"] or frame.args[2] or ""
	local no = frame.args["no"] or frame.args[3] or ""
	return p._bodysize(label, yes, no)
end

p._bodysize = function(label, yes, no)
	local function parse_arg(arg)
		local hash = {}
		for str in string.gmatch(arg, "([^,]+)") do
			local strip = str:gsub("^%s+", ""):gsub("%s+$", "")
			local class = p._class(strip)
			if p.shortcuts[class] ~= nil then
				hash[ p.shortcuts[class] ] = true
			else
				hash[ class ] = true
			end
		end
		return hash
	end
	
	local yes_hash = parse_arg(yes)
	local no_hash = parse_arg(no)
	
	local ordered_bodysize_keys = {}
	for k,v in pairs(p.fighters) do ordered_bodysize_keys[k] = p._class(v) end

	-- If "bears" have been mentioned, then only list bears icon
	-- Otherwise, list kuma and panda
	if yes_hash["bears"] or no_hash["bears"] then
		table.insert(ordered_bodysize_keys, "bears")
		local k = 1
		while k <= #ordered_bodysize_keys and ordered_bodysize_keys[k] ~= "kuma" do
			k = k+1
		end
		table.remove(ordered_bodysize_keys, k)
	else 
		table.insert(ordered_bodysize_keys, "panda")
	end
	table.sort(ordered_bodysize_keys)
	
	local yes_wikitext = ' '
	local no_wikitext = ''
	local untested_wikitext = ''
	for k,v in pairs(ordered_bodysize_keys) do
		local wt = "{{Fi|" .. v .. "}}"
		if yes_hash[v] ~= nil then
			yes_wikitext = yes_wikitext .. wt
			yes_hash[v] = nil
		elseif no_hash[v] ~= nil then
			no_wikitext = no_wikitext .. wt
			no_hash[v] = nil
		else
			untested_wikitext = untested_wikitext .. wt
		end
	end
	
	-- We removed the keys earlier to check for errors
	-- Any remaining keys in yes_hash or no_hash are invalid keys
	for k,v in pairs(yes_hash) do error("Unknown Fighter: " .. k) end
	for k,v in pairs(no_hash) do error("Unknown Fighter: " .. k) end
	
	local content = mw.html.create('span'):addClass("mw-collapsible-content")
		:node(mw.html.create('span'):addClass('bodysize-yes'):wikitext(yes_wikitext))
		:wikitext(" ")
		:node(mw.html.create('span'):addClass('bodysize-no'):wikitext(no_wikitext))
		:wikitext(" ")
		:node(mw.html.create('span'):addClass('bodysize-untested'):wikitext(untested_wikitext))
	
	content = mw.getCurrentFrame():preprocess( tostring(content) )
	
	-- Evil hack so that we get commas if we select the icons and copy+paste
	-- Maybe better to just not use {{Fi}} at all so it's decoupled from this?
	-- Matching: aria-hidden="true">jin</span>
	content = content:gsub('(aria%-hidden="true">[^<]-)(</span>)', '%1,%2')
	
	local ctn = mw.html.create('span'):addClass("bodysize mw-collapsible mw-collapsed")
	ctn:wikitext("【")
	ctn:node(mw.html.create('span'):addClass("bodysize-label"):wikitext(label))
	ctn:wikitext(" ")
	ctn:node(
		mw.html.create('span'):addClass("mw-collapsible-toggle")
			:node(mw.html.create('span'):addClass("mw-collapsible-text fg-link"))
		)
	ctn:wikitext(content)
	ctn:wikitext("】")
	
	return ctn
end

p.punishment = function(frame)
	local name = frame.args[1]
	return p._punishment(name)
end

p._punishment = function(name)
	data = mw.loadData('Module:Fighter/punishment')
	local block = data.block[name]
	if (block == nil) then
		error("Punishers not defined in [[Module:Fighter/punishment]] 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('punishment-scale')
	for i = 0,span,5 do
		local pip = mw.html.create('div'):addClass('punishment-scalepip')
			:css("width", string.format("%.2f%%", 100 * i / span))
			:node(mw.html.create('div'):addClass('punishment-piplabel'):wikitext(i))
		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('punishment')
	for pos,punishment in pairs(block) do
		local group = mw.html.create('div'):addClass('punishment-group')
		root:node(group)
		group:node(mw.html.create("div"):addClass('punishment-label')
			:wikitext(pos:gsub("^%l", string.upper) .. "ing punishment")
		)
		local grid = mw.html.create('div'):addClass('punishment-grid')
		group:node(grid)
		
		best = {}
		for i = 1,50 do
			-- don't carry rage/meter punishment, makes viz. look funky
			best[data.P_METER] = nil
	
			if punishment[i] ~= nil then
				for k,v in pairs(punishment[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 punishment[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)
				
				grid:node(mw.html.create('div'):addClass('punishment-startup')
					:wikitext("-" .. i)
				)
				local bars = mw.html.create('div'):addClass('punishment-bars')
				grid: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('punishment-bar')
							:addClass(class)
							: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('punishment-median')
							:css('width', string.format("%.2f%%", 100 * median / span))
					)
				end
			end
		end
		grid:node(mw.clone(scale))
	end
	
	return root
end

return p