Skip to content

Commit

Permalink
Merge pull request #550 from MattJeanes/parar-classicintdoors
Browse files Browse the repository at this point in the history
Classic style doors (#448)
  • Loading branch information
MattJeanes authored Dec 15, 2021
2 parents 170cf8c + ced112f commit 9e87ef7
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 44 deletions.
17 changes: 17 additions & 0 deletions lua/entities/gmod_tardis/modules/cl_classic_doors.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ENT:AddHook("ShouldDraw", "classic_doors_exterior", function(self)
if self.metadata.EnableClassicDoors
and wp.drawing and wp.drawingent == self.interior.portals.interior
then
return false
end

end)

ENT:AddHook("ShouldDrawPart", "classic_doors_exterior_door", function(self, part)
if self.metadata.EnableClassicDoors == true and part ~= nil
and wp.drawing and wp.drawingent == self.interior.portals.interior
and part == TARDIS:GetPart(self, "door")
then
return false
end
end)
61 changes: 35 additions & 26 deletions lua/entities/gmod_tardis/modules/sh_doors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if SERVER then
callback(state)
end)
end

function ENT:ToggleDoor(callback)
if not IsValid(self.interior) then return false end
if not self:GetData("doorchangecallback",false) then
Expand All @@ -29,12 +29,12 @@ if SERVER then
return false
end
doorstate=not doorstate

self:SetData("doorstatereal",doorstate,true)
self:SetData("doorchangewait",not doorstate)

self:CallHook("ToggleDoorReal",doorstate)

if doorstate then
self:SetData("doorstate",true,true)
self:SetData("doorchange",CurTime())
Expand All @@ -47,19 +47,23 @@ if SERVER then
if callback then
callbacks[callback]=true
end
self:SetData("doorchange",CurTime()+self.metadata.Exterior.DoorAnimationTime)
local dooranimtime = self.metadata.Exterior.DoorAnimationTime
if self.metadata.EnableClassicDoors == true then
dooranimtime = math.max(dooranimtime, self.metadata.Interior.IntDoorAnimationTime)
end
self:SetData("doorchange",CurTime() + dooranimtime)
end
return true
end

function ENT:OpenDoor(callback)
if self:GetData("doorstate",false) then
delay(callback,true)
else
self:ToggleDoor(callback)
end
end

function ENT:CloseDoor(callback)
if self:GetData("doorstate",false) ~= self:GetData("doorstatereal",false) then
local callbacks=self:GetData("doorchangecallback")
Expand All @@ -70,19 +74,19 @@ if SERVER then
self:ToggleDoor(callback)
end
end

function ENT:DoorOpen(real)
if real then
return self:GetData("doorstatereal",false)
else
return self:GetData("doorstate",false)
end
end

ENT:AddHook("Initialize", "doors", function(self)
self:SetBodygroup(1,1)
end)

ENT:AddHook("ToggleDoor", "intdoors", function(self,open)
local intdoor=TARDIS:GetPart(self.interior,"door")
if IsValid(intdoor) then
Expand Down Expand Up @@ -121,7 +125,7 @@ if SERVER then
net.WriteBool(open)
end)
end)

ENT:AddHook("Think", "doors", function(self)
if self:GetData("doorchangewait",false) and CurTime()>self:GetData("doorchange",0) then
self:SetData("doorchangewait",nil)
Expand All @@ -140,13 +144,13 @@ if SERVER then
end
end
end)

ENT:AddHook("ShouldThinkFast","doors",function(self)
if self:GetData("doorchangewait") then
return true
end
end)

ENT:AddHook("SkinChanged","doors",function(self,i)
local door=TARDIS:GetPart(self,"door")
local intdoor=TARDIS:GetPart(self.interior,"door")
Expand All @@ -157,7 +161,7 @@ if SERVER then
intdoor:SetSkin(i)
end
end)

ENT:AddHook("BodygroupChanged","doors",function(self,bodygroup,value)
local door=TARDIS:GetPart(self,"door")
local intdoor=TARDIS:GetPart(self.interior,"door")
Expand All @@ -178,7 +182,7 @@ else
type="bool",
option=true
})

function ENT:DoorOpen(real)
local door=self:GetPart("door")
if real and IsValid(door) then
Expand All @@ -187,7 +191,7 @@ else
return self:GetData("doorstate",false)
end
end

