Implements RADIO:NewTransmission()

the implementation made me realize the need for RADIO.VerifyFileName() and RADIO.ConvertFrequency(),
so they are both implemented in this commit to.
This commit is contained in:
Grey-Echo 2017-03-10 23:31:59 +01:00
parent c37d6e6f95
commit 921743bf20

View File

@ -19,8 +19,9 @@
-- @type RADIO
-- @extends Core.Base#BASE
MESSAGE = {
ClassName = "RADIO",
ClassName = "RADIO",
Identifiable = IDENTIFIABLE:New(),
FileName = "",
Frequency = 255000,
Power = 100,
Modulation = 0,
@ -34,7 +35,7 @@ MESSAGE = {
-- @param
-- @return #RADIO
-- @usage
-- -- This is for internal use only. To create a new RADIO, use @{Identifiable#IDENIFIABLE.GetRadio}
-- -- If you want to create a RADIO, you probably should use @{Identifiable#IDENIFIABLE.GetRadio}
function RADIO:New(identifiable)
local self = BASE:Inherit( self, BASE:New() )
self:F( { MessageText, MessageDuration, MessageCategory } )
@ -43,8 +44,52 @@ function RADIO:New(identifiable)
return self
end
--- Add the 'l10n/DEFAULT/' in the file name if necessary
-- @param #string File name
-- @return #string Corrected file name
-- @usage
-- -- internal use only
function RADIO.VerifyFileName(filename)
if filename:find("l10n/DEFAULT/") == nil then
filename = "l10n/DEFAULT/" .. filename
end
return filename
end
--- Whatever the Frequency's unit is, returns the frequency in Hz.
-- @param #number Frequency
-- @return #string Frequency in Hz
-- @usage
-- -- internal use only
-- -- Frequency has to be an integer.
function RADIO.ConvertFrequency(frequency)
local digitCount = 0
for i in string.gmatch(frequency, "%d") do
digitCount = digitCount + 1
end
for i = (9 - digitCount), 0, -1 do
frequency = frequency .. "0"
end
return frequency
end
--- Create a new transmission, that is to say, populate the RADIO with relevant data
-- @param #string Filename
-- @param #number Frequency
-- @param #number Modulation
-- @param #number Power
-- @return self
-- @usage
-- -- 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
function RADIO:NewTransmission(filename, frequency, mod, power)
self.FileName = RADIO.VerifyFile(filename)
self.Frequecy = RADIO.ConvertFrequency(frequency)
self.Modulation = mod
self.Power = power
end