モジュール:サンドボックス/Zerabat/コンピュータゲームレビュー

--
-- 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
--
--
-- This module will implement 
--
local p = {}
local reviewer = 
local aggregator = 
-- 2 arrays with the title and code of each predefined "system type" field to be used.
local system = 
-- 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
local keys
local halfkeysrev
local halfkeysagg
local platforms
local custome_agg
local custome_rev
local awardnums = {}
--
-- Splits a string on a delimiter n number of times.
--
function Split(str, delim, maxNb)
if string.find(str, delim) == nil then
return { str }
end
if maxNb == nil or maxNb  0 or #halfkeysagg > 0) and platforms >= 1 then
	     tbl2 = HtmlBuilder.create('table')
.addClass('infobox wikitable')
.attr('cellpadding', 0)
.attr('cellspacing', 0)
.css('width', '100%')
.css('border-bottom', 'none')
.css('margin', '0em')
.done()
elseif (#halfkeysrev > 0 or #halfkeysagg > 0 or custome_agg > 0 or custome_rev > 0) and  platforms == 0 then
tbl2 = HtmlBuilder.create('table')
.addClass('infobox wikitable')
.attr('cellpadding', 0)
.attr('cellspacing', 0)
.css('width', '100%')
.css('font-size', '100%')
.css('border-bottom', 'none')
.css('margin', '0em')
.done()
end
if #halfkeysrev > 0 and (platforms > 1 or string.lower(tostring(args'showplatforms')) == 'true') then
tbl2.tag('tr').tag('th')
.attr('colspan', #system + 1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
.done()
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', #system)
.css('background', '#e8f4f8')
.css('vertical-align', 'middle')
.wikitext('Score')
.done()
local forloop = tbl2.tag('tr')
for j = 1, #system do
if string.lower(tostring(argstostring(systemj2))) == 'true' then
forloop.tag('th').wikitext(tostring(systemj1))
end
end
elseif #halfkeysrev > 0 and platforms == 1 and string.lower(tostring(args'showplatforms')) ~= 'true' then
tbl2.tag('tr').tag('th')
.attr('colspan', '2')
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
.done()
	    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')
.done()
end
if platforms >= 1 then
for i = 1, #reviewer do
for k = 1, #halfkeysrev do
if revieweri2 == halfkeysrevk then
local forloop = tbl2.tag('tr')
forloop.tag('td')
.css('vertical-align','middle')
.wikitext(revieweri1)
.done()
for j = 1, #system do
local temp = tostring(revieweri2) .. '_' .. tostring(systemj2)
if string.lower(tostring(argstostring(systemj2))) == 'true' and argstemp ~= nil then
forloop.tag('td')
.css('vertical-align', 'middle')
.wikitext(tostring(argstemp))
elseif string.lower(tostring(argstostring(systemj2))) == 'true' and 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')
.done()
elseif string.lower(tostring(argstostring(systemj2))) == 'true' then
forloop.tag('td').done()
end
end
end
end
end
for i = 1, 10 do
if args'rev' .. tostring(i) ~= nil then
local forloop = tbl2.tag('tr')
forloop.tag('td').wikitext(tostring(args'rev' .. tostring(i)))
for j = 1, #system do
				    local temp = 'rev'.. tostring(i) .. '_' .. tostring(systemj2)
if string.lower(tostring(argstostring(systemj2))) == 'true' and argstemp ~= nil then
	                    forloop.tag('td')
.css('vertical-align','middle')
.wikitext(tostring(argstemp))
.done()
elseif string.lower(tostring(argstostring(systemj2))) == 'true' and 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')
.done()
elseif string.lower(tostring(argstostring(systemj2))) == 'true' then
forloop.tag('td').done()
end
end
end
end
if (#halfkeysagg > 0 and platforms > 1) and #halfkeysrev == 0 then
tbl2
.tag('tr')
.tag('th')
.attr('colspan', #system+1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Aggregate scores')
.done()
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', #system+1)
.css('background', '#e8f4f8')
.css('vertical-align', 'middle')
.wikitext('Score')
.done()
local forloop = tbl2.tag('tr')
for j = 1, #system do
if string.lower(tostring(argstostring(systemj2))) == 'true' then
forloop.tag('th').wikitext(tostring(systemj1))
end
end
elseif (#halfkeysagg > 0 and #halfkeysrev > 0) or (#halfkeysagg > 0 and platforms == 1)then
tbl2
.tag('tr')
.tag('th')
.attr('colspan', #system+1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Aggregate scores')
.done()
end
for i = 1, #aggregator do
for k = 1, #halfkeysagg do
if aggregatori2 == halfkeysaggk then
local forloop = tbl2.tag('tr')
forloop.tag('td')
.css('vertical-align','middle')
.wikitext(aggregatori1)
.done()
for j = 1, #system do
local temp = tostring(aggregatori2) .. '_' .. tostring(systemj2)
if string.lower(tostring(argstostring(systemj2))) == 'true' and argstemp ~= nil then
forloop.tag('td').wikitext(tostring(argstemp))
elseif string.lower(tostring(argstostring(systemj2))) == 'true' and 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')
.done()
elseif string.lower(tostring(argstostring(systemj2))) == 'true' then
forloop.tag('td').done()
end
end
end
end
end
	elseif platforms == 0 then
if #halfkeysagg > 0 or custome_agg > 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')
.done()
end
for i = 1, #aggregator do
for k = 1, #halfkeysagg do
if aggregatori2 == halfkeysaggk then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(aggregatori1)
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(argstostring(aggregatori2)))
.done()
end
end
end
for i = 1, 10 do
if args'agg' .. tostring(i) ~= nil then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(tostring(args'agg' .. tostring(i)))
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(args'agg'.. tostring(i) .. 'Score'))
.done()
end
end
if #halfkeysrev > 0 or custome_rev > 0 then
tbl2.tag('tr').tag('th')
.attr('colspan', #system + 1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
.done()
tbl2
.tag('tr')
.tag('th')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.wikitext('Publication')
.done()
.tag('th')
.attr('colspan', '25')
.css('background', '#e8f4f8')
.wikitext('Score')
.done()
for i = 1, #reviewer do
for k = 1, #halfkeysrev do
if revieweri2 == halfkeysrevk then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(revieweri1)
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(argstostring(revieweri2)))
.done()
end
end
end
for i = 1, 10 do
if args'rev' .. tostring(i) ~= nil then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(tostring(args'rev' .. tostring(i)))
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(args'rev'.. tostring(i) .. 'Score'))
.done()
end
end
end
	end
return tbl2
end
--
-- Inserts a award into the table output.
--
function award(tbl, awardnum)
local temp = tbl.tag('tr')
.tag('td')
.css('font-weight','bold')
.css('background-color','#f2f2f2')
.wikitext(args'award' .. awardnum .. 'Pub')
.done()
.tag('td')
.css('background-color','#f2f2f2')
.wikitext(args'award' .. awardnum)
.done()
return temp
end
--
-- Insert awards header and calls award row creation.
--
function awards()
if args'award1' then
local Cell = HtmlBuilder.create('table')
.addClass('infobox wikitable')
.css('width', '100%')
.css('margin', '0em')
.css('border-top', 'none')
.attr('cellpadding', 3)
.attr('cellspacing', 0)
Cell
.tag('tr')
.tag('th')
.attr('colspan', 2)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.css('border-top', 'none')
.wikitext('Awards')
.done()
Cell
.tag('tr')
.tag('th').wikitext('Publication')
.tag('th').wikitext('Award')
for i, awardnum in ipairs(awardnums) do
local awardRow = award(Cell, awardnum)
awardRow
.done()
end
return Cell
end
end
--
-- Main tables
--
function renderMainTable()
local tbl
if args'award1' or ((#halfkeysagg > 0 or #halfkeysrev > 0 or custome_agg > 0 or custome_rev > 0) and platforms >= 0) then
if platforms == 0 then
-- Width: 20% Seems better since it scales with the article size.
tbl = HtmlBuilder.create('table')
.attr('cellpadding', 0)
.attr('cellspacing', 0)
.css('background', 'transparent')
.css('padding', '0em')
.css('margin', '0em 1em 1em 1em')
.css('text-align', 'center')
.css('font-size', '80%')
if args.width then
tbl
.css('width',args.width)
else
tbl
.css('width', '23em')
end
else
tbl = HtmlBuilder.create('table')
.attr('cellpadding', 0)
.attr('cellspacing', 0)
.css('background', 'transparent')
.css('padding', '0em')
.css('margin', '0em 1em 1em 1em')
.css('text-align', 'center')
.css('font-size', '80%')
end
if args.state then
tbl
.addClass(args.state)
else
tbl
.addClass('collapsible')
end
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
tbl
.addClass('collapsible')
.addClass(args.state)
end
		tbl.css('float', args.align or 'right').css('clear', args.align or 'right')
renderTitleRow(tbl)
tbl
.tag('tr')
.tag('td')
.node(reviews())
.done()
tbl
.tag('tr')
.tag('td')
.node(awards())
.done()
else
category = categoryHandler{
main = 
}
category = category or  -- Check that we don't have a nil value for the category variable.
tbl = HtmlBuilder.create()
		tbl.wikitext(category)
end
return tbl
end
--
-- Creates the table and calls functions that create the reviews and awards tables/columns/rows.
--
function p._reviewbox(reviewBoxArgs)
local t = {}
local flags = {}
local nitem = {}
local halfargs = {}
local j = 1
-- calls for the args.
args = reviewBoxArgs
platforms = platforms()
custome_rev = custome_rev()
custome_agg = custome_agg()
-- sorts args by string.
for k in pairsByKeys(args) do
table.insert(t, k)
end
keys = t
-- creates a table of all unique reviewers.
for i=1,#keys do
if string.find(tostring(keysi), '_') ~= nil and platforms >= 1 then
halfargs = Split(tostring(keysi),'_')
for k=1, #reviewer do
if reviewerk2 == halfargs1 then
if not flagshalfargs1 then
flagshalfargs1 = true
nitemj = halfargs1
j = j + 1
end
end
end
elseif string.find(tostring(keysi), '_') == nil and platforms == 0 then
for k=1, #reviewer do
if reviewerk2 == keysi then
nitemj = keysi
j = j + 1
end
end
end
end
halfkeysrev = nitem
local flags = {}
local nitem = {}
local halfargs = {}
local j = 1
-- creates a table of all unique aggregators.
for i=1,#keys do
if string.find(tostring(keysi), '_') ~= nil and platforms >= 1 then
halfargs = Split(tostring(keysi),'_')
for k=1, #aggregator do
if aggregatork2 == halfargs1 then
if not flagshalfargs1 then
flagshalfargs1 = true
nitemj = halfargs1
j = j + 1
end
end
end
elseif string.find(tostring(keysi), '_') == nil and platforms == 0 then
for k=1, #aggregator do
if aggregatork2 == keysi then
nitemj = keysi
j = j + 1
end
end
end
end
halfkeysagg = nitem
-- sorts awards by number from args.
for k, v in pairs(args) do
local awardnum = ( .. k):match('^award(%d+)$')
if awardnum then table.insert(awardnums, tonumber(awardnum)) end
end
if awardnums then table.sort(awardnums) end
-- render the main body of the Review Box
local tbl = renderMainTable()
-- render the appropriate wrapper around the Review Box, depending on the border param
local res = HtmlBuilder.create()
res.node(tbl)
return tostring(res)
end
--
-- Main: frame function.
--
function p.reviewbox(frame)
-- ParserFunctions considers the empty string to be false, so to preserve the previous
-- behavior of , 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
argsk = v
end
end
return p._reviewbox(args)
end
return p