Module:Trailblazer Region
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Trailblazer Region/doc. [edit]
Module:Trailblazer Region is invoked by
.Module:Trailblazer Region is required by Module:Sandbox.
Module:Trailblazer Region is required by Module:Sandbox/User:Towelcat/TrailblazerQuestLine.
local p = {}
local lang = mw.getContentLanguage()
local regions = {
misthalin = true,
karamja = true,
asgarnia = true,
desert = true,
fremennik = true,
kandarin = true,
morytania = true,
tirannwn = true,
wilderness = true,
kourend = true,
varlamore = true,
}
function p._main(region, note, link, global_highlight, league)
if region == nil or string.lower(region) == "no" then
return "None"
end
local ret = {}
for value in string.gmatch(region, "[^,]+") do
-- Ampersand regions will always just show badges without text
if string.find(value, "&") then
local badge_result = p._badge(value, note, link, global_highlight, league)
table.insert(ret, badge_result)
else
local lower = string.lower(value)
local trimmed = lower:gsub("^%s*(.-)%s*$", "%1")
if regions[trimmed] then
local uc_region = lang:ucfirst(trimmed)
local icon = p._icon(trimmed, note, link, league)
local text
if link == nil or link ~= 'false' then
text = string.format('<span class="tbz-name">[[%s/Areas/%s|%s]]</span>', league, uc_region, uc_region)
else
text = uc_region
end
local cur_ret = highlight(string.format('%s %s', icon, text), uc_region, global_highlight)
table.insert(ret, cur_ret)
else
table.insert(ret, value)
end
end
end
return table.concat(ret, '')
end
function highlight(s, r, global_highlight)
r = string.lower(r)
local highlight_class = ""
if global_highlight ~= nil and global_highlight == 'false' then
highlight_class = "tbz-no-global"
end
return string.format('<span class="tbz-region %s" data-tbz-area="%s">%s<span class="tbz-check">✓</span></span>', highlight_class, r, s)
end
function p._icon(region, note, link, league)
if string.lower(region or '') == "no" then
return ""
else
region = lang:ucfirst(region)
end
if note == nil then
note = region
end
local label
if link == nil or link ~= 'false' then
label = string.format('%s/Areas/%s', league, region)
else
label = ''
end
return string.format('[[File:%s Area Badge.png|%s|link=%s]]', region, note, label)
end
function p._badge(region, note, link, global_highlight, league)
if region == nil or string.lower(region) == "no" then
return ""
end
local highlight_class = ""
if global_highlight ~= nil and global_highlight == 'false' then
highlight_class = "tbz-no-global"
end
local ret = {}
for value in string.gmatch(region, "[^,]+") do
local lower = string.lower(value)
-- Ampersand regions wrapped in additional badge span
if string.find(lower, '&') then
local ampersandRegions = {}
local ampersandBadges = {}
for curRegion in string.gmatch(lower, "[^&]+") do
curRegion = curRegion:gsub("^%s*(.-)%s*$", "%1")
if regions[curRegion] then
table.insert(ampersandRegions, curRegion)
local icon = p._icon(curRegion, note, link, league)
local cur_badge = string.format('<span class="tbz-badge %s" data-tbz-area="%s">%s</span>', highlight_class, curRegion, icon)
table.insert(ampersandBadges, cur_badge)
end
end
local ampersandString = table.concat(ampersandRegions, '&')
local innerBadgesString = table.concat(ampersandBadges, '&')
local cur_ret = string.format('<span class="tbz-badge tbz-badge-wrapper %s" data-tbz-area="%s">%s</span>', highlight_class, ampersandString, innerBadgesString)
table.insert(ret, cur_ret)
else
local trimmed = lower:gsub("^%s*(.-)%s*$", "%1")
if regions[trimmed] then
local icon = p._icon(trimmed, note, link, league)
local cur_ret = string.format('<span class="tbz-badge %s" data-tbz-area="%s">%s</span>', highlight_class, trimmed, icon)
table.insert(ret, cur_ret)
else
table.insert(ret, value)
end
end
end
return table.concat(ret, '')
end
function p._highlightedIcon(region, note, link, global_highlight, league)
return highlight(p._icon(region, note, link, league), region, global_highlight)
end
function p.main(frame)
local args = frame:getParent().args
local region = args[1]
local note = args.note
local link = args.link
local global_highlight = args.global_highlight
local frameargs = frame.args
local league = frameargs.league
return p._main(region, note, link, global_highlight, league)
end
function p.highlightedIcon(frame)
local args = frame:getParent().args
local region = args[1]
local note = args.note
local link = args.link
local global_highlight = args.global_highlight
local frameargs = frame.args
local league = frameargs.league
return p._highlightedIcon(region, note, link, global_highlight, league)
end
function p.icon(frame)
local args = frame:getParent().args
local region = args[1]
local note = args.note
local link = args.link
local frameargs = frame.args
local league = frameargs.league
return p._icon(region, note, link, league)
end
function p.badge(frame)
local args = frame:getParent().args
local region = args[1]
local note = args.note
local link = args.link
local global_highlight = args.global_highlight
local frameargs = frame.args
local league = frameargs.league
return p._badge(region, note, link, global_highlight, league)
end
return p