RogerDodger (talk | contribs) No edit summary |
RogerDodger (talk | contribs) No edit summary |
||
Line 32: | Line 32: | ||
end | end | ||
p. | p.punishment = function(frame) | ||
local name = frame.args[1] | local name = frame.args[1] | ||
return p. | return p._punishment(name) | ||
end | end | ||
p. | p._punishment = function(name) | ||
data = mw.loadData('Module:Fighter/ | data = mw.loadData('Module:Fighter/punishment') | ||
local block = data.block[name] | local block = data.block[name] | ||
if (block == nil) then | if (block == nil) then | ||
error("Punishers not defined in [[Module:Fighter/ | error("Punishers not defined in [[Module:Fighter/punishment]] for " .. name) | ||
end | end | ||
Line 58: | Line 58: | ||
end | end | ||
local scale = mw.html.create('div'):addClass(' | local scale = mw.html.create('div'):addClass('punishment-scale') | ||
for i = 0,span,5 do | for i = 0,span,5 do | ||
local pip = mw.html.create('div'):addClass(' | local pip = mw.html.create('div'):addClass('punishment-scalepip') | ||
:css("width", string.format("%.2f%%", 100 * i / span)) | :css("width", string.format("%.2f%%", 100 * i / span)) | ||
:node(mw.html.create('div'):addClass(' | :node(mw.html.create('div'):addClass('punishment-piplabel'):wikitext(i)) | ||
if i % 50 == 0 then | if i % 50 == 0 then | ||
pip:addClass('major') | pip:addClass('major') | ||
Line 71: | Line 71: | ||
end | end | ||
local root = mw.html.create('div'):addClass(' | local root = mw.html.create('div'):addClass('punishment') | ||
for pos, | for pos,punishment in pairs(block) do | ||
local group = mw.html.create('div'):addClass(' | local group = mw.html.create('div'):addClass('punishment-group') | ||
root:node(group) | root:node(group) | ||
group:node(mw.html.create("div"):addClass(' | group:node(mw.html.create("div"):addClass('punishment-label') | ||
:wikitext(pos:gsub("^%l", string.upper) .. "ing punishment") | :wikitext(pos:gsub("^%l", string.upper) .. "ing punishment") | ||
) | ) | ||
local grid = mw.html.create('div'):addClass(' | local grid = mw.html.create('div'):addClass('punishment-grid') | ||
group:node(grid) | group:node(grid) | ||
best = {} | best = {} | ||
for i = 1,50 do | for i = 1,50 do | ||
-- don't carry rage/meter | -- don't carry rage/meter punishment, makes viz. look funky | ||
best[data.P_METER] = nil | best[data.P_METER] = nil | ||
if | if punishment[i] ~= nil then | ||
for k,v in pairs( | for k,v in pairs(punishment[i]) 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 | ||
Line 101: | Line 101: | ||
end | end | ||
if | if punishment[i] ~= nil or (i >= 10 and i <= 15) then | ||
bestSortedKeys = {} | bestSortedKeys = {} | ||
for k,_ in pairs(best) do | for k,_ in pairs(best) do | ||
Line 111: | Line 111: | ||
end) | end) | ||
grid:node(mw.html.create('div'):addClass(' | grid:node(mw.html.create('div'):addClass('punishment-startup') | ||
:wikitext("-" .. i) | :wikitext("-" .. i) | ||
) | ) | ||
local bars = mw.html.create('div'):addClass(' | local bars = mw.html.create('div'):addClass('punishment-bars') | ||
grid:node(bars) | grid:node(bars) | ||
for i,k in ipairs(bestSortedKeys) do | for i,k in ipairs(bestSortedKeys) do | ||
Line 120: | Line 120: | ||
if class == true then class = 'bg-blue' end | if class == true then class = 'bg-blue' end | ||
bars:node( | bars:node( | ||
mw.html.create('div'):addClass(' | mw.html.create('div'):addClass('punishment-bar') | ||
:addClass(class) | :addClass(class) | ||
:css("width", string.format("%.2f%%", 100 * best[k] / span)) | :css("width", string.format("%.2f%%", 100 * best[k] / span)) | ||
Line 129: | Line 129: | ||
if median ~= nil then | if median ~= nil then | ||
bars:node( | bars:node( | ||
mw.html.create('div'):addClass(' | mw.html.create('div'):addClass('punishment-median') | ||
:css('width', string.format("%.2f%%", 100 * median / span)) | :css('width', string.format("%.2f%%", 100 * median / span)) | ||
) | ) |
Revision as of 09:19, 17 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.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