Shaleych (обсуждение | вклад) мНет описания правки |
Shaleych (обсуждение | вклад) мНет описания правки |
||
(не показано 57 промежуточных версий этого же участника) | |||
Строка 1: | Строка 1: | ||
− | local |
+ | 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_Tailoring.png|20px|ссылка=Кройка и шитье]]', |
− | [' |
+ | ['кузнечное дело'] = '[[Файл:Crafting_Profession_Weaponsmithing.png|20px|ссылка=Кузнечное дело]]', |
− | [' |
+ | ['нанесение узоров'] = '[[Файл:Crafting_Profession_Artificing.png|20px|ссылка=Нанесение узоров]]', |
− | [' |
+ | ['обработка кожи'] = '[[Файл:Crafting_Profession_Leatherworking.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 |
+ | 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' |
||
− | "_pageName", |
||
− | + | local args = { |
|
⚫ | |||
⚫ | |||
− | + | orderBy = 'level, _pageName', |
|
− | + | } |
|
⚫ | |||
− | "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 |
||
− | |||
⚫ | |||
− | , groupBy = "_pageName" , orderBy = level} |
||
− | |||
⚫ | |||
local r = result[1] |
local r = result[1] |
||
Строка 56: | Строка 28: | ||
tbl:addClass('wikitable') |
tbl:addClass('wikitable') |
||
− | tbl:tag("th"):attr('style', 'width: |
+ | 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: |
+ | 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 source = {} |
|
+ | if row.source then |
||
+ | for name in mw.text.gsplit(row.source, ",%s*") do |
||
+ | table.insert(source, item_icon.Main({args={name, ""}})) |
||
⚫ | |||
⚫ | |||
+ | 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() |
||
⚫ | |||
+ | |||
− | for i in string.gmatch(str1, "[^%p%d%s%c]+") do |
||
⚫ | |||
⚫ | |||
+ | for i in mw.text.gsplit(row.professions, ",%s*") do |
||
⚫ | |||
+ | end |
||
⚫ | |||
+ | 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 |
||
+ | |||
⚫ | |||
⚫ | |||
+ | 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"):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 |
||
⚫ | |||
⚫ | |||
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