Permanently protected модуль

Модуль:Atlas

Материал из Path of Exile Wiki
Перейти к: навигация, поиск
Документация модуля[просмотр] [править] [история] [очистить]

Хранит и форматирует данные, связанные с Атласом миров.

Подстраницы

--
-- Module for atlas tables and functions
--
-- Certain properties are tied to maps more closely and are handeled in Module:Item2

local m_cargo = require('Module:Cargo')
local m_util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs
local f_item_link = require('Module:Item link').item_link

local p = {}

-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------

local i18n = {
    headers = {
        region = 'Регион Атласа',
        white = 'Белые карты (T1-T5)',
        yellow = 'Жёлтые карты (T6-T10)',
        red = 'Красные карты (T11+)',
    },
}

-- ----------------------------------------------------------------------------
-- Helper functions and globals
-- ----------------------------------------------------------------------------

-- ----------------------------------------------------------------------------
-- Cargo tables
-- ----------------------------------------------------------------------------
local tables = {}

tables.atlas_regions = {
    table = 'atlas_regions',
    order = {'id', 'name'},
    fields = {
        id = {
            field = 'id',
            type = 'String',
        },
        name = {
            field = 'name',
            type = 'String',
        },
    },
}

tables.atlas_base_item_types = {
    table = 'atlas_base_item_types',
    order = {'region_id', 'tier_min', 'tier_max', 'tag', 'weight'},
    fields = {
        region_id = {
            field = 'region_id',
            type = 'String',
        },
        tier_min = {
            field = 'tier_min',
            type = 'Integer',
        },
        tier_max = {
            field = 'tier_max',
            type = 'Integer',
        },
        tag = {
            field = 'tag',
            type = 'String',
        },
        weight = {
            field = 'weight',
            type = 'Integer',
        },
        
    },
}
-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------

local p = {}

p.table_atlas_regions = m_cargo.declare_factory{data=tables.atlas_regions}
p.table_atlas_base_item_types = m_cargo.declare_factory{data=tables.atlas_base_item_types}

p.store_data = m_cargo.store_from_lua{tables=tables, module='Atlas'}

function p.atlas_base_item_types_per_region(frame)
    -- Get args
    local tpl_args = getArgs(frame, {
        parentFirst = true
    })
    local frame = m_util.misc.get_frame(frame)
    
    local query = {
        join='items._ID=items__tags._rowID, items__tags._value=atlas_base_item_types.tag, atlas_base_item_types.region_id=atlas_regions.id',
        where='atlas_regions.id IS NOT NULL AND items.rarity_id="normal"',
        orderBy='atlas_regions.name ASC, atlas_base_item_types.tier_min ASC, items.name ASC',
    }
    
    if tpl_args.where then
        query.where = string.format('%s AND (%s)', query.where, tpl_args.where)
    end
    
    local results=m_cargo.query(
        {
            'items',
            'items__tags',
            'atlas_base_item_types', 
            'atlas_regions', 
        },
        {
            'atlas_regions.name',
            'atlas_base_item_types.tier_min',
            'atlas_base_item_types.tier_max',
            'items.name',
            'items._pageName',
            'items.inventory_icon',
            'items.html',
        },
        query
    )
    
    local tbl = mw.html.create('table')
    tbl
        :attr('class', 'wikitable sortable')
        :tag('tr')
            :tag('th')
                :wikitext(i18n.headers.region)
                :done()
            :tag('th')
                :wikitext(i18n.headers.white)
                :done()
            :tag('th')
                :wikitext(i18n.headers.yellow)
                :done()
            :tag('th')
                :wikitext(i18n.headers.red)
                :done()
    
    local lastrow
    
    local regions_order = {}
    local regions = {}
    local tiers = {
        [1] = 5,
        [6] = 10,
        [11] = 16,
    }
    
    for _, row in ipairs(results) do
        local region = regions[row['atlas_regions.name']]
        if region == nil then
            table.insert(regions_order, row['atlas_regions.name'])
            regions[row['atlas_regions.name']] = {
                [1] = {},
                [6] = {},
                [11] = {},
            }
            region = regions[row['atlas_regions.name']]
        end
        
        for tier, items in pairs(region) do
            if tonumber(row['atlas_base_item_types.tier_min']) <= tier and tonumber(row['atlas_base_item_types.tier_max']) >= tiers[tier] then
                -- I use pageName here because I think it makes it easier to tell which boots are which as opposed to hovering over them or the tiny icons
                table.insert(items, f_item_link{page=row['items._pageName'], name=row['items._pageName'], inventory_icon=row['items.inventory_icon'] or '', html=row['items.html'] or '', skip_query=true})
            end
        end
    end
    
    for _, region_name in ipairs(regions_order) do
        local region = regions[region_name]
        local tr = tbl:tag('tr')
        tr
            :tag('td')
                :wikitext(string.format('[[%s]]', region_name))
                :done()
        for _, tier in ipairs({1, 6, 11}) do
            tr
                :tag('td')
                    :wikitext(table.concat(region[tier], '<br>') or '&nbsp;')
                    :done()
        end
    end
    
    return tostring(tbl)
end

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

return p