-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linkage reworks #419
Linkage reworks #419
Changes from 9 commits
e91eae9
bdc5c6d
ef731d1
de253ca
ce719e8
ac3b9e9
12e0443
6479163
209e5c1
e6c6a4b
730c197
c2c2d24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,18 +61,37 @@ end --------------------------------------------- | |
do -- Entity linking and unlinking -------------- | ||
local LinkText = "%s can't be linked to %s." | ||
local UnlinkText = "%s can't be unlinked from %s." | ||
local timer = timer | ||
|
||
function ENT:Link(Target) | ||
function ENT:Link(Target, FromChip) | ||
if not IsValid(Target) then return false, "Attempted to link an invalid entity." end | ||
if self == Target then return false, "Can't link an entity to itself." end | ||
|
||
local Class = Target:GetClass() | ||
local Function = ACF.GetClassLink(self:GetClass(), Class) | ||
local LinkData, Reversed = ACF.GetClassLink(self:GetClass(), Class) | ||
|
||
if LinkData == nil then return false, "Links between these two entities are impossible" end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
|
||
local Function = LinkData.Link | ||
local Check = LinkData.Check | ||
local ChipDelay = LinkData.ChipDelay | ||
|
||
local A, B = self, Target -- Default argument order | ||
if Reversed then A, B = Target, self end -- If reversed, reverse argument order | ||
|
||
if Function then | ||
return Function(self, Target) | ||
elseif self.DefaultLink then | ||
return self:DefaultLink(Target) | ||
if Check then | ||
local result, message = Check(A, B) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent capitalization |
||
if result then | ||
if FromChip and ChipDelay then | ||
timer.Simple(ChipDelay, function() | ||
if Check(A, B) then Function(A, B) end | ||
end) | ||
else Function(A, B) end | ||
end | ||
return result, message | ||
end | ||
return Function(A, B) | ||
end | ||
|
||
return false, LinkText:format(self.PluralName, Target.PluralName or Class) | ||
|
@@ -83,12 +102,16 @@ do -- Entity linking and unlinking -------------- | |
if self == Target then return false, "Can't unlink an entity from itself." end | ||
|
||
local Class = Target:GetClass() | ||
local Function = ACF.GetClassUnlink(self:GetClass(), Class) | ||
local LinkData, Reversed = ACF.GetClassLink(self:GetClass(), Class) | ||
local Function = LinkData.Unlink | ||
|
||
if LinkData == nil then return false, "Links between these two entities are impossible" end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
|
||
local A, B = self, Target -- Default argument order | ||
if Reversed then A, B = Target, self end -- If reversed, reverse argument order | ||
|
||
if Function then | ||
return Function(self, Target) | ||
elseif self.DefaultUnlink then | ||
return self:DefaultUnlink(Target) | ||
return Function(A, B) | ||
end | ||
|
||
return false, UnlinkText:format(self.PluralName, Target.PluralName or Class) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does ClassLink store any booleans that could end up being
false
? If not, comparingif X ~= nil
is unnecesary, you can just doif X
on that caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I hallucinated this not working but it seems it works now. The other ones with ~= nil will be fixed.