Module:Uses skill list: Difference between revisions

Content deleted Content added
Created page with "local p = {} local geprice = require('Module:Exchange')._price local commas = require('Module:Addcommas') local skillpic = require('Module:SCP')._main local yesno = require('Module:Yesno') local lang = mw.getContentLanguage() local trim = mw.text.trim -- Sorting function for two item objects, first by name, then by sub-text function sortItemsByNameSubtext(item1, item2) if (item1.output.name < item2.output.name) then return true elseif (item1.output.name > item2.out..."
 
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 24:
 
function p._main(args)
local materialsskills = {}
local materials_loweredskills_lowered = {}
local category = args.category and trim(args.category) or nil
-- Process skill arguments
if (args == nil) then
table.insert(materialsskills, mw.title.getCurrentTitle().text)
else
local i = 1
Line 35 ⟶ 37:
local arg = trim(args[i])
table.insert(materialsskills, arg)
materials_loweredskills_lowered[arg:lower()] = true
i = i + 1
Line 42 ⟶ 44:
end
 
-- FetchBuild dataSMW query
local query = {
'[[Uses skill::' .. table.concat(materialsskills, '||') .. ']]',
'[[Production JSON::+]]',
'?=#-',
Line 51 ⟶ 53:
}
-- Add category filter if provided
if category then
table.insert(query, '[[RecipeCategory::' .. category .. ']]')
end▼
 
-- Fetch data
local t1 = os.clock()
local smw_data = mw.smw.ask(query)
Line 84 ⟶ 92:
-- Render page
local t = mw.html.create('table')
t:addClass('wikitable sortable products-list align-center-1 align-right-3 align-right-4 autosort=3,a')
 
local ttlrow = t:tag('tr')
Line 110 ⟶ 118:
-- Render rows
for _, item in ipairs(data) do
local _foundskill_match = false
for _, matskill_info in ipairs(materials_lowereditem.skills) do▼
 
for _, mat_info in ipairs(itemif skills_lowered[skill_info.materialsname:lower()] dothen
_foundskill_match = true▼
if materials_lowered[mat_info.name:lower()] then
▲ _found = true
break
end
end
 
if _foundskill_match then
local name_str
 
Line 184 ⟶ 191:
local qty = mat_info.quantity:gsub('%-', '–')
local mat_name = mat_info.name
 
▲ for _, mat in ipairs(materials_lowered) do
if mat_name:lower() == mat then
mat_li:addClass('production-selected')
end
▲ end
 
if materials_lowered[mat_name:lower()] then
mat_li:addClass('production-selected')
end
if mat_sort_val == nil then
Line 223 ⟶ 220:
 
if rows == 0 then
return 'Failed to find products with those materialsskills - ensure they are spelled correctly. (ERR: no matsskills found in results)[[Category:Empty drop lists]]'
end