Module:WoodcutterPassiveList: Difference between revisions
switch to sorting after the SMW query
(based on MinerPassiveList) |
(switch to sorting after the SMW query) |
||
(One intermediate revision by the same user not shown) | |||
Line 12:
-- returns only directly needed parameter needed for the row,
-- other parameters are determined by subqueries of chained pages
-- Woodcutter cannot sort by any parameter, as Branches use Profession B but Split Wood uses profession A
local query = {
'[[Variant of::~*Tree||~Split Wood for*]]',
'? #- = name',
'?Image #- = Image',
'?Activity XP = XP',▼
'?Activity JSON = activityJSON',
'limit = 500'
}
Line 57 ⟶ 54:
-- iterate through products
for _, item in ipairs(results) do
-- if theres only one activity, wrap in table
if type(item.activityJSON)=='string' then
item.activityJSON = { item.activityJSON }
end
for j,json in ipairs(item.activityJSON) do
if string.find(json,'Branches') or string.find(json,'Split') then
local activityJSON = mw.text.jsonDecode(json)
item.XP = activityJSON.xp
item.lvl = activityJSON.level
item.duration = activityJSON.duration and tonumber(activityJSON.duration)
item.product = activityJSON.output[1].name
Line 72 ⟶ 76:
end
-- sort the results by recipe level
table.sort(resultsScreened, function(item1, item2)
local lvl1 = item1.lvl
local lvl2 = item2.lvl
if (lvl1 == nil) ~= (lvl2 == nil) then --one of two are empty
return lvl2 == nil -- true if lvl2 is nil but not lvl1, false if lvl1 is nil but not lvl2
end
if lvl1 == nil then
return false -- Both empty, equivalent
end
return lvl1 < lvl2 -- normal comparison
end)
return resultsScreened
Line 81 ⟶ 98:
-- iterate through products
for _, item in ipairs(results) do
item.givesCoins = string.find(item.product,'Split')
-- profit from selling the items
Line 121 ⟶ 140:
:tag('th')
:attr{ colspan = '2' }
:wikitext('
:done()
:tag('th')
Line 173 ⟶ 192:
-- products (coins or items)
:
:IF(item.coins)
:css{ ['border-right'] = '0', ['text-align'] = 'right' }▼
:tag('td')▼
:attr{ ['data-sort-value'] = item.product }▼
:css{ ['border-right'] = '0', ['text-align'] = 'right' }
:wikitext('0.005 × ')▼
:addClass('plinkt-link no-border')▼
:done()▼
:attr{ ['data-sort-value'] = item.product }
▲ :tag('td')
:wikitext(item.coins)
:css{ ['border-right'] = '0', ['text-align'] = 'center' }▼
:done()
▲ :addClass('plinkt-link no-border')
:ELSE()
:wikitext('[[File:' .. item.product .. '.png|link=' .. item.product .. '|30x30px]]')▼
:node(unknown_value_cell)
:done()▼
:
:
▲ :css{ ['border-right'] = '0', ['text-align'] = 'center' }
:wikitext('[[' .. item.product .. ']]')▼
:addClass('plinkt-link no-border')
:done()▼
:wikitext('[[File:Copper coin.png|20x20px]]')
▲ :done()
:tag('td')
:addClass('plinkt-link no-border')
:wikitext('Coins')
▲ :done()
:ELSE()
:tag('td')
▲ :css{ ['border-right'] = '0', ['text-align'] = 'right' }
:addClass('plinkt-link no-border')
▲ :attr{ ['data-sort-value'] = item.product }
▲ :wikitext('0.005 × ')
▲ :done()
:tag('td')
:addClass('plinkt-link no-border')
▲ :wikitext('[[File:' .. item.product .. '.png|link=' .. item.product .. '|30x30px]]')
:done()
:tag('td')
:addClass('plinkt-link no-border')
▲ :wikitext('[[' .. item.product .. ']]')
:done()
:END()
-- products per hour (items)
:
:tag('td')
▲ :css{ ['text-align'] = 'right' }
:addClass('table-na')
:wikitext('0.9 × [[File:' .. item.product .. '.png|link=' .. item.product .. '|30x30px]]')▼
:
:done()
:ELSE()
:tag('td')
:css{ ['text-align'] = 'right' }
▲ :wikitext('0.9 × [[File:' .. item.product .. '.png|link=' .. item.product .. '|30x30px]]')
:done()
:END()
-- profit per hour (coins)
|