Module:Test: Difference between revisions

From Elwiki
No edit summary
No edit summary
Tag: Manual revert
 
Line 1: Line 1:
require('Module:CommonFunctions')
require('Module:CommonFunctions')
require('Module:InfoboxProto');
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}
Line 6: Line 7:
function p.main(frame)
function p.main(frame)
     local args = getArgs(frame);
     local args = getArgs(frame);
 
     local infobox = require('Module:InfoboxProto').main(frame, args.title);
     function dump(o)
     local divclass = args.divclass;
        if type(o) == 'table' then
     if divclass == nil then
            local s = '{ '
         divclass = 'custom'
            for k, v in pairs(o) do
                if type(k) ~= 'number' then
                    k = '"' .. k .. '"'
                end
                s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
            end
            return s .. '} '
        else
            return tostring(o)
        end
    end
 
    -- Argument init
     local traits = args[3]
     if (traits == nil) then
         traits = '-, -'
     end
     end
     traits = split(traits);
     infobox:addClass('infobox-' .. divclass);
    local skill = args[2]


     -- Define the class blueprint for traits.
     for k, v in spairs(args) do
    Trait = {
         if string.match(k, 'data[0-9]+') ~= nil then
        name = "",
             local i = k:gsub('data', '');
         multipliers = {
            addField('data' .. i, args['label' .. i])
            mp_cost = 100,
            cooldown = 100,
            duration = 100
        },
        details = {
            mp_cost = {0, 0},
            cooldown = {0, 0},
             duration = {0, 0}
        }
    }
 
    function Trait:new(t)
        t = t or {}
        setmetatable(t, self)
        self.__index = self
 
        for k, v in pairs(t.values) do
            for i = 1, 2, 1 do
                v = v or self.values[k]
            end
         end
         end
        for k, v in pairs(t.details) do
            for i = 1, 2, 1 do
                v[i] = v[i] or {0, 0}
            end
        end
       
        return t
    end
    function Trait:math()
        for k, v in pairs(self.details) do
            for i = 1, 2, 1 do
                self.details[k][i] = v * (self.multipliers[k] / 100)
            end
        end
        return self
     end
     end
 
      
     -- Define the mother object of traits.
     return tostring(infobox);
     local reversed = Trait:new({
        name = "Reversed",
        values = {
            mp_multiplier = 60,
            cd_multiplier = 150,
            duration_multiplier = 100
        },
        details = {
            mp_cost = {300, 300},
            cooldown = {22, 22},
            duration = {0, 0}
        }
    })
 
    -- Output point
    -- return tostring(trait_table);
    return dump(reversed:math());


end
end


return p
return p

Latest revision as of 15:22, 17 June 2024

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

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

-- Main process
function p.main(frame)
    local args = getArgs(frame);
    local infobox = require('Module:InfoboxProto').main(frame, args.title);
    local divclass = args.divclass;
    if divclass == nil then
        divclass = 'custom'
    end
    infobox:addClass('infobox-' .. divclass);

    for k, v in spairs(args) do
        if string.match(k, 'data[0-9]+') ~= nil then
            local i = k:gsub('data', '');
            addField('data' .. i, args['label' .. i])
        end
    end
    
    return tostring(infobox);

end

return p