Neverwinter Wiki
мНет описания правки
мНет описания правки
 
(не показано 57 промежуточных версий этого же участника)
Строка 1: Строка 1:
local utf8 = require('Модуль:Utf8')
+
local item_icon = require('Модуль:Item_icon')
local itemIcon = require('Модуль:Item_icon')
 
   
 
local p = {}
 
local p = {}
local cargo = mw.ext.cargo
 
   
 
local professions = {
 
local professions = {
['Алхимия'] = '[[Файл:Crafting_Profession_Alchemy.png|20px|ссылка=Алхимия]]',
 
 
['алхимия'] = '[[Файл:Crafting_Profession_Alchemy.png|20px|ссылка=Алхимия]]',
 
['алхимия'] = '[[Файл:Crafting_Profession_Alchemy.png|20px|ссылка=Алхимия]]',
['Ковкадоспехов'] = '[[Файл:Crafting_Profession_Hvyarmoring.png|20px|ссылка=Ковка доспехов]]',
+
['ковка доспехов'] = '[[Файл:Crafting_Profession_Hvyarmoring.png|20px|ссылка=Ковка доспехов]]',
['ковкадоспехов'] = '[[Файл:Crafting_Profession_Hvyarmoring.png|20px|ссылка=Ковка доспехов]]',
+
['кройка и шитье'] = '[[Файл:Crafting_Profession_Tailoring.png|20px|ссылка=Кройка и шитье]]',
['Кройкаишитье'] = '[[Файл:Crafting_Profession_Tailoring.png|20px|ссылка=Кройка и шитье]]',
+
['кузнечное дело'] = '[[Файл:Crafting_Profession_Weaponsmithing.png|20px|ссылка=Кузнечное дело]]',
['кройкаишитье'] = '[[Файл:Crafting_Profession_Tailoring.png|20px|ссылка=Кройка и шитье]]',
+
['нанесение узоров'] = '[[Файл:Crafting_Profession_Artificing.png|20px|ссылка=Нанесение узоров]]',
['Кузнечноедело'] = '[[Файл:Crafting_Profession_Weaponsmithing.png|20px|ссылка=Кузнечное дело]]',
+
['обработка кожи'] = '[[Файл:Crafting_Profession_Leatherworking.png|20px|ссылка=Обработка кожи]]',
['кузнечноедело'] = '[[Файл:Crafting_Profession_Weaponsmithing.png|20px|ссылка=Кузнечное дело]]',
+
['ювелирное дело'] = '[[Файл:Crafting_Profession_Jewelcrafting.png|20px|ссылка=Ювелирное дело]]'
['Нанесениеузоров'] = '[[Файл:Crafting_Profession_Artificing.png|20px|ссылка=Нанесение узоров]]',
 
['нанесениеузоров'] = '[[Файл:Crafting_Profession_Artificing.png|20px|ссылка=Нанесение узоров]]',
 
['Обработкакожи'] = '[[Файл:Crafting_Profession_Leatherworking.png|20px|ссылка=Обработка кожи]]',
 
['обработкакожи'] = '[[Файл:Crafting_Profession_Leatherworking.png|20px|ссылка=Обработка кожи]]',
 
['Ювелирноедело'] = '[[Файл:Crafting_Profession_Jewelcrafting.png|20px|ссылка=Ювелирное дело]]',
 
['ювелирноедело'] = '[[Файл:Crafting_Profession_Jewelcrafting.png|20px|ссылка=Ювелирное дело]]'
 
 
}
 
}
   
 
function p.Main( frame )
 
function p.Main( frame )
local args = frame.args
+
local cargo = mw.ext.cargo
local fieldstable = {
+
tables = 'Recipes'
  +
fields = '_pageName, name, source,quantity,professions,level,material1_quantity,material1_item,material2_quantity,material2_item,material3_quantity,material3_item,material4_quantity,material4_item,material5_quantity,material5_item'
"_pageName",
 
"source",
+
local args = {
 
where = 'material1_item = "' .. frame.args[1] .. '" OR material2_item = "' .. frame.args[1] .. '" OR material3_item = "' .. frame.args[1] .. '" OR material4_item = "' .. frame.args[1] .. '" OR material5_item = "' .. frame.args[1] .. '"',
"quantity",
 
"professions",
+
orderBy = 'level, _pageName',
"level",
+
}
 
local result = cargo.query( tables, fields, args )
"material1_quantity",
 
"material1_item",
 
"material2_quantity",
 
"material2_item",
 
"material3_quantity",
 
"material3_item",
 
"material4_quantity",
 
"material4_item",
 
"material5_quantity",
 
"material5_item",
 
}
 
