Module:Harvest/sandbox

From Path of Exile Wiki
Jump to navigation Jump to search

This is the module sandbox page for Module:Harvest (diff).

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


Lua logo

This module depends on the following other modules:

Store Harvest related data

Subpages

No results


-------------------------------------------------------------------------------
-- 
--                              Module:Harvest
-- 
-- This module implements Template:Harvest crafting options
-------------------------------------------------------------------------------

require('Module:No globals')
local m_util = require('Module:Util')
local m_cargo = require('Module:Cargo')

-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('Harvest')

-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:Harvest/config/sandbox') or mw.loadData('Module:Harvest/config')

local i18n = cfg.i18n

-- ----------------------------------------------------------------------------
-- Cargo tables
-- ----------------------------------------------------------------------------

local tables = {}

tables.harvest_crafting_options = {
    table = 'harvest_crafting_options',
    fields = {
        ordinal = {
            field = 'ordinal',
            type = 'Integer',
        },
        id = {
            field = 'id',
            type = 'String',
        },
        effect = {
            field = 'effect',
            type = 'Text',
        },
        effect_html = {
            field = 'effect_html',
            type = 'Text',
        },
        cost_wild = {
            field = 'cost_wild',
            type = 'Integer',
        },
        cost_vivid = {
            field = 'cost_vivid',
            type = 'Integer',
        },
        cost_primal = {
            field = 'cost_primal',
            type = 'Integer',
        },
        cost_sacred = {
            field = 'cost_sacred',
            type = 'Integer',
        },
    },
}

-- ----------------------------------------------------------------------------
-- Data
-- ----------------------------------------------------------------------------

local data = {}

data.crafting_options_table = {
    {
        field = 'effect_html',
        header = i18n.crafting_options.effect,
    },
    {
        field = 'cost_wild',
        header = i18n.crafting_options.wild,
    },
    {
        field = 'cost_vivid',
        header = i18n.crafting_options.vivid,
    },
    {
        field = 'cost_primal',
        header = i18n.crafting_options.primal,
    },
    {
        field = 'cost_sacred',
        header = i18n.crafting_options.sacred,
    },
}

-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------

local function _crafting_options(tpl_args)
    local tbl = mw.html.create('table')
    tbl
        :addClass('wikitable sortable harvest-crafting-options-table')
    local tblhead = tbl:tag('tr')
    for _, tmap in ipairs(data.crafting_options_table) do
        tblhead
            :tag('th')
                :wikitext(tmap.header)
                :done()
    end
    local results = m_cargo.query(
        {tables.harvest_crafting_options.table},
        m_util.table.column(data.crafting_options_table, 'field'),
        {
            orderBy = 'ordinal ASC',
        }
    )
    local tblrow
    for _, row in ipairs(results) do
        tblrow = tbl:tag('tr')
        for _, tmap in ipairs(data.crafting_options_table) do
            tblrow
                :tag('td')
                    :wikitext(row[tmap.field])
                    :done()
        end
    end
    return tostring(tbl)
end

-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------

local p = {}

p.table_harvest_crafting_options = m_cargo.declare_factory{data=tables.harvest_crafting_options}
p.store_data = m_cargo.store_from_lua{tables=tables, module='Harvest'}

-- 
-- Template:Harvest crafting options
-- 
p.crafting_options = m_util.misc.invoker_factory(_crafting_options, {
    wrappers = cfg.wrappers.crafting_options,
})

return p