This module depends on the following other modules: |
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 = {}
-----
------------------------------------------------------------------------------------------------------
-- 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 .. ' '):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("''' · '''")
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