Shaleych (обсуждение | вклад) мНет описания правки |
Shaleych (обсуждение | вклад) мНет описания правки |
||
(не показаны 43 промежуточные версии этого же участника) | |||
Строка 4: | Строка 4: | ||
local p = {} |
local p = {} |
||
local cargo = mw.ext.cargo |
local cargo = mw.ext.cargo |
||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
function p.Main( frame ) |
function p.Main( frame ) |
||
Строка 37: | Строка 54: | ||
--Start the table |
--Start the table |
||
local tbl = mw.html.create('table') |
local tbl = mw.html.create('table') |
||
+ | |||
tbl:addClass('wikitable') |
tbl:addClass('wikitable') |
||
− | + | 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 |
--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 ps = { |
||
− | ['Алхимия'] = '[[Файл:Crafting_Profession_Alchemy.png|20px|ссылка=Алхимия]]', |
||
− | } |
||
− | + | local str1 = row.professions |
|
− | + | local str1 = string.gsub(str1, "%s+", "") |
|
− | local str2 = utf8.gsub(str1, "[^%p%d%s%c%s+]+", professions, '\n') |
||
− | local insigniaBonuses = {} |
+ | local insigniaBonuses = {} |
− | for i in string.gmatch( |
+ | for i in string.gmatch(str1, "[^%p%d%s%c]+") do |
table.insert(insigniaBonuses , professions[i]) |
table.insert(insigniaBonuses , professions[i]) |
||
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():done() |
||
+ | tr:tag("td"):wikitext('<span class="simpleCraftCalcResultCount" data-initial-count="' .. row.quantity .. '">' .. row.quantity .. '</span>'):done() |
||
− | tr:tag("td"):wikitext(itemIcon.Main({args={row.material1_item,""}}) .. itemIcon.Main({args={row.material2_item,""}}).. itemIcon.Main({args={row.material3_item,""}}) .. itemIcon.Main({args={row.material4_item,""}}) .. itemIcon.Main({args={row.material5_item,""}})):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 |
||
return tbl |
return tbl |
||
end |
end |
Версия от 15:34, 21 октября 2019
Для документации этого модуля может быть создана страница Модуль:Recipe list/doc
local utf8 = require('Модуль:Utf8')
local itemIcon = require('Модуль:Item_icon')
local p = {}
local cargo = mw.ext.cargo
local professions = {
['Алхимия'] = '[[Файл:Crafting_Profession_Alchemy.png|20px|ссылка=Алхимия]]',
['алхимия'] = '[[Файл:Crafting_Profession_Alchemy.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_Weaponsmithing.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 )
local args = frame.args
local fieldstable = {
"_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",
}
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]
--Start the table
local tbl = mw.html.create('table')
tbl:addClass('wikitable')
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 str1 = row.professions
local str1 = string.gsub(str1, "%s+", "")
local insigniaBonuses = {}
for i in string.gmatch(str1, "[^%p%d%s%c]+") do
table.insert(insigniaBonuses , professions[i])
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('<span class="simpleCraftCalcResultCount" data-initial-count="' .. row.quantity .. '">' .. row.quantity .. '</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