function ENT:DoorMoving()
local door=self:GetPart("door")
if IsValid(door) then
Expand All @@ -196,23 +200,28 @@ else
return false
end
end

ENT:OnMessage("ToggleDoorReal",function(self)
self:CallHook("ToggleDoorReal",net.ReadBool())
end)

ENT:AddHook("ToggleDoorReal","doorsounds",function(self,open)
local snds = self.metadata.Exterior.Sounds.Door
if snds.enabled and TARDIS:GetSetting("doorsounds-enabled") and TARDIS:GetSetting("sound") then
local extpart = self:GetPart("door")
local snd = open and snds.open or snds.close
if IsValid(extpart) and extpart.exterior:CallHook("ShouldEmitDoorSound")~=false then
extpart:EmitSound(snd)
local extsnds = self.metadata.Exterior.Sounds.Door
local intsnds = self.metadata.Interior.Sounds.Door or extsnds

if TARDIS:GetSetting("doorsounds-enabled") and TARDIS:GetSetting("sound") then
if extsnds.enabled then
local extpart = self:GetPart("door")
local extsnd = open and extsnds.open or extsnds.close
if IsValid(extpart) and extpart.exterior:CallHook("ShouldEmitDoorSound")~=false then
extpart:EmitSound(extsnd)
end
end
if IsValid(self.interior) then
if intsnds.enabled and IsValid(self.interior) then
local intpart = self.interior:GetPart("door")
local intsnd = open and intsnds.open or intsnds.close
if IsValid(intpart) then
intpart:EmitSound(snd)
intpart:EmitSound(intsnd)
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions lua/entities/gmod_tardis_interior/modules/cl_classic_doors.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ENT:AddHook("ShouldDrawPart", "classic_doors_intdoor", function(self, part)
if self.metadata.EnableClassicDoors == true and part ~= nil
and wp.drawing and wp.drawingent == self.portals.exterior
and part == TARDIS:GetPart(self, "intdoor")
then
return false
end
end)

ENT:AddHook("ShouldDrawPart", "classic_doors_door_mirror", function(self, part)
if self.metadata.EnableClassicDoors == true and part ~= nil
and part == TARDIS:GetPart(self, "door")
and not (wp.drawing and wp.drawingent == self.portals.exterior)
then
return false
end

end)
2 changes: 1 addition & 1 deletion lua/entities/gmod_tardis_interior/modules/sh_portals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ else
end
if dont then
return false, black
elseif (not (self.DoorOpen and self:DoorOpen(true))) and portal==self.portals.interior then
elseif (not (self.DoorOpen and self:DoorOpen(false))) and portal==self.portals.interior then
return false
elseif (not TARDIS:GetSetting("portals-enabled")) then
return false, self.portals.interior==portal or portal.black
Expand Down
2 changes: 1 addition & 1 deletion lua/tardis/controls/sh_control_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TARDIS:AddControl({
end
end,
serveronly=true,
power_independent = false,
power_independent = true,
screen_button = {
virt_console = true,
mmenu = false,
Expand Down
20 changes: 12 additions & 8 deletions lua/tardis/parts/door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if SERVER then
function PART:Initialize()
self:SetBodygroup(1,1) -- Sticker
self:SetBodygroup(2,1) -- Lit sign

if self.ExteriorPart then
self.ClientDrawOverride = true
self:SetSolid(SOLID_VPHYSICS)
Expand All @@ -26,7 +26,7 @@ if SERVER then
self:SetBodygroup(3,1) -- 3D sign
table.insert(self.interior.stuckfilter, self)
end

local metadata=self.exterior.metadata
local portal=self.ExteriorPart and metadata.Exterior.Portal or metadata.Interior.Portal
if portal then
Expand All @@ -38,7 +38,7 @@ if SERVER then
self:SetParent(self.parent)
end
end

function PART:Use(a)
if self.exterior:GetData("locked") then
if IsValid(a) and a:IsPlayer() then
Expand All @@ -55,12 +55,13 @@ if SERVER then
self.exterior:PlayerExit(a)
end
else
if self.exterior.metadata.EnableClassicDoors == true and not self.ExteriorPart then return end
if (self.exterior:GetData("repair-primed",false) or self.exterior:GetData("repairing",false)) and self.ExteriorPart then return end
self.exterior:ToggleDoor()
end
end
end

hook.Add("SkinChanged", "tardisi-door", function(ent,i)
if ent.TardisExterior then
local door=ent:GetPart("door")
Expand All @@ -80,14 +81,17 @@ else
self.DoorPos=0
self.DoorTarget=0
end

function PART:Think()
if self.ExteriorPart then
self.DoorTarget=self.exterior.DoorOverride or (self.exterior:GetData("doorstatereal",false) and 1 or 0)


local animtime = self.exterior.metadata.Exterior.DoorAnimationTime

-- Have to spam it otherwise it glitches out (http://facepunch.com/showthread.php?t=1414695)
self.DoorPos=self.exterior.DoorOverride or math.Approach(self.DoorPos,self.DoorTarget,FrameTime()*(1/self.exterior.metadata.Exterior.DoorAnimationTime))

self.DoorPos = self.exterior.DoorOverride or
math.Approach(self.DoorPos, self.DoorTarget, FrameTime() * (1 / animtime))

self:SetPoseParameter("switch", self.DoorPos)
self:InvalidateBoneCache()
elseif self.InteriorPart then -- copy exterior, no need to redo the calculation
Expand Down
51 changes: 51 additions & 0 deletions lua/tardis/parts/intdoor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local PART={}
PART.ID = "intdoor"
PART.Name = "Interior Doors"
PART.Model = "models/drmatt/tardis/exterior/door.mdl"
PART.AutoSetup = true
PART.AutoPosition = true
PART.ClientThinkOverride = true
PART.Collision = false
PART.NoStrictUse = true
PART.ShouldTakeDamage = true
PART.BypassIsomorphic = true


if SERVER then
function PART:Use(a)

if self.exterior:GetData("locked") then
if IsValid(a) and a:IsPlayer() then
if self.exterior:CallHook("LockedUse",a)==nil then
TARDIS:Message(a, "The doors are locked.")
end
end
else
if a:KeyDown(IN_WALK) then
self.exterior:PlayerExit(a)
end
end
end
else

function PART:Initialize()
self.IntDoorPos=0
self.IntDoorTarget=0
end

function PART:Think()
self.IntDoorTarget=self.exterior.IntDoorOverride or (self.exterior:GetData("doorstatereal",false) and 1 or 0)
local animtime = self.exterior.metadata.Interior.IntDoorAnimationTime
or self.exterior.metadata.Exterior.DoorAnimationTime

-- Have to spam it otherwise it glitches out (http://facepunch.com/showthread.php?t=1414695)
self.IntDoorPos = self.exterior.IntDoorOverride or
math.Approach(self.IntDoorPos, self.IntDoorTarget, FrameTime() * (1 / animtime))

self:SetPoseParameter("switch", self.IntDoorPos)
self:InvalidateBoneCache()

end
end

TARDIS:AddPart(PART)
File renamed without changes.
23 changes: 15 additions & 8 deletions lua/tardis/sh_parts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ function TARDIS.DrawOverride(self,override)
if self.NoDraw then return end
local int=self.interior
local ext=self.exterior

if IsValid(ext) then
if (self.InteriorPart and IsValid(int) and ((int:CallHook("ShouldDraw")~=false)
or (ext:DoorOpen()
and (self.ClientDrawOverride and LocalPlayer():GetPos():Distance(ext:GetPos())<TARDIS:GetSetting("portals-closedist"))
or (self.DrawThroughPortal and (int.scannerrender or (IsValid(wp.drawingent) and wp.drawingent:GetParent()==int)))
))) or (self.ExteriorPart
and (ext:CallHook("ShouldDraw")~=false)
or self.ShouldDrawOverride
) then

if (self.InteriorPart and IsValid(int)
and ((int:CallHook("ShouldDraw")~=false)
or (ext:DoorOpen()
and (self.ClientDrawOverride and LocalPlayer():GetPos():Distance(ext:GetPos()) < TARDIS:GetSetting("portals-closedist"))
or (self.DrawThroughPortal and (int.scannerrender or (IsValid(wp.drawingent) and wp.drawingent:GetParent()==int)))
)
)
) or (self.ExteriorPart
and (ext:CallHook("ShouldDraw")~=false)
or self.ShouldDrawOverride
)
then
if self.parent:CallHook("ShouldDrawPart", self) == false then return end
self.parent:CallHook("PreDrawPart",self)
if self.PreDraw then self:PreDraw() end
if self.UseTransparencyFix and (not override) then
Expand Down

0 comments on commit 9e87ef7

Please sign in to comment.