Forgot staged files
This commit is contained in:
parent
bacc7c617f
commit
e893f7fcb2
47
koptilnya/car_systems/entities/light.txt
Normal file
47
koptilnya/car_systems/entities/light.txt
Normal file
@ -0,0 +1,47 @@
|
||||
-- @shared
|
||||
-- @name Light
|
||||
-- @include ../helpers/helpers.txt
|
||||
require("../helpers/helpers.txt")
|
||||
|
||||
Light = class("Light")
|
||||
|
||||
function Light:initialize(params)
|
||||
self.target = 0
|
||||
self.entity = params.Entity
|
||||
self.colors = params.Colors
|
||||
self.lerpSpeed = params.LerpSpeed or 0.2
|
||||
self.active = false
|
||||
|
||||
self.entity:setColor(self.colors.Off)
|
||||
self.entity:suppressEngineLighting(true)
|
||||
end
|
||||
|
||||
|
||||
function Light:_process()
|
||||
local targetColor = self.colors.Off
|
||||
|
||||
if self.active == true and self.colors.Active then
|
||||
targetColor = self.target > 0 and self.colors.On or self.colors.Active
|
||||
elseif self.target > 0 then
|
||||
targetColor = self.colors.On
|
||||
end
|
||||
|
||||
self.entity:setColor(lerpColor(self.lerpSpeed, self.entity:getColor(), targetColor))
|
||||
end
|
||||
|
||||
|
||||
function Light:setActive(val)
|
||||
self.active = val
|
||||
end
|
||||
|
||||
|
||||
function Light:use(val)
|
||||
self.target = val or 0
|
||||
end
|
||||
|
||||
|
||||
function Light:update()
|
||||
self:_process()
|
||||
end
|
||||
|
||||
|
||||
11
koptilnya/car_systems/helpers/helpers.txt
Normal file
11
koptilnya/car_systems/helpers/helpers.txt
Normal file
@ -0,0 +1,11 @@
|
||||
function lerpColor(t, from, to)
|
||||
local clampedT = math.clamp(t, 0, 1)
|
||||
local outColor = Color(0, 0, 0, 0)
|
||||
|
||||
outColor.r = math.lerp(t, from.r, to.r)
|
||||
outColor.g = math.lerp(t, from.g, to.g)
|
||||
outColor.b = math.lerp(t, from.b, to.b)
|
||||
outColor.a = math.lerp(t, from.a, to.a)
|
||||
|
||||
return outColor
|
||||
end
|
||||
119
koptilnya/car_systems/lights_controller.txt
Normal file
119
koptilnya/car_systems/lights_controller.txt
Normal file
@ -0,0 +1,119 @@
|
||||
-- @shared
|
||||
-- @name Lights Controller
|
||||
-- @include ./entities/light.txt
|
||||
require("./entities/light.txt")
|
||||
|
||||
LightsController = class("LightsController")
|
||||
|
||||
function LightsController:initialize(config)
|
||||
-- self.leftTurnLights = Light:new({ Entity = config.Lights.LeftTurnLights, Colors = config.Colors.TurnLights })
|
||||
-- self.rightTurnLights = Light:new({ Entity = config.Lights.RightTurnLights, Colors = config.Colors.TurnLights })
|
||||
|
||||
self.stopLights = {}
|
||||
self.reverseLights = {}
|
||||
self.highBeamLights = {}
|
||||
self.lowBeamLights = {}
|
||||
self.fogLights = {}
|
||||
|
||||
if config.StopLights then
|
||||
for _, v in pairs(config.StopLights.Entities) do
|
||||
table.insert(self.stopLights, Light:new({Entity = v, Colors = config.StopLights.Colors, LerpSpeed = config.StopLights.LerpSpeed}))
|
||||
end
|
||||
end
|
||||
|
||||
if config.ReverseLights then
|
||||
for _, v in pairs(config.ReverseLights.Entities) do
|
||||
table.insert(self.reverseLights, Light:new({Entity = v, Colors = config.ReverseLights.Colors, LerpSpeed = config.StopLights.LerpSpeed}))
|
||||
end
|
||||
end
|
||||
|
||||
if config.LowBeamLights then
|
||||
for _, v in pairs(config.LowBeamLights.Entities) do
|
||||
table.insert(self.lowBeamLights, Light:new({Entity = v, Colors = config.LowBeamLights.Colors, LerpSpeed = config.StopLights.LerpSpeed}))
|
||||
end
|
||||
end
|
||||
|
||||
if config.HighBeamLights then
|
||||
for _, v in pairs(config.HighBeamLights.Entities) do
|
||||
table.insert(self.highBeamLights, Light:new({Entity = v, Colors = config.HighBeamLights.Colors, LerpSpeed = config.StopLights.LerpSpeed}))
|
||||
end
|
||||
end
|
||||
|
||||
if config.FogLights then
|
||||
for _, v in pairs(config.FogLights.Entities) do
|
||||
table.insert(self.fogLights, Light:new({Entity = v, Colors = config.FogLights.Colors, LerpSpeed = config.StopLights.LerpSpeed}))
|
||||
end
|
||||
end
|
||||
|
||||
-- self.stopLights = Light:new({Entity = config.Lights.StopLights, Colors = config.Colors.StopLights})
|
||||
-- self.reverseLights = Light:new({Entity = config.Lights.ReverseLights, Colors = config.Colors.ReverseLights})
|
||||
|
||||
self.active = false
|
||||
|
||||
-- self.colors = config.Colors
|
||||
|
||||
-- self.stopLights:setColor(self.colors.StopLight.Off)
|
||||
-- self.reverseLights:setColor(self.colors.ReverseLights.Off)
|
||||
|
||||
self.allLights = {}
|
||||
|
||||
table.add(self.allLights, self.stopLights)
|
||||
table.add(self.allLights, self.reverseLights)
|
||||
table.add(self.allLights, self.lowBeamLights)
|
||||
table.add(self.allLights, self.highBeamLights)
|
||||
table.add(self.allLights, self.fogLights)
|
||||
end
|
||||
|
||||
|
||||
function LightsController:useStopLights(on)
|
||||
for _, v in pairs(self.stopLights) do
|
||||
v:use(on)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function LightsController:useReverseLights(on)
|
||||
for _, v in pairs(self.reverseLights) do
|
||||
v:use(on)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function LightsController:useLowBeam(on)
|
||||
for _, v in pairs(self.lowBeamLights) do
|
||||
v:use(on)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function LightsController:useHighBeam(on)
|
||||
for _, v in pairs(self.highBeamLights) do
|
||||
v:use(on)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function LightsController:setActive(val)
|
||||
if self.active ~= val then
|
||||
local lights = {}
|
||||
table.add(lights, self.lowBeamLights)
|
||||
table.add(lights, self.stopLights)
|
||||
|
||||
for _, v in pairs(lights) do
|
||||
v:setActive(val)
|
||||
end
|
||||
|
||||
self.active = val
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function LightsController:update()
|
||||
for _, v in pairs(self.allLights) do
|
||||
v:update()
|
||||
end
|
||||
-- self.stopLights:update()
|
||||
-- self.reverseLights:update()
|
||||
end
|
||||
|
||||
|
||||
@ -2,7 +2,9 @@
|
||||
-- @name Ford Mustang GT 2015
|
||||
-- @author Opti1337, DarkSupah
|
||||
-- @include /koptilnya/mesh_loader/builder.txt
|
||||
-- @include /koptilnya/car_systems/lights_controller.txt
|
||||
require("/koptilnya/mesh_loader/builder.txt")
|
||||
require("/koptilnya/car_systems/lights_controller.txt")
|
||||
|
||||
DEBUG_MODE = true
|
||||
|
||||
@ -23,7 +25,8 @@ local MATERIALS = {
|
||||
MirrorsAndExhaust = "models/debug/debugwhite",
|
||||
Lights = "models/debug/debugwhite",
|
||||
Glass = "phoenix_storms/glass",
|
||||
ExteriorDetails2 = "models/debug/debugwhite"
|
||||
ExteriorDetails2 = "models/debug/debugwhite",
|
||||
LightsBase = "models/debug/debugwhite"
|
||||
}
|
||||
local COLORS = {
|
||||
Interior = Color(40, 40, 40),
|
||||
@ -40,14 +43,20 @@ local COLORS = {
|
||||
MirrorsAndExhaust = Color(255, 255, 255),
|
||||
Lights = Color(255, 255, 255),
|
||||
Glass = Color(255, 255, 255),
|
||||
ExteriorDetails2 = Color(130, 130, 130)
|
||||
ExteriorDetails2 = Color(130, 130, 130),
|
||||
LightsBase = Color(255, 255, 255)
|
||||
}
|
||||
|
||||
local builder = {}
|
||||
local lightsController = {}
|
||||
|
||||
if SERVER then
|
||||
builder = MeshBuilder:new(LINK)
|
||||
|
||||
builder.onObjectParsed = function(builder, objectsNames)
|
||||
printTable(objectsNames)
|
||||
end
|
||||
|
||||
|
||||
builder:build("Interior_body1_model0", Vector(0), Angle(0), SCALE, COLORS.Interior, MATERIALS.Interior, chip(), chip())
|
||||
builder:build("Torpedo_body1_model0.001", Vector(0), Angle(0), SCALE, COLORS.Torpedo, MATERIALS.Torpedo, chip(), chip())
|
||||
builder:build("Seats_body1_model0.002", Vector(0), Angle(0), SCALE, COLORS.Seats, MATERIALS.Seats, chip(), chip())
|
||||
@ -63,13 +72,50 @@ if SERVER then
|
||||
builder:build("Lights_body1_model0.012", Vector(0), Angle(0), SCALE, COLORS.Lights, MATERIALS.Lights, chip(), chip())
|
||||
builder:build("Glass_body1_model0.013", Vector(0), Angle(0), SCALE, COLORS.Glass, MATERIALS.Glass, chip(), chip())
|
||||
builder:build("ExteriorDetails_body1_model0.014", Vector(0), Angle(0), SCALE, COLORS.ExteriorDetails, MATERIALS.ExteriorDetails, chip(), chip())
|
||||
|
||||
local result = builder:getResult()
|
||||
builder:build("DoorPanels_body1_model0.003", Vector(0), Angle(0), SCALE, COLORS.Interior, MATERIALS.Interior, chip(), chip())
|
||||
|
||||
-- Lights
|
||||
local StopLights = builder:build("StopLights_body1_model0.016", Vector(0), Angle(0), SCALE, COLORS.LightsBase, MATERIALS.LightsBase, chip(), chip())
|
||||
local ReverseLights = builder:build("ReverseLight_body1_model0.015", Vector(0), Angle(0), SCALE, COLORS.LightsBase, MATERIALS.LightsBase, chip(), chip())
|
||||
local LowBeamLights = builder:build("LowBeamLights_body1_model0.006", Vector(0), Angle(0), SCALE, COLORS.LightsBase, MATERIALS.LightsBase, chip(), chip())
|
||||
local HighBeamLights = builder:build("HighBeamLights_body1_model0.017", Vector(0), Angle(0), SCALE, COLORS.LightsBase, MATERIALS.LightsBase, chip(), chip())
|
||||
local FogLights = builder:build("FogLights_body1_model0.018", Vector(0), Angle(0), SCALE, COLORS.LightsBase, MATERIALS.LightsBase, chip(), chip())
|
||||
|
||||
local result = builder:getResult()
|
||||
|
||||
local lights = {
|
||||
StopLights = {Entities = {StopLights}, LerpSpeed = 0.2, Colors = {On = Color(250, 0, 0), Off = Color(30, 0, 0), Active = Color(90, 0, 0)}},
|
||||
ReverseLights = {Entities = {ReverseLights}, LerpSpeed = 0.1, Colors = {On = Color(255, 255, 255), Off = Color(20, 20, 20)}},
|
||||
LowBeamLights = {Entities = {LowBeamLights}, LerpSpeed = 0.1, Colors = {On = Color(255, 255, 255), Off = Color(20, 20, 20)}},
|
||||
HighBeamLights = {Entities = {HighBeamLights}, LerpSpeed = 0.1, Colors = {On = Color(255, 255, 255), Off = Color(20, 20, 20)}},
|
||||
FogLights = {Entities = {FogLights}, LerpSpeed = 0.1, Colors = {On = Color(255, 255, 255), Off = Color(20, 20, 20)}}
|
||||
}
|
||||
|
||||
-- local lightsEntities = {StopLights = {StopLights}, ReverseLights = {ReverseLights}, LowBeamLights = {LowBeamLights}, HighBeamLights = {HighBeamLights}}
|
||||
-- local lightColors = {StopLights = {On = Color(250, 0, 0), Off = Color(30, 0, 0), Active = Color(90, 0, 0)}, ReverseLights = {On = Color(255, 255, 255), Off = Color(20, 20, 20), Active = Color(20, 20, 20)}}
|
||||
-- local lights = {Lights = lightsEntities, Colors = lightColors}
|
||||
|
||||
lightsController = LightsController:new(lights)
|
||||
|
||||
wire.adjustPorts({LightInputs = "table"}, {})
|
||||
|
||||
hook.add("think", "lights", function()
|
||||
lightsController:useStopLights(wire.ports.LightInputs.Stop)
|
||||
lightsController:useReverseLights(wire.ports.LightInputs.Reverse)
|
||||
lightsController:useLowBeam(wire.ports.LightInputs.LowBeam)
|
||||
lightsController:useHighBeam(wire.ports.LightInputs.HighBeam)
|
||||
|
||||
lightsController:setActive(wire.ports.LightInputs.LowBeam == 1)
|
||||
|
||||
lightsController:update()
|
||||
end
|
||||
)
|
||||
else
|
||||
function init()
|
||||
builder = MeshBuilder:new(LINK)
|
||||
end
|
||||
|
||||
|
||||
if hasPermission("http.get") and hasPermission("mesh") and hasPermission("entities.setRenderProperty", chip()) then
|
||||
init()
|
||||
else
|
||||
@ -79,6 +125,7 @@ else
|
||||
if permissionRequestSatisfied() then
|
||||
init()
|
||||
end
|
||||
end)
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user