local tables = 'Recipes'
 
local fields = table.concat(fieldstable,",")
 
-- optional parameters are grouped in one table
 
-- you can omit any or all of them, except joinOn if you use more than one table
 
 
local cargoquery = { where='material1_item = "' .. frame.args[1] .. '" OR material2_item = "' .. frame.args[1] .. '" OR material3_item = "' .. frame.args[1] .. '" OR material4_item = "' .. frame.args[1] .. '" OR material5_item = "' .. frame.args[1] .. '"'
 
, groupBy = "_pageName" , orderBy = level}
 
 
local result = mw.ext.cargo.query( tables, fields, cargoquery )
 
 
local r = result[1]
 
local r = result[1]
   
Строка 56: Строка 28:
   
 
tbl:addClass('wikitable')
 
tbl:addClass('wikitable')
tbl:tag("th"):attr('style', 'width: 210px'):wikitext("Предмет"):done()
+
tbl:tag("th"):attr('style', 'width:25em'):wikitext("Предмет"):done()
 
tbl:tag("th"):attr('style', 'width: 100px'):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: 40px'):wikitext("Уровень"):done()
 
tbl:tag("th"):attr('style', 'width: 140px'):wikitext("Результирующее кол-во"):done()
 
tbl:tag("th"):attr('style', 'width: 140px'):wikitext("Результирующее кол-во"):done()
tbl:tag("th"):attr('style', 'min-width: 300px'):wikitext("Материалы"):done()
+
tbl:tag("th"):attr('style', 'min-width:25em'):wikitext("Материалы"):done()
 
tbl:done()
 
tbl:done()
 
--Construct the rows in the table
 
--Construct the rows in the table
for _,row in ipairs(result) do
+
for _, row in ipairs(result) do
tr = tbl:tag("tr")
+
tr = tbl:tag("tr"):attr('class', 'simpleCraftCalcRecipeBase')
tr = tbl:add('class', 'simpleCraftCalcRecipeBase')
 
tr:tag("td"):wikitext(itemIcon.Main({args={row._pageName,""}})):done()
 
   
local str1 = row.professions
+
local str1 = string.gsub(str1, "%s+", "")
+
local source = {}
  +
if row.source then
  +
for name in mw.text.gsplit(row.source, ",%s*") do
  +
table.insert(source, item_icon.Main({args={name, ""}}))
 
end
 
end
   
  +
tr:tag("td"):wikitext((row.name and item_icon.Main({args={row.name, ""}}) or '') .. (row.source and '<br><small>(Изучается из: ' .. table.concat(source, ',<br>') ..')</small>' or '')):done()
local insigniaBonuses = {}
 
  +
for i in string.gmatch(str1, "[^%p%d%s%c]+") do
 
 
local text = {}
table.insert(insigniaBonuses , professions[i])
 
  +
for i in mw.text.gsplit(row.professions, ",%s*") do
 
