964
edits
No edit summary |
(Make costReduction parsing more robust) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local yesno = require('Module:Shared/Yesno') | |||
local Num = require('Module:Number') | local Num = require('Module:Number') | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
Line 147: | Line 148: | ||
function p._getCourseList(args) | function p._getCourseList(args) | ||
-- Parse optional parameters | -- Parse optional parameters | ||
local costReduction = { | local costReduction = { | ||
['GP'] = args['gpCostReduction'] | ['GP'] = Num.toNumberOrDefault(args['gpCostReduction'], 0), | ||
['SC'] = args['scCostReduction'] | ['SC'] = Num.toNumberOrDefault(args['scCostReduction'], 0), | ||
['Item'] = args['itemCostReduction'] | ['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0), | ||
} | } | ||
Line 163: | Line 160: | ||
local div = html:tag('div') | local div = html:tag('div') | ||
if includeObstacles then | if yesno(args['includeObstacles'], true) == true then | ||
div:tag('b'):wikitext('Obstacles') | div:tag('b'):wikitext('Obstacles') | ||
local tbl = mw.html.create("table") | local tbl = mw.html.create("table") | ||
Line 185: | Line 182: | ||
end | end | ||
if | if yesno(args['includeitems'], true) then | ||
div:tag('b'):wikitext('Items Required') | div:tag('b'):wikitext('Items Required') | ||
local ul = div:tag('ul') | local ul = div:tag('ul') | ||
Line 195: | Line 192: | ||
if courseItems['SC'] then ul:tag('li'):wikitext(getItemIcon('SC', courseItems['SC'])) end | if courseItems['SC'] then ul:tag('li'):wikitext(getItemIcon('SC', courseItems['SC'])) end | ||
local itemList = Shared.sortDictionary(courseItems['Items'], | |||
local itemList = Shared.sortDictionary(courseItems, | |||
function(a, b) return a.item < b.item end, | function(a, b) return a.item < b.item end, | ||
function(a, b) return {item = a, amount = b} end) | function(a, b) return {item = a, amount = b} end) | ||
Line 208: | Line 202: | ||
end | end | ||
if | if yesno(args['includeskills'], true) then | ||
div:tag('b'):wikitext('Skills Required') | div:tag('b'):wikitext('Skills Required') | ||
local ul2 = div:tag('ul') | local ul2 = div:tag('ul') | ||
Line 263: | Line 257: | ||
local sortedCosts = Shared.sortDictionary(costsTable['Items'], | local sortedCosts = Shared.sortDictionary(costsTable['Items'], | ||
function(a, b) return a.item < b. | function(a, b) return a.item < b.item end, | ||
function(a, b) return {item = a, amount = b} end) | function(a, b) return {item = a, amount = b} end) | ||
Line 294: | Line 288: | ||
--== Parse optional parameters==-- | --== Parse optional parameters==-- | ||
local showTotals = args['showtotals'] | local showTotals = yesno(args['showtotals'], true) | ||
local obstacleMastery = args['obstacleMastery'] | local obstacleMastery = yesno(args['obstacleMastery'], false) | ||
local costReduction = { | local costReduction = { | ||
['GP'] = args['gpCostReduction'] | ['GP'] = Num.toNumberOrDefault(args['gpCostReduction'], 0), | ||
['SC'] = args['scCostReduction'] | ['SC'] = Num.toNumberOrDefault(args['scCostReduction'], 0), | ||
['Item'] = args['itemCostReduction'] | ['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0), | ||
} | } | ||
edits