Module:Quest: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
>OmegaK2
(added support for multi bosses and specifying boss_link)
>Illviljan
(Link quest icons to quest page instead of file page.)
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
local util = require('Module:Util')
local p = {}
local p = {}


local g_frame, g_args
-----
 
------------------------------------------------------------------------------------------------------
-- Template: Quest
 
p.quest = function(frame)
    local args = getArgs(frame, {parentFirst = true})
    -- local g_frame = util.misc.get_frame(frame)
 
    --[[ test args
    = p.quest({
        name = 'The Shaper',
        boss = 'The Shaper',
        required = 'yes',
        start = 'Meeting Zana.',
        objective = 'Find the source of the strange disturbances in Maps.',
        completion = 'Talk to Zana',
        act = 3,
    })
    ]]--
 
    -----


local getArgs = require('Module:Arguments').getArgs
    local args_format_boss = function(args, key)
local show_reward = require('Module:QuestReward').show_reward
        local boss_key = 'boss' .. key
local util = require('Module:Util')
        local link_key = boss_key .. '_link'
        local image_key = boss_key .. '_image'
 
        if args[boss_key] == nil then
            error('Multiple bosses, but ' .. boss_key .. ' is empty')
        end
 
        args[link_key] = args[link_key] or args[boss_key]
        args[image_key] = args[image_key] or args[boss_key] .. '.png'
 
        return args
    end
 
    -----
 
    local create_boss_link = function(args, key)
        local boss_key = 'boss' .. key
        local link_key = boss_key .. '_link'
        local image_key = boss_key .. '_image'
 
        local link = string.format('[[%s|%s]]<br>', args[link_key], args[boss_key])
        local image = string.format('[[File:%s|alt=%s]]', args[image_key], args[boss_key])
 
        return link .. image
    end
 
    -----


--
     local create_quest_row = function(tbl, header, content)
-- For Template:Quest
        if content == nil then
--
            content = ''
