Neverwinter Wiki
Advertisement

Для документации этого модуля может быть создана страница Модуль:Recipe table/doc

local itemIcon = require('Модуль:Item_icon')

local p = {}

local professions = {
    ['алхимия'] = '[[Файл:Crafting_Profession_Alchemy.png|20px|ссылка=Алхимия]]',
    ['ковка доспехов'] = '[[Файл:Crafting_Profession_Hvyarmoring.png|20px|ссылка=Ковка доспехов]]',
    ['кройка и шитье'] = '[[Файл:Crafting_Profession_Tailoring.png|20px|ссылка=Кройка и шитье]]',
    ['кузнечное дело'] = '[[Файл:Crafting_Profession_Weaponsmithing.png|20px|ссылка=Кузнечное дело]]',
    ['нанесение узоров'] = '[[Файл:Crafting_Profession_Artificing.png|20px|ссылка=Нанесение узоров]]',
    ['обработка кожи'] = '[[Файл:Crafting_Profession_Leatherworking.png|20px|ссылка=Обработка кожи]]',
    ['ювелирное дело']  = '[[Файл:Crafting_Profession_Jewelcrafting.png|20px|ссылка=Ювелирное дело]]'
}

function p.Main( frame )
    local cargo = mw.ext.cargo
    tables = 'Recipes'
    fields = '_pageName,source,quantity,professions,level,material1_quantity,material1_item,material2_quantity,material2_item,material3_quantity,material3_item,material4_quantity,material4_item,material5_quantity,material5_item,_pageID,type'
    local args = {
        where='professions HOLDS LIKE "%' .. frame.args['профессия'] .. '%"',
        orderBy = 'level, _pageName',
    }
	if frame.args['тип'] ~= '' then
        args.where = args.where .. ' AND type = "' .. frame.args['тип'] .. '"'
    elseif frame.args['источник'] ~= "" then 
    	args.where = args.where .. ' AND source = "' .. frame.args['источник'] .. '"'
    end
    local result = cargo.query( tables, fields, args)
    local r = result[1]

    --Start the table
    local tbl = mw.html.create('table')
	tbl:addClass('wikitable sortable filter-table jquery-tablesorter')
		tbl:tag("th"):attr('style', 'width: 210px'):wikitext("Предмет"):done()
		tbl:tag("th"):attr('style', 'width: 100px'):wikitext("Профессия(и)"):done()
        tbl:tag("th"):attr('style', 'width: 40px'):wikitext("Уровень"):done()
        tbl:tag("th"):attr('style', 'width: 140px'):wikitext("Результирующее кол-во"):done()
        tbl:tag("th"):attr('style', 'min-width: 300px'):wikitext("Материалы"):done()
	tbl:done()
         --Construct the rows in the table
	for _,row in ipairs(result) do
		tr = tbl:tag("tr"):attr('class', 'simpleCraftCalcRecipeBase')
        	tr:tag("td"):wikitext(itemIcon.Main({args={row._pageName,""}})):done()

			local text = {}
            for i in mw.text.gsplit(row.professions, ",%s*") do
				table.insert(text, professions[i])
			end
            
            tr:tag("td"):attr('style', 'text-align: center'):wikitext(table.concat(text,' ')):done()
            tr:tag("td"):attr('style', 'text-align: center'):wikitext(row.level):done()

            local craftResultCount = tonumber(row.quantity)
            if craftResultCount > 0 then  
                craftResultCount = row.quantity
            else
                craftResultCount = 1
            end
            
			tr:tag("td"):wikitext('<span class="simpleCraftCalcResultCount" data-initial-count="'.. craftResultCount .. '">' .. craftResultCount .. '</span>'):done()
			
			if row.material5_item ~= "" then
				tr:tag("td"):wikitext('<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material1_item,""}}) .. '</dd>' .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material2_quantity .. '">' .. row.material2_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material2_item,""}}) .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material3_quantity .. '">' .. row.material3_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material3_item,""}}) .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material4_quantity .. '">' .. row.material4_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material4_item,""}}) .. '</dd><div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material5_quantity .. '">' .. row.material5_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material5_item,""}}) .. '</dd></div>'):done()
			elseif row.material4_item ~= "" then
				tr:tag("td"):wikitext('<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material1_item,""}}) .. '</dd>' .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material2_quantity .. '">' .. row.material2_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material2_item,""}}) .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material3_quantity .. '">' .. row.material3_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material3_item,""}}) .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material4_quantity .. '">' .. row.material4_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material4_item,""}}) .. '</dd></div>'):done()
			elseif row.material3_item ~= "" then
				tr:tag("td"):wikitext('<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material1_item,""}}) .. '</dd>' .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material2_quantity .. '">' .. row.material2_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material2_item,""}}) .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material3_quantity .. '">' .. row.material3_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material3_item,""}}) .. '</dd></div>'):done()
			elseif row.material2_item ~= "" then
				tr:tag("td"):wikitext('<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material1_item,""}}) .. '</dd>' .. '<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material2_quantity .. '">' .. row.material2_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material2_item,""}}) .. '</dd></div>'):done()
			elseif row.material1_item ~= "" then
				tr:tag("td"):wikitext('<div class="ingredients"><dt><span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span></dt><dd>' .. itemIcon.Main({args={row.material1_item,""}}) .. '</dd></div>'):done()
			end
		end
	return tbl
end
return p
Advertisement