## Groups core

Core Module - Permission Groups - Permission group making for factorio so you never have to make one by hand again

### Usage

    --- Example Group (Allow All)
    -- here we will create an admin group however we do not want them to use the map editor or mess with the permission groups
    Permission_Groups.new_group('Admin') -- this defines a new group called "Admin"
    :allow_all() -- this makes the default to allow any input action unless set other wise
    :disallow{ -- here we disallow the input action we don't want them to use
        'add_permission_group',
        'delete_permission_group',
        'import_permissions_string',
        'map_editor_action',
        'toggle_map_editor'
    }

    --- Example Group (Disallow All)
    -- here we will create a group that cant do anything but talk in chat
    Permission_Groups.new_group('Restricted') -- this defines a new group called "Restricted"
    :disallow_all() -- this makes the default to disallow any input action unless set other wise
    :allow('write_to_console') -- here we allow them to chat, {} can be used here if we had more than one action

### Dependencies

utils.game
utils.event
expcore.async

### Getters

new_group(name) | Defines a new permission group that can have it actions set in the config
get_group_by_name(name) | Returns the group with the given name, case sensitive
get_group_from_player(player) | Returns the group that a player is in

### Setters

reload_permissions() | Reloads/creates all permission groups and sets them to they configured state
set_player_group(player, group) | Sets a player's group to the one given, a player can only have one group at a time

### Actions

Permissions_Groups._prototype:set_action(action, state) | Sets the allow state of an action for this group, used internally but is safe to use else where
Permissions_Groups._prototype:allow(actions) | Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime
Permissions_Groups._prototype:disallow(actions) | Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime
Permissions_Groups._prototype:allow_all() | Sets the default state for any actions not given to be allowed, useful with :disallow
Permissions_Groups._prototype:disallow_all() | Sets the default state for any action not given to be disallowed, useful with :allow
Permissions_Groups._prototype:is_allowed(action) | Returns if an input action is allowed for this group

### Players

Permissions_Groups._prototype:create() | Creates or updates the permission group with the configured actions, used internally
Permissions_Groups._prototype:get_raw() | Returns the LuaPermissionGroup that was created with this group object, used internally
Permissions_Groups._prototype:add_player(player) | Adds a player to this group
Permissions_Groups._prototype:remove_player(player) | Removes a player from this group
Permissions_Groups._prototype:get_players([online]) | Returns all player that are in this group with the option to filter to online/offline only
Permissions_Groups._prototype:print(message) | Prints a message to every player in this group

### Dependencies

# utils.game
# utils.event
# expcore.async

### Getters

# new_group(name)

  Defines a new permission group that can have it actions set in the config

  Parameters:
  - name : (string) the name of the new group
  Returns:
  - (Permissions_Groups._prototype) the new group made with function to allow and disallow actions
  Usage:

      -- Defining a new permission group
      Groups.new_group('Admin')

# get_group_by_name(name)

  Returns the group with the given name, case sensitive

  Parameters:
  - name : (string) the name of the group to get
  Returns:
  - (Permissions_Groups._prototype or nil) the group with that name or nil if non found
  Usage:

      -- Getting a permision group
      local admin_group = Groups.get_group_by_name('Admin')

# get_group_from_player(player)

  Returns the group that a player is in

  Parameters:
  - player : (LuaPlayer) the player to get the group of can be name index etc
  Returns:
  - (Permissions_Groups._prototype or nil) the group with that player or nil if non found
  Usage:

      -- Get your permission group
      local group = Groups.get_group_from_player(game.player)

### Setters

# reload_permissions()

  Reloads/creates all permission groups and sets them to they configured state

  Usage:

      -- Reload the permission groups, used internally
      Groups.reload_permissions()

# set_player_group(player, group)

  Sets a player's group to the one given, a player can only have one group at a time

  Parameters:
  - player : (LuaPlayer) the player to effect can be name index etc
  - group : (string) the name of the group to give to the player
  Returns:
  - (boolean) true if the player was added successfully, false other wise
  Usage:

      -- Set your permission group
      Groups.set_player_group(game.player, 'Admin')

### Actions

