Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Table/IOTS: Difference between revisions

From Growtopia
>HashJona
mNo edit summary
>HashJona
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 15: Line 15:
['-'] = 13
['-'] = 13
}
}


function debug_result(var, debug_flag)
function debug_result(var, debug_flag)
Line 34: Line 35:
         line = mw.text.trim(line)
         line = mw.text.trim(line)
         if line ~= "" then
         if line ~= "" then
         
             local parts = mw.text.split(line, "|")
             local parts = mw.text.split(line, "|")
             local month = parts[1] or "-"
             local month = mw.text.trim(parts[1] or "-")
             local item  = parts[2] or ""
             local itemType = mw.text.trim(parts[2] or "-")
             local description = parts[3] or ""
             local item = mw.text.trim(parts[3] or "")
              
             if item ~= '' then
            local key = months[month]
            local key = months[month]
            if  results[key] == nil then  
            if  results[key] == nil then  
            results[key] = '|-\n|colspan="1" rowspan="2"|' .. month .. '\n|{{ItemLink|' .. item .. "}}\n|<i><nowiki>" .. description .. "</nowiki></i>"
            results[key] = {
            else
            month = month
            results[key] = results[key] .. '\n|-\n|{{ItemLink|' .. item .. "}}\n|<i><nowiki>" .. description .. "</nowiki></i>"
            }
            end
            if itemType:lower() == 'r' then
            results[key].royal = results[key].royal or item
            else
            results[key].normal = results[key].normal or item
            end
             end
             end
         end
         end
Line 57: Line 63:
     for _, key in ipairs(keys) do
     for _, key in ipairs(keys) do
         local entry = results[key]
         local entry = results[key]
         table.insert(sanitized, entry)
        local line = '|-\n|colspan="1" rowspan="2"|' .. entry.month .. '\n|'
        if entry.normal then
        line = line .. '{{ItemLink|' .. entry.normal .. "}}"
        line = line .. "\n|''{{Item/Description|" .. entry.normal .. "}}''"
        else
        line = line .. '\n|'
        end
        local line = line .. '\n|-\n|'
        if entry.royal then
        line = line .. '{{ItemLink|' .. entry.royal .. "}}"
        line = line .. "\n|''{{Item/Description|" .. entry.royal .. "}}''"
        else
        line = line .. '\n|'
        end
         table.insert(sanitized, line)
     end
     end
      
      

Latest revision as of 16:17, 3 November 2025

Documentation for this module may be created at Module:Table/IOTS/doc

local p = {}
local months = {
	January = 1,
	February = 2,
	March = 3,
	April = 4,
	May = 5,
	June = 6,
	July = 7,
	August = 8,
	September = 9,
	October = 10,
	November = 11,
	December = 12,
	['-'] = 13
}


function debug_result(var, debug_flag)
   if debug_flag == '1' then 
       return '<pre>' .. var .. '</pre>'
   else
       return mw.getCurrentFrame():preprocess(var)
   end
end
	
function p.build_table(frame) 
	local args = frame:getParent().args
	local debug_flag = args['debug'] or frame.args['debug'] or 0
	local data = args['data'] or ''
	local lines = mw.text.split(data, "\n")
	
	local results = {}
	for _, line in ipairs(lines) do
        line = mw.text.trim(line)
        if line ~= "" then
            local parts = mw.text.split(line, "|")
            local month = mw.text.trim(parts[1] or "-")
            local itemType = mw.text.trim(parts[2] or "-")
            local item  = mw.text.trim(parts[3] or "")
            if item ~= '' then
            	local key = months[month]
            	if  results[key] == nil then 
            		results[key] = {
            			month = month
            		}
            	end
            	if itemType:lower() == 'r' then
            		results[key].royal = results[key].royal or item
            	else
            		results[key].normal = results[key].normal or item
            	end
            end
        end
	end
	local keys = {}
	for k in pairs(results) do
		table.insert(keys, k)
	end
	table.sort(keys)
	
	local sanitized = {}
    for _, key in ipairs(keys) do
        local entry = results[key]
        local line = '|-\n|colspan="1" rowspan="2"|' .. entry.month .. '\n|'
        if entry.normal then
        	line = line .. '{{ItemLink|' .. entry.normal .. "}}"
        	line = line .. "\n|''{{Item/Description|" .. entry.normal .. "}}''"
        else 
        	line = line .. '\n|'
        end
        local line = line .. '\n|-\n|'
        if entry.royal then
        	line = line .. '{{ItemLink|' .. entry.royal .. "}}"
        	line = line .. "\n|''{{Item/Description|" .. entry.royal .. "}}''"
        else 
        	line = line .. '\n|'
        end
        table.insert(sanitized, line)
    end
    
    return debug_result(table.concat(sanitized, "\n"), debug_flag)
end

return p