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
     end
    infobox:addClass('infobox-' .. divclass);


     function CreateClass(...)
     for k, v in spairs(args) do
         -- "cls" is the new class
         if string.match(k, 'data[0-9]+') ~= nil then
        local cls, bases = {}, {...}
            local i = k:gsub('data', '');
        -- copy base class contents into the new class
            addField('data' .. i, args['label' .. i])
        for i, base in ipairs(bases) do
            for k, v in pairs(base) do
                cls[k] = v
            end
         end
         end
        -- set the class's __index, and start filling an "is_a" table that contains this class and all of its bases
        -- so you can do an "instance of" check using my_instance.is_a[MyClass]
        cls.__index, cls.is_a = cls, {
            [cls] = true
        }
        for i, base in ipairs(bases) do
            for c in pairs(base.is_a) do
                cls.is_a[c] = true
            end
            cls.is_a[base] = true
        end
        -- the class's __call metamethod
        setmetatable(cls, {
            __call = function(c, ...)
                local instance = setmetatable({}, c)
                -- run the init method if it's there
                local init = instance._init
                if init then
                    init(instance, ...)
                end
                return instance
            end
        })
        -- return the new class table, that's ready to fill with methods
        return cls
     end
     end
 
      
    -- Argument init
     return tostring(infobox);
    local traits = args[3]
    if (traits == nil) then
        traits = '-, -'
    end
    traits = split(traits);
    local skill = args[2]
 
    -- Define the class blueprint for traits.
    Trait = {
        name = "",
        values = {
            mp_multiplier = 100,
            cd_multiplier = 100,
            duration_multiplier = 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
 
        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 i = 1, 2, 1 do
            self.details.mp_cost[i] = self.details.mp_cost[i] * self.values.mp_multiplier
            self.details.cooldown[i] = self.details.cooldown[i] * self.values.cd_multiplier
            self.details.duration[i] = self.details.duration[i] * self.values.duration_multiplier
        end
        return self
    end
 
    -- Define the mother object of traits.
    local reversed = Trait:new({
        name = "Reversed",
        values = {
            mp_multiplier = 60,
            cd_multiplier = 150
        },
        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