ripple-new / GameLogic / Base / Module.lua
Module.lua
Raw
package.path = package.path .. ";../../?.lua"
package.path = package.path .. ";../../../../?/?.lua"
require("Command");
require("Functions.GlobalFunctions")

Module = {
    type = "Module",
    id = "nil",
    name = "module",
    description = "description",
    owner = {},
    moduleData = {
        type = "ModuleData"
    },
    moduleCommands = {
        type = "ModuleCommands"
    },
}

function Module:New(o, owner, name, description)
    if owner == nil then
        print("No valid owner. Cannot create module without owner.")
        return nil;
    end
    o = o or {};
    setmetatable(o, self);
    self.__index = self;
    if name ~= nil then self.name = name end
    if description ~= nil then self.description = description end
    return o;
end

function Module:Execute()
    for k,v in pairs(self.moduleCommands) do
        if k ~= "type" then v:Execute(self) end 
    end
    print("Module[".. self.name .."]: Executed Commands")
end

function Module:AddCommand(command)
    return GlobalFunctions.Add(self, command);
end

function Module:FindCommand(id)
    return GlobalFunctions.Find(self, id);
end

function Module:RemoveCommand(id)
    return GlobalFunctions.Remove(self, id);
end