function p.quest(frame)
         end
     g_args = getArgs(frame, {
        tbl
parentFirst = true
            :tag('tr')
})
                :tag('th'):wikitext(header .. '&nbsp;'):done()
    if frame == nil or type(frame) == 'table' then
                :tag('td'):wikitext(content)
         frame = mw.getCurrentFrame()
     end
     end
   
 
     g_frame = frame
     -----
   
 
     --
     --
     -- Args
     -- Args
     --
     --
   
 
     if g_args.name == nil or string.len(g_args.name) == 0 then
     if args.name == nil or string.len(args.name) == 0 then
         error('Name is required')
         error('Name is required')
     end
     end
   
 
     g_args.icon = g_args.icon or g_args.name .. ' Quest icon.png'
     args.icon = args.icon or args.name .. ' quest icon.png'
     g_args.boss = g_args.boss
     args.required = util.cast.boolean(args.required)
     if g_args.boss then
 
         local n = tonumber(g_args.boss)
     if args.boss then
         local n = tonumber(args.boss)
         -- The number of bosses were given
         -- The number of bosses were given
         if n then
         if n then
             g_args.boss = n
             args.boss = n
             for i=1, n do
             for i = 1, n do
                 args_format_boss(tostring(i))
                 args = args_format_boss(args, tostring(i))
             end
             end
         else
         else
             args_format_boss('')
             args = args_format_boss(args, '')
         end
         end
     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
     -- Formatting
     --
     --
   
 
     tbl = mw.html.create('table')
     local tbl = mw.html.create('table')
     tbl
     tbl
         :attr('style', 'width:300px; color: #bfbfbf; float:right; padding:0.1em; background-color:#1a1812; margin: 0px 0px 5px 5px;')
         :addClass('quest-table')
         :tag('tr')
         :tag('tr')
             :tag('td')
             :tag('td')
                :addClass('quest-table-iconbox')
                 :attr('colspan', 2)
                 :attr('colspan', 2)
                :attr('style', 'text-align:center;font-size:20px;font-weight:bold;')
                 :wikitext(string.format('%s<br>[[File:%s|alt=%s]]', args.name, args.icon, args.icon))
                 :wikitext(g_args.name .. '<br>[[File:' .. g_args.icon .. '|128x128px|alt=' .. g_args.icon .. ']]')
 
   
     local rtext = 'No'
     local rtext = ''
     if args.required then
     if g_args.required then
         rtext = 'Yes'
         rtext = 'Yes'
    else
        rtext = 'No'
     end
     end
     display_quest_add_row(tbl, 'Required: ', rtext)
     create_quest_row(tbl, 'Required', rtext)
   
 
     for _, v in pairs({'Start', 'Objective', 'Completion'}) do
     for _, v in pairs({'Start', 'Objective', 'Completion'}) do
         display_quest_add_row(tbl, v .. ': ', g_args[string.lower(v)])
         create_quest_row(tbl, v, args[string.lower(v)])
     end
     end
   
 
     if type(g_args.boss) == 'number' then
     if type(args.boss) == 'number' then
         local v = {}
         local boss_links = {}
         for i=1, g_args.boss do
         for i = 1, args.boss do
             v[#v+1] = display_format_boss(tostring(i))
             boss_links[#boss_links + 1] = create_boss_link(args, tostring(i)) .. '<br>'
            v[#v+1] = '<br>'
         end
         end
         display_quest_add_row(tbl, 'Boss: ', table.concat(v))
         create_quest_row(tbl, 'Boss', table.concat(boss_links))
     elseif type(g_args.boss) == 'string' then
     elseif type(args.boss) == 'string' then
         display_quest_add_row(tbl, 'Boss: ', display_format_boss(''))
         create_quest_row(tbl, 'Boss', create_boss_link(args, ''))
     end
     end
   
 
     if g_args.key_item then
     if args.key_item then
         display_quest_add_row(tbl, 'Key Item: ', g_args.key_item)
         create_quest_row(tbl, 'Key Item ', args.key_item)
     end
     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)
     return tostring(tbl)
end
end


function args_format_boss(key)
-----
     local boss_key = 'boss' .. key
 
     local link_key = boss_key .. '_link'
------------------------------------------------------------------------------------------------------
     local image_key = boss_key .. '_image'
-- Template: Quest list
     if g_args[boss_key] == nil then
 
        error('Multiple bosses, but ' .. boss_key .. ' is empty')
p.quest_list = function(frame)
    local args = getArgs(frame, {parentOnly = true})
     -- local frame = util.misc.get_frame(frame)
 
    -- test args
     -- = p.quest_list({'Lost in Love', 'A Fixture of Fate', 'Sceptre of God (quest)', 'The Shaper (quest)'})
 
     local tbl = mw.html.create('table')
    tbl:cssText('margin: 0 auto; text-align: center;')
 
    -- image row
 
     local image_row = tbl:tag('tr'):tag('td')
 
    local len = util.table.length(args)
    if len > 1 then
      image_row:attr('colspan', len * 2 - 1)
     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)
    for i, v in ipairs(args) do
    local boss_key = 'boss' .. key
        local s = string.gsub(v, ' %(quest%)', '')
    local v = {}
 
    -- Format the link
        if i > 1 then
    v[#v+1] = '[['
            image_row:wikitext("'''&nbsp;·&nbsp;'''")
    v[#v+1] = g_args[boss_key .. '_link']
        end
    v[#v+1] = '|'
 
    v[#v+1] = g_args[boss_key]
        image_row:wikitext(string.format('[[File:%s quest icon.png|60px|link=%s]]', s, s))
    v[#v+1] = ']]'
     end
     v[#v+1] = '<br>'
 
     -- Format the image
     -- name row
     v[#v+1] = '[[File:'
 
     v[#v+1] = g_args[boss_key .. '_image']
     local name_row = tbl:tag('tr')
    v[#v+1] = '|alt='
 
    v[#v+1] = g_args[boss_key]
     for i, v in ipairs(args) do
    v[#v+1] = ']]'
        local s = string.gsub(v, ' %(quest%)', '')
   
 
    return table.concat(v)
        if i > 1 then
end
            name_row:tag('td'):wikitext("'''·'''")
        end


function display_quest_add_row(tbl, head, content)
        name_row:tag('td'):wikitext(string.format('[[%s|%s]]', v, s))
    if content == nil then
        content = ''
     end
     end
     tbl
 
        :tag('tr')
     return tostring(tbl)
            :tag('td')
                :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

Latest revision as of 09:38, 26 August 2017

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


Lua logo

This module depends on the following other modules:

This module implements {{Quest}} and {{Quest list}}

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

local p = {}

-----

------------------------------------------------------------------------------------------------------
-- Template: Quest

p.quest = function(frame)
    local args = getArgs(frame, {parentFirst = true})
    -- local g_frame = util.misc.get_frame(frame)

    --[[ test args
    = p.quest({
        name = 'The Shaper',
        boss = 'The Shaper',
        required = 'yes',
        start = 'Meeting Zana.',
        objective = 'Find the source of the strange disturbances in Maps.',
        completion = 'Talk to Zana',
        act = 3,
    })
    ]]--

    -----

    local args_format_boss = function(args, key)
        local boss_key = 'boss' .. key
        local link_key = boss_key .. '_link'
        local image_key = boss_key .. '_image'

        if args[boss_key] == nil then
            error('Multiple bosses, but ' .. boss_key .. ' is empty')
        end

        args[link_key] = args[link_key] or args[boss_key]
        args[image_key] = args[image_key] or args[boss_key] .. '.png'

        return args
    end

    -----

    local create_boss_link = function(args, key)
        local boss_key = 'boss' .. key
        local link_key = boss_key .. '_link'
        local image_key = boss_key .. '_image'

        local link = string.format('[[%s|%s]]<br>', args[link_key], args[boss_key])
        local image = string.format('[[File:%s|alt=%s]]', args[image_key], args[boss_key])

        return link .. image
    end

    -----

    local create_quest_row = function(tbl, header, content)
        if content == nil then
            content = ''
        end
        tbl
            :tag('tr')
                :tag('th'):wikitext(header .. '&nbsp;'):done()
                :tag('td'):wikitext(content)
    end

    -----

    --
    -- Args
    --

    if args.name == nil or string.len(args.name) == 0 then
        error('Name is required')
    end

    args.icon = args.icon or args.name .. ' quest icon.png'
    args.required = util.cast.boolean(args.required)

    if args.boss then
        local n = tonumber(args.boss)
        -- The number of bosses were given
        if n then
            args.boss = n
            for i = 1, n do
                args = args_format_boss(args, tostring(i))
            end
        else
            args = args_format_boss(args, '')
        end
    end

    --
    -- Formatting
    --

    local tbl = mw.html.create('table')
    tbl
        :addClass('quest-table')
        :tag('tr')
            :tag('td')
                :addClass('quest-table-iconbox')
                :attr('colspan', 2)
                :wikitext(string.format('%s<br>[[File:%s|alt=%s]]', args.name, args.icon, args.icon))

    local rtext = 'No'
    if args.required then
        rtext = 'Yes'
    end
    create_quest_row(tbl, 'Required', rtext)

    for _, v in pairs({'Start', 'Objective', 'Completion'}) do
        create_quest_row(tbl, v, args[string.lower(v)])
    end

    if type(args.boss) == 'number' then
        local boss_links = {}
        for i = 1, args.boss do
            boss_links[#boss_links + 1] = create_boss_link(args, tostring(i)) .. '<br>'
        end
        create_quest_row(tbl, 'Boss', table.concat(boss_links))
    elseif type(args.boss) == 'string' then
        create_quest_row(tbl, 'Boss', create_boss_link(args, ''))
    end

    if args.key_item then
        create_quest_row(tbl, 'Key Item ', args.key_item)
    end

    return tostring(tbl)
end

-----

------------------------------------------------------------------------------------------------------
-- Template: Quest list

p.quest_list = function(frame)
    local args = getArgs(frame, {parentOnly = true})
    -- local frame = util.misc.get_frame(frame)

    -- test args
    -- = p.quest_list({'Lost in Love', 'A Fixture of Fate', 'Sceptre of God (quest)', 'The Shaper (quest)'})

    local tbl = mw.html.create('table')
    tbl:cssText('margin: 0 auto; text-align: center;')

    -- image row

    local image_row = tbl:tag('tr'):tag('td')

    local len = util.table.length(args)
    if len > 1 then
       image_row:attr('colspan', len * 2 - 1)
    end

    for i, v in ipairs(args) do
        local s = string.gsub(v, ' %(quest%)', '')

        if i > 1 then
            image_row:wikitext("'''&nbsp;·&nbsp;'''")
        end

        image_row:wikitext(string.format('[[File:%s quest icon.png|60px|link=%s]]', s, s))
    end

    -- name row

    local name_row = tbl:tag('tr')

    for i, v in ipairs(args) do
        local s = string.gsub(v, ' %(quest%)', '')

        if i > 1 then
            name_row:tag('td'):wikitext("'''·'''")
        end

        name_row:tag('td'):wikitext(string.format('[[%s|%s]]', v, s))
    end

    return tostring(tbl)
end

-----

return p