[dismiss]
The wiki is currently a work in progress. If you'd like to help out, please check the Community Portal and our getting started guide. Also, check out our sister project on poewiki.net.
Module:Quest: Difference between revisions
Jump to navigation
Jump to search
>94Connor949-gpuser m (Unless there's some particular reason for it, "Quest" in the icon names should not be capitalized.) |
>TheFrz mNo edit summary |
||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs | |||
local util = require('Module:Util') | |||
local p = {} | local p = {} | ||
local | ----- | ||
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' | |||
end | |||
----- | |||
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) | |||
end | |||
----- | |||
local display_quest_add_row = function(tbl, head, content) | |||
if content == nil then | |||
content = '' | |||
function | |||
if | |||
end | end | ||
tbl | |||
g_frame = frame | :tag('tr') | ||
:tag('th') | |||
:attr('scope', 'row') | |||
:wikitext(head) | |||
:done() | |||
:tag('td') | |||
:wikitext(content) | |||
:done() | |||
end | |||
----- | |||
------------------------------------------------------------------------------------------------------ | |||
-- Template: Quest | |||
p.quest = function(frame) | |||
local args = getArgs(frame, {parentFirst = true}) | |||
local g_frame = util.misc.get_frame(frame) | |||
-- test args | |||
-- | -- | ||
-- Args | -- Args | ||
-- | -- | ||
if | if args.name == nil or string.len(args.name) == 0 then | ||
error('Name is required') | error('Name is required') | ||
end | end | ||
args.icon = args.icon or args.name .. ' quest icon.png' | |||
if args.boss then | |||
if | local n = tonumber(args.boss) | ||
local n = tonumber( | |||
-- The number of bosses were given | -- The number of bosses were given | ||
if n then | if n then | ||
args.boss = n | |||
for i=1, n do | for i=1, n do | ||
args_format_boss(tostring(i)) | args_format_boss(args, tostring(i)) | ||
end | end | ||
else | else | ||
args_format_boss('') | 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 | |||
-- | -- | ||
-- Formatting | -- Formatting | ||
-- | -- | ||
tbl = mw.html.create('table') | local tbl = mw.html.create('table') | ||
tbl | tbl | ||
:attr('class', 'quest-table') | :attr('class', 'quest-table') | ||
Line 59: | Line 105: | ||
:attr('class', 'quest-table-iconbox') | :attr('class', 'quest-table-iconbox') | ||
:attr('colspan', 2) | :attr('colspan', 2) | ||
:wikitext( | :wikitext(string.format('%s<br>[[File:%s|alt=%s]]', args.name, args.icon, args.icon)) | ||
local rtext = '' | local rtext = '' | ||
if | if args.required then | ||
rtext = 'Yes' | rtext = 'Yes' | ||
else | else | ||
rtext = 'No' | rtext = 'No' | ||
end | end | ||
display_quest_add_row(tbl, 'Required | display_quest_add_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 | display_quest_add_row(tbl, v, args[string.lower(v)]) | ||
end | end | ||
if type( | if type(args.boss) == 'number' then | ||
local v = {} | local v = {} | ||
for i=1, | for i=1, args.boss do | ||
v[#v+1] = display_format_boss(tostring(i)) | v[#v + 1] = display_format_boss(args, tostring(i)) | ||
v[#v+1] = '<br>' | v[#v + 1] = '<br>' | ||
end | end | ||
display_quest_add_row(tbl, 'Boss | display_quest_add_row(tbl, 'Boss ', table.concat(v)) | ||
elseif type( | elseif type(args.boss) == 'string' then | ||
display_quest_add_row(tbl, 'Boss | display_quest_add_row(tbl, 'Boss ', display_format_boss(args, '')) | ||
end | end | ||
if args.key_item then | |||
display_quest_add_row(tbl, 'Key Item ', args.key_item) | |||
end | end | ||
return tostring(tbl) | |||
return | |||
end | end | ||
----- | |||
return p | return p |
Revision as of 13:17, 3 January 2017
This module implements {{Quest}}
and {{Quest list}}
The above documentation is transcluded from Module:Quest/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
local getArgs = require('Module:Arguments').getArgs
local util = require('Module:Util')
local p = {}
-----
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'
end
-----
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)
end
-----
local display_quest_add_row = function(tbl, head, content)
if content == nil then
content = ''
end
tbl
:tag('tr')
:tag('th')
:attr('scope', 'row')
:wikitext(head)
:done()
:tag('td')
:wikitext(content)
:done()
end
-----
------------------------------------------------------------------------------------------------------
-- Template: Quest
p.quest = function(frame)
local args = getArgs(frame, {parentFirst = true})
local g_frame = util.misc.get_frame(frame)
-- test args
--
-- 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'
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_format_boss(args, tostring(i))
end
else
args_format_boss(args, '')
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
--
-- 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 = ''
if 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, args[string.lower(v)])
end
if type(args.boss) == 'number' then
local v = {}
for i=1, args.boss do
v[#v + 1] = display_format_boss(args, tostring(i))
v[#v + 1] = '<br>'
end
display_quest_add_row(tbl, 'Boss ', table.concat(v))
elseif type(args.boss) == 'string' then
display_quest_add_row(tbl, 'Boss ', display_format_boss(args, ''))
end
if args.key_item then
display_quest_add_row(tbl, 'Key Item ', args.key_item)
end
return tostring(tbl)
end
-----
return p