Module:Quest: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
>TheFrz
mNo edit summary
>TheFrz
mNo edit summary
Line 6: Line 6:
-----
-----


local args_format_boss = function(args, key)
------------------------------------------------------------------------------------------------------
    local boss_key = 'boss' .. key
-- Template: Quest
    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'
end


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


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


     return table.concat(v)
     local args_format_boss = function(args, key)
end
        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


local display_quest_add_row = function(tbl, head, content)
        args[link_key] = args[link_key] or args[boss_key]
    if content == nil then
         args[image_key] = args[image_key] or args[boss_key] .. '.png'
         content = ''
       
        return args
     end
     end
    tbl
        :tag('tr')
            :tag('th')
                :attr('scope', 'row')
                :wikitext(head)
                :done()
            :tag('td')
                :wikitext(content)
                :done()
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


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


p.quest = function(frame)
    local create_quest_row = function(tbl, head, content)
    local args = getArgs(frame, {parentFirst = true})
        if content == nil then
    local g_frame = util.misc.get_frame(frame)
            content = ''
        end
        tbl
            :tag('tr')
                :tag('th'):wikitext(head):done()
                :tag('td'):wikitext(content)
    end


     -- test args
     -----


     --
     --
Line 76: Line 66:


     args.icon = args.icon or args.name .. ' quest icon.png'
     args.icon = args.icon or args.name .. ' quest icon.png'
    args.required = util.cast.boolean(args.required)
     if args.boss then
     if args.boss then
         local n = tonumber(args.boss)
         local n = tonumber(args.boss)
Line 81: Line 73:
         if n then
         if n then
             args.boss = n
             args.boss = n
             for i=1, n do
             for i = 1, n do
                 args_format_boss(args, tostring(i))
                 args = args_format_boss(args, tostring(i))
             end
             end
         else
         else
             args_format_boss(args, '')
             args = args_format_boss(args, '')
         end
         end
     end
     end
    args.key_item = args.key_item
    args.required = util.cast.boolean(args.required)
    args.start = args.start
    args.objective = args.objective
    args.completion = args.completion


     --
     --
Line 107: Line 94:
                 :wikitext(string.format('%s<br>[[File:%s|alt=%s]]', args.name, args.icon, args.icon))
                 :wikitext(string.format('%s<br>[[File:%s|alt=%s]]', args.name, args.icon, args.icon))


     local rtext = ''
     local rtext = 'No'
     if args.required then
     if args.required then
         rtext = 'Yes'
         rtext = 'Yes'
    else
        rtext = 'No'
     end
     end
     display_quest_add_row(tbl, 'Required ', rtext)
     create_quest_row(tbl, 'Required&nbsp;', rtext)


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


     if type(args.boss) == 'number' then
     if type(args.boss) == 'number' then
         local v = {}
         local boss_links = {}
         for i=1, args.boss do
         for i = 1, args.boss do
             v[#v + 1] = display_format_boss(args, 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&nbsp;', table.concat(boss_links))
     elseif type(args.boss) == 'string' then
     elseif type(args.boss) == 'string' then
         display_quest_add_row(tbl, 'Boss ', display_format_boss(args, ''))
         create_quest_row(tbl, 'Boss&nbsp;', create_boss_link(args, ''))
     end
     end


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



Revision as of 13:38, 3 January 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)

    -----

    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, head, content)
        if content == nil then
            content = ''
        end
        tbl
            :tag('tr')
                :tag('th'):wikitext(head):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
        :attr('class', 'quest-table')
        :tag('tr')
            :tag('td')
                :attr('class', '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&nbsp;', rtext)

    for _, v in pairs({'Start&nbsp;', 'Objective&nbsp;', 'Completion&nbsp;'}) 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&nbsp;', table.concat(boss_links))
    elseif type(args.boss) == 'string' then
        create_quest_row(tbl, 'Boss&nbsp;', create_boss_link(args, ''))
    end

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

    return tostring(tbl)
end

-----

return p