Skip to content

Commit

Permalink
Add Documentation To Namespace Helper Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
LengthenedGradient committed Apr 13, 2024
1 parent 1dfb4e0 commit b112372
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
28 changes: 26 additions & 2 deletions lua/acf/core/classes/grouped.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ function Classes.AddGroupItem(ID, GroupID, Destiny, Data)
return Class
end

--- Gets a group given its ID and the namespace it's stored in
--- Gets a group given its ID and the namespace it's stored in
--- If no such group exists, it will instead check for a group that has a group item with the given ID
--- @param Namespace string The namespace to lookup the group in
--- @param ID string The ID of the group
--- @param ID string The ID of the group, or the ID of a group item
--- @return table | nil # The group if found
function Classes.GetGroup(Namespace, ID)
if not istable(Namespace) then return end
Expand All @@ -101,9 +102,15 @@ function Classes.AddGroupedFunctions(Namespace, Entries)
if not istable(Namespace) then return end
if not istable(Entries) then return end

-- Note that all the functions for simple class namespaces apply too.
Classes.AddSimpleFunctions(Namespace, Entries)

-- Getters

--- Gets a group item from a group in the namespace
--- @param ClassID string The ID of the group
--- @param ID string The ID of the group item
--- @return table | nil # A group item
function Namespace.GetItem(ClassID, ID)
local Group = isstring(ClassID) and Entries[ClassID]

Expand All @@ -112,6 +119,10 @@ function Classes.AddGroupedFunctions(Namespace, Entries)
return isstring(ID) and Group.Lookup[ID] or nil
end

--- Gets all the group items for a given group in the namespace
--- If aliases exist in the namespace, they will be ignored in the returned table
--- @param ClassID string The ID of the group to explore
--- @return table<string,table> # A table mapping item's IDs to themselves
function Namespace.GetItemEntries(ClassID)
local Group = isstring(ClassID) and Entries[ClassID]

Expand All @@ -126,6 +137,10 @@ function Classes.AddGroupedFunctions(Namespace, Entries)
return Result
end

--- Gets all the group items for a given group in the namespace
--- If aliases exist in the namespace, they will be included in the returned table
--- @param ClassID string The ID of the group to explore
--- @return table<number, table> # An "array" (e.g. {class1,class2,...}) containing group items.
function Namespace.GetItemList(ClassID)
local Group = isstring(ClassID) and Entries[ClassID]

Expand All @@ -141,6 +156,11 @@ function Classes.AddGroupedFunctions(Namespace, Entries)
end

-- Aliases

--- Adds an alias to a group item
--- @param GroupID string # The ID of the group the group item belongs to
--- @param ID string # The ID of the group item to make an alias of
--- @param Alias string # The alias to apply to the given group item
function Namespace.AddItemAlias(GroupID, ID, Alias)
local Group = isstring(GroupID) and Entries[GroupID]

Expand All @@ -153,6 +173,10 @@ function Classes.AddGroupedFunctions(Namespace, Entries)
Lookup[Alias] = Lookup[ID]
end

--- Checks whether an ID is an alias of a group item
--- @param GroupID string # The ID of the group the group item belongs to
--- @param ID string # The ID to check
--- @return boolean # Whether the ID is an alias of a group item
function Namespace.IsItemAlias(GroupID, ID)
local Group = isstring(GroupID) and Entries[GroupID]

Expand Down
19 changes: 18 additions & 1 deletion lua/acf/core/classes/simple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ function Classes.AddSimpleFunctions(Namespace, Entries)
if not istable(Namespace) then return end
if not istable(Entries) then return end

-- Getter
-- Getters

--- Gets the (object/simple class/group) from the namespace with the given ID
--- @param ID string The ID of the (object/simple class/group)
--- @return table | nil # The (object/simple class/group)
function Namespace.Get(ID)
return isstring(ID) and Entries[ID] or nil
end

--- Gets all the (objects/simple classes/groups) belonging to the namespace
--- If aliases exist in the namespace, they will be ignored in the returned table
--- @return table<string,table> # A table mapping the an (object/simple class/group)'s ID to itself
function Namespace.GetEntries()
local Result = {}

Expand All @@ -56,6 +63,9 @@ function Classes.AddSimpleFunctions(Namespace, Entries)
return Result
end

--- Gets all the (objects/simple classes/groups) belonging to the namespace
--- If aliases exist in the namespace, they will be included in the returned table
--- @return table<number,table> # An "array" (e.g. {class1,class2,...}) containing (objects/simple classes/groups)
function Namespace.GetList()
local Result = {}
local Count = 0
Expand All @@ -70,13 +80,20 @@ function Classes.AddSimpleFunctions(Namespace, Entries)
end

-- Aliases

--- Adds an alias to a (objects/simple classes/groups)
--- @param ID string The ID of the (objects/simple classes/groups) to apply an alias to
--- @param Alias string The Alias to map to the given ID
function Namespace.AddAlias(ID, Alias)
if not isstring(ID) then return end
if not isstring(Alias) then return end

Entries[Alias] = Entries[ID]
end

--- Checks whether an ID is an alias
--- @param ID string The ID to check
--- @return boolean # Whether the ID is an alias
function Namespace.IsAlias(ID)
local Data = isstring(ID) and Entries[ID]

Expand Down

0 comments on commit b112372

Please sign in to comment.