Skip to content
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

Update request: options for bodygroups & light states fix #1077

Merged
merged 7 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions lua/entities/gmod_tardis/modules/cl_classic_doors.lua

This file was deleted.

4 changes: 4 additions & 0 deletions lua/entities/gmod_tardis/modules/sh_chameleon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,7 @@ ENT:AddHook("ShouldDrawPart", "chameleon_door", function(self, part)
return false
end
end)

function ENT:IsChameleonActive()
return self:GetData("chameleon_active", false)
end
67 changes: 65 additions & 2 deletions lua/entities/gmod_tardis/modules/sh_doors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,35 @@ if SERVER then
end)

ENT:AddHook("BodygroupChanged","doors",function(self,bodygroup,value)
if not self.metadata.SyncExteriorBodygroupToDoors then return end
if self:IsChameleonActive() then return end

local door=TARDIS:GetPart(self,"door")
local intdoor=TARDIS:GetPart(self.interior,"door")
if IsValid(door) then

if IsValid(door) and door:GetBodygroup(bodygroup) ~= value then
door:SetBodygroup(bodygroup,value)
end
if IsValid(intdoor) then

if IsValid(intdoor) and door:GetBodygroup(bodygroup) ~= value then
intdoor:SetBodygroup(bodygroup,value)
end
end)

ENT:AddHook("PartBodygroupChanged", "doors", function(self, part, bodygroup, value)
if not self.metadata.SyncDoorBodygroups then return end
if self:IsChameleonActive() then return end

if not IsValid(part) or part ~= self:GetPart("door") then return end
if not IsValid(self.interior) then return end
local door_int = self.interior:GetPart("door")
if not IsValid(door_int) then return end

if door_int:GetBodygroup(bodygroup) ~= value then
door_int:SetBodygroup(bodygroup, value)
end
end)

ENT:AddHook("CanChangeExterior","doors",function(self)
if self:DoorOpen() then
return false,false,"Chameleon.FailReasons.DoorsOpen",false
Expand Down Expand Up @@ -300,3 +319,47 @@ else
end
end)
end


--
-- Classic doors support
--
if CLIENT then

ENT:AddHook("ShouldDraw", "classic_doors_exterior", function(self)
if IsValid(self.interior) and 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 IsValid(self.interior) and 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)

ENT:AddHook("PlayerEnter", "classic_doors_intdoor_sound", function(self,ply,notp)
if not IsValid(self.interior) then return end
if self.metadata.EnableClassicDoors ~= true then return end
if self.metadata.NoSoundOnEnter == true then return end

local intdoor = TARDIS:GetPart(self.interior, "intdoor")
if not IsValid(intdoor) then return end

local door_sounds = self.metadata.Interior.Sounds.Door
if not door_sounds then return end

local door_sound = self:GetData("doorstatereal") and door_sounds.open or door_sounds.close
if not door_sound then return end

if intdoor.IntDoorPos ~= nil and intdoor.IntDoorPos ~= 0 and intdoor.IntDoorPos ~= 1 then
sound.Play(door_sound, self.interior:LocalToWorld( self.metadata.Interior.Fallback.pos ))
end
end)
end
5 changes: 0 additions & 5 deletions lua/entities/gmod_tardis_interior/modules/cl_door.lua

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ function ENT:SetData(k,v,network)
end

function ENT:GetData(k,default)
return IsValid(self.exterior) and self.exterior:GetData(k, default) or default
if IsValid(self.exterior) then
return self.exterior:GetData(k, default)
else
return default
end
end

function ENT:ClearData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function ENT:ApplyLightState(state)
self:SendMessage("light_state", {state} )
else
local ldata = self.light_data
if not ldata then return end
ChangeSingleLightState(ldata.main, state)
ParseLightTable(ldata.main, self, 20)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
-- Door

ENT:AddHook("PartBodygroupChanged", "doors", function(self, part, bodygroup, value)
if not self.metadata.SyncDoorBodygroups then return end
if self.exterior:IsChameleonActive() then return end

if not IsValid(part) or part ~= self:GetPart("door") then return end
if not IsValid(self.exterior) then return end
local door_ext = self.exterior:GetPart("door")
if not IsValid(door_ext) then return end

if door_ext:GetBodygroup(bodygroup) ~= value then
door_ext:SetBodygroup(bodygroup, value)
end
end)

if SERVER then return end

function ENT:DoorOpen(...)
return self.exterior:DoorOpen(...)
end


--
-- Classic doors support
--

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
Expand Down
6 changes: 5 additions & 1 deletion lua/entities/gmod_tardis_part/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ function ENT:SetData(k,v,network)
end

function ENT:GetData(k,default)
return IsValid(self.exterior) and self.exterior:GetData(k, default) or default
if IsValid(self.exterior) then
return self.exterior:GetData(k, default)
else
return default
end
end

hook.Add("BodygroupChanged", "tardis_parts", function(ent,bodygroup,value)
Expand Down
17 changes: 9 additions & 8 deletions lua/matproxy/matproxy_tardis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,17 @@ end
local function matproxy_tardis_power_bind(self, mat, ent)
if not IsValid(ent) or not IsValid(ent.exterior) or not ent.TardisPart then return end

local on = ent.exterior:GetPower()
local var = ent.exterior:GetPower() and self.on_var or self.off_var
if not var then return end

if self.last_on ~= on then
self.last_on = on
local value = mat:GetVector(var)

local var = on and self.on_var or self.off_var
if not var then return end

mat:SetVector(self.ResultTo, mat:GetVector(var))
if var ~= self.last_var or value ~= self.last_value then
self.last_var = var
self.last_value = value
mat:SetVector(self.ResultTo, value)
end

end

matproxy.Add({
Expand All @@ -128,7 +129,7 @@ matproxy.Add({
init = function( self, mat, values )
self.ResultTo = values.resultvar
end,

bind = function( self, mat, ent )
if not IsValid(ent) or not ent.TardisPart then return end

Expand Down
6 changes: 3 additions & 3 deletions lua/matproxy/matproxy_tardis_default_int.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ matproxy.Add({
bind = function(self, mat, ent)
if not IsValid(ent) or not ent.TardisPart then return end

local col = ent:GetData("default_int_env_color") or Color(0,200,255)
local col = ent:GetData("default_int_env_color", Color(0,200,255))
local power = ent.exterior and ent.exterior:GetPower()

if self.lastcol ~= col or self.lastpower ~= power then
Expand All @@ -35,7 +35,7 @@ matproxy.Add({
bind = function(self, mat, ent)
if not IsValid(ent) or not ent.TardisPart then return end

local col = ent:GetData("default_int_floor_lights_color") or Color(230,230,210)
local col = ent:GetData("default_int_floor_lights_color", Color(230,230,210))

if self.lastcol ~= col then
self.lastcol = col
Expand All @@ -56,7 +56,7 @@ matproxy.Add({
bind = function(self, mat, ent)
if not IsValid(ent) or not ent.TardisPart then return end

local col = ent:GetData("default_int_rotor_color") or Color(255,255,255)
local col = ent:GetData("default_int_rotor_color", Color(255,255,255))

if self.lastcol ~= col then
self.lastcol = col
Expand Down
1 change: 1 addition & 0 deletions lua/tardis/interiors/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ T.Timings = {
TakeOffState = 0,
ParkingState = 0,
}
T.SyncExteriorBodygroupToDoors = true

TARDIS:AddInterior(T)

Expand Down
Loading