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/Wrench: Difference between revisions

From Growtopia
>HashJona
mNo edit summary
>HashJona
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
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)  
function p.build_table(frame)  
local args = frame:getParent().args
local args = frame:getParent().args
local debug_flag = args['debug'] or frame.args['debug'] or 0
local data = args['data'] or ''
local data = args['data'] or ''
if args == '' then
return ''
end
local lines = mw.text.split(data, "\n")
local lines = mw.text.split(data, "\n")
local results = {}
local results = {}
for _, line in ipairs(lines) do
for _, line in ipairs(lines) do
         line = mw.text.trim(line)
         line = mw.text.trim(line)
         if line ~= "" then
         if line ~= "" then
         
            line = line:gsub("%s*%$%$%$", "")
         
             local parts = mw.text.split(line, "|")
             local parts = mw.text.split(line, "|")
             local month = parts[1] or ""
             local month = parts[1] or "-"
             local item  = parts[2] or ""
             local item  = parts[3] or ""
 
           
             -- 4. Insert into a Lua table
             local key = months[month]
             table.insert(results, {
             if  results[key] == nil then
                month = mw.text.trim(month),
            results[key] = {
                item  = mw.text.trim(item),
            month = month
             })
            }
            end
           
            if item:lower():find("style") then
            results[key].style = item
            elseif item:lower():find("decoration") then
            results[key].decoration = item
             end
         end
         end
end
end
local output = {}
local keys = {}
for _, row in ipairs(results) do
for k in pairs(results) do
        table.insert(output, "1- " .. row.month .. ", 2-" .. row.item)
table.insert(keys, k)
end
table.sort(keys)
local sanitized = {}
    for _, key in ipairs(keys) do
        local entry = results[key]
        local line = '|-\n|' .. entry.month
        if entry.style then
            line = line .. "\n|{{ItemLink|" .. entry.style .. "}}"
        end
        if entry.decoration then
            line = line .. "\n|{{ItemLink|" .. entry.decoration .. "}}"
        end
        table.insert(sanitized, line)
     end
     end
 
   
     return table.concat(output, '\n')
     return debug_result(table.concat(sanitized, "\n"), debug_flag)
end
end


return p
return p

Latest revision as of 06:20, 19 November 2025

Documentation for this module may be created at Module:Table/Wrench/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 = parts[1] or "-"
            local item  = parts[3] or ""
            
            local key = months[month]
            if  results[key] == nil then 
            	results[key] = {
            		month = month
            	}
            end
            
            if item:lower():find("style") then
            	results[key].style = item
            elseif item:lower():find("decoration") then
            	results[key].decoration = item
            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|' .. entry.month
        if entry.style then
            line = line .. "\n|{{ItemLink|" .. entry.style .. "}}"
        end
        if entry.decoration then
            line = line .. "\n|{{ItemLink|" .. entry.decoration .. "}}"
        end
        table.insert(sanitized, line)
    end
    
    return debug_result(table.concat(sanitized, "\n"), debug_flag)
end

return p