Skip to content

Commit

Permalink
Added Spaces For Annotations
Browse files Browse the repository at this point in the history
Probably should start using this convention across the files (also similar to the deprecated??? annotations from before)
  • Loading branch information
LengthenedGradient committed Apr 7, 2024
1 parent fd07095 commit d46e14a
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 101 deletions.
30 changes: 15 additions & 15 deletions lua/acf/core/classes/object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ local Classes = ACF.Classes
local Stored = {}
local Queued = {}

---Creates a new instance of the provided class
---If The class has an "OnCalled" method defined, it will run that.
---@param Class table The class to create an instance of
---@return table # The newly created instance
--- Creates a new instance of the provided class
--- If The class has an "OnCalled" method defined, it will run that.
--- @param Class table The class to create an instance of
--- @return table # The newly created instance
local function CreateInstance(Class)
local New = {}

Expand All @@ -23,9 +23,9 @@ local function CreateInstance(Class)
return New
end

---Used to queue classes that are waiting for their base classes to be loaded
---@param ID string The id of the classs to queue
---@param Base table The base class
--- Used to queue classes that are waiting for their base classes to be loaded
--- @param ID string The id of the classs to queue
--- @param Base table The base class
local function QueueBaseClass(ID, Base)
if not Queued[Base] then
Queued[Base] = { [ID] = true }
Expand All @@ -34,9 +34,9 @@ local function QueueBaseClass(ID, Base)
end
end

---Updates/Initializes a metatable for a class and "parents" it to a base class
---@param Class table The class to be initialized/updated
---@param Base string The base class of the provided class
--- Updates/Initializes a metatable for a class and "parents" it to a base class
--- @param Class table The class to be initialized/updated
--- @param Base string The base class of the provided class
local function AttachMetaTable(Class, Base)
local OldMeta = getmetatable(Class) or {}

Expand Down Expand Up @@ -70,11 +70,11 @@ local function AttachMetaTable(Class, Base)
end)
end

---Creates a new object with the given ID, as a subclass of the Base class provided
---@param ID string The ID of the new sub class to add
---@param Base string The ID of the base class the sub class will inherit from
---@param Destiny table A table that the new object will be indexed into, with the ID as key
---@return table # The created class
--- Creates a new object with the given ID, as a subclass of the Base class provided
--- @param ID string The ID of the new sub class to add
--- @param Base string The ID of the base class the sub class will inherit from
--- @param Destiny table A table that the new object will be indexed into, with the ID as key
--- @return table # The created class
function Classes.AddObject(ID, Base, Destiny)
if not isstring(ID) then return end
if not istable(Destiny) then return end
Expand Down
163 changes: 80 additions & 83 deletions lua/acf/core/utilities/util_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ do -- HTTP Request
end
end

---Sends a Fetch request, to the given url, with the given headers.
---For further elaboration, please read this function's definition and SuccessfulRequest.
---To better understand the inputs, please check: https://wiki.facepunch.com/gmod/http.Fetch.
---@param Link string The http endpoint to send a fetch request to.
---@param Headers table Headers to use in the http request
---@param OnSuccess fun(Body:string,Data:table)
---@param OnFailure fun(Error:string)
--- Sends a Fetch request, to the given url, with the given headers.
--- For further elaboration, please read this function's definition and SuccessfulRequest.
--- To better understand the inputs, please check: https://wiki.facepunch.com/gmod/http.Fetch.
--- @param Link string The http endpoint to send a fetch request to.
--- @param Headers table Headers to use in the http request
--- @param OnSuccess fun(Body:string,Data:table)
--- @param OnFailure fun(Error:string)
function ACF.StartRequest(Link, OnSuccess, OnFailure, Headers)
if not isstring(Link) then return end
if not isfunction(OnSuccess) then OnSuccess = nil end
Expand Down Expand Up @@ -220,10 +220,10 @@ do
end

