Module:Calculator/AgilityObstacle: Difference between revisions

Add sorting of calculated obstacles
No edit summary
(Add sorting of calculated obstacles)
Line 10: Line 10:
local Debug = require('Module:Debug') -- Comment out when Module is finalised.
local Debug = require('Module:Debug') -- Comment out when Module is finalised.


-- Adds the the highest level to the dictionary, or the level, if the key isn't present.
-- Gets all associated metadata from an obstacle based on its name.
local function addHighestLevelRequirement(tbl, skill, level)
Shared.addOrUpdate(tbl, skill,
function(x)
if x then
return math.max(x, level)
else
return level
end
end
)
end
 
-- Adds the item amount to the dictionary, or just the amount if the key isn't present.
local function concatItemRequirements(tbl, item, amount)
Shared.addOrUpdate(tbl, item,
function(x)
x = x or 0
return x + amount
end
)
end
 
local function getObstacle(name)
local function getObstacle(name)
name = Shared.specialTitleCase(name)
name = Shared.specialTitleCase(name)
Line 101: Line 79:
end
end


-- Sort course on category
local sortFunc = function(a, b)
-- Special case to sort pillars AFTER all regular obstacles.
    local pillar = { ["Pillar"] = 99, ["Elite Pillar"] = 100 }
return (pillar[a.Slot] or a.Slot) < (pillar[b.Slot] or b.Slot)
end
table.sort(courseObstacles, sortFunc)
return {
return {
Obstacles = courseObstacles,
Obstacles = courseObstacles,
2,875

edits