Module:Video game reviews/sandbox: Difference between revisions

Content deleted Content added
Jackmcbarn (talk | contribs)
make the functions more useful
Jackmcbarn (talk | contribs)
rm unhelpful comments
Line 8:
--
 
--
-- This module will implement {{Video game multiple console reviews}}
--
local p = {}
 
Line 17 ⟶ 14:
local aggregator = {{'[[GameRankings]]','GR'}, {'[[Metacritic]]','MC'}}
 
-- 2 arrays with the title and code of each predefined "system type" field to be used.
local system = {{'[[Atari 2600]]','A2600'}, {'[[ColecoVision]]','CV'}, {'[[Nintendo DS|DS]]','DS'}, {'[[Game Boy]]','GB'}, {'[[Game Boy Advance|GBA]]','GBA'}, {'[[Game Boy Color|GBC]]','GBC'}, {'[[List of video game consoles|General]]', 'GEN'}, {'[[iOS]]','iOS'}, {'[[N-Gage (device)|N-Gage]]','N-G'}, {'[[Nintendo 64|N64]]','N64'}, {'[[Nintendo Entertainment System|NES]]','NES'}, {'[[GameCube|GC]]','NGC'}, {'[[Nvidia Shield|Shield]]','NSHI'}, {'[[Personal Computer|PC]]','PC'}, {'[[PlayStation|PS]]','PS'}, {'[[PlayStation 2|PS2]]','PS2'}, {'[[PlayStation 3|PS3]]','PS3'}, {'[[PlayStation 4|PS4]]','PS4'}, {'[[PlayStation Portable|PSP]]','PSP'}, {'[[Dreamcast]]','SDC'}, {'[[Sega Game Gear|SGG]]','SGG'}, {'[[Super Nintendo Entertainment System|SNES]]','SNES'}, {'[[Sega Genesis|Mega Drive]]','SMD'}, {'[[Master System]]','SMS'}, {'[[Sega Saturn|Saturn]]','SSAT'}, {'[[TurboGrafx-16]]','TG16'}, {'[[PlayStation Vita]]','VITA'}, {'[[Xbox]]','XBOX'}, {'[[Xbox 360]]','X360'}, {'[[Xbox One]]','XONE'}, {'[[Wii]]','WII'}}
 
local data = mw.loadData('Module:Video game reviews/data')
 
-- Require necessary modules.
local HtmlBuilder = require('Module:HtmlBuilder')
local categoryHandler = require('Module:Category handler').main
 
-- Set aliases for often-used functions to reduce table lookups.
local args
local frame
Line 37 ⟶ 31:
local awardnums = {}
 
--
-- Splits a string on a delimiter n number of times.
--
function Split(str, delim)
if string.find(str, delim) == nil then
Line 68 ⟶ 59:
end
 
--
-- Returns the count of how many custom aggregators and reviewers are active.
--
function getActiveCustomAggregatorsAndReviewers(args)
local aggregators, reviewers = {}, {}
Line 83 ⟶ 71:
end
 
--
-- Title row
--
function renderTitleRow(tbl)
local titleCell = tbl.tag('tr').tag('th').css('font-size', '120%')
Line 117 ⟶ 102:
end
 
--
-- Insert reviews
--
function reviews()
local arg_system
Line 432 ⟶ 414:
end
 
--
-- Inserts a award into the table output.
--
function award(tbl, awardnum)
local temp = tbl.tag('tr')
Line 449 ⟶ 428:
end
 
--
-- Insert awards header and calls award row creation.
--
function awards()
if args['award1'] then
Line 483 ⟶ 459:
end
end
 
--
-- Main tables
--
 
function renderMainTable()
Line 552 ⟶ 524:
main = '[[Category:Empty templates on articles]]'
}
category = category or '' -- Check that we don't have a nil value for the category variable.
tbl = HtmlBuilder.create()
tbl.wikitext(category)
Line 559 ⟶ 531:
end
 
--
-- Creates the table and calls functions that create the reviews and awards tables/columns/rows.
--
function p._reviewbox(reviewBoxArgs)
local t = {}
Line 568 ⟶ 537:
local halfargs = {}
local j = 1
-- calls for the args.
args = reviewBoxArgs
local activeSystems = getActiveSystems(args)
Line 642 ⟶ 610:
if awardnums then table.sort(awardnums) end
 
-- render the main body of the Review Box
local tbl = renderMainTable()
 
Line 653 ⟶ 620:
end
 
--
-- Main: frame function.
--
function p.reviewbox(frame)
-- ParserFunctions considers the empty string to be false, so to preserve the previous