Module:Minimap
The above documentation is transcluded from Module:Minimap/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.
--
-- Module for bestiary templates
--
--local m_cargo = require('Module:Cargo')
local m_util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------
local i18n = {
errors = {
invalid_icon_size = 'The specified icon size "%s" is invalid. Only large (64), medium (32) and small (16) are supported.',
invalid_minimap_icon = 'The specified minimap icon id "%s" could not be found',
},
}
-- ----------------------------------------------------------------------------
-- Helper functions and globals
-- ----------------------------------------------------------------------------
-- Number of columns in the sprite sheet
local columns = 14
-- ----------------------------------------------------------------------------
-- Cargo tables
-- ----------------------------------------------------------------------------
--[[local tables = {}
tables.table_name = {
table = 'table_name',
order = {'id'},
fields = {
id = {
field = 'id',
type = 'String',
required = true,
},
},
}
]]
-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------
local p = {}
function p.minimap_icon(frame)
-- Get args
tpl_args = getArgs(frame, {
parentFirst = true
})
frame = m_util.misc.get_frame(frame)
local size
if tpl_args.size == 'large' or tpl_args.size == '64' then
size = 64
elseif tpl_args.size == 'medium' or tpl_args.size == '32'then
size = 32
elseif tpl_args.size == 'small' or tpl_args.size == '16' or tpl_args.size == nil then
size = 16
else
error(string.format(i18n.errors.invalid_icon_size, tpl_args.size))
end
minimap = mw.loadData('Module:Minimap/minimap_icons_lookup')
index = minimap[tpl_args.id]
if index == nil then
error(string.format(i18n.errors.invalid_minimap_icon, tostring(tpl_args.id)))
end
-- Offset for lua indexes
index = index - 1
column = index % columns
row = math.floor(index/columns)
local span = mw.html.create('span')
span
:addClass('minimap_icon')
:addClass('minimap_' .. size)
:css('background-position-x', (-1 * column * size) .. 'px')
:css('background-position-y', (-1 * row * size) .. 'px')
if tpl_args.text then
span
:addClass('tooltip-activator')
:tag('span')
:addClass('tooltip-content')
:wikitext(tpl_args.text)
end
return tostring(span)
end
-- ----------------------------------------------------------------------------
-- End
-- ----------------------------------------------------------------------------
return p