Module:Minimap: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
>OmegaK2
(Module for the minimap icons from the game's minimap icon sprite sheet)
 
>OmegaK2
(Reference chart for the minimap icon ids)
Line 26: Line 26:
-- Number of columns in the sprite sheet
-- Number of columns in the sprite sheet
local columns = 14
local columns = 14
local x = 896
local y = 2304
local h = {}
function h.position(index)
    -- Offset for lua indexes
    index = index - 1
    column = index % columns
    row = math.floor(index/columns)
   
    return row, column
end
h.args = {}
function h.args.size(tpl_args, frame)
    local size
    if tpl_args.size == 'large' or tonumber(tpl_args.size) == 64 then
        size = 64
    elseif tpl_args.size == 'medium' or tonumber(tpl_args.size) == 32 then
        size = 32
    elseif tpl_args.size == 'small' or tonumber(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
   
    tpl_args.size = size
end


-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
Line 52: Line 81:
function p.minimap_icon(frame)
function p.minimap_icon(frame)
     -- Get args
     -- Get args
     tpl_args = getArgs(frame, {
     local tpl_args = getArgs(frame, {
         parentFirst = true
         parentFirst = true
     })
     })
     frame = m_util.misc.get_frame(frame)
     frame = m_util.misc.get_frame(frame)
      
      
     local size
     -- Validate & convert size to pixels
     if tpl_args.size == 'large' or tpl_args.size == '64' then
     h.args.size(tpl_args, frame)
        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')
     local minimap = mw.loadData('Module:Minimap/minimap_icons_lookup')
      
      
     index = minimap[tpl_args.id]
     local index = minimap[tpl_args.id]
     if index == nil then
     if index == nil then
         error(string.format(i18n.errors.invalid_minimap_icon, tostring(tpl_args.id)))
         error(string.format(i18n.errors.invalid_minimap_icon, tostring(tpl_args.id)))
     end
     end
      
      
     -- Offset for lua indexes
     local row, column = h.position(index)
    index = index - 1
    column = index % columns
    row = math.floor(index/columns)
      
      
     local span = mw.html.create('span')
     local span = mw.html.create('span')
     span
     span
         :addClass('minimap_icon')
         :addClass('minimap_icon')
         :addClass('minimap_' .. size)
         :addClass('minimap_' .. tpl_args.size)
         :css('background-position-x', (-1 * column * size) .. 'px')
         :css('background-position-x', (-1 * column * tpl_args.size) .. 'px')
         :css('background-position-y', (-1 * row * size) .. 'px')
         :css('background-position-y', (-1 * row * tpl_args.size) .. 'px')
          
          
     if tpl_args.text then
     if tpl_args.text then
Line 95: Line 113:
     end
     end
      
      
    return tostring(span)
end
-- complete chart of all the icons rather then just single icons to reference the IDs
function p.minimap_chart(frame)
    -- Get args
    local tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)
   
    -- Validate & convert size to pixels
    h.args.size(tpl_args, frame)
   
    local minimap = mw.loadData('Module:Minimap/minimap_icons')
   
    local ratio = 64/tpl_args.size
   
    local span = mw.html.create('span')
    span
        :addClass('minimap_icon')
        :addClass('minimap_grid')
        :css('width', x/ratio .. 'px')
        :css('height', y/ratio .. 'px')
        :css('background-size', string.format('%spx auto', x/ratio))
       
    for index, data in ipairs(minimap) do
        local row, column = h.position(index)
        span
            :tag('span')
                :addClass('tooltip-activator')
                :addClass('minimap_'  .. tpl_args.size)
                -- CSS also starts counting at one it seems
                :css('grid-area', string.format('%s / %s', row+1, column+1, row+1, column+1))
                --:css('top', (tpl_args.size * row) .. 'px')
                --:css('left', (tpl_args.size * column) .. 'px')
                :tag('span')
                    :addClass('tooltip-content')
                    :wikitext(data.id)
    end
       
     return tostring(span)
     return tostring(span)
end
end

Revision as of 16:28, 17 May 2020

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


This Module is used by Template:Minimap icon.

Related asset File:Minimap icons.png

--
-- 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
local x = 896
local y = 2304

local h = {}

function h.position(index)
    -- Offset for lua indexes
    index = index - 1
    column = index % columns
    row = math.floor(index/columns)
    
    return row, column
end

h.args = {}
function h.args.size(tpl_args, frame)
    local size
    if tpl_args.size == 'large' or tonumber(tpl_args.size) == 64 then
        size = 64
    elseif tpl_args.size == 'medium' or tonumber(tpl_args.size) == 32 then
        size = 32
    elseif tpl_args.size == 'small' or tonumber(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
    
    tpl_args.size = size
end

-- ----------------------------------------------------------------------------
-- 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
    local tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)
    
    -- Validate & convert size to pixels
    h.args.size(tpl_args, frame)
    
    local minimap = mw.loadData('Module:Minimap/minimap_icons_lookup')
    
    local index = minimap[tpl_args.id]
    if index == nil then
        error(string.format(i18n.errors.invalid_minimap_icon, tostring(tpl_args.id)))
    end
    
    local row, column = h.position(index)
    
    local span = mw.html.create('span')
    span
        :addClass('minimap_icon')
        :addClass('minimap_' .. tpl_args.size)
        :css('background-position-x', (-1 * column * tpl_args.size) .. 'px')
        :css('background-position-y', (-1 * row * tpl_args.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

-- complete chart of all the icons rather then just single icons to reference the IDs
function p.minimap_chart(frame)
    -- Get args
    local tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)
    
    -- Validate & convert size to pixels
    h.args.size(tpl_args, frame)
    
    local minimap = mw.loadData('Module:Minimap/minimap_icons')
    
    local ratio = 64/tpl_args.size
    
    local span = mw.html.create('span')
    span
        :addClass('minimap_icon')
        :addClass('minimap_grid')
        :css('width', x/ratio .. 'px')
        :css('height', y/ratio .. 'px')
        :css('background-size', string.format('%spx auto', x/ratio))
        
    for index, data in ipairs(minimap) do
        local row, column = h.position(index)
        span
            :tag('span')
                :addClass('tooltip-activator')
                :addClass('minimap_'  .. tpl_args.size)
                -- CSS also starts counting at one it seems
                :css('grid-area', string.format('%s / %s', row+1, column+1, row+1, column+1))
                --:css('top', (tpl_args.size * row) .. 'px')
                --:css('left', (tpl_args.size * column) .. 'px')
                :tag('span')
                    :addClass('tooltip-content')
                    :wikitext(data.id)
    end
        
    return tostring(span)
end

-- ----------------------------------------------------------------------------
-- End
-- ----------------------------------------------------------------------------

return p