Module:Damage: Difference between revisions

no edit summary
No edit summary
Tag: Manual revert
No edit summary
Tag: Reverted
Line 8: Line 8:
function p.main(frame)
function p.main(frame)
     local args = getArgs(frame)
     local args = getArgs(frame)
    local out


     function inArgs(key)
     function inArgs(key)
Line 14: Line 15:
         end
         end
     end
     end
    local modes = { 'PvE', 'PvP' }


     -- Define the schema for the table
     -- Define the schema for the table
     local tableSchema = {
     local tableSchema = {}
         PvE = {},
    for _, mode in ipairs(modes) do
         PvP = {}
         tableSchema[mode] = {}
     }
    end
 
    function forEach(func)
        for _, mode in ipairs(modes) do
            func(mode)
         end
     end


     -- Function to create a new table with the desired schema
     -- Function to create a new table with the desired schema
Line 155: Line 164:
     -- Store a configuration that will tell the main function how to behave given different inputs.
     -- Store a configuration that will tell the main function how to behave given different inputs.
     -- It will always take the first value if available. If not, fall back to the other (recursively).
     -- It will always take the first value if available. If not, fall back to the other (recursively).
     local DAMAGE_CONFIG = {
     local BASE_DAMAGE_CONFIG = {
         total_damage = {
         total_damage = {
             damage_numbers = { 'dmg' },
             damage_numbers = { 'dmg' },
Line 198: Line 207:
         },
         },
     }
     }
    local DAMAGE_CONFIG = {}
    function handleCancel()
        local processed_keys = {}
        for config_key, config_value in pairs(BASE_DAMAGE_CONFIG) do
            if not config_key:match('cancel_') then
                local new_config_value = {}
                for arg_table_key, arg_table in pairs(config_value) do
                    local new_arg_table = {}
                    for _, arg in ipairs(arg_table) do
                        table.insert(new_arg_table, 'cancel_' .. arg)
                    end
                    new_config_value[arg_table_key] = new_arg_table
                end
                local new_key = 'cancel_' .. config_key
                DAMAGE_CONFIG[new_key] = new_config_value
                processed_keys[new_key] = true
            end
        end
        return processed_keys
    end
    handleCancel()
    DAMAGE_CONFIG = table.fuse(BASE_DAMAGE_CONFIG, DAMAGE_CONFIG)
     -- Inherits values from args if not provided, but usage suggests that they're meant to be generated.
     -- Inherits values from args if not provided, but usage suggests that they're meant to be generated.
     function inherit(mode)
     function inherit(mode)
Line 217: Line 252:
                             Alternatively, it can contain an "i" to template the value to inherit.
                             Alternatively, it can contain an "i" to template the value to inherit.
                         ]]
                         ]]
                         while i <= #(args.dmg) do
                        local cancel_dmg_len = args.cancel_dmg and #(args.cancel_dmg) or 0
                         while i <= (#(args.dmg) + cancel_dmg_len) do
                             local main_arg_value = main_arg_values[i]
                             local main_arg_value = main_arg_values[i]


Line 224: Line 260:
                                 -- No inheritance from itself.
                                 -- No inheritance from itself.
                                 if inherit_arg and inherit_arg[i] and inherit_arg[i] ~= '' and ix ~= 1 then
                                 if inherit_arg and inherit_arg[i] and inherit_arg[i] ~= '' and ix ~= 1 then
                                     -- Only inherit if empty or nil
                                     -- Only inherit if empty
                                     if main_arg_value == '' then
                                     if main_arg_value == '' then
                                         args[main_key_prefixed][i] = inherit_arg[i]
                                         args[main_key_prefixed][i] = inherit_arg[i]
Line 243: Line 279:
     end
     end


     inherit('PvE')
     forEach(inherit)
    inherit('PvP')


     local DAMAGE_PARSED = createDamageDataTable()
     local DAMAGE_PARSED = createDamageDataTable()
Line 267: Line 302:
                         if k == 'provided' then
                         if k == 'provided' then
                             output_value = false
                             output_value = false
                        else
                            output_value = {}
                         end
                         end
                     end
                     end
Line 278: Line 315:
     end
     end


     parseConfig('PvE')
     forEach(parseConfig)
    parseConfig('PvP')


     -- Detected "count", for skills like Clementine, Enough Mineral, etc.
     -- Detected "count", for skills like Clementine, Enough Mineral, etc.
Line 342: Line 378:
                     if trait.value then
                     if trait.value then
                         WITH_TRAITS[mode][damage_key .. ((trait.key == 'useful' or trait.key == '') and "" or ('_' .. trait.key))] =
                         WITH_TRAITS[mode][damage_key .. ((trait.key == 'useful' or trait.key == '') and "" or ('_' .. trait.key))] =
                             damage_value * trait.value
                             damage_value * (string.find(damage_key, 'useful') and trait.value or 1)
                     end
                     end
                 end
                 end
Line 702: Line 738:
     function doTable()
     function doTable()
         doHeaders()
         doHeaders()
         doContentByMode('PvE')
         forEach(doContentByMode)
        doContentByMode('PvP')
     end
     end


Line 728: Line 763:
     local variables = doVariables(frame, FINAL_DAMAGE, OPTIONS.prefix)
     local variables = doVariables(frame, FINAL_DAMAGE, OPTIONS.prefix)


    if out ~= nil then
        return inspect_dump(frame, out)
    end
   
     return variables .. bug .. (OPTIONS.do_table and tostring(TABLE) or '')
     return variables .. bug .. (OPTIONS.do_table and tostring(TABLE) or '')
end
end