Module:Calculator/AgilityObstacle: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}


local Num = require('Module:Number')
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Agility = require('Module:Skills/Agility')
local Agility = require('Module:Skills/Agility')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Skills = require('Module:Skills')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Debug = require('Module:Debug') -- Comment out when Module is finalised.
local Debug = require('Module:Debug') -- Comment out when Module is finalised.
Line 140: Line 137:
div:tag('b'):wikitext('Obstacles')
div:tag('b'):wikitext('Obstacles')
local tbl = mw.html.create("table")
local tbl = mw.html.create("table")
         :addClass("wikitable sticky-header text-align-left")
         :addClass("wikitable stickyHeader text-align-left")
        
        
         tbl :tag("tr")
         tbl :tag("tr")
Line 195: Line 192:
end
end


function p._getCourseTable(obstacleNames)
function p.getCourseTable(frame)
local result = ''
local args = frame:getParent().args
local obstacles = {}
return p._getCourseList(args)
for i, name in ipairs(obstacleNames) do
end
local obst = Agility.getObstacle(Shared.trim(name))
if obst == nil then
result = result .. Shared.printError('Invalid Obstacle Name "' .. name .. '"') .. '<br/>'
else
table.insert(obstacles, obst)
end
end
 
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!Slot!!Name!!Bonuses!!Requirements!!Cost'
 
local catLog = {}
table.sort(obstacles, function(a, b) return a.category < b.category end)
 
local catCounts = {}
for i, obst in ipairs(obstacles) do
if catCounts[obst.category] == nil then
catCounts[obst.category] = 1
else
catCounts[obst.category] = catCounts[obst.category] + 1
end
end
 
for i, obst in ipairs(obstacles) do
result = result..'\r\n|-'
result = result..'\r\n|'
if catLog[obst.category] == nil then
local rowspan = catCounts[obst.category]
result = result..'rowspan="'..rowspan..'" style="border:1px solid black"|'..(obst.category + 1)..'||'
catLog[obst.category] = true
end
result = result..obst.name


function p._getCourseTable(args)
--== Local Functions for formatting Obstacle MetaData ==--
local function getBonusses(obstacle)
local bonuses = {}
local bonuses = {}
--After that, adding the bonuses
for bonusName, bonusValue in pairs(obstacle.modifiers) do
for bonusName, bonusValue in pairs(obst.modifiers) do
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
end
end
Line 242: Line 207:
table.insert(bonuses, '<span style="color:red">None :(</span>')
table.insert(bonuses, '<span style="color:red">None :(</span>')
end
end
result = result..'||'..table.concat(bonuses, '<br/>')
return table.concat(bonuses, '<br/>')
 
end
--Grabbing requirements to create
result = result..'|| ' .. formatObstacleRequirements(obst)
local function getRequirements(requirementsTable)
 
local skillList = Shared.sortDictionary(requirementsTable,
--Finally, the cost
function(a, b) return a.skill < b.skill end,
result = result..'|| data-sort-value="'..obst.gpCost..'"|'.. formatObstacleCosts(obst)
function(a, b) return {skill = a, level = b} end)
local res = {}
for _, v in pairs(skillList) do
Icons._SkillReq(v.skill, v.level)
end
return table.concat(bonuses, '<br/>')
end
local function getCosts(costsTable)
-- Order table with GP, SC first, then the other items.
    local sortedCosts = {}
    if costsTable['GP'] then table.insert(sortedCosts, {item = 'GP', amount = costsTable['GP']}) end
    if costsTable['SC'] then table.insert(sortedCosts, {item = 'SC', amount = costsTable['SC']}) end
   
    for k, v in pairs(costsTable) do
    if k ~= 'GP' and k ~= 'SC' then
    table.insert(sortedCosts, {item = k, amount = v})
    end
    end
   
    local res = {}
    for _, v in pairs(sortedCosts) do
    table.insert(res, getItemIcon(v.item, v.amount))
    end
return table.concat(res, '<br/>')
end
end
--== Start of table formatting ==--
local obstacleNames = parseObstacleArgs(args)
local courseRequirements = p.calculateCourse(obstacleNames, true)


result = result..'\r\n|}'
local showTotals = args['showtotals'] or true


return result
local tbl = mw.html.create("table")
end
      :addClass("wikitable stickyHeader")
     
    tbl :tag('tr')
:tag('th'):wikitext('Slot')
:tag('th'):wikitext('Obstacle')
:tag('th'):wikitext('Bonuses')
:tag('th'):wikitext('Requirements')
:tag('th'):wikitext('Costs')


function p.getCourseTable(frame)
for _, obstacle in pairs(courseRequirements.Obstacles) do
local obstNameStr = frame.args ~= nil and frame.args[1] or frame
tbl :tag('tr')
local obstacleNames = Shared.splitString(obstNameStr, ',')
:tag('td'):wikitext(obstacle.Slot)
:tag('td'):wikitext(Icons.Icon({obstacle.Name, type='agility'}))
:tag('td'):wikitext(getBonusses(obstacle.Obstacle))
:tag('td'):wikitext(getRequirements(obstacle.LevelRequirements))
:tag('td'):wikitext(getCosts(obstacle.ItemCosts))
end
return p._getCourseTable(obstacleNames)
--local obstacleInfo = {
--Name = obstacle.name,
--Slot = slot,
--Obstacle = obstacle,
--LevelRequirements = Agility.getObstacleRequirements(obstacle),
--ItemCosts = Agility.getObstacleCosts(obstacle),
--}
 
return tostring(tbl)
end
end


return p
return p
2,875

edits