Module:Calculator/AgilityObstacle: Difference between revisions

Add expansion icon to obstacle
No edit summary
(Add expansion icon to obstacle)
 
(15 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 6: Line 7:
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Debug = require('Module:Debug') -- Comment out when Module is finalised.


local function getItemIcon(itemName, amount)
local function getItemIcon(itemName, amount)
Line 18: Line 18:
return Icons.Icon({itemName, type='item', qty = amount, notext=true})
return Icons.Icon({itemName, type='item', qty = amount, notext=true})
end
local function getObstacleIcon(obstacle)
local obs = obstacle.Obstacle
return Icons.getExpansionIcon(obs.id) .. Icons.Icon({obs.name, type='agility'})
end
end


Line 25: Line 30:
local obstacle = Agility.getObstacle(name) or Agility.getPillar(name)
local obstacle = Agility.getObstacle(name) or Agility.getPillar(name)
if obstacle == nil then
if obstacle == nil then
error("Unknown Agility obstacle or pillar name: " .. name)
error("Unknown Agility obstacle or pillar name: " .. (name or '<name is nil>'))
end
end


Line 87: Line 92:
-- required to build this agility course.
-- required to build this agility course.
local courseLevelRequirements = {}
local courseLevelRequirements = {}
local courseItemCosts = {}
local courseItemCosts = {
['Items'] = {}
}
for _, obstacle in pairs(courseObstacles) do
for _, obstacle in pairs(courseObstacles) do
Line 104: Line 111:
for item, amount in pairs(obstacleCosts['Items']) do
for item, amount in pairs(obstacleCosts['Items']) do
funcPoolCosts(courseItemCosts, item, amount)
funcPoolCosts(courseItemCosts['Items'], item, amount)
end
end
end
end
Line 145: Line 152:
function p._getCourseList(args)
function p._getCourseList(args)
-- Parse optional parameters
-- Parse optional parameters
local includeItems = args['includeitems'] or true
local includeSkills = args['includeskills'] or true
local includeObstacles = args['includeObstacles'] or true
local costReduction = {
local costReduction = {
['GP']  = args['gpCostReduction'] or 0,
['GP']  = Num.toNumberOrDefault(args['gpCostReduction'], 0),
['SC']  = args['scCostReduction'] or 0,
['SC']  = Num.toNumberOrDefault(args['scCostReduction'], 0),
['Item'] = args['itemCostReduction'] or 0,
['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0),
}
}
Line 161: Line 164:
     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 176: Line 179:
:wikitext(v.Slot)
:wikitext(v.Slot)
:tag('td')
:tag('td')
:wikitext(Icons.Icon({v.Name, type='agility'}))
:wikitext(getObstacleIcon(v))
end
end
Line 183: Line 186:
     end
     end


     if includeItems then
     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')
    
    
     local itemList = Shared.sortDictionary(courseRequirements.CourseItemCosts,  
    local courseItems = courseRequirements.CourseItemCosts
    -- Put GP and SC at the top, and remove them from the list
    -- to avoid sorting and re-adding them below.
    if courseItems['GP'] then ul:tag('li'):wikitext(getItemIcon('GP', courseItems['GP'])) end
    if courseItems['SC'] then ul:tag('li'):wikitext(getItemIcon('SC', courseItems['SC'])) end
 
     local itemList = Shared.sortDictionary(courseItems['Items'],  
     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 197: Line 206:
     end
     end
if includeSkills then
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 245: Line 254:
local function getCosts(costsTable)
local function getCosts(costsTable)
local res = {}
   
-- Order table with GP, SC first, then the other items.
-- Order table with GP, SC first, then the other items.
    local sortedCosts = {}
     if costsTable['GP'] then table.insert(res, getItemIcon('GP', costsTable['GP'])) end
     if costsTable['GP'] then table.insert(sortedCosts, {item = 'GP', amount = costsTable['GP']}) end
     if costsTable['SC'] then table.insert(res, getItemIcon('SC', costsTable['SC'])) end
     if costsTable['SC'] then table.insert(sortedCosts, {item = 'SC', amount = costsTable['SC']}) end
 
   
     local sortedCosts = Shared.sortDictionary(costsTable['Items'],
     for k, v in pairs(costsTable) do
function(a, b) return a.item < b.item end,
    if k ~= 'GP' and k ~= 'SC' then
function(a, b) return {item = a, amount = b} end)
    table.insert(sortedCosts, {item = k, amount = v})
 
    end
    end
   
    local res = {}
     for _, v in pairs(sortedCosts) do
     for _, v in pairs(sortedCosts) do
     table.insert(res, getItemIcon(v.item, v.amount))
     table.insert(res, getItemIcon(v.item, v.amount))
Line 285: Line 292:


--== Parse optional parameters==--
--== Parse optional parameters==--
local showTotals = args['showtotals'] or true
local showTotals = yesno(args['showtotals'], false)
local obstacleMastery = args['obstacleMastery'] or false
local showbonus = yesno(args['showbonus'], true)
local showrequirements = yesno(args['showrequirements'], true)
local showcosts = yesno(args['showcosts'], true)
local obstacleMastery = yesno(args['obstacleMastery'], false)
 
local costReduction = {
local costReduction = {
['GP']  = args['gpCostReduction'] or 0,
['GP']  = Num.toNumberOrDefault(args['gpCostReduction'], 0),
['SC']  = args['scCostReduction'] or 0,
['SC']  = Num.toNumberOrDefault(args['scCostReduction'], 0),
['Item'] = args['itemCostReduction'] or 0,
['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0),
}
}
Line 299: Line 309:
--== Start of table formatting ==--
--== Start of table formatting ==--
local tbl = mw.html.create("table")
local tbl = mw.html.create("table")
       :addClass("wikitable stickyHeader")
       :addClass("wikitable stickyheader")
     
   
     tbl :tag('tr')
     local thr = tbl:tag('tr')
:tag('th'):wikitext('Slot')
    thr:tag('th'):wikitext('Slot')
:tag('th'):wikitext('Obstacle')
thr:tag('th'):wikitext('Obstacle')
:tag('th'):wikitext('Bonuses')
:tag('th'):wikitext('Requirements')
if showbonus then
:tag('th'):wikitext('Costs')
thr:tag('th'):wikitext('Bonuses')
end
if showrequirements then
thr:tag('th'):wikitext('Requirements')
end
if showcosts then
thr:tag('th'):wikitext('Costs')
end


for _, obstacle in pairs(courseRequirements.Obstacles) do
for _, obstacle in pairs(courseRequirements.Obstacles) do
tbl :tag('tr')
local tr = tbl:tag('tr')
:tag('td')
tr  :tag('td')
:css('text-align', 'right')
:css('text-align', 'right')
:wikitext(obstacle.Slot)
:wikitext(obstacle.Slot)
:tag('td'):wikitext(Icons.Icon({obstacle.Name, type='agility'}))
:tag('td'):wikitext(getObstacleIcon(obstacle))
:tag('td'):wikitext(getBonusses(obstacle.Obstacle))
:tag('td'):wikitext(getRequirements(obstacle.LevelRequirements))
if showbonus then
:tag('td'):wikitext(getCosts(obstacle.ItemCosts))
tr:tag('td'):wikitext(getBonusses(obstacle.Obstacle))
end
if showrequirements then
tr:tag('td'):wikitext(getRequirements(obstacle.LevelRequirements))
end
if showcosts then
tr:tag('td'):wikitext(getCosts(obstacle.ItemCosts))
end
end
end
if showTotals == true then
if showTotals == true then
tbl :tag('tr')
local tr = tbl:tag('tr')
:tag('th')
tr  :tag('th')
:attr('colspan', 2)
:attr('colspan', 2)
:wikitext('Totals')
:wikitext('Totals')
:tag('td')
if showbonus then
:wikitext(getTotalBonuses(courseRequirements.Obstacles))
tr  :tag('td')
:tag('td')
:wikitext(getTotalBonuses(courseRequirements.Obstacles))
:wikitext(getRequirements(courseRequirements.CourseLevelRequirements))
end
:tag('td')
if showrequirements then
:wikitext(getCosts(courseRequirements.CourseItemCosts))
tr  :tag('td')
:wikitext(getRequirements(courseRequirements.CourseLevelRequirements))
end
if showcosts then
tr  :tag('td')
:wikitext(getCosts(courseRequirements.CourseItemCosts))
end
end
end


Line 336: Line 366:


function p.test()
function p.test()
local obstacles = {"Rope Climb","Monkey Bars"," Balance Seesaw","Elite Pillar of Conflict"}
--local obstacles = {"Rope Climb","Monkey Bars"," Balance Seesaw","Elite Pillar of Conflict"}
local obs = p.calculateCourse(obstacles)
--local obs = p.calculateCourse(obstacles)
 
mw.logObject(getObstacle('rope trap'))
 
Debug.log(obs.CourseItemCosts)
end
end
return p
return p
918

edits