# Permissions_Groups._prototype:set_action(action, state)

  Sets the allow state of an action for this group, used internally but is safe to use else where

  Parameters:
  - action : (string or defines.input_action) the action that you want to set the state of
  - state : (boolean) the state that you want to set it to, true = allow, false = disallow
  Returns:
  - (Permissions_Groups._prototype) returns self so function can be chained
  Usage:

      -- Set an action to be disallowed
      group:set_action('toggle_map_editor', false)

# Permissions_Groups._prototype:allow(actions)

  Sets an action or actions to be allowed for this group even with disallow_all triggered, Do not use in runtime

  Parameters:
  - actions : (string or Array) the action or actions that you want to allow for this group
  Returns:
  - (Permissions_Groups._prototype) returns self so function can be chained
  Usage:

      -- Allow some actions
      group:allow{
          'write_to_console'
      }

# Permissions_Groups._prototype:disallow(actions)

  Sets an action or actions to be disallowed for this group even with allow_all triggered, Do not use in runtime

  Parameters:
  - actions : (string or Array) the action or actions that you want to disallow for this group
  Returns:
  - (Permissions_Groups._prototype) returns self so function can be chained
  Usage:

      -- Disalow some actions
      group:disallow{
          'add_permission_group',
          'delete_permission_group',
          'import_permissions_string',
          'map_editor_action',
          'toggle_map_editor'
      }

# Permissions_Groups._prototype:allow_all()

  Sets the default state for any actions not given to be allowed, useful with :disallow

  Returns:
  - (Permissions_Groups._prototype) returns self so function can be chained
  Usage:

      -- Allow all actions unless given by disallow
      group:allow_all()

# Permissions_Groups._prototype:disallow_all()

  Sets the default state for any action not given to be disallowed, useful with :allow

  Returns:
  - (Permissions_Groups._prototype) returns self so function can be chained
  Usage:

      -- Disallow all actions unless given by allow
      group:disallow_all()

# Permissions_Groups._prototype:is_allowed(action)

  Returns if an input action is allowed for this group

  Parameters:
  - action : (string or defines.input_action) the action that you want to test for
  Returns:
  - (boolean) true if the group is allowed the action, false other wise
  Usage:

      -- Test if a group is allowed an action
      local allowed = group:is_allowed('write_to_console')

### Players

# Permissions_Groups._prototype:create()

  Creates or updates the permission group with the configured actions, used internally

  Returns:
  - (LuaPermissionGroup) the permission group that was created
  Usage:

      -- Create the permission group so players can be added, used internally
      group:create()

# Permissions_Groups._prototype:get_raw()

  Returns the LuaPermissionGroup that was created with this group object, used internally

  Returns:
  - (LuaPermissionGroup) the raw lua permission group
  Usage:

      -- Get the factorio api permision group, used internally
      local permission_group = group:get_raw()

# Permissions_Groups._prototype:add_player(player)

  Adds a player to this group

  Parameters:
  - player : (LuaPlayer) LuaPlayer the player you want to add to this group can be name or index etc
  Returns:
  - (boolean) true if the player was added successfully, false other wise
  Usage:

      -- Add a player to this permission group
      group:add_player(game.player)

# Permissions_Groups._prototype:remove_player(player)

  Removes a player from this group

  Parameters:
  - player : (LuaPlayer) LuaPlayer the player you want to remove from this group can be name or index etc
  Returns:
  - (boolean) true if the player was removed successfully, false other wise
  Usage:

      -- Remove a player from this permission group
      group:remove_player(game.player)

# Permissions_Groups._prototype:get_players([online])

  Returns all player that are in this group with the option to filter to online/offline only

  Parameters:
  - online : (boolean) if nil returns all players, if true online players only, if false returns online players only (optional)
  Returns:
  - (table) a table of players that are in this group; filtered if online param is given
  Usage:

      -- Get all players in this group
      local online_players = group:get_players()

      -- Get all online players in this group
      local online_players = group:get_players(true)

# Permissions_Groups._prototype:print(message)

  Prints a message to every player in this group

  Parameters:
  - message : (string) the message that you want to send to the players
  Returns:
  - (number) the number of players that received the message
  Usage:

      -- Print a message to all players in thie group
      group:print('Hello, World!')