Module:Sandbox: Difference between revisions

From Path of Exile 2 Wiki
Jump to navigation Jump to search
>OmegaK2
No edit summary
m (257 revisions imported)
 
(57 intermediate revisions by 4 users not shown)
Line 1: Line 1:
local p = {}
-- This is not an actual module. Do not add code.
local getArgs
 
-- for testing
local quest_data = {
    {
        reward="Ground Slam",
        reward_type="skill",
        class="Marauder",
        difficulty="Normal",
        quest="Enemy at the Gate",
    },
    {
        reward="Molten Strike",
        reward_type="skill",
        class="Marauder",
        difficulty="Normal",
        quest="Enemy at the Gate",
    },
}
 
local poe_classes = {'Marauder', 'Templar', 'Witch', 'Shadow', 'Ranger', 'Duelist', 'Scion'}
 
function p.table(frame)
    if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
    local args = getArgs(frame, {
parentFirst = true
})
   
    args.reward = args.reward or args.Reward
    args.reward_type = args.reward_type or args.rewardType or args.RewardType
    args.class = args.class or args.Class
    args.difficulty = args.difficulty or args.Difficulty
    args.quest = args.quest or args.Quest
    args.display_style = args.display_style or args.displayStyle or args.DisplayStyle or 'full'
   
    -- parser
   
    local return_data = {}
   
   
    for key, row in ipairs(quest_data) do
        (function()
            for k, v in ipairs({"reward", "reward_type", "class", "quest", "difficulty"}) do
                if args[v] ~= nil and row[v] ~= args[v] then return end
            end
           
            table.insert(return_data, row)
        end)()
    end
   
    local outstr
    if args.display_style == 'full' then
        outstr = display_full(return_data)
    end
   
    return outstr
end
 
function display_full(return_data)
    local tbl = mw.html.create('table')
    local tblhead = tbl:tag('tr')
   
    tbl
        :addClass('wikitable')
       
    tblhead
        :tag('th')
            :wikitext('Class')
    for garbage, value in ipairs(poe_classes) do
        tblrow
            :tag('th')
                :attr('rowspan', 2)
                :wikitext('[[' .. value .. ']]')
    end
    tbl
        :tag('tr')
            :tag('th')
                :wikitext('Quest')
   
    local format_data = {}
   
    -- reformat to make proper lists
    -- quest_diff: class: [rowA, rowB]
    for garbage, row in ipairs(return_data) do
        key = {}
        for k, v in ipairs({'quest', 'difficulty'}) do
            key[v] = row[v]
        end
       
        if format_data[key] == nil then
            format_data[key] = {}
            format_data[key][row['class']] = {row}
        elseif format_data[key][row['class']] == nil then
            format_data[key][row['class']] = {row}
        else
            table.insert(format_data[key][row['class']], row)
        end
    end
   
    -- lastly add to table
    for quest_diff, columns in ipairs(format_data) do
        local tblrow = tbl:tag('tr')
        tblrow
            :tag('td')
                :wikitext(quest_diff['quest'])
       
        if columns['All'] ~= nil then
            tblrow
                :tag('td')
                    :attr('colspan', 7)
                    :wikitext(format_reward(row['All']))
        else
            for garbage, class in ipairs(poe_classes) do
                local txt = ''
                if columns[class] ~= nil then
                    txt = format_reward(columns[class])
                end
                tblrow
                    :tag('td')
                        :wikitext(txt)
            end
        end
       
    end
   
    return tostring(tbl)
end
 
function format_reward(row)
    -- Take a row and format it accordingly
    local output
    if row['reward_type'] == 'skill' then
        output = frame:expandTemplate{title='sl', args={row['reward']}}
    elseif row['reward_type'] == 'item' then
        output = frame:expandTemplate{title='il', args={row['reward']}}
    else
        output = row['reward']
    end
   
    if row['display'] ~= nil then
        output = replace_vars{row[display], reward=output}
    end
   
    return output
end
 
 
function replace_vars(str, vars)
  -- Allow replace_vars{str, vars} syntax as well as replace_vars(str, {vars})
  if not vars then
    vars = str
    str = vars[1]
  end
  return (string_gsub(str, "({([^}]+)})",
    function(whole,i)
      return vars[i] or whole
    end))
end
 
return p

Latest revision as of 01:33, 23 September 2024

Module documentation[view] [edit] [history] [purge]


This page is not an actual Scribunto module. It exists to provide editors a place to create experimental modules.

Naming your modules

To keep things tidy, please use the following format to name your experimental modules:

Module:Sandbox/Your username/Module name

Cleaning up unused modules

Experimental modules may be deleted by admins upon request or after a long period of inactivity.

List of modules in this area

For a list of the experimental modules under Module:Sandbox, see Special:PrefixIndex/Module:Sandbox/.

-- This is not an actual module. Do not add code.