Module:Sandbox: Difference between revisions

From Path of Exile 2 Wiki
Jump to navigation Jump to search
>OmegaK2
No edit summary
>OmegaK2
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local g_frame
local getArgs = require('Module:Arguments').getArgs


-- local quest_data = mw.loadData('Module:QuestReward/data')
local g_frame, g_args
local quest_data = require('Module:QuestReward/data')


local poe_classes = {'Marauder', 'Templar', 'Witch', 'Shadow', 'Ranger', 'Duelist', 'Scion'}
local getArgs = require('Module:Arguments').getArgs
local poe_difficulties = {'Normal', 'Cruel', 'Merciless'}
local show_reward = require('Module:QuestReward').show_reward
local data_keys = {'reward', 'type', 'class', 'difficulty', 'quest', 'quest_id', 'act', 'itemlevel', 'rarity', 'sockets', 'page_link'}
local util = require('Module:Util')
local supported_compares = {'eq', 'neq', 'lt', 'gt', 'le', 'ge'}


function p.table(frame)
--
     --if not getArgs then
-- For Template:Quest
-- getArgs = require('Module:Arguments').getArgs
--
--end
function p.quest(frame)
    -- TODO: Remove
     g_args = getArgs(frame, {
     if frame == nil then
parentFirst = true
})
     if frame == nil or type(frame) == 'table' then
         frame = mw.getCurrentFrame()
         frame = mw.getCurrentFrame()
     end
     end
      
      
    local args = getArgs(frame, {
parentFirst = true
})
     g_frame = frame
     g_frame = frame
      
      
     args.filter_by_difficulty = args.filter_by_difficulty or 1
     --
     --args.filter_by_act = args.filter_by_act or 1
     -- Args
     --args.filter_by_quest_id = args.quest_id or 1
     --
     args.display_style = args.display_style or args.displayStyle or args.DisplayStyle or 'full'
      
    if g_args.name == nil or string.len(g_args.name) == 0 then
        error('Name is required')
    end
      
      
     args.order_by_difficulty = args.order_by_difficulty or 'le'
     g_args.icon = g_args.icon or g_args.name .. ' Quest icon.png'
     args.order_by_act = args.order_by_act or 'le'
     g_args.boss = g_args.boss
     args.order_by_quest_id = args.order_by_quest_id or 'le'
    if g_args.boss then
        local n = tonumber(g_args.boss)
        -- The number of bosses were given
        if n then
            g_args.boss = n
            for i=1, n do
                args_format_boss(tostring(i))
            end
        else
            args_format_boss('')
        end
    end
     g_args.key_item = g_args.key_item
    g_args.required = util.cast.boolean(g_args.required)
    g_args.start = g_args.start
    g_args.objective = g_args.objective
    g_args.completion = g_args.completion
      
      
     local out = ''
     --
    -- Formatting
    --
      
      
     if args.order_priority == nil then
     tbl = mw.html.create('table')
         args.order_priority = {'difficulty', 'act', 'quest_id'}
    tbl
        :attr('class', 'quest-table')
         --:attr('style', 'width:300px; color: #bfbfbf; float:right; padding:0.1em; background-color:#1a1812; margin: 0px 0px 5px 5px;')
        :tag('tr')
            :tag('td')
                :attr('colspan', 2)
                --:attr('style', 'text-align:center;font-size:20px;font-weight:bold;')
                :wikitext(g_args.name .. '<br>[[File:' .. g_args.icon .. '|128x128px|alt=' .. g_args.icon .. ']]')
   
    local rtext = ''
    if g_args.required then
        rtext = 'Yes'
     else
     else
         local temp = split(args.order_priority)
         rtext = 'No'
        local out = {}
    end
        for _, key1 in ipairs(temp) do
    display_quest_add_row(tbl, 'Required: ', rtext)
            if in_array(data_keys, key1) then
   
                table.insert(out, key1)
    for _, v in pairs({'Start', 'Objective', 'Completion'}) do
            else
        display_quest_add_row(tbl, v .. ': ', g_args[string.lower(v)])
                error("Invalid key in order priority" .. key1)  
    end
             end
   
    if type(g_args.boss) == 'number' then
        local v = {}
        for i=1, g_args.boss do
            v[#v+1] = display_format_boss(tostring(i))
             v[#v+1] = '<br>'
         end
         end
         args.order_priority = out
         display_quest_add_row(tbl, 'Boss: ', table.concat(v))
    elseif type(g_args.boss) == 'string' then
        display_quest_add_row(tbl, 'Boss: ', display_format_boss(''))
    end
   
    if g_args.key_item then
        display_quest_add_row(tbl, 'Key Item: ', g_args.key_item)
     end
     end
      
      
     local filter_keys = {}
     local quest_rewards = show_reward{data_type='default', show_empty_message=false, filter_by_quest=g_args.name}
     local search_keys = {}
     g_frame:callParserFunction('#vardefine', {'quest_rewards', quest_rewards})
      
      
     for _, key in ipairs(data_keys) do
     local vendor_rewards = show_reward{data_type='vendor', show_empty_message=false, filter_by_quest=g_args.name}
        out = out .. ' ' .. tostring(args['filter_by_' .. key])
    g_frame:callParserFunction('#vardefine', {'vendor_rewards', vendor_rewards})
        if args['filter_by_' .. key] ~= nil then
   
            filter_keys[key] = args['filter_by_' .. key]
    return tostring(tbl)
        end
end
        if args['order_by_' .. key] ~= nil then
 
            comp = args['order_by_' .. key]
function args_format_boss(key)
            if in_array(supported_compares, comp) then
    local boss_key = 'boss' .. key
                table.insert(search_keys, {key=key, cmp=comp})
    local link_key = boss_key .. '_link'
            else
    local image_key = boss_key .. '_image'
                error("Invalid compare: " .. comp)
    if g_args[boss_key] == nil then
            end
        error('Multiple bosses, but ' .. boss_key .. ' is empty')
        end
     end
     end
    g_args[link_key] = g_args[link_key] or g_args[boss_key]
    g_args[image_key] = g_args[image_key] or g_args[boss_key] .. '.png'
end
function display_format_boss(key)
    local boss_key = 'boss' .. key
    local v = {}
    -- Format the link
    v[#v+1] = '[['
    v[#v+1] = g_args[boss_key .. '_link']
    v[#v+1] = '|'
    v[#v+1] = g_args[boss_key]
    v[#v+1] = ']]'
    v[#v+1] = '<br>'
    -- Format the image
    v[#v+1] = '[[File:'
    v[#v+1] = g_args[boss_key .. '_image']
    v[#v+1] = '|alt='
    v[#v+1] = g_args[boss_key]
    v[#v+1] = ']]'
      
      
     return out
     return table.concat(v)
end
end
 
function in_array(array, key)
function display_quest_add_row(tbl, head, content)
     for _, v in ipairs(array) do
     if content == nil then
        if v == key then return true end
        content = ''
     end
     end
     return false
     tbl
        :tag('tr')
            :tag('th')
                --:attr('style', 'text-align: right; font-weight: bold; background-color: #332f24;')
                :attr('scope', 'row')
                :wikitext(head)
                :done()
            :tag('td')
                --:attr('style', 'text-align: center; background-color: #26231b;')
                :wikitext(content)
                :done()
end
end
 
return p
return p

Revision as of 16:28, 10 July 2015

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/.

local p = {}

local g_frame, g_args

local getArgs = require('Module:Arguments').getArgs
local show_reward = require('Module:QuestReward').show_reward
local util = require('Module:Util')

--
-- For Template:Quest
--
function p.quest(frame)
    g_args = getArgs(frame, {
		parentFirst = true
	})
    if frame == nil or type(frame) == 'table' then
        frame = mw.getCurrentFrame()
    end
    
    g_frame = frame
    
    --
    -- Args
    --
    
    if g_args.name == nil or string.len(g_args.name) == 0 then
        error('Name is required')
    end
    
    g_args.icon = g_args.icon or g_args.name .. ' Quest icon.png'
    g_args.boss = g_args.boss
    if g_args.boss then
        local n = tonumber(g_args.boss)
        -- The number of bosses were given
        if n then
            g_args.boss = n
            for i=1, n do
                args_format_boss(tostring(i))
            end
        else
            args_format_boss('')
        end
    end
    g_args.key_item = g_args.key_item
    g_args.required = util.cast.boolean(g_args.required)
    g_args.start = g_args.start
    g_args.objective = g_args.objective
    g_args.completion = g_args.completion
    
    --
    -- Formatting
    --
    
    tbl = mw.html.create('table')
    tbl
        :attr('class', 'quest-table')
        --:attr('style', 'width:300px; color: #bfbfbf; float:right; padding:0.1em; background-color:#1a1812; margin: 0px 0px 5px 5px;')
        :tag('tr')
            :tag('td')
                :attr('colspan', 2)
                --:attr('style', 'text-align:center;font-size:20px;font-weight:bold;')
                :wikitext(g_args.name .. '<br>[[File:' .. g_args.icon .. '|128x128px|alt=' .. g_args.icon .. ']]')
     
    local rtext = ''
    if g_args.required then
        rtext = 'Yes'
    else
        rtext = 'No'
    end
    display_quest_add_row(tbl, 'Required: ', rtext)
     
    for _, v in pairs({'Start', 'Objective', 'Completion'}) do
        display_quest_add_row(tbl, v .. ': ', g_args[string.lower(v)])
    end
    
    if type(g_args.boss) == 'number' then
        local v = {}
        for i=1, g_args.boss do
            v[#v+1] = display_format_boss(tostring(i))
            v[#v+1] = '<br>'
        end
        display_quest_add_row(tbl, 'Boss: ', table.concat(v))
    elseif type(g_args.boss) == 'string' then
        display_quest_add_row(tbl, 'Boss: ', display_format_boss(''))
    end
    
    if g_args.key_item then
        display_quest_add_row(tbl, 'Key Item: ', g_args.key_item)
    end
    
    local quest_rewards = show_reward{data_type='default', show_empty_message=false, filter_by_quest=g_args.name}
    g_frame:callParserFunction('#vardefine', {'quest_rewards', quest_rewards})
    
    local vendor_rewards = show_reward{data_type='vendor', show_empty_message=false, filter_by_quest=g_args.name}
    g_frame:callParserFunction('#vardefine', {'vendor_rewards', vendor_rewards})
    
    return tostring(tbl)
end

function args_format_boss(key)
    local boss_key = 'boss' .. key
    local link_key = boss_key .. '_link'
    local image_key = boss_key .. '_image'
    if g_args[boss_key] == nil then
        error('Multiple bosses, but ' .. boss_key .. ' is empty')
    end
    g_args[link_key] = g_args[link_key] or g_args[boss_key]
    g_args[image_key] = g_args[image_key] or g_args[boss_key] .. '.png'
end

function display_format_boss(key)
    local boss_key = 'boss' .. key
    local v = {}
    -- Format the link
    v[#v+1] = '[['
    v[#v+1] = g_args[boss_key .. '_link']
    v[#v+1] = '|'
    v[#v+1] = g_args[boss_key]
    v[#v+1] = ']]'
    v[#v+1] = '<br>'
    -- Format the image
    v[#v+1] = '[[File:'
    v[#v+1] = g_args[boss_key .. '_image']
    v[#v+1] = '|alt='
    v[#v+1] = g_args[boss_key]
    v[#v+1] = ']]'
    
    return table.concat(v)
end

function display_quest_add_row(tbl, head, content)
    if content == nil then
        content = ''
    end
    tbl
        :tag('tr')
            :tag('th')
                --:attr('style', 'text-align: right; font-weight: bold; background-color: #332f24;')
                :attr('scope', 'row')
                :wikitext(head)
                :done()
            :tag('td')
                --:attr('style', 'text-align: center; background-color: #26231b;')
                :wikitext(content)
                :done()
end

return p