Module:Cooking Effects List: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local util_args = require('Module:Args Utility') local util_cargo = require('Module:Cargo Utility') local util_map = require('Module:Map Utility') local util_html = require('M...") |
mNo edit summary |
||
(10 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
function p.basicEffects(frame) | function p.basicEffects(frame) | ||
return p.main(frame, 'UnitEffects') | return p.main(frame, 'UnitEffects') | ||
end | |||
function p.triggerConditions(frame) | |||
return p.main(frame, 'Triggers') | |||
end | |||
function p.triggeredEffects(frame) | |||
return p.main(frame, 'TriggeredEffects') | |||
end | |||
function p.setcols(type) | |||
if type == 'UnitEffects' then | |||
effectrow = 'Basic Effect' | |||
elseif type == 'Triggers' then | |||
effectrow = 'Trigger Condition' | |||
elseif type == 'TriggeredEffects' then | |||
effectrow = 'Triggered Effect' | |||
else | |||
error('There was no effect type name: ' .. (type or 'nil')) | |||
end | |||
COLUMNS[1] = effectrow | |||
end | end | ||
Line 20: | Line 41: | ||
frame=mw.getCurrentFrame() | frame=mw.getCurrentFrame() | ||
p.setcols(effecttype) | |||
local data = h.makeAndRunQuery(effecttype) | local data = h.makeAndRunQuery(effecttype) | ||
h.formatRows(data, effecttype) | h.formatRows(data, effecttype) | ||
Line 31: | Line 53: | ||
function h.makeQuery(type) | function h.makeQuery(type) | ||
local query = { | local query = { | ||
tables = { 'CookingEffects=CE' }, | tables = { 'CookingEffects=CE', 'CookingEffects__'..type..'=CEID' }, | ||
fields = { | join = {'CE._ID=CEID._rowID'}, | ||
where = 'CE._pageNamespace="0"', | fields = {'CEID._value=Type', 'CONCAT("[[", CE._pageName, "|", PlainName,"]]")=CookingDomain', 'PlainName'}, | ||
orderBy = | where = 'CE._pageNamespace="0" AND CEID._value <> ""', | ||
orderBy = 'PlainName ASC' | |||
} | } | ||
return query | return query | ||
Line 40: | Line 63: | ||
function h.formatRows(data, type) | function h.formatRows(data, type) | ||
util_map.rowsInPlace(data, h.formatOneRow) | util_map.rowsInPlace(data, h.formatOneRow, type) | ||
end | end | ||
function h.formatOneRow(row) | function h.formatOneRow(row, type) | ||
row[ | row[COLUMNS[1]] = row.Type | ||
row['Cooking Domain'] = row.CookingDomain | row['Cooking Domain'] = row.CookingDomain:gsub('-based]]', ']]') | ||
row['Possible Ingredients'] = mw.getCurrentFrame():expandTemplate{ title = 'food that grants', args = { row.PlainName, 'commas' } } | row['Possible Ingredients'] = mw.getCurrentFrame():expandTemplate{ title = 'food that grants', args = { row.PlainName, 'commas' } } | ||
end | end | ||
Line 52: | Line 75: | ||
local output = mw.html.create() | local output = mw.html.create() | ||
local tbl = output:tag('table') | local tbl = output:tag('table') | ||
:addClass(' | :addClass('cargoDynamicTable display dataTable') | ||
:addClass('sortable') | :addClass('sortable') | ||
util_html.printHeader(tbl, COLUMNS) | -- util_html.printHeader(tbl, COLUMNS) | ||
tbl:tag('tr') | |||
:tag('th'):css('width','470px'):wikitext(COLUMNS[1]) | |||
:tag('th'):css('width','130px'):wikitext(COLUMNS[2]) | |||
:tag('th'):wikitext(COLUMNS[3]) | |||
util_html.printRowsByList(tbl, data, COLUMNS) | util_html.printRowsByList(tbl, data, COLUMNS) | ||
return output | return output |
Latest revision as of 00:45, 1 September 2020
local util_args = require('Module:Args Utility')
local util_cargo = require('Module:Cargo Utility')
local util_map = require('Module:Map Utility')
local util_html = require('Module:HTML Utility')
local util_table = require('Module:Table Utility')
local util_text = require('Module:Text Utility')
local favilink = require('Module:Favilink')
local COLUMNS = { 'Unit Effects', 'Cooking Domain', 'Possible Ingredients' }
local h = {}
local p = {}
function p.basicEffects(frame)
return p.main(frame, 'UnitEffects')
end
function p.triggerConditions(frame)
return p.main(frame, 'Triggers')
end
function p.triggeredEffects(frame)
return p.main(frame, 'TriggeredEffects')
end
function p.setcols(type)
if type == 'UnitEffects' then
effectrow = 'Basic Effect'
elseif type == 'Triggers' then
effectrow = 'Trigger Condition'
elseif type == 'TriggeredEffects' then
effectrow = 'Triggered Effect'
else
error('There was no effect type name: ' .. (type or 'nil'))
end
COLUMNS[1] = effectrow
end
function p.main(frame, effecttype)
frame=mw.getCurrentFrame()
p.setcols(effecttype)
local data = h.makeAndRunQuery(effecttype)
h.formatRows(data, effecttype)
return h.makeOutput(data)
end
function h.makeAndRunQuery(args)
return util_cargo.queryAndCast(h.makeQuery(args))
end
function h.makeQuery(type)
local query = {
tables = { 'CookingEffects=CE', 'CookingEffects__'..type..'=CEID' },
join = {'CE._ID=CEID._rowID'},
fields = {'CEID._value=Type', 'CONCAT("[[", CE._pageName, "|", PlainName,"]]")=CookingDomain', 'PlainName'},
where = 'CE._pageNamespace="0" AND CEID._value <> ""',
orderBy = 'PlainName ASC'
}
return query
end
function h.formatRows(data, type)
util_map.rowsInPlace(data, h.formatOneRow, type)
end
function h.formatOneRow(row, type)
row[COLUMNS[1]] = row.Type
row['Cooking Domain'] = row.CookingDomain:gsub('-based]]', ']]')
row['Possible Ingredients'] = mw.getCurrentFrame():expandTemplate{ title = 'food that grants', args = { row.PlainName, 'commas' } }
end
function h.makeOutput(data)
local output = mw.html.create()
local tbl = output:tag('table')
:addClass('cargoDynamicTable display dataTable')
:addClass('sortable')
-- util_html.printHeader(tbl, COLUMNS)
tbl:tag('tr')
:tag('th'):css('width','470px'):wikitext(COLUMNS[1])
:tag('th'):css('width','130px'):wikitext(COLUMNS[2])
:tag('th'):wikitext(COLUMNS[3])
util_html.printRowsByList(tbl, data, COLUMNS)
return output
end
return p