------------------------------------------------------------------------
---Saves the physical properties/constraints/etc of an entity to the "Entities" table.
---Should be used before calling Update functions on acf entities. Call RestoreEntity after.
---Necessary because some components will update their physics object on update (e.g. ammo crates/scaleable guns)
---@param Entity table The entity to index
--- Saves the physical properties/constraints/etc of an entity to the "Entities" table.
--- Should be used before calling Update functions on acf entities. Call RestoreEntity after.
--- Necessary because some components will update their physics object on update (e.g. ammo crates/scaleable guns)
--- @param Entity table The entity to index
function ACF.SaveEntity(Entity)
if not IsValid(Entity) then return end

Expand All @@ -248,9 +248,9 @@ do
end)
end

---Sets the properties/constraints/etc of an entity from the "Entities" table.
---Should be used after calling Update functions on acf entities.
---@param Entity table - The entity to restore
--- Sets the properties/constraints/etc of an entity from the "Entities" table.
--- Should be used after calling Update functions on acf entities.
--- @param Entity table - The entity to restore
function ACF.RestoreEntity(Entity)
if not IsValid(Entity) then return end
if not Entities[Entity] then return end
Expand Down Expand Up @@ -294,12 +294,11 @@ do -- Entity linking
]]--
local EntityLink = {}

---Returns links to the entry
---@param Entity table The entity to check
---@param VarName string The field of the entity that stores link sources (e.g. "Entity.FuelTanks" for engines)
---@param SingleEntry boolean | nil Whether the entity supports a single source link or multiple
---@return table<table, true> # A table whose keys are the link source entities and whose values are all true
---@see EntityLink
--- Returns links to the entry
--- @param Entity table The entity to check
--- @param VarName string The field of the entity that stores link sources (e.g. "Entity.FuelTanks" for engines)
--- @param SingleEntry boolean | nil Whether the entity supports a single source link or multiple
--- @return table<table, true> # A table whose keys are the link source entities and whose values are all true
local function GetEntityLinks(Entity, VarName, SingleEntry)
if not Entity[VarName] then return {} end

Expand All @@ -316,14 +315,13 @@ do -- Entity linking
return Result
end

---If your entity can link/unlink other entities, you should use this
---Registers that all entities of this class have a field which refers to its link source(s)
---Certain E2/SF functions require this in order to function (e.g. getting linked wheels of a gearbox)
---Example usage: ACF.RegisterLinkSource("acf_engine", "FuelTanks")
---@param Class string The name of the class
---@param VarName string The field referencing one of the class' link source(s)
---@param SingleEntry boolean | nil Whether the entity supports a single source link or multiple
---@see EntityLink
--- If your entity can link/unlink other entities, you should use this
--- Registers that all entities of this class have a field which refers to its link source(s)
--- Certain E2/SF functions require this in order to function (e.g. getting linked wheels of a gearbox)
--- Example usage: ACF.RegisterLinkSource("acf_engine", "FuelTanks")
--- @param Class string The name of the class
--- @param VarName string The field referencing one of the class' link source(s)
--- @param SingleEntry boolean | nil Whether the entity supports a single source link or multiple
function ACF.RegisterLinkSource(Class, VarName, SingleEntry)
local Data = EntityLink[Class]

Expand All @@ -340,10 +338,9 @@ do -- Entity linking
end
end

---Returns all the link source callables for this entity
---@param Class string The name of the class
---@return table<string, fun(Entity:table):table> # All the relevant link source callables
---@see EntityLink on how the callables work
--- Returns all the link source callables for this entity
--- @param Class string The name of the class
--- @return table<string, fun(Entity:table):table> # All the relevant link source callables
function ACF.GetAllLinkSources(Class)
if not EntityLink[Class] then return {} end

Expand All @@ -356,19 +353,19 @@ do -- Entity linking
return Result
end

---Returns the link source callable of a given class and VarName
---@param Class string The name of the class
---@param VarName string The varname for the given class
---@return fun(Entity:table):table # The link source callable
--- Returns the link source callable of a given class and VarName
--- @param Class string The name of the class
--- @param VarName string The varname for the given class
--- @return fun(Entity:table):table # The link source callable
function ACF.GetLinkSource(Class, VarName)
if not EntityLink[Class] then return end

return EntityLink[Class][VarName]
end

