Module:ModuleShowVariantsOrSingle: Difference between revisions

From The First Descendant Wiki
No edit summary
No edit summary
Line 38: Line 38:
      
      
     local result = ""
     local result = ""
     if tonumber(frame.args.count) > 1 then
     if arg_count > 1 then
         result = moreThanOne(frame.args.module_name)
         result = moreThanOne(frame.args.module_name)
        for i=1, (arg_count+2) do
            result = result .. frame.args[i]
        end
     end
     end


Line 46: Line 49:
      
      


     return frame:preprocess(count)
     return frame:preprocess(result)
end
end


return p
return p

Revision as of 22:45, 5 June 2024

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

------------------------------------
-- Modules can have variants, or they can be one of a kind.
-- It doesn't make sense to show all the variant fluff if a module is one of a kind.

local p = {}


local function moreThanOne(module_name)
    local variants_chapter = "== Variants ==\n{{Template:ModuleTableCompareLevels|module_name=" .. module_name .. "}}\n\n"
    local variant_details_chapter = "== Variant Details ==\n"
    return variants_chapter .. variant_details_chapter
end



function p.processData(frame)
    if frame.args.count == nil then
        return "ERROR: Module:ModuleShowVariantsOrSingle not passed a count. Please tell us on Discord!"
    end

    local smw_count = tonumber(frame.args.count)

    -- Count how many Template:ModuleUniqueDetails have been included as params
    -- If this doesn't match how many SMW entries there are, someone screwed up data entry
    local arg_count = 0
    for k, v in pairs(frame.args) do
        if v ~= '' then
            arg_count = arg_count + 1
        end
    end

    -- Two args are the module name and smw count
    if (arg_count-2) ~= smw_count then
        return "ERROR: The Module page template requires each module to be defined twice. Make sure you put it in both spots!"
    end


    
    local result = ""
    if arg_count > 1 then
        result = moreThanOne(frame.args.module_name)
        for i=1, (arg_count+2) do
            result = result .. frame.args[i]
        end
    end

    

    

    return frame:preprocess(result)
end

return p