Module:Test: Difference between revisions

From Elwiki
(Bot: Automated import of articles *** existing text overwritten ***)
(Bot: Automated import of articles *** existing text overwritten ***)
Line 58: Line 58:
     dmg = 500, 700, 800 (string) -> dmg = { 500, 700, 800 } (table)
     dmg = 500, 700, 800 (string) -> dmg = { 500, 700, 800 } (table)
     --]]
     --]]
     for k, v in pairs(args) do
     for k, v in ipairs(args) do
         -- We don't want passives that contain a comma in their names to be included in this.
         -- We don't want passives that contain a comma in their names to be included in this.
         if not string.find(k, 'passive') and not string.find(k, 'combine') then
         if not string.find(k, 'passive') and not string.find(k, 'combine') then

Revision as of 15:33, 5 April 2023

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

require('Module:CommonFunctions');
local getArgs = require('Module:Arguments').getArgs
local inspect = require('Module:Inspect').inspect
local p = {}

-- Main process
function p.main(frame)
    local args = getArgs(frame)

    function inArgs(key)
        if args[key] ~= nil then
            return true
        end
    end

    -- Define a table with parsed damage information of all kind.
    local DAMAGE_DATA = {}

    -- Store a configuration that will tell the main function how to behave given different inputs.
    local DAMAGE_CONFIG = {
        total_damage = {
            damage_numbers = args.dmg,
            hit_counts = args.hits
        },
        total_damage_awakening = {
            damage_numbers = args.awk_dmg or args.dmg,
            hit_counts = args.awk_hits or args.hits
        },
        average_damage = {
            damage_numbers = args.dmg,
            hit_counts = args.avg_hits
        },
        average_damage_awakening = {
            damage_numbers = args.awk_dmg or args.dmg,
            hit_counts = args.avg_awk_hits or args.hits
        },
        -- Store the logic for Useful traits
        total_damage_useful = {
            damage_numbers = args.dmg,
            hit_counts = args.hits_useful or args.hits
        },
        total_damage_awakening_useful = {
            damage_numbers = args.awk_dmg or args.dmg,
            hit_counts = args.awk_hits_useful or args.awk_hits or args.hits_useful or args.hits
        },
        average_damage_useful = {
            damage_numbers = args.dmg,
            hit_counts = args.avg_hits_useful or args.avg_hits
        },
        average_damage_awakening_useful = {
            damage_numbers = args.awk_dmg or args.dmg,
            hit_counts = args.avg_awk_hits_useful or args.avg_awk_hits or args.hits_useful or args.hits
        },
    }

    --[[
    Change how args are received.
    dmg = 500, 700, 800 (string) -> dmg = { 500, 700, 800 } (table)
    --]]
    for k, v in ipairs(args) do
        -- We don't want passives that contain a comma in their names to be included in this.
        if not string.find(k, 'passive') and not string.find(k, 'combine') then
            args[k] = split(v)
        end
    end

    function dump(tbl)
        local ret = {}
        for k, v in pairs(args) do
            table.insert(ret, k .. ': ' .. inspect(v))
        end
        return frame:preprocess(table.concat(ret, "<br/>"))
    end

    -- Dump all values if wanted.
    if args.dump == 'true' then
        return dump(args)
    end

    -- return frame:preprocess('<pre><nowiki>' .. inspect(args) .. '</nowiki></pre>')
end

return p