---Returns a table of entities linked to the given entity.
---@param Entity The entity to get links from
---@return table<table,true> # A table mapping entities to true.
--- Returns a table of entities linked to the given entity.
--- @param Entity The entity to get links from
--- @return table<table,true> # A table mapping entities to true.
function ACF.GetLinkedEntities(Entity)
if not IsValid(Entity) then return {} end

Expand Down Expand Up @@ -405,10 +402,10 @@ do -- Entity linking
]]--
local ClassLink = { Link = {}, Unlink = {} }

---Registers a link or unlink between two classes and how to handle them.
---@param Class1 string The first class in the link
---@param Class2 string The other class in the link
---@param Function fun(Entity1:table,Entity2:table)
--- Registers a link or unlink between two classes and how to handle them.
--- @param Class1 string The first class in the link
--- @param Class2 string The other class in the link
--- @param Function fun(Entity1:table,Entity2:table)
local function RegisterNewLink(Action, Class1, Class2, Function)
if not isfunction(Function) then return end

Expand Down Expand Up @@ -444,36 +441,36 @@ do -- Entity linking
end
end

---Registers that two classes can be linked, and how to handle entitities of their class being linked.
---@param Class1 string The first class in the link
---@param Class2 string The other class in the link
---@param Function fun(Entity1:table,Entity2:table)
--- Registers that two classes can be linked, and how to handle entitities of their class being linked.
--- @param Class1 string The first class in the link
--- @param Class2 string The other class in the link
--- @param Function fun(Entity1:table,Entity2:table)
function ACF.RegisterClassLink(Class1, Class2, Function)
RegisterNewLink("Link", Class1, Class2, Function)
end

---Returns the callback defined previously by "RegisterClassLink", between Class1 and Class2
---@param Class1 string The first class in the link
---@param Class2 string The other class in the link
---@param Function fun(Entity1:table,Entity2:table)
--- Returns the callback defined previously by "RegisterClassLink", between Class1 and Class2
--- @param Class1 string The first class in the link
--- @param Class2 string The other class in the link
--- @param Function fun(Entity1:table,Entity2:table)
function ACF.GetClassLink(Class1, Class2)
if not ClassLink.Link[Class1] then return end

return ClassLink.Link[Class1][Class2]
end

---Registers that two classes can be unlinked, and how to handle entitities of their class being unlinked.
---@param Class1 string The first class in the link
---@param Class2 string The other class in the link
---@param Function fun(Entity1:table,Entity2:table)
--- Registers that two classes can be unlinked, and how to handle entitities of their class being unlinked.
--- @param Class1 string The first class in the link
--- @param Class2 string The other class in the link
--- @param Function fun(Entity1:table,Entity2:table)
function ACF.RegisterClassUnlink(Class1, Class2, Function)
RegisterNewLink("Unlink", Class1, Class2, Function)
end

---Returns the callback defined previously by "RegisterClassUnlink", between Class1 and Class2
---@param Class1 string The first class in the link
---@param Class2 string The other class in the link
---@param Function fun(Entity1:table,Entity2:table)
--- Returns the callback defined previously by "RegisterClassUnlink", between Class1 and Class2
--- @param Class1 string The first class in the link
--- @param Class2 string The other class in the link
--- @param Function fun(Entity1:table,Entity2:table)
function ACF.GetClassUnlink(Class1, Class2)
if not ClassLink.Unlink[Class1] then return end

Expand All @@ -493,9 +490,9 @@ do -- Entity inputs
]]--
local Inputs = {}

---Returns the table mapping a class' inputs to a function that handles them
---@param Class string The class to get data from
---@return table<string,fun(Entity:table,Value:any)> # A table of input names to functions that handle them
--- Returns the table mapping a class' inputs to a function that handles them
--- @param Class string The class to get data from
--- @return table<string,fun(Entity:table,Value:any)> # A table of input names to functions that handle them
local function GetClass(Class)
if not Inputs[Class] then
Inputs[Class] = {}
Expand All @@ -504,10 +501,10 @@ do -- Entity inputs
return Inputs[Class]
end

