Skip to content

Commit

Permalink
Merge pull request #45 from StyledStrike/add-headlight-color-networkvar
Browse files Browse the repository at this point in the history
Add `HeadlightColor` network variable
  • Loading branch information
StyledStrike authored Jan 6, 2025
2 parents 9d779ff + c484c69 commit 2a066b3
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 34 deletions.
6 changes: 3 additions & 3 deletions lua/autorun/sh_glide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Glide.MOUSE_FLY_MODE = {
CAMERA = 2 -- Free camera
}

-- Default color for headlights
Glide.DEFAULT_HEADLIGHT_COLOR = Color( 255, 231, 176 )

if SERVER then
-- Surface grip multipliers for wheels
Glide.SURFACE_GRIP = {
Expand All @@ -71,9 +74,6 @@ if SERVER then
end

if CLIENT then
-- Default color for headlights
Glide.DEFAULT_HEADLIGHT_COLOR = Color( 255, 221, 141 )

-- Vehicle camera types
Glide.CAMERA_TYPE = {
CAR = 0,
Expand Down
16 changes: 14 additions & 2 deletions lua/entities/base_glide_car/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function ENT:OnGearChange( _, _, gear )
end
end

function ENT:OnHeadlightColorChange()
self.headlightState = 0 -- Let OnUpdateMisc recreate the lights
end

--- Override this base class function.
function ENT:OnEngineStateChange( _, lastState, state )
if state == 1 then
Expand Down Expand Up @@ -250,6 +254,7 @@ local DrawLightSprite = Glide.DrawLightSprite

local COLOR_BRAKE = Color( 255, 0, 0, 255 )
local COLOR_REV = Color( 255, 255, 255, 200 )
local COLOR_HEADLIGHT = Color( 255, 255, 255 )

--- Implement this base class function.
function ENT:OnUpdateMisc()
Expand All @@ -265,6 +270,13 @@ function ENT:OnUpdateMisc()
local headlightState = self:GetHeadlightState()
local isHeadlightOn = headlightState > 0

if isHeadlightOn then
local colorVec = self:GetHeadlightColor()
COLOR_HEADLIGHT.r = colorVec[1] * 255
COLOR_HEADLIGHT.g = colorVec[2] * 255
COLOR_HEADLIGHT.b = colorVec[3] * 255
end

-- Render lights and sprites
local myPos = self:GetPos()
local pos, dir
Expand All @@ -274,7 +286,7 @@ function ENT:OnUpdateMisc()
dir = self:LocalToWorld( l.dir ) - myPos

if isHeadlightOn and l.type == "headlight" then
DrawLightSprite( pos, dir, l.size or 30, l.color or COLOR_REV, true )
DrawLightSprite( pos, dir, l.size or 30, COLOR_HEADLIGHT, true )

elseif isBraking and l.type == "brake" then
DrawLightSprite( pos, dir, l.size or 30, COLOR_BRAKE, true )
Expand Down Expand Up @@ -311,7 +323,7 @@ function ENT:OnUpdateMisc()

for _, v in ipairs( self.Headlights ) do
v.angles = v.angles or Angle( 10, 0, 0 )
self:CreateHeadlight( v.offset, v.angles, v.color )
self:CreateHeadlight( v.offset, v.angles, COLOR_HEADLIGHT )
end
end

Expand Down
3 changes: 3 additions & 0 deletions lua/entities/base_glide_car/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function ENT:OnPostInitialize()
self:SetHeadlightState( 0 )
self:SetGear( 0 )

local headlightColor = Glide.DEFAULT_HEADLIGHT_COLOR
self:SetHeadlightColor( Vector( headlightColor.r / 255, headlightColor.g / 255, headlightColor.b / 255 ) )

self:SetSteering( 0 )
self:SetEngineRPM( 0 )
self:SetEngineThrottle( 0 )
Expand Down
6 changes: 5 additions & 1 deletion lua/entities/base_glide_car/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function ENT:SetupDataTables()
self:NetworkVar( "Float", "EngineRPM" )
self:NetworkVar( "Float", "EngineThrottle" )

-- Wheel and suspension properties, allow editing with the C menu.
-- All DT variables below are editable properties
self:NetworkVar( "Vector", "HeadlightColor", { KeyName = "HeadlightColor", Edit = { type = "VectorColor", order = 0, category = "#glide.settings" } } )
self:NetworkVar( "Vector", "TireSmokeColor", { KeyName = "TireSmokeColor", Edit = { type = "VectorColor", order = 0, category = "#glide.editvar.wheels" } } )

local order = 0
Expand Down Expand Up @@ -113,6 +114,9 @@ function ENT:SetupDataTables()
if CLIENT then
-- Callback used to play gear change sounds
self:NetworkVarNotify( "Gear", self.OnGearChange )

-- Callback used to update the light color
self:NetworkVarNotify( "HeadlightColor", self.OnHeadlightColorChange )
end
end

Expand Down
12 changes: 6 additions & 6 deletions lua/entities/gtav_airbus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ if CLIENT then
}

ENT.Headlights = {
{ offset = Vector( 292, 30, -10 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ offset = Vector( 292, -30, -10 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ offset = Vector( 292, 30, -10 ) },
{ offset = Vector( 292, -30, -10 ) }
}

ENT.LightSprites = {
{ type = "brake", offset = Vector( -293, 41, 10.5 ), dir = Vector( -1, 0, 0 ) },
{ type = "brake", offset = Vector( -293, -41, 10.5 ), dir = Vector( -1, 0, 0 ) },
{ type = "reverse", offset = Vector( -293, 36, 10.5 ), dir = Vector( -1, 0, 0 ) },
{ type = "reverse", offset = Vector( -293, -36, 10.5 ), dir = Vector( -1, 0, 0 ) },
{ type = "headlight", offset = Vector( 290, 41.5, -11 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 290, -41.5, -11 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 290, 31, -11 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 290, -31, -11 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ type = "headlight", offset = Vector( 290, 41.5, -11 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 290, -41.5, -11 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 290, 31, -11 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 290, -31, -11 ), dir = Vector( 1, 0, 0 ) }
}

function ENT:OnCreateEngineStream( stream )
Expand Down
4 changes: 2 additions & 2 deletions lua/entities/gtav_blazer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ if CLIENT then

ENT.LightSprites = {
{ type = "brake", offset = Vector( -33, 0, 9 ), dir = Vector( -1, 0, 0 ), lightRadius = 50 },
{ type = "headlight", offset = Vector( 20, 0, 9 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ type = "headlight", offset = Vector( 20, 0, 9 ), dir = Vector( 1, 0, 0 ) }
}

ENT.Headlights = {
{ offset = Vector( 19, 0, 18 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ offset = Vector( 19, 0, 18 ) }
}

ENT.StartSound = "Glide.Engine.BikeStart1"
Expand Down
12 changes: 6 additions & 6 deletions lua/entities/gtav_dukes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ if CLIENT then
}

ENT.Headlights = {
{ offset = Vector( 102, 25, 2 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ offset = Vector( 102, -25, 2 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ offset = Vector( 102, 25, 2 ) },
{ offset = Vector( 102, -25, 2 ) }
}

ENT.LightSprites = {
{ type = "brake", offset = Vector( -125, 13, 5 ), dir = Vector( -1, 0, 0 ) },
{ type = "brake", offset = Vector( -125, -13, 5 ), dir = Vector( -1, 0, 0 ) },
{ type = "reverse", offset = Vector( -125, 21, 5 ), dir = Vector( -1, 0, 0 ) },
{ type = "reverse", offset = Vector( -125, -21, 5 ), dir = Vector( -1, 0, 0 ) },
{ type = "headlight", offset = Vector( 106, 29, -1 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 106, 22, -1 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 106, -29, -1 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 106, -22, -1 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ type = "headlight", offset = Vector( 106, 29, -1 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 106, 22, -1 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 106, -29, -1 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 106, -22, -1 ), dir = Vector( 1, 0, 0 ) }
}

function ENT:OnCreateEngineStream( stream )
Expand Down
12 changes: 6 additions & 6 deletions lua/entities/gtav_gauntlet_classic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ if CLIENT then
}

ENT.Headlights = {
{ offset = Vector( 102, 25, 14 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ offset = Vector( 102, -25, 14 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ offset = Vector( 102, 25, 14 ) },
{ offset = Vector( 102, -25, 14 ) }
}

ENT.LightSprites = {
{ type = "headlight", offset = Vector( 104, 33, 13.5 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 104, 25.5, 13.5 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 104, -33, 13.5 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 104, -25.5, 13.5 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 104, 33, 13.5 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 104, 25.5, 13.5 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 104, -33, 13.5 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 104, -25.5, 13.5 ), dir = Vector( 1, 0, 0 ) },
{ type = "brake", offset = Vector( -100, 19, 18 ), dir = Vector( -1, 0, 0 ) },
{ type = "brake", offset = Vector( -100, -19, 18 ), dir = Vector( -1, 0, 0 ) },
{ type = "reverse", offset = Vector( -99, 27, 6 ), dir = Vector( -1, 0, 0 ) },
Expand Down
4 changes: 2 additions & 2 deletions lua/entities/gtav_sanchez.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ if CLIENT then

ENT.LightSprites = {
{ type = "brake", offset = Vector( -43, 0, 17.5 ), dir = Vector( -1, 0, 0 ), lightRadius = 50 },
{ type = "headlight", offset = Vector( 26, 0, 19.6 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ type = "headlight", offset = Vector( 26, 0, 19.6 ), dir = Vector( 1, 0, 0 ) }
}

ENT.Headlights = {
{ offset = Vector( 28, 0, 27 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ offset = Vector( 28, 0, 27 ) }
}

function ENT:OnCreateEngineStream( stream )
Expand Down
8 changes: 4 additions & 4 deletions lua/entities/gtav_speedo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ if CLIENT then
}

ENT.Headlights = {
{ offset = Vector( 105, 32, 6.2 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ offset = Vector( 105, -32, 6.2 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ offset = Vector( 105, 32, 6.2 ) },
{ offset = Vector( 105, -32, 6.2 ) },
}

ENT.LightSprites = {
{ type = "brake", offset = Vector( -118, 37, 20 ), dir = Vector( -1, 0, 0 ) },
{ type = "brake", offset = Vector( -118, -37, 20 ), dir = Vector( -1, 0, 0 ) },
{ type = "reverse", offset = Vector( -118, 38, 15 ), dir = Vector( -1, 0, 0 ) },
{ type = "reverse", offset = Vector( -118, -38, 15 ), dir = Vector( -1, 0, 0 ) },
{ type = "headlight", offset = Vector( 105, 32, 6.2 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR },
{ type = "headlight", offset = Vector( 105, -32, 6.2 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ type = "headlight", offset = Vector( 105, 32, 6.2 ), dir = Vector( 1, 0, 0 ) },
{ type = "headlight", offset = Vector( 105, -32, 6.2 ), dir = Vector( 1, 0, 0 ) }
}

function ENT:OnCreateEngineStream( stream )
Expand Down
4 changes: 2 additions & 2 deletions lua/entities/gtav_wolfsbane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ if CLIENT then

ENT.LightSprites = {
{ type = "brake", offset = Vector( -45, 0, 5 ), dir = Vector( -1, 0, 0 ), lightRadius = 50 },
{ type = "headlight", offset = Vector( 27, 0, 17 ), dir = Vector( 1, 0, 0 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ type = "headlight", offset = Vector( 27, 0, 17 ), dir = Vector( 1, 0, 0 ) }
}

ENT.Headlights = {
{ offset = Vector( 28, 0, 27 ), color = Glide.DEFAULT_HEADLIGHT_COLOR }
{ offset = Vector( 28, 0, 27 ) }
}

function ENT:OnCreateEngineStream( stream )
Expand Down

0 comments on commit 2a066b3

Please sign in to comment.