Skip to content

Latest commit

 

History

History
170 lines (100 loc) · 3.74 KB

KeybindCategory.html.md

File metadata and controls

170 lines (100 loc) · 3.74 KB

KeybindCategory

Class: KeybindCategory

Creates a class KeybindCategory, which is a manageable category and wrapper for a group of Keybind objects, acting like a container for them.

The system is designed so that a Keybind's name is an unique identifier for that keybind within a Category. Different categories may have a keybind with the same name.

KeybindCategory Object

Attributes:

Attribute Type Description
name string The name of the Category. Must be unique.
keybinds table table with Keybind values

Methods:

Keybind management:


create(name)

Method: create(string name)

Return: KeybindCategory

Description:
Creates an object of this class.

Example:

local cat = KeybindCategory:create("MyNewCategory")

remove()

Method: remove()

Return: void

Description:
Removes all Keybinds from this category’s keybinds list, by executing Keybind:remove() on each of them, which makes sure that each Keybind is gracefully detached from the system and nothing messes up due to their abrupt removal, then makes the keybinds an empty table again.

Example:

local cat = KeybindManager:getCategoryByName("Turning")
cat:remove()

injectAsOption()

Method: injectAsOption()

Return: void

Description:
If client_options is loaded, injects this Category into the UI at that module.

Example:

local cat = KeybindCategory:create("Movement")
KeybindManager:addCategory(cat)

cat:injectAsOption()

example


getKeybinds( )

Method: getKeybinds()

Return: table of Keybind objects.

Description: Returns a table of all Keybinds that have been added to this category.

Example:

	local cat = KeybindManager:getCategoryByName("myCategory")
	for _, keybind in pairs(cat:getKeybinds()) do
		print("Keybind [" .. keybind.name .. "] found in this category.")
	end

getKeybindByName(name)

Method: hasKeybindByName(string name)

Return: Keybindor nil

Description: Checks if there is a Keybind whose name matches the provided name inside this category, and if yes, returns it.

Example:

	local cat = KeybindManager:getCategoryByName("myCategory")
	if cat:getKeybindByName("Walk North") then
		-- Found that keybind in this category.
	end

removeKeybindByName(name)

Method: removeKeybindByName(string name)

Return: void

Description: Checks if there is a Keybind whose name matches the provided name inside this category, and if yes, executes Keybind:remove() on it.

Example:

	local cat = KeybindManager:getCategoryByName("myCategory")
	cat:removeKeybindByName("Walk North") -- RIP in pepperoni 

addKeybind(Keybind)

Method: addKeybind(Keybind keybind)

Return: bool

Description: Adds a Keybind into this category’s keybinds table.

If possible, inserts it at the index which the Keybind.defaultIndex attribute suggested (this helps with sorting default keybinds to always display in the same order in the UI).

Use this method as a gate for validating whether Keybinds should be added to the category if you come up with any new rules for that.

Example:

	local kbind = Keybind:create(params~)
	local cat = KeybindManager:getCategoryByName("myCategory")
	cat:addKeybind(kbind)