Fix various bugs in RADIO

This is the first implementation that PLAY A SOUND !
The whole RADIO class isn't tested thoroughly though
This commit is contained in:
Grey-Echo 2017-03-10 23:33:21 +01:00
parent b75d90092d
commit 65c61a15b4
6 changed files with 54 additions and 38 deletions

View File

@ -18,9 +18,9 @@
--- The RADIO class
-- @type RADIO
-- @extends Core.Base#BASE
MESSAGE = {
RADIO = {
ClassName = "RADIO",
Positionable = POSITIONABLE:New(),
Positionable,
FileName = "",
Frequency = 0,
Modulation = 0,
@ -37,20 +37,21 @@ MESSAGE = {
-- @return self
-- @usage
-- -- If you want to create a RADIO, you probably should use @{Positionable#POSITIONABLE.GetRadio}
function RADIO.New(positionable)
function RADIO:New(positionable)
local self = BASE:Inherit( self, BASE:New() )
-- self:F( { MessageText, MessageDuration, MessageCategory } )
self:F(positionable)
self.Positionable = positionable
return self
end
--- Add the 'l10n/DEFAULT/' in the file name if necessary
-- @param #string File name
-- @return #string Corrected file name
-- @param #RADIO self
-- @param #string FileName Filename of the sound
-- @return #string FileName Corrected file name
-- @usage
-- -- internal use only
function RADIO.VerifyFileName(filename)
function RADIO:VerifyFileName(filename)
if filename:find("l10n/DEFAULT/") == nil then
filename = "l10n/DEFAULT/" .. filename
end
@ -68,15 +69,16 @@ end
-- -- In this function the data is especially relevant if the broadcaster is anything but a UNIT or a GROUP,
-- -- but it will work with a UNIT or a GROUP anyway
-- -- Only the RADIO and the Filename are mandatory
function RADIO:NewTransmission(filename, frequency, mod, power)
self.FileName = RADIO.VerifyFile(filename)
if frequency ~= nil then
function RADIO:NewGenericTransmission(filename, frequency, mod, power)
self:F2({self, filename, frequency, mod, power})
self.FileName = RADIO:VerifyFileName(filename)
if frequency ~= "" then
self.Frequecy = frequency * 1000 -- Convert to Hz
end
if mod ~= nil then
if mod ~= 3 then
self.Modulation = mod
end
if power ~= nil then
if power ~= 0 then
self.Power = power
end
return self
@ -96,21 +98,22 @@ end
-- -- but it will work for any POSITIONABLE
-- -- Only the RADIO and the Filename are mandatory
-- -- Loop : O is no loop, 1 is loop
function RADIO:NewTransmissionForUnit(filename, subtitle, subtitleDuraction, frequency, mod, loop)
self.FileName = RADIO.VerifyFile(filename)
if subtitle ~= nil then
function RADIO:NewUnitTransmission(filename, subtitle, subtitleDuration, frequency, mod, loop)
self:F2({filename, subtitle, subtitleDuration, frequency, mod, loop})
self.FileName = RADIO:VerifyFileName(filename)
if subtitle ~= "" then
self.Subtitle = subtitle
end
if subtitleDuration ~= nil then
if subtitleDuration ~= 0 then
self.SubtitleDuration = subtitleDuration
end
if frequency ~= nil then
self.Frequecy = frequency * 1000 -- Convert to Hz
if frequency ~= 0 then
self.Frequency = frequency * 1000 -- Convert to Hz
end
if mod ~= nil then
if mod ~= 3 then
self.Modulation = mod
end
if loop ~= nil then
if loop ~= 3 then
self.Loop = loop
end
return self
@ -127,13 +130,14 @@ end
-- -- If your POSITIONABLE is a UNIT or a GROUP, the Power is ignored.
-- -- If your POSITIONABLE is not a UNIT or a GROUP, the Subtitle, SubtitleDuration and Loop are ignored
function RADIO:Broadcast()
self:F()
-- If the POSITIONABLE is actually a Unit or a Group, use the more complicated DCS function
if Positionable.ClassName == "UNIT" or Positionable.ClassName == "GROUP" then
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
-- If the user didn't change the frequency, he wants to use the on defined in the Mission Editor.
-- Else we set the frequency of the UNIT or the GROUP in DCS
if self.Frequency == 0 then
self.Positionable:GetDCSUnit():getController():setCommand({
id = 'SetFrequency',
if self.Frequency ~= 0 then
self.Positionable:GetDCSObject():getController():setCommand({
id = "SetFrequency",
params = {
frequency = self.Frequency,
modulation = self.Modulation,
@ -141,7 +145,7 @@ function RADIO:Broadcast()
})
end
self.Positionable:GetDCSUnit():getController():setCommand({
self.Positionable:GetDCSObject():getController():setCommand({
id = "TransmitMessage",
params = {
file = self.FileName,
@ -152,7 +156,7 @@ function RADIO:Broadcast()
})
else
-- If the POSITIONABLE is anything else, we revert to the general function
trigger.action.radioTransmission(ClassName, self.Positionable:PositionVec3(), Modulation, 1, Frequency, Power)
trigger.action.radioTransmission(self.FileName, self.Positionable:PositionVec3(), self.Modulation, 1, self.Frequency, self.Power)
end
return self
end

View File

@ -433,10 +433,10 @@ function POSITIONABLE:Message( Message, Duration, Name )
end
--- Create a @{Radio#RADIO}, to allow radio transmission for this POSITIONABLE
-- Set parameters with the methods provided, then use @{Radio#RADIO.Broadcast} to actually broadcast the message
-- @param self
-- @return #RADIO
-- Set parameters with the methods provided, then use RADIO:Broadcast() to actually broadcast the message
-- @param #POSITIONABLE self
-- @return #RADIO Radio
function POSITIONABLE:GetRadio()
local Radio = RADIO.New(self)
return Radio
self:F2(self)
return RADIO:New(self)
end

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170308_1432' )
env.info( 'Moose Generation Timestamp: 20170308_2255' )
local base = _G

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170308_1432' )
env.info( 'Moose Generation Timestamp: 20170308_2255' )
local base = _G

View File

@ -1,6 +1,18 @@
BASE:TraceAll(1)
BASE:TraceLevel(3)
local Player = UNIT:FindByName("Player")
Player:MessageToAll("MainScript Started", 10, "")
Player:MessageToAll("MainScript Started 2", 10, "")
local PlayerRadio = Player:GetRadio()
PlayerRadio:NewTransmission("Noise.ogg", "Subtitle", 10, 251000, 0, 0)
PlayerRadio:Broadcast()
local Transmiter = UNIT:FindByName("Transmiter")
local TransmiterRadio = Transmiter:GetRadio()
TransmiterRadio:NewUnitTransmission("Noise.ogg", "Subtitle", 10, 251000, 0, 0)
TransmiterRadio:E({
TransmiterRadio.Positionable,
TransmiterRadio.FileName,
TransmiterRadio.Subtitle,
TransmiterRadio.SubtitleDuration,
TransmiterRadio.Frequency,
TransmiterRadio.Modulation,
})
TransmiterRadio:Broadcast()