<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FUser%3AJakesterwars%2FUses_material_list</id>
	<title>Module:Sandbox/User:Jakesterwars/Uses material list - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FUser%3AJakesterwars%2FUses_material_list"/>
	<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Sandbox/User:Jakesterwars/Uses_material_list&amp;action=history"/>
	<updated>2026-04-30T06:39:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.runerealm.org/index.php?title=Module:Sandbox/User:Jakesterwars/Uses_material_list&amp;diff=35219&amp;oldid=prev</id>
		<title>Alex at 23:13, 16 October 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Sandbox/User:Jakesterwars/Uses_material_list&amp;diff=35219&amp;oldid=prev"/>
		<updated>2024-10-16T23:13:23Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://wiki.runerealm.org/index.php?title=Module:Sandbox/User:Jakesterwars/Uses_material_list&amp;amp;diff=35219&amp;amp;oldid=35217&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Alex</name></author>
	</entry>
	<entry>
		<id>https://wiki.runerealm.org/index.php?title=Module:Sandbox/User:Jakesterwars/Uses_material_list&amp;diff=35217&amp;oldid=prev</id>
		<title>Alex: Created page with &quot;local p = {}  local geprice = require(&#039;Module:Exchange&#039;)._price local commas = require(&#039;Module:Addcommas&#039;) local skillpic = require(&#039;Module:SCP&#039;)._main local yesno = require(&#039;Module:Yesno&#039;) 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 &lt; item2.output.name) then 		return true 	elseif (item1.output.name &gt; item2.out...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Sandbox/User:Jakesterwars/Uses_material_list&amp;diff=35217&amp;oldid=prev"/>
		<updated>2024-10-16T23:13:23Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local p = {}  local geprice = require(&amp;#039;Module:Exchange&amp;#039;)._price local commas = require(&amp;#039;Module:Addcommas&amp;#039;) local skillpic = require(&amp;#039;Module:SCP&amp;#039;)._main local yesno = require(&amp;#039;Module:Yesno&amp;#039;) 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 &amp;lt; item2.output.name) then 		return true 	elseif (item1.output.name &amp;gt; item2.out...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
local geprice = require(&amp;#039;Module:Exchange&amp;#039;)._price&lt;br /&gt;
local commas = require(&amp;#039;Module:Addcommas&amp;#039;)&lt;br /&gt;
local skillpic = require(&amp;#039;Module:SCP&amp;#039;)._main&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
local lang = mw.getContentLanguage()&lt;br /&gt;
local trim = mw.text.trim&lt;br /&gt;
&lt;br /&gt;
-- Sorting function for two item objects, first by name, then by sub-text&lt;br /&gt;
function sortItemsByNameSubtext(item1, item2)&lt;br /&gt;
	if (item1.output.name &amp;lt; item2.output.name) then&lt;br /&gt;
		return true&lt;br /&gt;
	elseif (item1.output.name &amp;gt; item2.output.name) then&lt;br /&gt;
		return false&lt;br /&gt;
	else&lt;br /&gt;
		return (item1.output.subtxt or &amp;#039;&amp;#039;) &amp;lt; (item2.output.subtxt or &amp;#039;&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	return p._main(frame:getParent().args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._main(args)&lt;br /&gt;
	local materials = {}&lt;br /&gt;
	local materials_lowered = {}&lt;br /&gt;
	&lt;br /&gt;
	if (args == nil) then&lt;br /&gt;
		table.insert(materials, mw.title.getCurrentTitle().text)&lt;br /&gt;
	else&lt;br /&gt;
		local i = 1&lt;br /&gt;
		&lt;br /&gt;
		while args[i] do&lt;br /&gt;
			local arg = trim(args[i])&lt;br /&gt;
			&lt;br /&gt;
			table.insert(materials, arg)&lt;br /&gt;
	    	materials_lowered[arg:lower()] = true&lt;br /&gt;
	    	&lt;br /&gt;
			i = i + 1&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    -- Fetch data&lt;br /&gt;
    local query = {&lt;br /&gt;
        &amp;#039;[[Uses material::&amp;#039;..table.concat(materials, &amp;#039;||&amp;#039;)..&amp;#039;]]&amp;#039;,&lt;br /&gt;
        &amp;#039;[[Production JSON::+]]&amp;#039;,&lt;br /&gt;
        &amp;#039;?=#-&amp;#039;,&lt;br /&gt;
        &amp;#039;?Production JSON = json&amp;#039;,&lt;br /&gt;
        limit = args.limit or 500,&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    local t1 = os.clock()&lt;br /&gt;
    local smw_data = mw.smw.ask(query)&lt;br /&gt;
    local t2 = os.clock()&lt;br /&gt;
&lt;br /&gt;
    if not smw_data then&lt;br /&gt;
        return &amp;#039;Failed to find products with those materials - ensure they are spelled correctly. (ERR: no results from SMW)[[Category:Empty drop lists]]&amp;#039;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    mw.log(string.format(&amp;#039;SMW: entries %d, time elapsed: %.3f ms.&amp;#039;, #smw_data, (t2 - t1) * 1000))&lt;br /&gt;
&lt;br /&gt;
    -- Post-process&lt;br /&gt;
    data = {}&lt;br /&gt;
&lt;br /&gt;
    for _, e in ipairs(smw_data) do&lt;br /&gt;
    	if type(e.json) == &amp;#039;string&amp;#039; then&lt;br /&gt;
            local json = mw.text.jsonDecode(e.json)&lt;br /&gt;
            table.insert(data, json)&lt;br /&gt;
        elseif type(e.json) == &amp;#039;table&amp;#039; then&lt;br /&gt;
        	for _, f in ipairs(e.json) do&lt;br /&gt;
        		local json = mw.text.jsonDecode(f)&lt;br /&gt;
                table.insert(data, json)&lt;br /&gt;
        	end&lt;br /&gt;
    	end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    smw_data = nil&lt;br /&gt;
    &lt;br /&gt;
    -- Items with different variants (e.g. Divine battlemage potion has (1), (2), (3), (4) variants)&lt;br /&gt;
    -- or methods (e.g. &amp;quot;4-dose oil&amp;quot; vs &amp;quot;3-dose oil&amp;quot; for pyre logs) may not come in sorted, so now do a final alphabetical sort on name, sub-text&lt;br /&gt;
    table.sort(data, sortItemsByNameSubtext)&lt;br /&gt;
&lt;br /&gt;
    -- Render page&lt;br /&gt;
    local t = mw.html.create(&amp;#039;table&amp;#039;)&lt;br /&gt;
    t:addClass(&amp;#039;wikitable sortable products-list align-center-1 align-right-3 align-right-4&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
    local ttlrow = t:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
        :tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
            :attr(&amp;#039;colspan&amp;#039;, &amp;#039;2&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;Item&amp;#039;)&lt;br /&gt;
        :done()&lt;br /&gt;
        :tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;Members&amp;#039;)&lt;br /&gt;
            :done()&lt;br /&gt;
        :tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
            :attr(&amp;#039;data-sort-type&amp;#039;, &amp;#039;number&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;Skills&amp;#039;)&lt;br /&gt;
        :done()&lt;br /&gt;
        :tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
            :attr(&amp;#039;data-sort-type&amp;#039;, &amp;#039;number&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;XP&amp;#039;)&lt;br /&gt;
        :done()&lt;br /&gt;
        :tag(&amp;#039;th&amp;#039;)&lt;br /&gt;
            :wikitext(&amp;#039;Materials&amp;#039;)&lt;br /&gt;
        :done()&lt;br /&gt;
&lt;br /&gt;
    local rows = 0&lt;br /&gt;
&lt;br /&gt;
    -- Render rows&lt;br /&gt;
    for _, item in ipairs(data) do&lt;br /&gt;
        local _found = false&lt;br /&gt;
&lt;br /&gt;
        for _, mat_info in ipairs(item.materials) do&lt;br /&gt;
            if materials_lowered[mat_info.name:lower()] then&lt;br /&gt;
                _found = true&lt;br /&gt;
                break&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        if _found then&lt;br /&gt;
            local name_str&lt;br /&gt;
&lt;br /&gt;
            if (tonumber(item.output.quantity) or 0) &amp;gt; 1 then&lt;br /&gt;
                name_str = string.format(&amp;#039;[[%s]] × %s&amp;#039;, item.output.name, item.output.quantity)&lt;br /&gt;
            else&lt;br /&gt;
                name_str = string.format(&amp;#039;[[%s]]&amp;#039;, item.output.name)&lt;br /&gt;
            end&lt;br /&gt;
            &lt;br /&gt;
            if item.output.subtxt then&lt;br /&gt;
            	name_str = string.format(&amp;#039;%s &amp;lt;br /&amp;gt;&amp;lt;small&amp;gt;(%s)&amp;lt;/small&amp;gt;&amp;#039;, name_str, item.output.subtxt)	&lt;br /&gt;
            end&lt;br /&gt;
            &lt;br /&gt;
            local member_str&lt;br /&gt;
&lt;br /&gt;
            if item.members == &amp;#039;Yes&amp;#039; then&lt;br /&gt;
				member_str = &amp;quot;[[File:Member icon.png|center|link=Members|alt=Members]]&amp;quot;	&lt;br /&gt;
			elseif item.members == &amp;#039;No&amp;#039; then&lt;br /&gt;
				member_str = &amp;quot;[[File:Free-to-play icon.png|center|link=Free-to-play|alt=Free-to-play]]&amp;quot;	&lt;br /&gt;
			end&lt;br /&gt;
		&lt;br /&gt;
            local experience_cell = mw.html.create(&amp;#039;td&amp;#039;)&lt;br /&gt;
            experience_cell:addClass(&amp;#039;plainlist&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
            local experience_ul = experience_cell:tag(&amp;#039;ul&amp;#039;)&lt;br /&gt;
            experience_ul:addClass(&amp;#039;skills-list&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
            local skills_cell = mw.html.create(&amp;#039;td&amp;#039;)&lt;br /&gt;
            skills_cell:addClass(&amp;#039;plainlist&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
            local skills_ul = skills_cell:tag(&amp;#039;ul&amp;#039;)&lt;br /&gt;
            skills_ul:addClass(&amp;#039;skills-list&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
            if #item.skills == 0 then&lt;br /&gt;
        		local skill_li = skills_ul:tag(&amp;#039;li&amp;#039;)&lt;br /&gt;
        		local experience_li = experience_ul:tag(&amp;#039;li&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
        		experience_cell:addClass(&amp;#039;table-na&amp;#039;):css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
        		experience_li:wikitext(string.format(&amp;#039;None&amp;#039;))&lt;br /&gt;
        		skills_cell:addClass(&amp;#039;table-na&amp;#039;):css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
        		skill_li:wikitext(string.format(&amp;#039;None&amp;#039;))&lt;br /&gt;
        	else&lt;br /&gt;
        		for index, v in ipairs(item.skills) do&lt;br /&gt;
            		local skill_li = skills_ul:tag(&amp;#039;li&amp;#039;)&lt;br /&gt;
            		local experience_li = experience_ul:tag(&amp;#039;li&amp;#039;)&lt;br /&gt;
            		local stripped_experience = v.experience:gsub(&amp;#039;,&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
            		skill_li&lt;br /&gt;
                        :attr(&amp;#039;data-sort-value&amp;#039;, index == 1 and v.level or &amp;#039;&amp;#039;)&lt;br /&gt;
                        :wikitext(skillpic(lang:ucfirst(v.name), v.level))&lt;br /&gt;
            		experience_li&lt;br /&gt;
                        :attr(&amp;#039;data-sort-value&amp;#039;, index == 1 and v.experience or &amp;#039;&amp;#039;)&lt;br /&gt;
                        :wikitext(tonumber(stripped_experience) ~= nil and skillpic(lang:ucfirst(v.name), v.experience) or v.experience)&lt;br /&gt;
        		end&lt;br /&gt;
        	end&lt;br /&gt;
&lt;br /&gt;
            local mats_ul = mw.html.create(&amp;#039;ul&amp;#039;)&lt;br /&gt;
            mats_ul:addClass(&amp;#039;products-materials&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
            local mat_sort_val = nil&lt;br /&gt;
&lt;br /&gt;
            for _, mat_info in ipairs(item.materials) do&lt;br /&gt;
                local mat_li = mats_ul:tag(&amp;#039;li&amp;#039;)&lt;br /&gt;
                local qty = mat_info.quantity:gsub(&amp;#039;%-&amp;#039;, &amp;#039;–&amp;#039;)&lt;br /&gt;
                local mat_name = mat_info.name&lt;br /&gt;
&lt;br /&gt;
            	for _, mat in ipairs(materials_lowered) do&lt;br /&gt;
            		if mat_name:lower() == mat then&lt;br /&gt;
            			mat_li:addClass(&amp;#039;production-selected&amp;#039;)&lt;br /&gt;
            		end&lt;br /&gt;
            	end&lt;br /&gt;
&lt;br /&gt;
                if materials_lowered[mat_name:lower()] then&lt;br /&gt;
                    mat_li:addClass(&amp;#039;production-selected&amp;#039;)&lt;br /&gt;
                end&lt;br /&gt;
                &lt;br /&gt;
                if mat_sort_val == nil then&lt;br /&gt;
                	mat_sort_val = qty&lt;br /&gt;
                end&lt;br /&gt;
                &lt;br /&gt;
                mat_li:wikitext(string.format(&amp;#039;%s × [[%s]]&amp;#039;, commas._add(qty), mat_name))&lt;br /&gt;
            end&lt;br /&gt;
&lt;br /&gt;
            local prow = t:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
            	:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
            		:wikitext(item.output.image)&lt;br /&gt;
                :tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
                	:attr(&amp;#039;data-sort-value&amp;#039;, item.product)&lt;br /&gt;
                    :wikitext(name_str)&lt;br /&gt;
                :done()&lt;br /&gt;
                :tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
                	:wikitext(member_str)&lt;br /&gt;
                :node(skills_cell)&lt;br /&gt;
                :node(experience_cell)&lt;br /&gt;
                :tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
                	:attr(&amp;#039;data-sort-value&amp;#039;, mat_sort_val)&lt;br /&gt;
                	:addClass(&amp;#039;plainlist&amp;#039;)&lt;br /&gt;
                    :node(mats_ul)&lt;br /&gt;
                :done()&lt;br /&gt;
            rows = rows + 1&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if rows == 0 then&lt;br /&gt;
        return &amp;#039;Failed to find products with those materials - ensure they are spelled correctly. (ERR: no mats found in results)[[Category:Empty drop lists]]&amp;#039;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return t&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[ DEBUG COPYPASTA&lt;br /&gt;
= p._main({&amp;#039;Mithril bar&amp;#039;})&lt;br /&gt;
--]]&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Alex</name></author>
	</entry>
</feed>