<?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%3AUses_material_list%2FSandbox</id>
	<title>Module:Uses material list/Sandbox - 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%3AUses_material_list%2FSandbox"/>
	<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Uses_material_list/Sandbox&amp;action=history"/>
	<updated>2026-05-14T23:31:15Z</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:Uses_material_list/Sandbox&amp;diff=38444&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 local split = mw.text.split  function p.main(frame) 	return p._main(frame:getParent().args) end  function p._main(args) 	local materials = {} 	if (args == nil) then 		table.insert(materials, mw.title.getCurrentTitle().text...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Uses_material_list/Sandbox&amp;diff=38444&amp;oldid=prev"/>
		<updated>2024-10-17T10:24:09Z</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 local split = mw.text.split  function p.main(frame) 	return p._main(frame:getParent().args) end  function p._main(args) 	local materials = {} 	if (args == nil) then 		table.insert(materials, mw.title.getCurrentTitle().text...&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;
local split = mw.text.split&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;
	if (args == nil) then&lt;br /&gt;
		table.insert(materials, mw.title.getCurrentTitle().text)&lt;br /&gt;
	else&lt;br /&gt;
		local splitMultiple = {}&lt;br /&gt;
		for type in string.gmatch(args[1], &amp;#039;([^,]+)&amp;#039;) do&lt;br /&gt;
			table.insert(splitMultiple, type)&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		for _, v in ipairs(splitMultiple) do&lt;br /&gt;
			mw.log(v)&lt;br /&gt;
			table.insert(materials, trim(v))&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local materialsLowered = {}&lt;br /&gt;
	for index, material in pairs(materials) do&lt;br /&gt;
	    materialsLowered[material:lower()] = true&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;
    local t1 = os.clock()&lt;br /&gt;
    local smwdata = mw.smw.ask(query)&lt;br /&gt;
    local t2 = os.clock()&lt;br /&gt;
&lt;br /&gt;
    if not smwdata 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;
    mw.log(string.format(&amp;#039;SMW: entries %d, time elapsed: %.3f ms.&amp;#039;, #smwdata, (t2 - t1) * 1000))&lt;br /&gt;
&lt;br /&gt;
    -- Post-process&lt;br /&gt;
    data = {}&lt;br /&gt;
    for _, e in ipairs(smwdata) do&lt;br /&gt;
    	if type(e[&amp;#039;json&amp;#039;]) == &amp;#039;string&amp;#039; then&lt;br /&gt;
            local j = mw.text.jsonDecode(e[&amp;#039;json&amp;#039;])&lt;br /&gt;
            table.insert(data, j)&lt;br /&gt;
        elseif type(e[&amp;#039;json&amp;#039;]) == &amp;#039;table&amp;#039; then&lt;br /&gt;
        	for _, f in ipairs(e[&amp;#039;json&amp;#039;]) do&lt;br /&gt;
        		local j = mw.text.jsonDecode(f)&lt;br /&gt;
                table.insert(data, j)&lt;br /&gt;
        	end&lt;br /&gt;
    	end&lt;br /&gt;
    end&lt;br /&gt;
    smwdata = nil&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;
    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;
        for _,mat_info in ipairs(item.materials) do&lt;br /&gt;
            if materialsLowered[mat_info.name:lower()] == true then&lt;br /&gt;
                _found = true&lt;br /&gt;
                break&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
        if _found then&lt;br /&gt;
            local namestr&lt;br /&gt;
            if (tonumber(item.output.quantity) or 1) &amp;gt; 1 then&lt;br /&gt;
                namestr = string.format(&amp;#039;[[%s]] × %s&amp;#039;, item.output.name, item.output.quantity)&lt;br /&gt;
            else&lt;br /&gt;
                namestr = 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;
            	namestr = string.format(&amp;#039;%s &amp;lt;br /&amp;gt;&amp;lt;small&amp;gt;(%s)&amp;lt;/small&amp;gt;&amp;#039;, namestr, item.output.subtxt)	&lt;br /&gt;
            end&lt;br /&gt;
            &lt;br /&gt;
            local memberstr&lt;br /&gt;
            members = item.members&lt;br /&gt;
            if members == &amp;#039;Yes&amp;#039; then&lt;br /&gt;
				memberstr = &amp;quot;[[File:Member icon.png|center|link=Members]]&amp;quot;	&lt;br /&gt;
			elseif members == &amp;#039;No&amp;#039; then&lt;br /&gt;
				memberstr = &amp;quot;[[File:Free-to-play icon.png|center|link=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;
            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;
                :css({&lt;br /&gt;
                    [&amp;#039;list-style-type&amp;#039;] = &amp;#039;none&amp;#039;,&lt;br /&gt;
                    [&amp;#039;list-style-image&amp;#039;] = &amp;#039;none&amp;#039;,&lt;br /&gt;
                    margin = 0&lt;br /&gt;
                })&lt;br /&gt;
            local skills_cell = mw.html.create(&amp;#039;td&amp;#039;)&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;
                :css({&lt;br /&gt;
                    [&amp;#039;list-style-type&amp;#039;] = &amp;#039;none&amp;#039;,&lt;br /&gt;
                    [&amp;#039;list-style-image&amp;#039;] = &amp;#039;none&amp;#039;,&lt;br /&gt;
                    margin = 0&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;
        		experience_cell:addClass(&amp;#039;table-na&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;)&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 = string.gsub(v.experience, &amp;#039;,&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
            		skill_li:attr(&amp;#039;data-sort-value&amp;#039;, index == 1 and v.level or &amp;#039;&amp;#039;):wikitext(skillpic(lang:ucfirst(v.name), v.level))&lt;br /&gt;
            		experience_li:attr(&amp;#039;data-sort-value&amp;#039;, index == 1 and v.experience or &amp;#039;&amp;#039;):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;
            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;
                :css({&lt;br /&gt;
                    [&amp;#039;list-style-type&amp;#039;] = &amp;#039;none&amp;#039;,&lt;br /&gt;
                    [&amp;#039;list-style-image&amp;#039;] = &amp;#039;none&amp;#039;,&lt;br /&gt;
                    margin = 0&lt;br /&gt;
                })&lt;br /&gt;
            local materialsortvalue = nil&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 = string.gsub(mat_info.quantity, &amp;#039;%-&amp;#039;, &amp;#039;–&amp;#039;)&lt;br /&gt;
                local matnm = mat_info.name&lt;br /&gt;
            	for _,mat in ipairs(materialsLowered) do&lt;br /&gt;
            		if mat_info.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;
                if materialsLowered[mat_info.name:lower()] == true then&lt;br /&gt;
                    mat_li:addClass(&amp;#039;production-selected&amp;#039;)&lt;br /&gt;
                end&lt;br /&gt;
                &lt;br /&gt;
                if materialsortvalue == nil then&lt;br /&gt;
                	materialsortvalue = 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), matnm))&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(namestr)&lt;br /&gt;
                :done()&lt;br /&gt;
                :tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
                	:wikitext(memberstr)&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;, materialsortvalue)&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>