mirror of
https://github.com/Michatec/wk_wars2x.git
synced 2026-04-01 08:26:27 +02:00
Vehicle data sending optimised and automated
This commit is contained in:
31
cl_radar.lua
31
cl_radar.lua
@@ -375,9 +375,11 @@ end
|
|||||||
--[[------------------------------------------------------------------------
|
--[[------------------------------------------------------------------------
|
||||||
Radar antenna functions
|
Radar antenna functions
|
||||||
------------------------------------------------------------------------]]--
|
------------------------------------------------------------------------]]--
|
||||||
function RADAR:ToggleAntenna( ant )
|
function RADAR:ToggleAntenna( ant, cb )
|
||||||
if ( self:IsPowerOn() ) then
|
if ( self:IsPowerOn() ) then
|
||||||
self.vars.antennas[ant].xmit = not self.vars.antennas[ant].xmit
|
self.vars.antennas[ant].xmit = not self.vars.antennas[ant].xmit
|
||||||
|
|
||||||
|
if ( cb ) then cb() end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -668,9 +670,9 @@ RegisterNUICallback( "setAntennaMode", function( data )
|
|||||||
end )
|
end )
|
||||||
|
|
||||||
RegisterNUICallback( "toggleAntenna", function( data )
|
RegisterNUICallback( "toggleAntenna", function( data )
|
||||||
RADAR:ToggleAntenna( data.value )
|
RADAR:ToggleAntenna( data.value, function()
|
||||||
|
|
||||||
SendNUIMessage( { _type = "antennaXmit", ant = data.value, on = RADAR:IsAntennaTransmitting( data.value ) } )
|
SendNUIMessage( { _type = "antennaXmit", ant = data.value, on = RADAR:IsAntennaTransmitting( data.value ) } )
|
||||||
|
end )
|
||||||
end )
|
end )
|
||||||
|
|
||||||
|
|
||||||
@@ -713,9 +715,24 @@ function RADAR:Main()
|
|||||||
-- Work out what has to be sent
|
-- Work out what has to be sent
|
||||||
-- need to find a way to automate this in a loop
|
-- need to find a way to automate this in a loop
|
||||||
local av = self:GetActiveVehicles()
|
local av = self:GetActiveVehicles()
|
||||||
local test = { ["front"] = {}, ["rear"] = {} }
|
data.antennas = { ["front"] = nil, ["rear"] = nil }
|
||||||
|
|
||||||
if ( self:IsAntennaTransmitting( "front" ) ) then
|
for ant in UTIL:Values( { "front", "rear" } ) do
|
||||||
|
if ( self:IsAntennaTransmitting( ant ) ) then
|
||||||
|
data.antennas[ant] = {}
|
||||||
|
|
||||||
|
for i = 1, 2 do
|
||||||
|
data.antennas[ant][i] = { speed = "¦¦¦" }
|
||||||
|
|
||||||
|
-- The vehicle data exists for this slot
|
||||||
|
if ( av[ant][i] ~= nil ) then
|
||||||
|
data.antennas[ant][i].speed = UTIL:FormatSpeed( self:GetVehSpeedFormatted( av[ant][i].speed ) )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[if ( self:IsAntennaTransmitting( "front" ) ) then
|
||||||
if ( av["front"][1] ~= nil ) then
|
if ( av["front"][1] ~= nil ) then
|
||||||
test["front"].speed = UTIL:FormatSpeed( self:GetVehSpeedFormatted( av["front"][1].speed ) )
|
test["front"].speed = UTIL:FormatSpeed( self:GetVehSpeedFormatted( av["front"][1].speed ) )
|
||||||
else
|
else
|
||||||
@@ -741,10 +758,10 @@ function RADAR:Main()
|
|||||||
else
|
else
|
||||||
test["rear"].fast = "¦¦¦"
|
test["rear"].fast = "¦¦¦"
|
||||||
end
|
end
|
||||||
end
|
end]]
|
||||||
|
|
||||||
-- Send the update to the NUI side
|
-- Send the update to the NUI side
|
||||||
SendNUIMessage( { _type = "update", speed = data.patrolSpeed, antennas = test } )
|
SendNUIMessage( { _type = "update", speed = data.patrolSpeed, antennas = data.antennas } )
|
||||||
|
|
||||||
self:ResetRadarStage()
|
self:ResetRadarStage()
|
||||||
self:ResetRayTraceState()
|
self:ResetRayTraceState()
|
||||||
|
|||||||
18
nui/radar.js
18
nui/radar.js
@@ -137,20 +137,12 @@ function updateDisplays( ps, ants )
|
|||||||
{
|
{
|
||||||
elements.patrolSpeed.html( ps );
|
elements.patrolSpeed.html( ps );
|
||||||
|
|
||||||
if ( ants["front"].speed != null ) {
|
for ( let ant in ants )
|
||||||
elements.antennas["front"].targetSpeed.html( ants["front"].speed );
|
{
|
||||||
|
if ( ants[ant] != null ) {
|
||||||
|
elements.antennas[ant].targetSpeed.html( ants[ant][0].speed );
|
||||||
|
elements.antennas[ant].fast.speed.html( ants[ant][1].speed );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ants["front"].fast != null ) {
|
|
||||||
elements.antennas["front"].fast.speed.html( ants["front"].fast );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ants["rear"].speed != null ) {
|
|
||||||
elements.antennas["rear"].targetSpeed.html( ants["rear"].speed );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ants["rear"].fast != null ) {
|
|
||||||
elements.antennas["rear"].fast.speed.html( ants["rear"].fast );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user