Module:Quest: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
>OmegaK2
(Module for quest pages)
 
>OmegaK2
No edit summary
Line 8: Line 8:


--
--
-- Implements Template:Quest
-- For Template:Quest
--
--
function p.quest(frame)
function p.quest_infobox(frame)
     g_args = getArgs(frame, {
     g_args = getArgs(frame, {
parentFirst = true
parentFirst = true
Line 45: Line 45:
     -- Formatting
     -- Formatting
     --
     --
   
    out = {}
    out[#out+1] = '__TOC__\n'
      
      
     tbl = mw.html.create('table')
     tbl = mw.html.create('table')
Line 71: Line 68:
      
      
     if g_args.boss then
     if g_args.boss then
         v = {}
         v = '[[' .. g_args.boss .. ']]<br>[[File:' .. g_args.boss_image .. '|alt=' .. g_args.boss .. ']]'
        v[#v+1] = '[['
         display_quest_add_row(tbl, 'Boss: ', v)
        v[#v+1] = g_args.boss
        v[#v+1] = ']]<br>[[File:'
        v[#v+1] = g_args.boss_image
        v[#v+1] = '|alt='
        v[#v+1] = g_args.boss
        v[#v+1] = ']]'
         display_quest_add_row(tbl, 'Boss: ', table.concat(v))
     end
     end
      
      
Line 86: Line 76:
     end
     end
      
      
     out[#out+1] = tostring(tbl)
     return tostring(tbl)
    out[#out+1] = '==Walkthough==\n\n'
    if string.len(g_args.walkthough) == 0 then
        out[#out+1] = 'No walkthough yet, you can help by adding it.\n\n'
    else
        out[#out+1] = g_args.walkthough
    end
       
    local rewards = show_reward{data_type='default', show_empty_message=False, filter_by_quest=g_args.name}
    if string.len(rewards) > 0 then
        out[#out+1] = '==Quest rewards==\n\n'
        out[#out+1] = rewards
        out[#out+1] = '\n'
    end
   
    local rewards = show_reward{data_type='vendor', show_empty_message=False, filter_by_quest=g_args.name}
    if string.len(rewards) > 0 then
        out[#out+1] = '==Vendor rewards==\n\n'
        out[#out+1] = rewards
        out[#out+1] = '\n'
    end
       
    out[#out+1] = '[[Category: Quests]]\n'
    if g_args.act then
        out[#out+1] = '[[Category: Act ' .. g_args.act .. 'quests]]\n'
    end
   
    return table.concat(out)
end
end


Line 120: Line 83:
         content = ''
         content = ''
     end
     end
     tbl:tag('tr')
     tbl
        :tag('td')
        :tag('tr')
            :attr('style', 'text-align: right; font-weight: bold; background-color: #332f24;')
            :tag('td')
            :attr('scope', 'row')
                :attr('style', 'text-align: right; font-weight: bold; background-color: #332f24;')
            :wikitext(head)
                :attr('scope', 'row')
        :tag('td')
                :wikitext(head)
            :attr('style', 'text-align: center; background-color: #26231b;')
                :done()
            :wikitext(content)
            :tag('td')
                :attr('style', 'text-align: center; background-color: #26231b;')
                :wikitext(content)
                :done()
end
end


return p
return p

Revision as of 15:39, 9 July 2015

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


Lua logo

This module depends on the following other modules:

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

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_infobox(frame)
    g_args = getArgs(frame, {
		parentFirst = true
	})
    if frame == nil or type(frame) == 'table' then
        frame = mw.getCurrentFrame()
    end
    
    g_frame = frame
    
    --
    -- Args
    --
    
    if string.len(g_args.name) == 0 then
        error('Name is required')
    end
    
    g_args.page_name = g_args.page_name or g_args.name
    g_args.icon = g_args.icon or g_args.name .. ' Quest icon.png'
    g_args.boss = g_args.boss
    if g_args.boss then
        g_args.boss_image = g_args.boss_image or g_args.boss .. ' Ingame.jpg'
    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
    g_args.act = g_args.act
    g_args.walkthough = g_args.walkthough or ''
    
    --
    -- Formatting
    --
    
    tbl = mw.html.create('table')
    tbl
        :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 g_args.boss then
        v = '[[' .. g_args.boss .. ']]<br>[[File:' .. g_args.boss_image .. '|alt=' .. g_args.boss .. ']]'
        display_quest_add_row(tbl, 'Boss: ', v)
    end
    
    if g_args.key_item then
        display_quest_add_row(tbl, 'Key Item: ', g_frame.expandTemplate('il', g_args.key_item))
    end
    
    return tostring(tbl)
end

function display_quest_add_row(tbl, head, content)
    if content == nil then
        content = ''
    end
    tbl
        :tag('tr')
            :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

return p