From b709965c76b5a96484dc979d860e7172d0dc5236 Mon Sep 17 00:00:00 2001
From: LengthenedGradient
<109800352+LengthenedGradient@users.noreply.github.com>
Date: Sat, 6 Apr 2024 21:53:38 -0400
Subject: [PATCH 1/7] Documentation Update
Adds documentation for certain functions related to entity creation.
---
lua/acf/core/classes/helpers.lua | 3 +-
lua/acf/core/classes/object.lua | 28 +++-
lua/acf/core/utilities/util_sv.lua | 147 +++++++++++++++++-
lua/acf/core/validation_sv.lua | 2 +
.../core/custom/acffunctions.lua | 11 +-
5 files changed, 177 insertions(+), 14 deletions(-)
diff --git a/lua/acf/core/classes/helpers.lua b/lua/acf/core/classes/helpers.lua
index 992ff1e69..918bad18f 100644
--- a/lua/acf/core/classes/helpers.lua
+++ b/lua/acf/core/classes/helpers.lua
@@ -1,6 +1,7 @@
local Classes = ACF.Classes
-
+---Adds a sbox limit for this class
+---@param Data {Name:string, Amount:number, Text:string}
function Classes.AddSboxLimit(Data)
if CLIENT then return end
if ConVarExists("sbox_max" .. Data.Name) then return end
diff --git a/lua/acf/core/classes/object.lua b/lua/acf/core/classes/object.lua
index 89788b3cf..3c04c06ea 100644
--- a/lua/acf/core/classes/object.lua
+++ b/lua/acf/core/classes/object.lua
@@ -6,10 +6,14 @@ 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
local function CreateInstance(Class)
local New = {}
+ -- This simulates "instantiation" among other things (https://www.lua.org/pil/13.4.1.html)
setmetatable(New, { __index = table.Copy(Class) })
if New.OnCalled then
@@ -19,6 +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
local function QueueBaseClass(ID, Base)
if not Queued[Base] then
Queued[Base] = { [ID] = true }
@@ -27,26 +34,31 @@ 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
local function AttachMetaTable(Class, Base)
local OldMeta = getmetatable(Class) or {}
if Base then
- local BaseClass = Stored[Base]
+ local BaseClass = Stored[Base] -- Retrieve the base class from ID
if BaseClass then
- Class.BaseClass = BaseClass
- OldMeta.__index = BaseClass
+ Class.BaseClass = BaseClass -- Class' base class becomes BaseClass
+ OldMeta.__index = BaseClass -- Class inherits from BaseClass
else
QueueBaseClass(Class.ID, Base)
end
end
+ -- Update the "constructor" of the class to create an instance of the updated class
OldMeta.__call = function()
return CreateInstance(Class)
end
setmetatable(Class, OldMeta)
+ -- A tick later, classes will be guaranteed to have been loaded.
timer.Simple(0, function()
if Class.OnLoaded then
Class:OnLoaded()
@@ -58,6 +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
function Classes.AddObject(ID, Base, Destiny)
if not isstring(ID) then return end
if not istable(Destiny) then return end
@@ -67,8 +84,9 @@ function Classes.AddObject(ID, Base, Destiny)
Class.ID = ID
- AttachMetaTable(Class, Base)
+ AttachMetaTable(Class, Base) -- Attach a metatable to "Class" with "Base" as parent
+ -- If this class is a base class for other class(es), Attach metatables to all its sub classes with itself as base class.
if Queued[ID] then
for K in pairs(Queued[ID]) do
AttachMetaTable(Stored[K], ID)
diff --git a/lua/acf/core/utilities/util_sv.lua b/lua/acf/core/utilities/util_sv.lua
index 29f05a469..1af7dd35e 100644
--- a/lua/acf/core/utilities/util_sv.lua
+++ b/lua/acf/core/utilities/util_sv.lua
@@ -42,6 +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)
function ACF.StartRequest(Link, OnSuccess, OnFailure, Headers)
if not isstring(Link) then return end
if not isfunction(OnSuccess) then OnSuccess = nil end
@@ -101,7 +108,9 @@ do -- HTTP Request
end)
end
-do -- Entity saving and restoring
+-- Entity saving and restoring
+-- Necessary because some components will update their physics object on update (e.g. ammo crates/scaleable guns)
+do
local ConstraintTypes = duplicator.ConstraintType
local Entities = {}
@@ -135,7 +144,6 @@ do -- Entity saving and restoring
end
end
- -- Similar to constraint.RemoveAll
local function ClearConstraints(Entity)
local Constraints = Entity.Constraints
@@ -211,7 +219,10 @@ do -- Entity saving and restoring
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
function ACF.SaveEntity(Entity)
if not IsValid(Entity) then return end
@@ -229,11 +240,16 @@ do -- Entity saving and restoring
ClearConstraints(Entity)
+ -- If for whatever reason the entity is removed before RestoreEntity is called,
+ -- Update the entity table
Entity:CallOnRemove("ACF_RestoreEntity", function()
Entities[Entity] = nil
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
function ACF.RestoreEntity(Entity)
if not IsValid(Entity) then return end
if not Entities[Entity] then return end
@@ -252,12 +268,37 @@ do -- Entity saving and restoring
Entities[Entity] = nil
+ -- Disables the CallOnRemove callback from earlier
Entity:RemoveCallOnRemove("ACF_RestoreEntity")
end
end
do -- Entity linking
+ --[[
+ Example structure of EntityLink:
+
+ EntityLink = {
+ ["acf_engine"] = {
+ ["FuelTanks"] = function(Entity)
+ return GetEntityLinks(Entity, "FuelTanks", nil)
+ end,
+ ["Gearboxes"] = function(Entity)
+ return GetEntityLinks(Entity, "Gearboxes", nil)
+ end
+ }
+ }
+
+ This example demonstrates that any entity of the acf_engine class has the fields FuelTanks and Gearboxes in its entity table that reference their respective link sources.
+ This is done to localize the functions for optimization reasons.
+ ]]--
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
# A table whos keys are the link source entities and whos values are all true
+ ---@see EntityLink
local function GetEntityLinks(Entity, VarName, SingleEntry)
if not Entity[VarName] then return {} end
@@ -274,7 +315,14 @@ do -- Entity linking
return Result
end
- -- If your entity can link/unlink other entities, you should use this
+ ---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
function ACF.RegisterLinkSource(Class, VarName, SingleEntry)
local Data = EntityLink[Class]
@@ -291,6 +339,10 @@ do -- Entity linking
end
end
+ ---Returns all the link source callables for this entity
+ ---@param Class string The name of the class
+ ---@return table # All the relevant link source callables
+ ---@see EntityLink on how the callables work
function ACF.GetAllLinkSources(Class)
if not EntityLink[Class] then return {} end
@@ -303,12 +355,17 @@ 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
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.
function ACF.GetLinkedEntities(Entity)
if not IsValid(Entity) then return {} end
@@ -327,7 +384,28 @@ do -- Entity linking
return Result
end
+ --[[
+ Example structure of ClassLink:
+
+ ClassLink = {
+ ["Link"] = {
+ ["acf_ammo"] = {
+ ["acf_gun"] = function(Ent1, Ent2) -- Handles linking guns and ammo
+ }
+ },
+ ["Unlink"] = {
+ ["acf_ammo"] = {
+ ["acf_gun"] = function(Ent1, Ent2) -- Handles unlinking guns and ammo
+ }
+ }
+ }
+ ]]--
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)
local function RegisterNewLink(Action, Class1, Class2, Function)
if not isfunction(Function) then return end
@@ -363,20 +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)
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)
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)
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)
function ACF.GetClassUnlink(Class1, Class2)
if not ClassLink.Unlink[Class1] then return end
@@ -385,8 +479,20 @@ do -- Entity linking
end
do -- Entity inputs
+ --[[
+ Example structure of inputs:
+
+ Inputs = {
+ ["acf_ammo"] = {
+ ["Load"] = function(Entity, Value) -- Handles when the "Load" wire input is triggered
+ }
+ }
+ ]]--
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 # A table of input names to functions that handle them
local function GetClass(Class)
if not Inputs[Class] then
Inputs[Class] = {}
@@ -395,6 +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
function ACF.AddInputAction(Class, Name, Action)
if not Class then return end
if not Name then return end
@@ -405,6 +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)
function ACF.GetInputAction(Class, Name)
if not Class then return end
if not Name then return end
@@ -414,6 +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
function ACF.GetInputActions(Class)
if not Class then return end
@@ -422,8 +539,24 @@ do -- Entity inputs
end
do -- Extra overlay text
+ --[[
+ Example structure of Classes:
+
+ Classes = {
+ ["acf_ammo"] = {
+ ["Kinematic"] = function(Entity), -- Returns text containing muzzle vel, drag coef, etc.
+ ["Explosive"] = function(Entity) -- Returns text containing explosive mass, blast radius, etc.
+ }
+ }
+
+ *Note that unlike most examples this isn't actually used anywhere at the time of writing.*
+ ]]--
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
function ACF.RegisterOverlayText(ClassName, Identifier, Function)
if not isstring(ClassName) then return end
if Identifier == nil then return end
@@ -440,6 +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
function ACF.RemoveOverlayText(ClassName, Identifier)
if not isstring(ClassName) then return end
if Identifier == nil then return end
@@ -451,6 +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
function ACF.GetOverlayText(Entity)
local Class = Classes[Entity:GetClass()]
diff --git a/lua/acf/core/validation_sv.lua b/lua/acf/core/validation_sv.lua
index 92f4c3694..a2e693ea1 100644
--- a/lua/acf/core/validation_sv.lua
+++ b/lua/acf/core/validation_sv.lua
@@ -212,6 +212,8 @@ function ACF.Check(Entity, ForceUpdate) -- IsValid but for ACF
return Entity.ACF.Type
end
+---Initializes the entity's armor properties. If ACF_Activate is defined by the entity, that is called.
+---@param Recalc booloean Whether or not to recalculate the health
function ACF.Activate(Entity, Recalc)
-- Density of steel = 7.8g cm3 so 7.8kg for a 1mx1m plate 1m thick
local PhysObj = Entity:GetPhysicsObject()
diff --git a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
index dce992253..b1dd18541 100644
--- a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
+++ b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
@@ -39,6 +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 Linked The linked entities
local function GetLinkedWheels(Target)
local Queued = { [Target] = true }
local Checked = {}
@@ -52,9 +55,9 @@ local function GetLinkedWheels(Target)
Queued[Current] = nil
Checked[Current] = true
-
- for Name, Action in pairs(Sources) do
- for Entity in pairs(Action(Current)) do
+
+ for Name, Action in pairs(Sources) do -- For all source types
+ for Entity in pairs(Action(Current)) do -- For all entities of this source type
if not (Checked[Entity] or Queued[Entity]) then
if Name == "Wheels" then
Checked[Entity] = true
@@ -76,7 +79,7 @@ end
__e2setcost(2)
---returns current ACF drag divisor
+-- Returns current ACF drag divisor
e2function number acfDragDiv()
return ACF.DragDiv
end
From 6908ae6596f9d1ae4394405600a66697b2b04e5d Mon Sep 17 00:00:00 2001
From: LengthenedGradient
<109800352+LengthenedGradient@users.noreply.github.com>
Date: Sun, 7 Apr 2024 11:49:51 -0400
Subject: [PATCH 2/7] Fix Linter Issues and Typos
---
lua/acf/core/utilities/util_sv.lua | 9 ++++++---
.../gmod_wire_expression2/core/custom/acffunctions.lua | 4 ++--
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/lua/acf/core/utilities/util_sv.lua b/lua/acf/core/utilities/util_sv.lua
index 1af7dd35e..d0b053474 100644
--- a/lua/acf/core/utilities/util_sv.lua
+++ b/lua/acf/core/utilities/util_sv.lua
@@ -144,6 +144,7 @@ do
end
end
+ -- Similar to constraint.RemoveAll
local function ClearConstraints(Entity)
local Constraints = Entity.Constraints
@@ -297,7 +298,7 @@ do -- Entity linking
---@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 # A table whos keys are the link source entities and whos values are all true
+ ---@return table # A table whose keys are the link source entities and whose values are all true
---@see EntityLink
local function GetEntityLinks(Entity, VarName, SingleEntry)
if not Entity[VarName] then return {} end
@@ -355,7 +356,7 @@ do -- Entity linking
return Result
end
- -- Returns the link source callable of a given class and VarName
+ ---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
@@ -365,7 +366,9 @@ do -- Entity linking
return EntityLink[Class][VarName]
end
- -- Returns a table of entities linked to the given entity.
+ ---Returns a table of entities linked to the given entity.
+ ---@param Entity The entity to get links from
+ ---@return table # A table mapping entities to true.
function ACF.GetLinkedEntities(Entity)
if not IsValid(Entity) then return {} end
diff --git a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
index b1dd18541..6ee0650b2 100644
--- a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
+++ b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
@@ -55,10 +55,10 @@ local function GetLinkedWheels(Target)
Queued[Current] = nil
Checked[Current] = true
-
+
for Name, Action in pairs(Sources) do -- For all source types
for Entity in pairs(Action(Current)) do -- For all entities of this source type
- if not (Checked[Entity] or Queued[Entity]) then
+ if not (Checked[Entity] or Queued[Entity]) then
if Name == "Wheels" then
Checked[Entity] = true
Linked[Entity] = true
From fd070959c2f9e7e107a09110a00827cbccd5a92b Mon Sep 17 00:00:00 2001
From: LengthenedGradient
<109800352+LengthenedGradient@users.noreply.github.com>
Date: Sun, 7 Apr 2024 11:53:14 -0400
Subject: [PATCH 3/7] Fix Linter Typo
---
lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
index 6ee0650b2..d524aafb8 100644
--- a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
+++ b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
@@ -58,7 +58,7 @@ local function GetLinkedWheels(Target)
for Name, Action in pairs(Sources) do -- For all source types
for Entity in pairs(Action(Current)) do -- For all entities of this source type
- if not (Checked[Entity] or Queued[Entity]) then
+ if not (Checked[Entity] or Queued[Entity]) then
if Name == "Wheels" then
Checked[Entity] = true
Linked[Entity] = true
From d46e14a9adeb315389ce98590601e82ec9e548a5 Mon Sep 17 00:00:00 2001
From: LengthenedGradient
<109800352+LengthenedGradient@users.noreply.github.com>
Date: Sun, 7 Apr 2024 12:32:11 -0400
Subject: [PATCH 4/7] Added Spaces For Annotations
Probably should start using this convention across the files (also similar to the deprecated??? annotations from before)
---
lua/acf/core/classes/object.lua | 30 ++--
lua/acf/core/utilities/util_sv.lua | 163 +++++++++---------
.../core/custom/acffunctions.lua | 6 +-
3 files changed, 98 insertions(+), 101 deletions(-)
diff --git a/lua/acf/core/classes/object.lua b/lua/acf/core/classes/object.lua
index 3c04c06ea..172005bdc 100644
--- a/lua/acf/core/classes/object.lua
+++ b/lua/acf/core/classes/object.lua
@@ -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 = {}
@@ -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 }
@@ -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 {}
@@ -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
diff --git a/lua/acf/core/utilities/util_sv.lua b/lua/acf/core/utilities/util_sv.lua
index d0b053474..a7a7d5156 100644
--- a/lua/acf/core/utilities/util_sv.lua
+++ b/lua/acf/core/utilities/util_sv.lua
@@ -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
@@ -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
@@ -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
@@ -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 # 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 # 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
@@ -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]
@@ -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 # 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 # All the relevant link source callables
function ACF.GetAllLinkSources(Class)
if not EntityLink[Class] then return {} end
@@ -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 # 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 # A table mapping entities to true.
function ACF.GetLinkedEntities(Entity)
if not IsValid(Entity) then return {} end
@@ -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
@@ -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
@@ -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 # 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 # A table of input names to functions that handle them
local function GetClass(Class)
if not Inputs[Class] then
Inputs[Class] = {}
@@ -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
@@ -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
@@ -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
+ --- 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
function ACF.GetInputActions(Class)
if not Class then return end
@@ -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
@@ -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
@@ -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()]
diff --git a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
index d524aafb8..f4c40ec45 100644
--- a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
+++ b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
@@ -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 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 Linked The linked entities
local function GetLinkedWheels(Target)
local Queued = { [Target] = true }
local Checked = {}
From 62860ea57249f145afe2e6ddae87d815326978a5 Mon Sep 17 00:00:00 2001
From: LengthenedGradient
<109800352+LengthenedGradient@users.noreply.github.com>
Date: Sun, 7 Apr 2024 13:46:29 -0400
Subject: [PATCH 5/7] Fix Typo
---
lua/acf/core/validation_sv.lua | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lua/acf/core/validation_sv.lua b/lua/acf/core/validation_sv.lua
index a2e693ea1..6c9e29567 100644
--- a/lua/acf/core/validation_sv.lua
+++ b/lua/acf/core/validation_sv.lua
@@ -213,7 +213,7 @@ function ACF.Check(Entity, ForceUpdate) -- IsValid but for ACF
end
---Initializes the entity's armor properties. If ACF_Activate is defined by the entity, that is called.
----@param Recalc booloean Whether or not to recalculate the health
+---@param Recalc boolean Whether or not to recalculate the health
function ACF.Activate(Entity, Recalc)
-- Density of steel = 7.8g cm3 so 7.8kg for a 1mx1m plate 1m thick
local PhysObj = Entity:GetPhysicsObject()
From 3d6a406d16f3860da6d99147a82193913624c64e Mon Sep 17 00:00:00 2001
From: thecraftianman <64441307+thecraftianman@users.noreply.github.com>
Date: Mon, 8 Apr 2024 19:48:37 -0400
Subject: [PATCH 6/7] Improve consistency of docs
---
lua/acf/core/classes/helpers.lua | 4 +-
lua/acf/core/classes/object.lua | 12 +--
lua/acf/core/utilities/util_sv.lua | 86 +++++++++----------
lua/acf/core/validation_sv.lua | 4 +-
.../core/custom/acffunctions.lua | 4 +-
5 files changed, 55 insertions(+), 55 deletions(-)
diff --git a/lua/acf/core/classes/helpers.lua b/lua/acf/core/classes/helpers.lua
index 918bad18f..c5ca903ed 100644
--- a/lua/acf/core/classes/helpers.lua
+++ b/lua/acf/core/classes/helpers.lua
@@ -1,7 +1,7 @@
local Classes = ACF.Classes
----Adds a sbox limit for this class
----@param Data {Name:string, Amount:number, Text:string}
+--- Adds an sbox limit for this class
+--- @param Data {Name:string, Amount:number, Text:string}
function Classes.AddSboxLimit(Data)
if CLIENT then return end
if ConVarExists("sbox_max" .. Data.Name) then return end
diff --git a/lua/acf/core/classes/object.lua b/lua/acf/core/classes/object.lua
index 172005bdc..7ebcf8706 100644
--- a/lua/acf/core/classes/object.lua
+++ b/lua/acf/core/classes/object.lua
@@ -7,9 +7,9 @@ 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
+--- 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 = {}
@@ -24,8 +24,8 @@ local function CreateInstance(Class)
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
+--- @param ID string The id of the class to queue
+--- @param Base string The base class
local function QueueBaseClass(ID, Base)
if not Queued[Base] then
Queued[Base] = { [ID] = true }
@@ -86,7 +86,7 @@ function Classes.AddObject(ID, Base, Destiny)
AttachMetaTable(Class, Base) -- Attach a metatable to "Class" with "Base" as parent
- -- If this class is a base class for other class(es), Attach metatables to all its sub classes with itself as base class.
+ -- If this class is a base class for other class(es), attach metatables to all its sub classes with itself as base class.
if Queued[ID] then
for K in pairs(Queued[ID]) do
AttachMetaTable(Stored[K], ID)
diff --git a/lua/acf/core/utilities/util_sv.lua b/lua/acf/core/utilities/util_sv.lua
index a7a7d5156..7707c2147 100644
--- a/lua/acf/core/utilities/util_sv.lua
+++ b/lua/acf/core/utilities/util_sv.lua
@@ -42,11 +42,11 @@ do -- HTTP Request
end
end
- --- Sends a Fetch request, to the given url, with the given headers.
+ --- 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
+ --- 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)
@@ -109,7 +109,7 @@ do -- HTTP Request
end
-- Entity saving and restoring
--- Necessary because some components will update their physics object on update (e.g. ammo crates/scaleable guns)
+-- Necessary because some components will update their physics object on update (e.g. ammo crates/scalable guns)
do
local ConstraintTypes = duplicator.ConstraintType
local Entities = {}
@@ -220,9 +220,9 @@ 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)
+ --- 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/scalable guns).
--- @param Entity table The entity to index
function ACF.SaveEntity(Entity)
if not IsValid(Entity) then return end
@@ -249,8 +249,8 @@ do
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
+ --- 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
@@ -294,7 +294,7 @@ do -- Entity linking
]]--
local EntityLink = {}
- --- Returns links to the entry
+ --- 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
@@ -315,12 +315,12 @@ 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")
+ --- Registers that all entities of this class have a field which refers to its link source(s).
+ --- If your entity can link/unlink other entities, you should use this.
+ --- 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 VarName string The field referencing one of the class's 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]
@@ -338,7 +338,7 @@ do -- Entity linking
end
end
- --- Returns all the link source callables for this entity
+ --- Returns all the link source callables for this entity.
--- @param Class string The name of the class
--- @return table # All the relevant link source callables
function ACF.GetAllLinkSources(Class)
@@ -353,10 +353,10 @@ do -- Entity linking
return Result
end
- --- Returns the link source callable of a given class and VarName
+ --- 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
+ --- @return fun(Entity:table):table | nil # The link source callable, or nil if the class doesn't have one
function ACF.GetLinkSource(Class, VarName)
if not EntityLink[Class] then return end
@@ -364,8 +364,8 @@ do -- Entity linking
end
--- Returns a table of entities linked to the given entity.
- --- @param Entity The entity to get links from
- --- @return table # A table mapping entities to true.
+ --- @param Entity table The entity to get links from
+ --- @return table # A table mapping entities to true
function ACF.GetLinkedEntities(Entity)
if not IsValid(Entity) then return {} end
@@ -396,7 +396,7 @@ do -- Entity linking
["Unlink"] = {
["acf_ammo"] = {
["acf_gun"] = function(Ent1, Ent2) -- Handles unlinking guns and ammo
- }
+ }
}
}
]]--
@@ -405,7 +405,7 @@ do -- Entity linking
--- 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)
+ --- @param Function fun(Class1:table, Class2:table)
local function RegisterNewLink(Action, Class1, Class2, Function)
if not isfunction(Function) then return end
@@ -441,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.
+ --- Registers that two classes can be linked, as well as how to handle entities 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)
+ --- @param Function fun(Entity1:table, Entity2:table) The linking function defined between an entity of Class1 and an entity of Class2; this should always return a boolean for link status and a string for link message
function ACF.RegisterClassLink(Class1, Class2, Function)
RegisterNewLink("Link", Class1, Class2, Function)
end
- --- Returns the callback defined previously by "RegisterClassLink", between Class1 and Class2
+ --- Returns the callback defined previously by ACF.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)
+ --- @return fun(Entity1:table, Entity2:table) | nil # The linking function defined between an entity of Class1 and an entity of Class2, or nil if Class1 has no linking functions
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.
+ --- Registers that two classes can be unlinked, as well as how to handle entities 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)
+ --- @param Function fun(Entity1:table, Entity2:table) The unlinking function defined between an entity of Class1 and an entity of Class2
function ACF.RegisterClassUnlink(Class1, Class2, Function)
RegisterNewLink("Unlink", Class1, Class2, Function)
end
- --- Returns the callback defined previously by "RegisterClassUnlink", between Class1 and Class2
+ --- Returns the callback defined previously by ACF.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)
+ --- @return fun(Entity1:table, Entity2:table) | nil # The unlinking function defined between an entity of Class1 and an entity of Class2, or nil if Class1 has no unlinking functions
function ACF.GetClassUnlink(Class1, Class2)
if not ClassLink.Unlink[Class1] then return end
@@ -490,9 +490,9 @@ do -- Entity inputs
]]--
local Inputs = {}
- --- Returns the table mapping a class' inputs to a function that handles them
+ --- Returns the table mapping a class's inputs to a function that handles them.
--- @param Class string The class to get data from
- --- @return table # A table of input names to functions that handle them
+ --- @return table # A table of input names to functions that handle them
local function GetClass(Class)
if not Inputs[Class] then
Inputs[Class] = {}
@@ -501,7 +501,7 @@ do -- Entity inputs
return Inputs[Class]
end
- --- For a given class, add an input action for when an 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
@@ -515,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.
+ --- Returns the callback defined previously by ACF.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)
+ --- @param Name string The wire input retrieve from
+ --- @return fun(Entity:table, Value:any) | nil # The callback for the given class and wire input name, or nil if the arguments are invalid
function ACF.GetInputAction(Class, Name)
if not Class then return end
if not Name then return end
@@ -528,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".
+ --- For a given class, returns a table of wire input names mapped to their handlers, defined previously by ACF.AddInputAction.
--- @param Class string The class to retrieve from
- --- @return table
+ --- @return table | nil # A table of wire input names mapped to their handlers, or nil if Class is invalid
function ACF.GetInputActions(Class)
if not Class then return end
@@ -573,9 +573,9 @@ do -- Extra overlay text
end
end
- --- Removes a overlay callback defined previously by "RegisterOverlayText"
+ --- Removes an overlay callback defined previously by ACF.RegisterOverlayText.
--- @param ClassName string Name of the class to affect
- --- @param Identifier string The identitifer of the function to be removed
+ --- @param Identifier string The identifier of the function to be removed
function ACF.RemoveOverlayText(ClassName, Identifier)
if not isstring(ClassName) then return end
if Identifier == nil then return end
@@ -587,7 +587,7 @@ do -- Extra overlay text
Class[Identifier] = nil
end
- --- Given an entity, returns its overlay text, made by concatinating the overlay functions for its class
+ --- Given an entity, returns its overlay text, made by concatenating 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)
@@ -705,7 +705,7 @@ do -- Special squishy functions
DmgResult:SetThickness(0.01) -- squishy squishy brain matter, no resistance
HitRes = DmgResult:Compute()
- Damage = Damage + (HitRes.Damage * 50 * math.max(1,HitRes.Overkill * 0.25)) -- yuge damage, yo brains just got scrambled by a BOOLET
+ Damage = Damage + (HitRes.Damage * 50 * math.max(1, HitRes.Overkill * 0.25)) -- yuge damage, yo brains just got scrambled by a BOOLET
end
return Damage, HitRes
diff --git a/lua/acf/core/validation_sv.lua b/lua/acf/core/validation_sv.lua
index 6c9e29567..c9f2f1fb1 100644
--- a/lua/acf/core/validation_sv.lua
+++ b/lua/acf/core/validation_sv.lua
@@ -212,8 +212,8 @@ function ACF.Check(Entity, ForceUpdate) -- IsValid but for ACF
return Entity.ACF.Type
end
----Initializes the entity's armor properties. If ACF_Activate is defined by the entity, that is called.
----@param Recalc boolean Whether or not to recalculate the health
+--- Initializes the entity's armor properties. If ACF_Activate is defined by the entity, that method is called as well.
+--- @param Recalc boolean Whether or not to recalculate the health
function ACF.Activate(Entity, Recalc)
-- Density of steel = 7.8g cm3 so 7.8kg for a 1mx1m plate 1m thick
local PhysObj = Entity:GetPhysicsObject()
diff --git a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
index f4c40ec45..24cedcdfb 100644
--- a/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
+++ b/lua/entities/gmod_wire_expression2/core/custom/acffunctions.lua
@@ -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?)
+--- Returns a table of all the linked wheels of a given entity (usually a gearbox?)
--- @param Target table Entity to get linked entities from
---- @return table Linked The linked entities
+--- @return table Linked The linked entities
local function GetLinkedWheels(Target)
local Queued = { [Target] = true }
local Checked = {}
From eb3ff05f4ecaa09663d52b47b7d316174ef40e83 Mon Sep 17 00:00:00 2001
From: thecraftianman <64441307+thecraftianman@users.noreply.github.com>
Date: Mon, 8 Apr 2024 20:19:30 -0400
Subject: [PATCH 7/7] Fix one more docs inconsistency
---
lua/acf/core/utilities/util_sv.lua | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lua/acf/core/utilities/util_sv.lua b/lua/acf/core/utilities/util_sv.lua
index 7707c2147..608aadeec 100644
--- a/lua/acf/core/utilities/util_sv.lua
+++ b/lua/acf/core/utilities/util_sv.lua
@@ -405,7 +405,7 @@ do -- Entity linking
--- 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(Class1:table, Class2:table)
+ --- @param Function fun(Entity1:table, Entity2:table)
local function RegisterNewLink(Action, Class1, Class2, Function)
if not isfunction(Function) then return end
@@ -504,7 +504,7 @@ do -- Entity inputs
--- 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
+ --- @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