Home
Random
Log in
Settings
About Brighter Shores Wiki
Disclaimers
Search
Editing
Module:ProfessionList
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local currency = require('Module:Currency') local search = require('Module:RecipeTreeSearch') 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.." '''?''' (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 -- screenFunction takes a decoded recipe/activity JSON and returns true if it is to be kept function p.generate_recipe_table(queryString,screenFunction) -- 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 -- collate structure local recipes = {} -- iterate through pages found for _, page in ipairs(pages) do -- first iterate through activities if page.activityJSON ~= nil then if type(page.activityJSON)=='string' then page.activityJSON = { page.activityJSON } end for _, JSON in ipairs(page.activityJSON) do local item = mw.text.jsonDecode(JSON) item.pageName = page.pageName item.pageImage = page.pageImage item.type = 'activity' table.insert(recipes,item) end end -- same iteration through recipes if page.recipeJSON ~= nil then if type(page.recipeJSON)=='string' then page.recipeJSON = { page.recipeJSON } end for _, JSON in ipairs(page.recipeJSON) do local item = mw.text.jsonDecode(JSON) item.pageName = page.pageName item.pageImage = page.pageImage item.type = 'recipe' table.insert(recipes,item) end end end -- if none of the pages had recipes of activities, skip the rest of this function if recipes == nil or recipes[1] == nil then return nil end -- output structure local output = {} -- screen using screenFunction for _, item in ipairs(recipes) do if screenFunction(item) then table.insert(output,item) end end -- if all of the results were screened, skip the rest of this function if output == nil or output[1] == nil then return nil end -- sort the output by the .level parameter table.sort(output, function(item1, item2) -- if one of the two has no leve if (item1.level == nil) ~= (item2.level == nil) then -- true if lvl2 is nil but not lvl1, false if lvl1 is nil but not lvl2 return item2.level == nil end if item1.level == nil then -- if both are empty, treat as equivalent return false end -- normal comparison return item1.level < item2.level end) -- perform a number of useful calculations on the data that are widely useful -- like cost of materials, profit of products, recipe tree search for _,item in ipairs(output) do item.product = item.output[1].name or '' -- perform the full recipe tree search on the product local fullRecipe = search.main(item.product) -- overwrite any parameters from the original recipe with their counterparts from the full recipe -- when product is nil, no data is overwritten for key,value in pairs(fullRecipe) do item[key] = value end -- include the price of selling the product item.sellPrice = search.getShopSellPrice(item.product) item.profit = item.buyPrice and item.sellPrice and item.sellPrice - item.buyPrice item.profitPerXP = item.profit and item.xp and item.profit / item.xp end return output end function p.one_column_image_text(sort,materials) local materialCell = mw.html.create('td') for _, mat in ipairs(item.materials) do materialCell:wikitext(mat.quantity .. ' × [[File:' .. mat.name .. '.png|18px|link=' .. mat.name .. ']] [[' .. mat.name .. ']]<br>') end return materialCell end function p.two_column_image_text(sort,image,text,link) return mw.html.create('td') :css{ ['border-right'] = '0', ['text-align'] = 'right', ['max-width'] = '100px' } :attr{ ['data-sort-value'] = sort } :wikitext(' [[' .. image .. '|link=' .. link .. '|30x30px]]') :done() :tag('td') :addClass('plinkt-link no-border') :wikitext('[[' .. link .. '|' .. text ..']]') :done() end function p.three_column_image_text(sort,quantity,image,text,link) return mw.html.create('td') :css{ ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' } :attr{ ['data-sort-value'] = sort } :wikitext(quantity .. ' ×') :done() :tag('td') :addClass('plinkt-image no-border') :css{ ['border-left'] = '0', ['padding-left'] = '0' } :wikitext('[[' .. image .. '|link=' .. link .. '|30px]]') :done() :tag('td') :addClass('plinkt-link no-border') :wikitext('[[' .. link .. '|' .. text .. ']]') :done() end return p
Summary:
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see
Brighter Shores:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Templates used on this page:
Template:Documentation
(
edit
)
Template:Extension DPL
(
edit
)
Template:Helper module
(
edit
)
Module:Array
(
edit
)
Module:Currency
(
edit
)
Module:DPLlua
(
edit
)
Module:DependencyList
(
edit
)
Module:Documentation
(
edit
)
Module:Helper module
(
edit
)
Module:Mw.html extension
(
edit
)
Module:Paramtest
(
edit
)
Module:ProfessionList
(
edit
)
Module:ProfessionList/doc
(
edit
)
Module:Tooltip
(
edit
)
Module:WoodcutterList
(
edit
)
Module:WoodcutterPassiveList
(
edit
)
Module:Yesno
(
view source
) (semi-protected)
This page is a member of a hidden category:
Category:Pages using DynamicPageList3 parser function