table.insert(text, professions[mw.ustring.lower(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 resulting_craft_count = tonumber(row.quantity) > 0 and tonumber(row.quantity) or 1
  +
 
tr:tag("td"):wikitext('<span class="simpleCraftCalcResultCount" data-initial-count="'.. resulting_craft_count .. '">' .. resulting_craft_count .. '</span>'):done()
 
  +
local ingredients = {}
  +
for i = 1, 5 do
  +
local item = row['material'..i..'_item']
  +
local quantity = row['material'..i..'_quantity']
  +
if item ~= nil then
  +
table.insert(ingredients, '<div><span class="simpleCraftCalcIngredientCount" style="padding-right: 3px;" data-initial-count="'.. quantity .. '">' .. quantity .. '</span> ' .. item_icon.Main({args={item, ""}}) .. '</div>')
 
end
 
end
  +
end
tr:tag("td"):attr('style', 'text-align: center'):wikitext(table.concat(insigniaBonuses,' ')):done()
 
tr:tag("td"):attr('style', 'text-align: center'):wikitext(row.level):done()
+
tr:tag("td"):wikitext(table.concat(ingredients, '\n'))
  +
tr:tag("td"):wikitext():done()
 
 
if row.material5_item ~= "" then
 
tr:tag("td"):wikitext('<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material1_item,""}}) .. '\n' .. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material2_quantity .. '">' .. row.material2_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material2_item,""}}) .. '\n' .. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material3_quantity .. '">' .. row.material3_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material3_item,""}}) .. '\n'.. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material4_quantity .. '">' .. row.material4_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material4_item,""}}) .. '\n'.. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material5_quantity .. '">' .. row.material5_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material5_item,""}})):done()
 
elseif row.material4_item ~= "" then
 
tr:tag("td"):wikitext('<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material1_item,""}}) .. '\n' .. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material2_quantity .. '">' .. row.material2_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material2_item,""}}) .. '\n' .. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material3_quantity .. '">' .. row.material3_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material3_item,""}}) .. '\n'.. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material4_quantity .. '">' .. row.material4_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material4_item,""}})):done()
 
elseif row.material3_item ~= "" then
 
tr:tag("td"):wikitext('<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material1_item,""}}) .. '\n' .. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material2_quantity .. '">' .. row.material2_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material2_item,""}}) .. '\n' .. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material3_quantity .. '">' .. row.material3_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material3_item,""}})):done()
 
elseif row.material2_item ~= "" then
 
tr:tag("td"):wikitext('<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material1_item,""}}) .. '\n' .. '<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material2_quantity .. '">' .. row.material2_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material2_item,""}})):done()
 
elseif row.material1_item ~= "" then
 
tr:tag("td"):wikitext('<span class="simpleCraftCalcIngredientCount" data-initial-count="'.. row.material1_quantity .. '">' .. row.material1_quantity .. '</span>' .. ' ' .. itemIcon.Main({args={row.material1_item,""}})):done()
 
end
 
 
end
 
end
 
return tbl
 
return tbl

Текущая версия от 12:00, 7 июля 2023

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

local item_icon = 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, name, source,quantity,professions,level,material1_quantity,material1_item,material2_quantity,material2_item,material3_quantity,material3_item,material4_quantity,material4_item,material5_quantity,material5_item'
    local args = {
        where   = 'material1_item = "' .. frame.args[1] .. '" OR material2_item = "' .. frame.args[1] .. '" OR material3_item = "' .. frame.args[1] .. '" OR material4_item = "' .. frame.args[1] .. '" OR material5_item = "' .. frame.args[1] .. '"',
        orderBy = 'level, _pageName',
    }
    local result = cargo.query( tables, fields, args )
    local r = result[1]

        --Start the table
	local tbl = mw.html.create('table')

	tbl:addClass('wikitable')
		tbl:tag("th"):attr('style', 'width:25em'):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:25em'):wikitext("Материалы"):done()
	tbl:done()
         --Construct the rows in the table
	for _, row in ipairs(result) do
		tr = tbl:tag("tr"):attr('class', 'simpleCraftCalcRecipeBase')

        
        local source = {}
		if row.source then
			for name in mw.text.gsplit(row.source, ",%s*") do
				table.insert(source, item_icon.Main({args={name, ""}}))
			end
        end

        tr:tag("td"):wikitext((row.name and item_icon.Main({args={row.name, ""}}) or '') .. (row.source and '<br><small>(Изучается из: ' .. table.concat(source, ',<br>') ..')</small>' or '')):done()

		local text  = {}
        for i in mw.text.gsplit(row.professions, ",%s*") do
            table.insert(text, professions[mw.ustring.lower(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 resulting_craft_count = tonumber(row.quantity) > 0 and tonumber(row.quantity) or 1
            
		tr:tag("td"):wikitext('<span class="simpleCraftCalcResultCount" data-initial-count="'.. resulting_craft_count  .. '">' .. resulting_craft_count  .. '</span>'):done()
		
		local ingredients = {}
        for i = 1, 5 do
            local item = row['material'..i..'_item']
            local quantity = row['material'..i..'_quantity']
            if item ~= nil then
                table.insert(ingredients, '<div><span class="simpleCraftCalcIngredientCount" style="padding-right: 3px;" data-initial-count="'.. quantity .. '">' .. quantity .. '</span> ' .. item_icon.Main({args={item, ""}}) .. '</div>')
            end
        end
        tr:tag("td"):wikitext(table.concat(ingredients, '\n'))
        
		end
	return tbl
end
return p