Module:Quest reward: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
>OmegaK2
No edit summary
>OmegaK2
No edit summary
Line 17: Line 17:
     },
     },
     messages = {
     messages = {
         storage = 'Attempted to store %s rows in "%s_rewards" table',
         storage = 'Attempted to store rows %s to %s in "%s_rewards" table',
     },
     },
}
}
Line 122: Line 122:
     -- mw.loadData has some problems...
     -- mw.loadData has some problems...
     local data = require(string.format('Module:Quest reward/data/%s', tpl_args.tbl))
     local data = require(string.format('Module:Quest reward/data/%s', tpl_args.tbl))
     for i=tpl_args.index_start or 1, tpl_args.index_end or #data do  
     local imin = tpl_args.index_start or 1
    local imax = tpl_args.index_end or #data
    for i=imin, imax or #data do  
         local row = data[i]
         local row = data[i]
         if row == nil then
         if row == nil then
Line 132: Line 134:
     end
     end
      
      
     return string.format(i18n.messages.storage, #data, tpl_args.tbl)
     return string.format(i18n.messages.storage, imin, imax, tpl_args.tbl)
end
end



Revision as of 17:26, 28 April 2018

--
-- Module for bestiary templates
--

local m_util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs

local p = {}

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

local i18n = {
    errors = {
        invalid_table = 'Invalid table selected. Valid choices are either quest or vendor',
    },
    messages = {
        storage = 'Attempted to store rows %s to %s in "%s_rewards" table',
    },
}

-- ----------------------------------------------------------------------------
-- Cargo
-- ----------------------------------------------------------------------------

local tables = {}

tables.quest_rewards = {
    table = 'quest_rewards',
    fields = {
        quest = {
            field = 'quest',
            type = 'String',
        },
        quest_id = {
            field = 'quest_id',
            type = 'Integer',
        },
        -- still needed?
        act = {
            field = 'act',
            type = 'Integer',
        },
        classes = {
            field = 'classes',
            type = 'String',
        },
        sockets = {
            field = 'sockets',
            type = 'Integer',
        },
        item_level = {
            field = 'item_level',
            type = 'Integer',
        },
        rarity = {
            field = 'rarity',
            type = 'String',
        },
        reward = {
            field = 'reward',
            type = 'Page',
        },
    },
}

tables.vendor_rewards = {
    table = 'vendor_rewards',
    fields = {
        quest = {
            field = 'quest',
            type = 'String',
        },
        quest_id = {
            field = 'quest_id',
            type = 'Integer',
        },
        act = {
            field = 'act',
            type = 'Integer',
        },
        reward = {
            field = 'reward',
            type = 'Page',
        },
        npc = {
            field = 'npc',
            type = 'String',
        },
        classes = {
            field = 'classes',
            type = 'String',
        },
    }
}

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

-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------

local p = {}

p.table_quest_rewards = m_util.cargo.declare_factory{data=tables.quest_rewards}
p.table_vendor_rewards = m_util.cargo.declare_factory{data=tables.vendor_rewards}

function p.store_data(frame)
    -- Get args
    tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)
    
    if tables[tpl_args.tbl .. '_rewards'] == nil then
        error(i18n.errors.invalid_table)
    end
    
    -- mw.loadData has some problems...
    local data = require(string.format('Module:Quest reward/data/%s', tpl_args.tbl))
    local imin = tpl_args.index_start or 1
    local imax = tpl_args.index_end or #data 
    for i=imin, imax or #data do 
        local row = data[i]
        if row == nil then
            break
        end
        -- get full table name
        row._table = tables[tpl_args.tbl .. '_rewards'].table
        m_util.cargo.store(frame, row)
    end
    
    return string.format(i18n.messages.storage, imin, imax, tpl_args.tbl)
end

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

return p