Module:VgData/sandbox
| This is the module sandbox page for Module:VgData (diff). |
This module creates a set of tables useful for video game List pages. The module pulls data from accompanying data pages, and then outputs a table containing the specified parameters and terms.
Usage
The module takes up to 4 named Parameters, and uses those to determine the type of table you're looking to make. it then uses any provided Terms to fill that table with the appropriate information.
Terms must be defined on the appropriate template page, and must have the exact spelling, capitalization, and punctuation as on the template page, or else the table will provide an "undefined parameter" message. Terms must be given in alphabetical order, in order to display correctly
Example
For example, the code {{#invoke:VgData|main|ct=platform|col=3|DC|DS|GBA|GBC|Wii}} will output the Platform variant of the table in 3 column-pairs with the specified platforms, as seen below:
| DC | Dreamcast | DS | Nintendo DS, DSiWare, iQue DS | GBA | Game Boy Advance, iQue GBA |
| GBC | Game Boy Color | Wii | Wii, WiiWare, Wii Virtual Console |
Parameters
The following Parameters are supported within the module:
ct: This is used to select the type of table you want to create. This element is required for the table to generate. The following table types are supported:platform: This element creates a table of video game platformsgenre: This element creates a table of video game genres and their related subgenres
all: This optional element can be used with any table type. If set totrue, the table will output every element listed on the specific data page for that table type.ver: This element is only used in conjunction with thegenretable, and is used to select the version of the video game genre table you're building. The following versions are currently supported:none: Ifveris left off, or you usever=none, then the table will generate with no genre preset. In this case, you can add any supported sub-genre, and the module will output a custom table for your needsRPG: This version sets the table to pull elements from the RPG genre dataset. In conjunction withall, this will output the default RPG tableStrategy: This version sets the table to pull elements from the Strategy genre dataset. In conjunction withall, this will output the default Strategy table
col: This sets the number of column-pairs you want the table to use (setting this number to 2 will create a 4 column table). If not included, this value defaults to 3 for all table types
Terms
In addition to parameters, each table type has specific terms that can be input. Each of these elements are listed on the specific template page for that chart type. For a list of all the terms, see one of the following related Template pages:
- For the
platformtable type, see Template:VgPlatforms - For the
genretable type, see Template:VgGenres
require('strict')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- pull arguments from Invoke and process them appropriately
function p.main(frame)
local args = getArgs(frame)
args.ct = tostring(frame.args["ct"])
args.all = not(not(frame.args["all"]))
args.col = frame.args["col"] or 3
args.ver = tostring(frame.args["ver"]) or "none"
local page
local caption
if args.ct == "platform" then
page = "VgPlatforms"
caption = "Video game platforms"
elseif args.ct == "genre" then
page = "VgGenres"
caption = "Video game genres"
elseif args.ct == "release" then
page = "VgRelease"
caption = "Types of releases"
args.col = 1
else
return "Table type not found"
end
local max = 0
for i, j in ipairs(args) do
max = max + 1
end
return p.import(args, page, caption, max)
end
-- get the specific table block, and iterate each row (lines starting with |)
function p.import(args, page, caption, max)
local content = mw.title.makeTitle( 'Template', page ):getContent()
local twiki
if args.ct == "genre" then
if args.ver == nil or args.ver == "none" then
twiki = content:match("<%!%-%- " .. args.ct .. "%-%->(.-)<%!%-%- /" .. args.ct .. "%-%->")
else
twiki = content:match("<%!%-%- " .. args.ver .. "%-%->(.-)<%!%-%- /" .. args.ver .. "%-%->")
end
else
twiki = content:match("<%!%-%- " .. args.ct .. "%-%->(.-)<%!%-%- /" .. args.ct .. "%-%->")
end
if args.all == true then
args = {}
end
local input = {}
for row in twiki:gmatch("%|(.-)\n") do
local cells = {}
local temp = row:gsub("|", "\t", 1) -- split on cell separators (converts first "|" to \t and splits on that)
for cell in temp:gmatch("[^\t]+") do
table.insert(cells, mw.text.trim(cell))
end
if args.all == true then
table.insert(args, cells[1])
max = max + 1
end
input[cells[1]] = cells[2]
end
return p.out(args, caption, max, input)
end
-- filter input data based on args and create a new table
function p.out(args, caption, max, input)
local output = '<table class="wikitable" style="width: 100%; background-color: #ffffff; font-size: 85%;"><caption>' .. caption .. '</caption>'
local coloutput = ""
local key = 1
while key <= max do
coloutput = "<tr>"
for l = 1, args.col do
if key <= max then
if input[args[key]] == nil then
coloutput = coloutput .. '<td style="background-color: #e3e3e3;"><b>' .. args[key] .. '</b></td><td>' .. 'Term not found' .. '</td>'
else
coloutput = coloutput .. '<td style="background-color: #e3e3e3;"><b>' .. args[key] .. '</b></td><td>' .. input[args[key]] .. '</td>'
end
else
coloutput = coloutput .. '<td style="background-color: #e3e3e3;"></td><td></td>'
end
key = key + 1
end
output = output .. coloutput .. "</tr>"
end
output = output .. "</table>"
return output
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.