Difference between revisions of "Module:Video game reviews/sandbox"
Jump to navigation
Jump to search
blackwiki>Jackmcbarn (fix more overly wide colspans) |
blackwiki>Jackmcbarn (remove the copy of system from this file) |
||
| Line 15: | Line 15: | ||
local aggregator = {{'[[GameRankings]]','GR'}, {'[[Metacritic]]','MC'}} | local aggregator = {{'[[GameRankings]]','GR'}, {'[[Metacritic]]','MC'}} | ||
| − | |||
| − | |||
local data = mw.loadData('Module:Video game reviews/data') | local data = mw.loadData('Module:Video game reviews/data') | ||
| Line 201: | Line 199: | ||
.wikitext(aggregator[i][1]) | .wikitext(aggregator[i][1]) | ||
| − | for | + | for _,systemCode in ipairs(activeSystems) do |
| − | local temp = tostring(aggregator[i][2]) .. '_' .. tostring( | + | local temp = tostring(aggregator[i][2]) .. '_' .. tostring(systemCode) |
| − | if | + | if args[temp] ~= nil then |
forloop.tag('td').wikitext(tostring(args[temp])) | forloop.tag('td').wikitext(tostring(args[temp])) | ||
| − | elseif | + | elseif string.lower(tostring(args['na'])) == 'true' then |
forloop.tag('td') | forloop.tag('td') | ||
.css('color', 'lightgray') | .css('color', 'lightgray') | ||
| Line 212: | Line 210: | ||
.addClass('table-na') | .addClass('table-na') | ||
.wikitext('N/A') | .wikitext('N/A') | ||
| − | + | else | |
forloop.tag('td') | forloop.tag('td') | ||
end | end | ||
Revision as of 22:39, 17 July 2014
Documentation for this module may be created at Module:Video game reviews/sandbox/doc
--
-- Module layout for reviewer section in the work
--
-- 1 get args
-- 2 extract all reviewer args
-- 3 sort args for reviewer then system
-- 4 output args value where reviewer + system correlate
--
require('Module:No globals')
local p = {}
local reviewer = {{'[[1UP.com]]', '1UP'}, {'[[ActionTrip]]', 'Atrip'}, {'[[Adventure Gamers]]', 'AdvGamers'}, {'[[AllGame]]', 'Allgame'}, {'[[Amstrad Action]]', 'AAction'}, {'[[Amtix!]]', 'Amtix'}, {'[[Computer and Video Games]]', 'CVG'}, {'[[Crash (magazine)|Crash]]', 'CRASH'}, {'[[Destructoid]]', 'Destruct'}, {'[[Dragon (magazine)]]', 'Dragon'}, {'[[Edge (magazine)|Edge]]', 'Edge'}, {'[[Electronic Gaming Monthly]]', 'EGM'}, {'[[Eurogamer]]', 'EuroG'}, {'[[Famitsu]]', 'Fam'}, {'[[G4 (TV channel)|G4]]', 'G4'}, {'GameCritics', 'GCritics'}, {'[[GameFan]]', 'GameFan'}, {'[[Game Informer]]', 'GI'}, {'[[GamePro]]', 'GamePro'}, {'[[Game Revolution]]', 'GameRev'}, {'[[GamesMaster]]', 'GMaster'}, {'[[GamesRadar]]', 'GRadar'}, {'[[GameSpot]]', 'GSpot'}, {'[[GameSpy]]', 'GSpy'}, {'[[GamesTM]]', 'GTM'}, {'[[GameTrailers]]', 'GT'}, {'GameWire', 'GW'}, {'[[GameZone]]', 'GameZone'}, {'[[Giant Bomb]]', 'GB'}, {'[[Hyper (magazine)|Hyper Magazine]]', 'Hyper'}, {'[[IGN]]', 'IGN'}, {'[[Joystiq]]', 'Joystiq'}, {'[[Maximum PC]]', 'MaxPC'}, {'[[NGC Magazine]]', 'N64'}, {'[[NGC Magazine]]', 'NGC'}, {'[[NGamer]]', 'NG'}, {'NintendoLife', 'NLife'}, {'[[Nintendo Power]]', 'NP'}, {'Nintendo World Report', 'NWR'}, {'[[Official Nintendo Magazine]]', 'ONM'}, {'[[Official U.S. PlayStation Magazine|Official PlayStation Magazine (US)]]', 'OPM'}, {'[[PlayStation Official Magazine (UK)|Official PlayStation Magazine (UK)]]', 'OPMUK'}, {'[[Official PlayStation Magazine (Australia)]]', 'OPMAU'}, {'[[Official Xbox Magazine]]', 'OXM'}, {'[[Official Xbox Magazine|Official Xbox Magazine UK]]', 'OXMUK'}, {'[[PALGN]]', 'PALGN'}, {'[[PC Format]]', 'PCF'}, {'[[PC Gamer|PC Gamer UK]]', 'PCGUK'}, {'[[PC Gamer|PC Gamer US]]', 'PCGUS'}, {'[[PC PowerPlay]]', 'PCPP'}, {'[[PC Zone]]', 'PCZone'}, {'[[Play (UK magazine)|Play Magazine]]', 'Play'}, {'[[Polygon (website)|Polygon]]', 'Poly'}, {'[[PlayStation: The Official Magazine|PlayStation Magazine]]', 'PSM'}, {'[[PSM3|PlayStation 3 Magazine]]', 'PSM3'}, {'[[RPGamer]]', 'RPG'}, {'[[Sinclair User]]', 'SUser'}, {'[[TeamXbox]]', 'TX'}, {'[[VideoGamer.com]]', 'VG'}, {'[[X-Play]]', 'XPlay'}, {'[[Your Sinclair]]', 'YSinclair'}}
local aggregator = {{'[[GameRankings]]','GR'}, {'[[Metacritic]]','MC'}}
local data = mw.loadData('Module:Video game reviews/data')
local HtmlBuilder = require('Module:HtmlBuilder')
local function getActiveSystems(args)
local activeSystems = {}
for k,v in pairs(args) do
if data.systems[k] and v:lower() == 'true' then
table.insert(activeSystems, k)
end
end
table.sort(activeSystems, function(a, b)
return data.systems[a].sortkey < data.systems[b].sortkey
end)
return activeSystems
end
local function getArgKeyTables(orderedKeys)
local reviewers, aggregators, awards = {}, {}, {}
for _,v in ipairs(orderedKeys) do
if v:match('^rev(%d+)$') then
table.insert(reviewers, v)
elseif v:match('^agg(%d+)$') then
table.insert(aggregators, v)
elseif v:match('^award(%d+)$') then
table.insert(awards, v)
end
end
return reviewers, aggregators, awards
end
local function renderTitleRow(tbl, plain, title)
local titleCell = tbl.tag('tr').tag('th').css('font-size', '120%')
if plain then
titleCell
.tag('span')
.css('padding-left', '5.7em')
.wikitext(' ')
end
if title then
titleCell
.wikitext(title)
else
titleCell
.addClass('Reception')
.wikitext('Reception')
end
end
local function renderSystemHeadingRow(builder, activeSystems)
builder = builder.tag('tr')
for _,v in ipairs(activeSystems) do
builder.tag('th').wikitext(data.systems[v].name)
end
end
local function renderRatingsBySystem(builder, reviewerCode, reviewerName, activeSystems, args)
builder = builder.tag('tr')
builder.tag('td')
.css('vertical-align','middle')
.wikitext(reviewerName)
for _,systemCode in ipairs(activeSystems) do
local reviewerAndSystemCode = reviewerCode .. '_' .. systemCode
local cell = builder.tag('td')
if args[reviewerAndSystemCode] then
cell
.css('vertical-align', 'middle')
.wikitext(args[reviewerAndSystemCode])
elseif args.na and args.na:lower() == 'true' then
cell
.css('color', 'lightgray')
.css('vertical-align','middle')
.css('text-align', 'center')
.addClass('table-na')
.wikitext('N/A')
end
end
end
local function renderReviews(builder, providedReviewers, providedAggregators, activeSystems, customAggregatorKeys, customReviewerKeys, args)
local arg_system
local tbl2 = builder.tag('table')
.addClass('infobox wikitable')
.attr('cellpadding', 0)
.attr('cellspacing', 0)
.css('width', '100%')
.css('border-bottom', 'none')
.css('margin', '0em')
if #activeSystems == 0 then
tbl2.css('font-size', '100%')
end
if #providedReviewers > 0 and (#activeSystems > 1 or (args.showplatforms and args.showplatforms:lower() == 'true')) then
tbl2.tag('tr').tag('th')
.attr('colspan', #activeSystems + 1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
tbl2
.tag('tr')
.tag('th')
.attr('rowspan', '2')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext('Publication')
.done()
.tag('th')
.attr('colspan', #activeSystems)
.css('background', '#e8f4f8')
.css('vertical-align', 'middle')
.wikitext('Score')
renderSystemHeadingRow(tbl2, activeSystems)
elseif #providedReviewers > 0 and #activeSystems == 1 and (not args.showplatforms or args.showplatforms:lower() ~= 'true') then
tbl2.tag('tr').tag('th')
.attr('colspan', '2')
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
tbl2
.tag('tr')
.tag('th')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext('Publication')
.done()
.tag('th')
.css('background', '#e8f4f8')
.css('vertical-align', 'middle')
.wikitext('Score')
end
if #activeSystems >= 1 then
for _,reviewerCode in ipairs(providedReviewers) do
renderRatingsBySystem(tbl2, reviewerCode, data.reviewers[reviewerCode].name, activeSystems, args)
end
for _,v in ipairs(customReviewerKeys) do
renderRatingsBySystem(tbl2, v, args[v], activeSystems, args)
end
if (#providedAggregators > 0 and #activeSystems > 1) and #providedReviewers == 0 then
tbl2
.tag('tr')
.tag('th')
.attr('colspan', #activeSystems+1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Aggregate scores')
tbl2
.tag('tr')
.tag('th')
.attr('rowspan', '2')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext('Publication')
.done()
.tag('th')
.attr('colspan', #activeSystems+1)
.css('background', '#e8f4f8')
.css('vertical-align', 'middle')
.wikitext('Score')
renderSystemHeadingRow(tbl2, activeSystems)
elseif (#providedAggregators > 0 and #providedReviewers > 0) or (#providedAggregators > 0 and #activeSystems == 1)then
tbl2
.tag('tr')
.tag('th')
.attr('colspan', #activeSystems+1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Aggregate scores')
end
for i = 1, #aggregator do
for k = 1, #providedAggregators do
if aggregator[i][2] == providedAggregators[k] then
local forloop = tbl2.tag('tr')
forloop.tag('td')
.css('vertical-align','middle')
.wikitext(aggregator[i][1])
for _,systemCode in ipairs(activeSystems) do
local temp = tostring(aggregator[i][2]) .. '_' .. tostring(systemCode)
if args[temp] ~= nil then
forloop.tag('td').wikitext(tostring(args[temp]))
elseif string.lower(tostring(args['na'])) == 'true' then
forloop.tag('td')
.css('color', 'lightgray')
.css('vertical-align','middle')
.css('text-align', 'center')
.addClass('table-na')
.wikitext('N/A')
else
forloop.tag('td')
end
end
end
end
end
elseif #activeSystems == 0 then
if #providedAggregators > 0 or #customAggregatorKeys > 0 then
tbl2
.tag('tr')
.tag('th')
.attr('colspan', 2)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Aggregate scores')
.done()
.tag('tr')
.tag('th')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.wikitext('Aggregator')
.done()
.tag('th')
.css('background', '#e8f4f8')
.wikitext('Score')
end
for i = 1, #aggregator do
for k = 1, #providedAggregators do
if aggregator[i][2] == providedAggregators[k] then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(aggregator[i][1])
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(args[tostring(aggregator[i][2])]))
end
end
end
for _,v in ipairs(customAggregatorKeys) do
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(args[v])
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(args[v .. 'Score'])
end
if #providedReviewers > 0 or #customReviewerKeys > 0 then
tbl2.tag('tr').tag('th')
.attr('colspan', 2)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
tbl2
.tag('tr')
.tag('th')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.wikitext('Publication')
.done()
.tag('th')
.attr('colspan', 2)
.css('background', '#e8f4f8')
.wikitext('Score')
for i = 1, #reviewer do
for k = 1, #providedReviewers do
if reviewer[i][2] == providedReviewers[k] then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(reviewer[i][1])
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(args[tostring(reviewer[i][2])]))
end
end
end
for _,v in ipairs(customReviewerKeys) do
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(args[v])
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(args[v .. 'Score'])
end
end
end
end
local function renderAwards(builder, args, awardKeys)
local Cell = builder.tag('table')
.addClass('infobox wikitable')
.css('width', '100%')
.css('margin', '0em')
.css('border-top', 'none')
.attr('cellpadding', 3)
.attr('cellspacing', 0)
.tag('tr')
.tag('th')
.attr('colspan', 2)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.css('border-top', 'none')
.wikitext('Awards')
.done()
.done()
.tag('tr')
.tag('th')
.wikitext('Publication')
.done()
.tag('th')
.wikitext('Award')
.done()
.done()
for _,v in ipairs(awardKeys) do
Cell.tag('tr')
.tag('td')
.css('font-weight','bold')
.css('background-color','#f2f2f2')
.wikitext(args[v .. 'Pub'])
.done()
.tag('td')
.css('background-color','#f2f2f2')
.wikitext(args[v])
end
end
local function renderMainTable(providedReviewers, providedAggregators, awardKeys, activeSystems, customAggregatorKeys, customReviewerKeys, args)
local tbl = HtmlBuilder.create('table')
.attr('cellpadding', 0)
.attr('cellspacing', 0)
.addClass(args.state or 'collapsible')
.css('background', 'transparent')
.css('padding', '0em')
.css('margin', '0em 1em 1em 1em')
.css('text-align', 'center')
.css('font-size', '80%')
.css('float', args.align or 'right')
.css('clear', args.align or 'right')
if #activeSystems == 0 then
-- Width: 20% Seems better since it scales with the article size.
tbl
.css('width', args.width or '23em')
end
if args.title and args.state ~= 'plain' and args.state ~= 'off' then
tbl
.addClass('collapsible')
.addClass(args.state)
end
renderTitleRow(tbl, args.state == 'plain', args.title)
if args.subtitle then
tbl
.tag('tr')
.tag('th')
.css('font-size', '120%')
.wikitext(args.subtitle)
end
renderReviews(tbl.tag('tr').tag('td'), providedReviewers, providedAggregators, activeSystems, customAggregatorKeys, customReviewerKeys, args)
if #awardKeys ~= 0 then
renderAwards(tbl.tag('tr').tag('td'), args, awardKeys)
end
return tbl
end
local function getProvidedReviewersAndAggregators(args, usePlatforms)
local providedReviewers, providedAggregators = {}, {}
if usePlatforms then
local seen = {}
for k in pairs(args) do
local splitPos = string.find(k, '_')
if splitPos then
local halfarg = string.sub(k, 1, splitPos - 1)
if not seen[halfarg] then
seen[halfarg] = true
if data.reviewers[halfarg] then
table.insert(providedReviewers, halfarg)
elseif data.aggregators[halfarg] then
table.insert(providedAggregators, halfarg)
end
end
end
end
else
for k in pairs(args) do
if not string.find(k, '_') then
if data.reviewers[k] then
table.insert(providedReviewers, k)
elseif data.aggregators[k] then
table.insert(providedAggregators, k)
end
end
end
end
table.sort(providedReviewers, function(a, b)
return data.reviewers[a].sortkey < data.reviewers[b].sortkey
end)
table.sort(providedAggregators, function(a, b)
return data.aggregators[a].sortkey < data.aggregators[b].sortkey
end)
return providedReviewers, providedAggregators
end
function p._reviewbox(args)
local sortedArgKeys = {}
for k in pairs(args) do
if type(k) == 'string' then
table.insert(sortedArgKeys, k)
end
end
table.sort(sortedArgKeys)
local activeSystems = getActiveSystems(args)
local customReviewerKeys, customAggregatorKeys, awardKeys = getArgKeyTables(sortedArgKeys)
local providedReviewers, providedAggregators = getProvidedReviewersAndAggregators(args, #activeSystems ~= 0)
if #customAggregatorKeys ~= 0 or #customReviewerKeys ~= 0 or #providedAggregators ~= 0 or #providedReviewers ~= 0 or #awardKeys ~= 0 then
return renderMainTable(providedReviewers, providedAggregators, awardKeys, activeSystems, customAggregatorKeys, customReviewerKeys, args)
elseif mw.title.getCurrentTitle().namespace == 0 then
return '[[Category:Empty templates on articles]]'
end
end
function p.reviewbox(frame)
-- ParserFunctions considers the empty string to be false, so to preserve the previous
-- behavior of {{Video game multiple console reviews}}, change any empty arguments to nil, so Lua will consider
-- them false too.
local args = {}
local parent_args = frame:getParent().args;
for k, v in pairs(parent_args) do
if v ~= '' then
args[k] = v
end
end
return p._reviewbox(args)
end
return p