---For a given class, add an input action for when an input is triggered
---@param Class string The class to apply to
---@param Name string The wire input to trigger on
---@param Action fun(Entity:table,Value:any) The function that gets called when the wire input is triggered
--- For a given class, add an input action for when an input is triggered
--- @param Class string The class to apply to
--- @param Name string The wire input to trigger on
--- @param Action fun(Entity:table,Value:any) The function that gets called when the wire input is triggered
function ACF.AddInputAction(Class, Name, Action)
if not Class then return end
if not Name then return end
Expand All @@ -518,10 +515,10 @@ do -- Entity inputs
Data[Name] = Action
end

---Returns the callback defined previously by "AddInputAction", for the given class and wire input name.
---@param Class string The class to retrieve from
---@param Name string The wire input retrieve from
---@return fun(Entity:table,Value:any)
--- Returns the callback defined previously by "AddInputAction", for the given class and wire input name.
--- @param Class string The class to retrieve from
--- @param Name string The wire input retrieve from
--- @return fun(Entity:table,Value:any)
function ACF.GetInputAction(Class, Name)
if not Class then return end
if not Name then return end
Expand All @@ -531,9 +528,9 @@ do -- Entity inputs
return Data[Name]
end

---For a given class, returns a table of wire input names mapped to their handlers, defined previously by "AddInputAction".
---@param Class string The class to retrieve from
---@return table<string,fun(Entity:table,Value:any)>
--- For a given class, returns a table of wire input names mapped to their handlers, defined previously by "AddInputAction".
--- @param Class string The class to retrieve from
--- @return table<string,fun(Entity:table,Value:any)>
function ACF.GetInputActions(Class)
if not Class then return end

Expand All @@ -556,10 +553,10 @@ do -- Extra overlay text
]]--
local Classes = {}

---Registers a function that provides text for the overlay, with a given Identifier, for a given class.
---@param ClassName string Name of the class to register for
---@param Identifier string The identitifer to assosciate the function with
---@param Function fun(Entity:table):string A function which takes the entity and returns some text for the identifier
--- Registers a function that provides text for the overlay, with a given Identifier, for a given class.
--- @param ClassName string Name of the class to register for
--- @param Identifier string The identitifer to assosciate the function with
--- @param Function fun(Entity:table):string A function which takes the entity and returns some text for the identifier
function ACF.RegisterOverlayText(ClassName, Identifier, Function)
if not isstring(ClassName) then return end
if Identifier == nil then return end
Expand All @@ -576,9 +573,9 @@ do -- Extra overlay text
end
end

---Removes a overlay callback defined previously by "RegisterOverlayText"
---@param ClassName string Name of the class to affect
---@param Identifier string The identitifer of the function to be removed
--- Removes a overlay callback defined previously by "RegisterOverlayText"
--- @param ClassName string Name of the class to affect
--- @param Identifier string The identitifer of the function to be removed
function ACF.RemoveOverlayText(ClassName, Identifier)
if not isstring(ClassName) then return end
if Identifier == nil then return end
Expand All @@ -590,9 +587,9 @@ do -- Extra overlay text
Class[Identifier] = nil
end

---Given an entity, returns its overlay text, made by concatinating the overlay functions for its class
---@param Entity table The entity to generate overlay text for
---@return string # The overlay text for this entity
--- Given an entity, returns its overlay text, made by concatinating the overlay functions for its class
--- @param Entity table The entity to generate overlay text for
--- @return string # The overlay text for this entity
function ACF.GetOverlayText(Entity)
local Class = Classes[Entity:GetClass()]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ local function GetReloadTime(Entity)
return (Unloading or NewLoad) and Entity.MagReload or Entity.ReloadTime or 0
end

---Returns a table of all the linked wheels of a given entity (usually gearbox?)
---@param Target table Entity to get linked entities from
---@return table<table,true> Linked The linked entities
--- Returns a table of all the linked wheels of a given entity (usually gearbox?)
--- @param Target table Entity to get linked entities from
--- @return table<table,true> Linked The linked entities
local function GetLinkedWheels(Target)
local Queued = { [Target] = true }
local Checked = {}
Expand Down

0 comments on commit d46e14a

Please sign in to comment.