Skip to content

Commit

Permalink
Merge pull request #592 from MattJeanes/dev
Browse files Browse the repository at this point in the history
January 2022 Update
  • Loading branch information
MattJeanes authored Jan 18, 2022
2 parents d56e121 + eaffbb5 commit 3f6ab8c
Show file tree
Hide file tree
Showing 22 changed files with 824 additions and 203 deletions.
5 changes: 4 additions & 1 deletion lua/entities/gmod_tardis/modules/cl_music.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ TARDIS:AddSetting({

function ENT:StopMusic()
if IsValid(self.music) then
if self.music:GetState() == GMOD_CHANNEL_PLAYING then
TARDIS:Message(LocalPlayer(), "Music stopped")
end
self.music:Stop()
self.music=nil
end
end

Expand Down Expand Up @@ -65,6 +67,7 @@ end

function ENT:PlayMusic(url,resolved)
if not resolved then
TARDIS:Message(LocalPlayer(), "Loading music...")
url=self:ResolveMusicURL(url)
end
if url and TARDIS:GetSetting("music-enabled") and TARDIS:GetSetting("sound") then
Expand Down
85 changes: 44 additions & 41 deletions lua/entities/gmod_tardis/modules/sh_cloak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ TARDIS:AddKeyBind("cloak-toggle",{
})

ENT:AddHook("Initialize", "cloak", function(self)
self:SetData("cloak", false)
self:SetData("cloak", false)

self:SetData("modelmins", self:OBBMins())
self:SetData("modelmins", self:OBBMins())
local maxs = self:OBBMaxs()
maxs.z = maxs.z + 25
self:SetData("modelmaxs", maxs)
self:SetData("modelheight", (self:GetData("modelmaxs").z - self:GetData("modelmins").z))
self:SetData("modelmaxs", maxs)
self:SetData("modelheight", (self:GetData("modelmaxs").z - self:GetData("modelmins").z))

self:SetData("phase-percent",1)
self:SetData("phase-percent",1)
end)

function ENT:GetCloak()
return self:GetData("cloak",false)
end

if SERVER then
function ENT:SetCloak(on)
function ENT:SetCloak(on)
if self:CallHook("CanToggleCloak")==false then return false end
self:SetData("cloak", on)
self:SendMessage("cloak", function()
Expand All @@ -41,12 +41,12 @@ if SERVER then
self:DrawShadow(not on)
end
return true
end
function ENT:ToggleCloak()
local on = not self:GetData("cloak", false)
return self:SetCloak(on)
end
end
function ENT:ToggleCloak()
local on = not self:GetData("cloak", false)
return self:SetCloak(on)
end

ENT:AddHook("HandleE2", "cloak", function(self,name,e2)
if name == "Phase" and TARDIS:CheckPP(e2.player, self) then
Expand All @@ -68,15 +68,15 @@ if SERVER then
end
end)
else
TARDIS:AddSetting({
id = "cloaksound-enabled",
name = "Cloak Sound",
desc = "Toggles whether or not sounds play when TARDIS cloaking is toggled",
section = "Sound",
value = true,
type = "bool",
option = true
})
TARDIS:AddSetting({
id = "cloaksound-enabled",
name = "Cloak Sound",
desc = "Toggles whether or not sounds play when TARDIS cloaking is toggled",
section = "Sound",
value = true,
type = "bool",
option = true
})

ENT:AddHook("Initialize", "cloak-material", function(self)
self.PhaseMaterial = Material(self.metadata.Exterior.PhaseMaterial or "models/drmatt/tardis/exterior/phase_noise.vmt")
Expand All @@ -90,20 +90,23 @@ else
local target = self:GetData("cloak",false) and -0.5 or 1
local animating = self:GetData("cloak-animating",false)
local percent = self:GetData("phase-percent",1)
if percent == target and animating then
self:SetData("cloak-animating", false)
if percent == target then
if animating then
self:SetData("cloak-animating", false)
end
return
elseif percent ~= target and not animating then
elseif not animating then
self:SetData("cloak-animating", true)
end
local timepassed = CurTime() - self:GetData("phase-lastTick",CurTime())
self:SetData("phase-lastTick", CurTime())
if self:GetData("cloak",false) then
self:SetData("phase-percent", math.Approach(percent, target, 0.5 * timepassed))
else
self:SetData("phase-percent", math.Approach(percent, target, 0.5 * timepassed))
end
self:SetData("phase-highPercent", math.Clamp(self:GetData("phase-percent",1) + 0.5, 0, 1))

local timepassed = CurTime() - self:GetData("phase-lastTick",CurTime())
self:SetData("phase-lastTick", CurTime())
if self:GetData("cloak",false) then
self:SetData("phase-percent", math.Approach(percent, target, 0.5 * timepassed))
else
self:SetData("phase-percent", math.Approach(percent, target, 0.5 * timepassed))
end
self:SetData("phase-highPercent", math.Clamp(self:GetData("phase-percent",1) + 0.5, 0, 1))

local pos = self:GetPos() + self:GetUp() * (self:GetData("modelmaxs").z - (self:GetData("modelheight") * self:GetData("phase-highPercent",1)))
local pos2 = self:GetPos() + self:GetUp() * (self:GetData("modelmaxs").z - (self:GetData("modelheight") * self:GetData("phase-percent",1)))
Expand All @@ -124,22 +127,22 @@ else
return
end
oldClip = render.EnableClipping(true)
local restoreT = ent:GetMaterial()
local restoreT = ent:GetMaterial()

local normal = self:GetUp()
local pos = self:GetData("phase-highPos",Vector(0,0,0))
local dist = normal:Dot(pos)
local normal = self:GetUp()
local pos = self:GetData("phase-highPos",Vector(0,0,0))
local dist = normal:Dot(pos)

local normal2 = self:GetUp() * -1
local normal2 = self:GetUp() * -1
local pos2 = self:GetData("phase-pos",Vector(0,0,0))
local dist2 = normal2:Dot(pos2)

ent:SetRenderClipPlane(normal, dist)
ent:SetRenderClipPlane(normal, dist)

render.PushCustomClipPlane(normal, dist)
render.PushCustomClipPlane(normal, dist)
render.MaterialOverride(self.PhaseMaterial)

render.PushCustomClipPlane(normal2, dist2)
render.PushCustomClipPlane(normal2, dist2)
ent:DrawModel()
render.PopCustomClipPlane()
render.PopCustomClipPlane()
Expand All @@ -152,7 +155,7 @@ else
render.EnableClipping(oldClip)
end

ENT:AddHook("Draw", "cloak", dodraw)
ENT:AddHook("Draw", "cloak", dodraw)

ENT:AddHook("PostDraw", "cloak", postdraw)

Expand Down
12 changes: 12 additions & 0 deletions lua/entities/gmod_tardis/modules/sh_doors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ if SERVER then
end
end)

ENT:AddHook("Think", "int_door_skin", function(self)
-- this fixes interior door skin if it's chosen at spawn
-- we can not do it at the beginning because the interior doesn't exist yet
if self:GetData("intdoor_skin_needs_update", false) and IsValid(self.interior) then
local intdoor=TARDIS:GetPart(self.interior,"door")
if IsValid(intdoor) then
self:SetData("intdoor_skin_needs_update", false, true)
intdoor:SetSkin(self:GetSkin())
end
end
end)

ENT:AddHook("SkinChanged","doors",function(self,i)
local door=TARDIS:GetPart(self,"door")
local intdoor=TARDIS:GetPart(self.interior,"door")
Expand Down
2 changes: 1 addition & 1 deletion lua/entities/gmod_tardis/modules/sh_flight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ if SERVER then
if on and self:CallHook("CanTurnOnFlight")==false then
return false
end
if on and self:GetData("physlock",false)==true then
if on and self:GetPhyslock()==true then
local pilot = self:GetData("pilot",nil)
if IsValid(pilot) and pilot:IsPlayer() then
TARDIS:Message(pilot, "WARNING: Physical lock engaged")
Expand Down
55 changes: 7 additions & 48 deletions lua/entities/gmod_tardis/modules/sh_health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ TARDIS:AddSetting({
networked=true
})

TARDIS:AddSetting({
id="redecorate-interior",
name="Redecoration interior",
value="default",
networked=true
})

ENT:AddHook("Initialize","health-init",function(self)
self:SetData("health-val", TARDIS:GetSetting("health-max"), true)
if SERVER and WireLib then
Expand Down Expand Up @@ -81,20 +74,20 @@ if SERVER then
if nvnum < 0 then
nvnum = 1
end
TARDIS:SetSetting("health-max", nvnum, true)
for k,v in pairs(ents.FindByClass("gmod_tardis")) do
TARDIS:SetSetting("health-max", nvnum, true)
for k,v in pairs(ents.FindByClass("gmod_tardis")) do
if v:GetHealth() > nvnum then
v:ChangeHealth(nvnum)
end
end
end
end, "UpdateOnChange")

cvars.AddChangeCallback("tardis2_damage", function(cvname, oldvalue, newvalue)
TARDIS:SetSetting("health-enabled", tobool(newvalue), true)
end, "UpdateOnChange")

ENT:AddWireOutput("Health", "TARDIS Health")

function ENT:Explode(f)
local force = 60
if f ~= nil then
Expand Down Expand Up @@ -152,15 +145,8 @@ if SERVER then
end

function ENT:FinishRepair()
if self:CallHook("ShouldRedecorate") then
local ent = TARDIS:SpawnTARDIS(self:GetCreator(),{
metadataID = TARDIS:GetSetting("redecorate-interior","default",self:GetCreator()),
finishrepair = true,
pos = self:GetPos()+Vector(0,0,2),
ang = self:GetAngles()
})
self:Remove()
ent:GetPhysicsObject():Sleep()
if self:CallHook("ShouldRedecorate") and self:Redecorate() then

return
end
self:EmitSound(self.metadata.Exterior.Sounds.RepairFinish)
Expand Down Expand Up @@ -217,29 +203,6 @@ if SERVER then
end
end)

ENT:AddHook("ShouldRedecorate", "health", function(self)
return (self:GetData("redecorate",false) and TARDIS:GetSetting("redecorate-interior","default",self:GetCreator()) ~= self.metadata.ID) and true or nil
end)

ENT:AddHook("CustomData", "health-redecorate", function(self, customdata)
if customdata.finishrepair then
self:SetPos(customdata.pos)
self:SetAngles(customdata.ang)
self:SetData("finishrepair",true)
end
end)

ENT:AddHook("Initialize", "health-redecorate", function(self)
if not self:GetData("finishrepair",false) then return end
timer.Simple(0.5, function()
if not IsValid(self) then return end
self:GetPhysicsObject():Wake()
self:EmitSound(self.metadata.Exterior.Sounds.RepairFinish)
self:FlashLight(1.5)
end)
self:SetData("finishrepair",nil)
end)

ENT:AddHook("CanTogglePower", "health", function(self)
if (not (self:GetData("health-val", 0) > 0)) or (self:GetData("repairing",false) or self:GetData("repair-primed", false)) then
return false
Expand Down Expand Up @@ -380,9 +343,5 @@ if SERVER then
end
end
end)
else
ENT:AddHook("Initialize", "redecorate-reset", function(self)
if not IsValid(self) or (not LocalPlayer() == self:GetCreator()) then return end
TARDIS:SetSetting("redecorate-interior",self.metadata.ID,true)
end)

end
16 changes: 10 additions & 6 deletions lua/entities/gmod_tardis/modules/sh_physlock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ TARDIS:AddKeyBind("physlock-toggle",{
exterior=true
})

function ENT:GetPhyslock()
return self:GetData("physlock",false)
end

if CLIENT then return end

function ENT:SetPhyslock(on)
Expand Down Expand Up @@ -46,24 +50,24 @@ function ENT:SetPhyslock(on)
end

function ENT:TogglePhyslock()
local on = not self:GetData("physlock", false)
local on = not self:GetPhyslock()
return self:SetPhyslock(on)
end

hook.Add("PlayerUnfrozeObject", "tardis-physlock", function(ply,ent,phys)
if ent:GetClass()=="gmod_tardis" and ent:GetData("physlock",false)==true then
if ent:GetClass()=="gmod_tardis" and ent:GetPhyslock()==true then
phys:EnableMotion(false)
end
end)

hook.Add("PhysgunDrop", "tardis-physlock", function(ply,ent)
if ent:GetClass()=="gmod_tardis" and ent:GetData("physlock",false)==true then
if ent:GetClass()=="gmod_tardis" and ent:GetPhyslock()==true then
ent:GetPhysicsObject():EnableMotion(false)
end
end)

ENT:AddHook("MatStart", "physlock", function(self)
if not self:GetData("physlock",false) then
if not self:GetPhyslock() then
self.phys:EnableMotion(true)
self.phys:Wake()
end
Expand All @@ -73,7 +77,7 @@ ENT:AddHook("PowerToggled", "physlock", function(self,on)
if on and self:GetData("power-lastphyslock", false) == true then
self:SetPhyslock(true)
else
self:SetData("power-lastphyslock", self:GetData("physlock", false))
self:SetData("power-lastphyslock", self:GetPhyslock())
self:SetPhyslock(false)
end
end)
Expand All @@ -86,7 +90,7 @@ end)

ENT:AddHook("HandleE2", "physlock", function(self, name, e2)
if name == "GetPhyslocked" then
return self:GetData("physlock",false) and 1 or 0
return self:GetPhyslock() and 1 or 0
elseif name == "Physlock" and TARDIS:CheckPP(e2.player, self) then
return self:TogglePhyslock() and 1 or 0
end
Expand Down
Loading

0 comments on commit 3f6ab8c

Please sign in to comment.