Module:Video game series reviews/sandbox
Appearance
![]() | This is the module sandbox page for Module:Video game series reviews (diff). |
Main module for {{Video game series reviews}}.
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local Vgwd = require('Module:Video game wikidata/sandbox')
local p = {}
local columns = {
['mc'] = nil,
['gr'] = nil,
['fam'] = nil,
['sales'] = nil,
['year'] = nil,
}
local function sortByNumber(a,b)
return a['num'] < b['num']
end;
local function getVGWD(frame, reviewer)
-- Obey local override on displaying this reviewer, don't bother trying to get Wikidata.
if(columns[reviewer] == false) then
return nil;
end;
local vgwdScore = Vgwd.setReviewer(reviewer);
if(vgwdScore ~= nil) then
return vgwdScore;
end;
return Vgwd.printReviewScores(frame);
end;
local function buildGame(num,args)
local game = {}
game['num'] = num;
game['name'] = args["game"..num];
game['qid'] = args["qid"..num];
game['mc'] = args["mc"..num];
game['gr'] = args["gr"..num];
game['fam'] = args["fam"..num];
game['sales'] = args["sales"..num];
game['year'] = args["year"..num];
if(game['qid'] ~= nil) then
local vgwdScore = Vgwd.setGame(game["qid"]);
if(vgwdScore == nil) then
game['updateLink'] = Vgwd.getUpdateLink();
if(game['mc'] == nil) then
game['mc'] = getVGWD(frame, 'mc')
end;
if(game['gr'] == nil) then
game['gr'] = getVGWD(frame, 'gr')
end;
if(game['fam'] == nil) then
game['fam'] = getVGWD(frame, 'fam')
end;
if(game['name'] == nil) then
local sitelink = Vgwd.getSitelink();
local label = Vgwd.getLabel();
if(sitelink ~= label) then
game['name'] = "[[" .. sitelink .. "|" .. label "]]";
else
game['name'] = "[[" .. sitelink .. "]]";
end;
end;
else
-- Entity wasn't found... How to represent? TODO.
end;
end;
checkColumn(game, 'mc');
checkColumn(game, 'gr');
checkColumn(game, 'fam');
checkColumn(game, 'year');
checkColumn(game, 'sales');
return game;
end;
local function checkColumn(game, column)
if(game[column] ~= nil and columns[column] ~= false) then
columns[column] = true;
end;
end;
function p.main(frame)
local args = getArgs(frame)
return p._main(frame, args)
end
function p._main(frame, args)
-- Get specified values of column display parameters. Nil = Unspecified.
if(args["mc"]) then
columns['mc'] = yesno(args.mc);
end
if(args["gr"]) then
columns['gr'] = yesno(args.gr);
end
if(args["fam"]) then
columns['fam'] = yesno(args.fam);
end
if(args["sales"]) then
columns['sales'] = yesno(args.sales);
end
if(args["years"]) then
columns['year'] = yesno(args.years);
end
Vgwd.setDateFormat(args["df"]);
Vgwd.setSystem(nil);
Vgwd.setGenerateReferences(true);
Vgwd.setShowSystem(true);
Vgwd.setShowUpdateLink(false);
local games = {};
local gameRead = {};
for k, v in pairs(args) do
if(string.find(k, "game%d+") or string.find(k, "qid%d+")) then
local num = tonumber(string.match(k, "%d+"))
if(num ~= nil) then
if(gameRead[num] == nil) then
gameRead[num] = true;
table.insert(games, buildGame(num,args));
end;
end;
end;
end;
-- So after all that, we didn't find any games to output? Let's try another route.
if(#games < 1) then
-- Reset vgwd to current page, presumably a series.
local vgwdScore = Vgwd.setGame();
if(vgwdScore == nil) then
local parts = Vgwd.getParts();
for i,part in pairs(parts) do
table.insert(games, buildGame(i,args));
end;
else
-- Entity wasn't found... How to represent? TODO.
end;
end;
table.sort(games, sortByNumber)
local ret = "{| class=\"wikitable plainrowheaders\" style=\"font-size: 90%; float: right; clear: right; margin:0.5em 0 0.5em 1em;\"\n"
ret = ret .."|+ style=\"font-size: 111.11%;\" | "
if args.title then
ret = ret .. args.title
elseif columns['sales'] then
if columns['fam'] then
ret = ret .. "Sales and review scores"
elseif columns['gr'] or columns['mc'] then
ret = ret .. "Sales and aggregate review scores"
else
ret = ret .. "Sales"
end
elseif columns['fam'] then
if columns['gr'] or columns['mc'] then
ret = ret .. "Japan and Western review scores"
else
ret = ret .. "Famitsu review scores"
end
else
ret = ret .. "Aggregate review scores"
end
if args.updated then
ret = ret .. "<br /><small>''As of " .. args.updated ..".''</small>"
end
ret = ret .. " \n"
ret = ret .. "! scope=\"col\" | Game \n"
if columns['year'] then
ret = ret .. "! scope=\"col\" | Year\n"
end
if columns['sales'] then
ret = ret .. "! scope=\"col\" | " .. (args.sales_title or "Units sold") .. " \n"
end
if columns['fam'] then
ret = ret .. "! scope=\"col\" | " .. (args.fam_title or "''[[Famitsu scores|Famitsu]]''") .. " \n"
end
if columns['gr'] then
ret = ret .. "! scope=\"col\" | " .. (args.gr_title or "[[GameRankings]]") .. " \n"
end
if columns['mc'] then
ret = ret .. "! scope=\"col\" | " .. (args.mc_title or "[[Metacritic]]") .. " \n"
end
-- Print the reviews
for i,game in ipairs(games) do
ret = ret .. "|-\n"
ret = ret .. "! scope=\"row\" | ''" .. game['name']
if(game['updateLink']) then
ret = ret .. " " .. game['updateLink'];
end;
ret = ret .. "'' \n"
if columns['year'] then
ret = ret .. "| style=\"text-align: center;\" | " .. (game['year'] or '') .. " \n"
end
if columns['sales'] then
ret = ret .. "| style=\"text-align: center;\" | " .. (game['sales'] or '') .. " \n"
end
if columns['fam'] then
ret = ret .. "| style=\"text-align: center;\" | " .. (game['fam'] or '') .. " \n"
end
if columns['gr'] then
ret = ret .. "| style=\"text-align: center;\" | " .. (game['gr'] or '') .. " \n"
end
if columns['mc'] then
ret = ret .. "| style=\"text-align: center;\" | " .. (game['mc'] or '') .. " \n"
end
end;
ret = ret .. "|}"
return ret
end
return p