RogerDodger (talk | contribs) No edit summary |
RogerDodger (talk | contribs) No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
local data = mw.text.jsonDecode(json) | local data = mw.text.jsonDecode(json) | ||
local labels = { "Poke", "Mixup", "Okiwaza", "Whiff punish", "Okizeme", "Pressure" } | local labels = { "Poke", "Mixup", "Okiwaza", "Whiff punish", "Okizeme", "Pressure", "Defense" } | ||
local ranks = {} | |||
for _,fighter in ipairs(data["unsorted"]) do | |||
ranks[fighter] = {} | |||
end | |||
for _,label in ipairs(labels) do | |||
for i,fighter in ipairs(data[label]) do | |||
ranks[fighter][label] = i | |||
end | |||
end | end | ||
p.all = function() | p.all = function() | ||
local wikitable = mw.html.create('table'):addClass('punishers sortable') | local wikitable = mw.html.create('table'):addClass('punishers sortable') | ||
Line 49: | Line 42: | ||
end | end | ||
return wikitable | local radars = '' | ||
for _,fighter in ipairs(data["unsorted"]) do | |||
radars = radars .. p._radar(fighter) .. "\n" | |||
end | |||
return tostring(wikitable) .. "\n\n" .. | |||
mw.getCurrentFrame():preprocess("{{Row|" .. radars .. "}}") | |||
end | |||
p.radar = function(frame) | |||
local fighter = frame.args[1] | |||
return frame:preprocess( p._radar(fighter) ) | |||
end | |||
p._radar = function(fighter) | |||
local archetype = ranks[fighter] | |||
if archetype == nil then error("Unknown character: " .. fighter) end | |||
local points = "" | |||
for _,label in ipairs(labels) do | |||
points = points .. string.format("%.5f", 1 - ((archetype[label] - 1) / 49)) .. " " .. label .. "\n" | |||
end | |||
return "{{Label|" .. fighter .. "|\n<radar size=\"280\">\n" .. points .. "</radar>}}" | |||
end | end | ||
return p | return p |
Revision as of 15:56, 20 January 2022
Documentation for this module may be created at Module:Archetype/doc
local G = require("Module:G")
local p = {}
local json = mw.title.makeTitle("User", "RogerDodger/archetypes.json"):getContent()
local data = mw.text.jsonDecode(json)
local labels = { "Poke", "Mixup", "Okiwaza", "Whiff punish", "Okizeme", "Pressure", "Defense" }
local ranks = {}
for _,fighter in ipairs(data["unsorted"]) do
ranks[fighter] = {}
end
for _,label in ipairs(labels) do
for i,fighter in ipairs(data[label]) do
ranks[fighter][label] = i
end
end
p.all = function()
local wikitable = mw.html.create('table'):addClass('punishers sortable')
-- Headings
local heads = mw.html.create('tr')
heads:node(mw.html.create('th'):wikitext("Character"))
for _,label in ipairs(labels) do
heads:node(mw.html.create('th'):wikitext(label))
end
heads:node(mw.html.create('th'):wikitext("Total"))
wikitable:node(heads)
-- Body
for _,fighter in ipairs(data["unsorted"]) do
local row = mw.html.create('tr')
local n = 0
row:node(mw.html.create('td'):wikitext("[[" .. fighter .. "]]"))
for _,label in ipairs(labels) do
local i = ranks[fighter][label]
n = n + i
row:node(mw.html.create('td'):wikitext(i):addClass(G._main(i,1,50,true)))
end
row:node(mw.html.create('td'):wikitext(n))
wikitable:node(row)
end
local radars = ''
for _,fighter in ipairs(data["unsorted"]) do
radars = radars .. p._radar(fighter) .. "\n"
end
return tostring(wikitable) .. "\n\n" ..
mw.getCurrentFrame():preprocess("{{Row|" .. radars .. "}}")
end
p.radar = function(frame)
local fighter = frame.args[1]
return frame:preprocess( p._radar(fighter) )
end
p._radar = function(fighter)
local archetype = ranks[fighter]
if archetype == nil then error("Unknown character: " .. fighter) end
local points = ""
for _,label in ipairs(labels) do
points = points .. string.format("%.5f", 1 - ((archetype[label] - 1) / 49)) .. " " .. label .. "\n"
end
return "{{Label|" .. fighter .. "|\n<radar size=\"280\">\n" .. points .. "</radar>}}"
end
return p