Module:ProfessionList: Difference between revisions
(Created page with "local currency = require('Module:Currency') local p = {} -- this module provides functions that are commonly used among all of the modules to greate tables of profession activities -- such as AlchemistList, DetectivePassiveList, BlacksmithSmeltingList, and so on -- creates the html directly for a currency cell of a table -- will always be 10 cells wide, for currency alignment -- if not supplied with an amount, displays "unknown" -- use within :node() function p.curren...") |
No edit summary |
||
Line 24: | Line 24: | ||
-- creates the html for an unknown value cell |
-- creates the html for an unknown value cell |
||
-- use within :node() |
-- use within :node() |
||
function p.unknown_value_cell() |
function p.unknown_value_cell(N) |
||
return mw.html.create('td') |
return mw.html.create('td') |
||
:addClass('table-bg-gray') |
:addClass('table-bg-gray') |
||
:css{ ['text-align'] = 'center' } |
:css{ ['text-align'] = 'center' } |
||
:attr{ colspan = tostring(N) } |
|||
:wikitext("''unknown''") |
:wikitext("''unknown''") |
||
:done() |
:done() |
||
Line 33: | Line 34: | ||
-- creates the html for an unknown value cell, with a link to edit the page that has the unknown parameter |
-- creates the html for an unknown value cell, with a link to edit the page that has the unknown parameter |
||
-- NOT YET FUNCTIONAL |
|||
-- use within :node() |
-- use within :node() |
||
function p. |
function p.unknown_value_edit_cell(page,N) |
||
local url = tostring(mw.uri.fullUrl(page,'action=edit')) |
|||
return mw.html.create('td') |
return mw.html.create('td') |
||
:addClass('table-bg-gray') |
:addClass('table-bg-gray') |
||
:css{ ['text-align'] = 'center' } |
:css{ ['text-align'] = 'center' } |
||
:attr{ colspan = tostring(N) } |
|||
:wikitext("''unknown''") |
:wikitext('['..url.." ''unknown'' (edit)]") |
||
:done() |
:done() |
||
end |
end |
||
Line 51: | Line 53: | ||
local query = { |
local query = { |
||
queryString, |
queryString, |
||
'? #- = |
'? #- = pageName', |
||
'?Image #- = pageImage', |
'?Image #- = pageImage', |
||
'?Activity JSON = activityJSON', |
'?Activity JSON = activityJSON', |
||
Line 63: | Line 65: | ||
return nil |
return nil |
||
end |
end |
||
-- output structure |
-- output structure |
||
local output = {} |
local output = {} |
||
Line 77: | Line 79: | ||
else |
else |
||
for _, json in page.activityJSON do |
for _, json in page.activityJSON do |
||
json.type = 'activity' |
|||
table.insert(JSONs,json) |
table.insert(JSONs,json) |
||
end |
end |
||
Line 85: | Line 88: | ||
table.insert(JSONs,page.recipeJSON) |
table.insert(JSONs,page.recipeJSON) |
||
else |
else |
||
for _, json in page. |
for _, json in page.recipeJSON do |
||
json.type = 'recipe' |
|||
table.insert(JSONs,json) |
table.insert(JSONs,json) |
||
end |
end |
||
Line 97: | Line 101: | ||
--decode the JSON to a Lua table, add data from the page that had it |
--decode the JSON to a Lua table, add data from the page that had it |
||
local item = mw.text.jsonDecode(JSON) |
local item = mw.text.jsonDecode(JSON) |
||
item.page = page. |
item.page = page.pageName |
||
item.pageImage = page.pageImage |
item.pageImage = page.pageImage |
||
--insert into output table |
--insert into output table |
||
table.insert(output, |
table.insert(output,item) |
||
end |
end |
||
end |
end |
||
end |
end |
||
return output |
return output |
||
Revision as of 22:24, 18 December 2024
This module is a helper module to be used by other modules; it may not designed to be invoked directly. See Brighter Shores:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here
Function | Type | Use |
---|---|---|
currency_cell(amount) | amount : number, or nil | Returns the HTML to create a table currency cell using module:currency._cell .If instead it is supplied with nil then a 10x1 cell is created with the text "unknown". |
unknown_value_cell(size) | size : integer | Returns the HTML to create a size x1 cell with the text "unknown".Use within :node() |
unknown_value_edit_cell(page,size) | page : string, name of pagesize : integer | Returns the HTML to create a size x1 cell with a link to edit the specified page.Use within :node() |
generate_recipe_table(queryString) | queryString : string, SMW queryscreenFunction : function, table > boolean | Generates a table of recipes and activities from a Semantic MediaWiki query string and a screening function.
Module:RecipeTreeSearch |
one_column_image_text(sort,materials) | sort : string, to sort the multicolumn cell bymaterials : table, each entry is a name/quantity pair for an item to display | Produces 1 cells with multiple lines of text in a standard format to display a list of materials for a recipe. Includes the quantity of each material. |
two_column_image_text(sort,image,text,link) | sort : string, to sort the multicolumn cell by
link : string, page to link the image and text to | Produces 2 cells in a standard format to display an image and some text, which link to the same page. For example: the image and name of a skill node, but linking to the item they make. |
three_column_image_text(sort,quantity,image,text,link) | sort : string, to sort the multicolumn cell by
link : string, page to link the image and text to | Produces 3 cells in a standard format to display a quantity, an image, and some text, which link to the same page. For example: the quantity, image, and name of a recipe product. |
local currency = require('Module:Currency')
local p = {}
-- this module provides functions that are commonly used among all of the modules to greate tables of profession activities
-- such as AlchemistList, DetectivePassiveList, BlacksmithSmeltingList, and so on
-- creates the html directly for a currency cell of a table
-- will always be 10 cells wide, for currency alignment
-- if not supplied with an amount, displays "unknown"
-- use within :node()
function p.currency_cell(amount)
if not amount then
return mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:attr{ colspan = '10' }
:wikitext("''unknown''")
:done()
end
return currency._cell(amount, { html = 'yes' })
end
-- creates the html for an unknown value cell
-- use within :node()
function p.unknown_value_cell(N)
return mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:attr{ colspan = tostring(N) }
:wikitext("''unknown''")
:done()
end
-- creates the html for an unknown value cell, with a link to edit the page that has the unknown parameter
-- use within :node()
function p.unknown_value_edit_cell(page,N)
local url = tostring(mw.uri.fullUrl(page,'action=edit'))
return mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:attr{ colspan = tostring(N) }
:wikitext('['..url.." ''unknown'' (edit)]")
:done()
end
-- generates a table of recipes and activities from a Semantic MediaWiki query string
-- the queryString is just a selection of pages, from any combination of SMW properties and categories
-- for pages with multiple recipes or activities, will make on entry into the results table for each
function p.generate_recipe_table(queryString)
-- first formulate the query to get the list of pages
local query = {
queryString,
'? #- = pageName',
'?Image #- = pageImage',
'?Activity JSON = activityJSON',
'?Recipe JSON = recipeJSON',
'limit = 500'
}
local pages = mw.smw.ask(query)
-- if no pages were found, skip the rest of this function
if pages == nil then
return nil
end
-- output structure
local output = {}
-- iterate through pages found
for _, page in ipairs(pages) do
-- combine the activityJSON and recipeJSON into one table
local JSONs = {}
if page.activityJSON ~= nil then
if type(page.activityJSON)=='string' then
table.insert(JSONs,page.activityJSON)
else
for _, json in page.activityJSON do
json.type = 'activity'
table.insert(JSONs,json)
end
end
end
if page.recipeJSON ~= nil then
if type(page.recipeJSON)=='string' then
table.insert(JSONs,page.recipeJSON)
else
for _, json in page.recipeJSON do
json.type = 'recipe'
table.insert(JSONs,json)
end
end
end
-- iterate through combined list of JSONs and extract the info
if JSONs[1] ~= nil then
for _, JSON in ipairs(JSONs) do
--decode the JSON to a Lua table, add data from the page that had it
local item = mw.text.jsonDecode(JSON)
item.page = page.pageName
item.pageImage = page.pageImage
--insert into output table
table.insert(output,item)
end
end
end
return output
end
return p