Skip to content

Commit

Permalink
Add CFW requirement
Browse files Browse the repository at this point in the history
Closes #27
  • Loading branch information
thecraftianman committed May 18, 2024
1 parent 6439556 commit ab54a27
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 72 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Ammunition is customizable with varying ballistic performance along with armor b
ACF Requires these to work

Wiremod ([Workshop](https://steamcommunity.com/workshop/filedetails/?id=160250458) or [Github](https://github.com/wiremod))
Contraption Framework ([Workshop](https://steamcommunity.com/sharedfiles/filedetails/?id=3154971187) or [Github](https://github.com/ACF-Team/CFW))

Prop Protection with [CPPI](http://ulyssesmod.net/archive/CPPI_v1-3.pdf) is not required, but highly recommended. We'd recommend Nadmod PP ([Workshop](https://steamcommunity.com/sharedfiles/filedetails/?id=159298542) or [Github](https://github.com/Nebual/NadmodPP)).

Expand Down
64 changes: 0 additions & 64 deletions lua/acf/contraption/contraption_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,70 +213,6 @@ function Contraption.CalcMassRatio(Ent, Tally)
end
end

do -- ACF Parent Detouring
local Detours = {}

function Contraption.AddParentDetour(Class, Variable)
if not Class then return end
if not Variable then return end

Detours[Class] = function(Entity)
return Entity[Variable]
end
end

hook.Add("Initialize", "ACF Parent Detour", function()
timer.Simple(1,function()
local EntMeta = FindMetaTable("Entity")
local SetParent = SetParent or EntMeta.SetParent
local GetParent = GetParent or EntMeta.GetParent

function EntMeta:SetParent(Entity, ...)
if not IsValid(self) then return end
local SavedParent
if (IsValid(self:GetParent()) and self:GetParent().ACF_OnParented) and not IsValid(Entity) then
self:GetParent():ACF_OnParented(self,false)
end

if IsValid(Entity) then
local Detour = Detours[Entity:GetClass()]

if Entity.ACF_OnParented then
SavedParent = Entity
end

if Detour then
Entity = Detour(Entity) or Entity
end
end

SetParent(self, Entity, ...)

if IsValid(SavedParent) then
SavedParent:ACF_OnParented(self,true)
end
end

function EntMeta:GetParent()
if not IsValid(self) then return end
local Parent = GetParent(self)

if IsValid(Parent) then
local Detour = Detours[Parent:GetClass()]

if Detour then
Parent = Detour(Parent) or Parent
end
end

return Parent
end

hook.Remove("Initialize", "ACF Parent Detour")
end)
end)
end

do -- ASSUMING DIRECT CONTROL

local BlockedTools = {
Expand Down
12 changes: 6 additions & 6 deletions lua/entities/acf_turret/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ do -- Spawn and Update funcs
local Entities = Classes.Entities
local Turrets = Classes.Turrets

Contraption.AddParentDetour("acf_turret", "Rotator")
CFW.addParentDetour("acf_turret", "Rotator")

local Inputs = {
"Active (Enables movement of the turret.)",
Expand Down Expand Up @@ -365,7 +365,7 @@ do -- Spawn and Update funcs
end

local function Proxy_ACF_OnParent(self, _, _)
if (not IsValid(self.ACF_TurretAncestor)) or (not Contraption.HasAncestor(self, self.ACF_TurretAncestor)) then self.ACF_OnParented = nil self.ACF_TurretAncestor = nil return end
if (not IsValid(self.ACF_TurretAncestor)) or (not Contraption.HasAncestor(self, self.ACF_TurretAncestor)) then self.CFW_OnParented = nil self.ACF_TurretAncestor = nil return end

self.ACF_TurretAncestor:UpdateTurretMass(false)
end
Expand All @@ -378,11 +378,11 @@ do -- Spawn and Update funcs

local function ParentLink(Turret, Entity, Connect)
if Connect then
Entity.ACF_OnParented = Proxy_ACF_OnParent
Entity.CFW_OnParented = Proxy_ACF_OnParent
Entity.ACF_OnMassChange = Proxy_ACF_OnMassChange
Entity.ACF_TurretAncestor = Turret
else
Entity.ACF_OnParented = nil
Entity.CFW_OnParented = nil
Entity.ACF_OnMassChange = nil
Entity.ACF_TurretAncestor = nil
end
Expand Down Expand Up @@ -1022,15 +1022,15 @@ do -- Metamethods
self:UpdateOverlay()
end

function ENT:ACF_OnParented(Entity, _) -- Potentially called many times a second, so we won't force mass to update
function ENT:CFW_OnParented(Entity, _) -- Potentially called many times a second, so we won't force mass to update
local Class = Entity:GetClass()

if Class == "acf_turret_rotator" then return end

self:UpdateTurretMass(false)

-- Should only be called when parenting, checks the position of the motor relative to the ring
-- Shooouuld be using ACF_OnParented as it was made with this in mind, but turret entities will overwrite it with the above function to ensure everything is captured
-- Shooouuld be using CFW_OnParented as it was made with this in mind, but turret entities will overwrite it with the above function to ensure everything is captured
if Class == "acf_turret_motor" then Entity:ValidatePlacement() end
if IsValid(self.Motor) then self.Motor:ValidatePlacement() end
end
Expand Down
4 changes: 2 additions & 2 deletions lua/entities/acf_turret_rotator/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include("shared.lua")

ACF.Contraption.AddParentDetour("acf_turret_rotator", "Turret")
CFW.addParentDetour("acf_turret_rotator", "Turret")

-- One can't exist without the other
function ENT:OnRemove()
Expand All @@ -10,7 +10,7 @@ function ENT:OnRemove()
end

-- This shouldn't be called usually due to parent detouring, but in the offchance that this is ever directly unparented from the turret ring, destroy it and the turret entity since it is no longer a valid turret
function ENT:ACF_OnParented(Entity, Connected)
function ENT:CFW_OnParented(Entity, Connected)
if not IsValid(Entity) then return end

if Connected == false and Entity == self.Turret then self:Remove() end
Expand Down

0 comments on commit ab54a27

Please sign in to comment.