Editing Module:ProfessionList
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
local currency = require('Module:Currency') |
local currency = require('Module:Currency') |
||
local search = require('Module:RecipeTreeSearch') |
|||
local p = {} |
local p = {} |
||
Line 42: | Line 41: | ||
:css{ ['text-align'] = 'center' } |
:css{ ['text-align'] = 'center' } |
||
:attr{ colspan = tostring(N) } |
:attr{ colspan = tostring(N) } |
||
:wikitext('['..url.." '' |
:wikitext('['..url.." ''unknown'' (edit)]") |
||
:done() |
:done() |
||
end |
end |
||
Line 49: | Line 48: | ||
-- the queryString is just a selection of pages, from any combination of SMW properties and categories |
-- 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 |
-- for pages with multiple recipes or activities, will make on entry into the results table for each |
||
function p.generate_recipe_table(queryString) |
|||
-- 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 |
-- first formulate the query to get the list of pages |
||
Line 68: | Line 66: | ||
end |
end |
||
-- |
-- output structure |
||
local |
local output = {} |
||
-- iterate through pages found |
-- iterate through pages found |
||
for _, page in ipairs(pages) do |
for _, page in ipairs(pages) do |
||
-- combine the activityJSON and recipeJSON into one table |
|||
-- first iterate through activities |
|||
local JSONs = {} |
|||
if page.activityJSON ~= nil then |
if page.activityJSON ~= nil then |
||
if type(page.activityJSON)=='string' then |
if type(page.activityJSON)=='string' then |
||
table.insert(JSONs,page.activityJSON) |
|||
else |
|||
for _, |
for _, json in page.activityJSON do |
||
json.type = 'activity' |
|||
local item = mw.text.jsonDecode(JSON) |
|||
table.insert(JSONs,json) |
|||
item.pageName = page.pageName |
|||
end |
|||
item.pageImage = page.pageImage |
|||
item.type = 'activity' |
|||
table.insert(recipes,item) |
|||
end |
end |
||
end |
end |
||
-- same iteration through recipes |
|||
if page.recipeJSON ~= nil then |
if page.recipeJSON ~= nil then |
||
if type(page.recipeJSON)=='string' 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 |
||
end |
|||
for _, JSON in ipairs(page.recipeJSON) do |
|||
-- 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) |
local item = mw.text.jsonDecode(JSON) |
||
item. |
item.page = page.pageName |
||
item.pageImage = page.pageImage |
item.pageImage = page.pageImage |
||
item.type = 'recipe' |
|||
--insert into output table |
|||
table.insert(output,item) |
|||
end |
end |
||
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 |
|||
local sell = search.getShopSellPrice(item.product) |
|||
local qty = item.output[1].quantity |
|||
item.sellPrice = sell and qty and sell * qty |
|||
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 |
end |
||
return output |
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 |
end |