diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index c27e8e5..83adb6e 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -9,6 +9,7 @@ - [Setup](./gremlin/setup.md) - [Usage](./gremlin/usage.md) - [Functions](./gremlin/functions.md) + - [Comms](./gremlin/functions/comms.md) - [Events](./gremlin/functions/events.md) - [Log](./gremlin/functions/log.md) - [Menu](./gremlin/functions/menu.md) diff --git a/docs/gremlin/functions/comms.md b/docs/gremlin/functions/comms.md new file mode 100644 index 0000000..2c733bb --- /dev/null +++ b/docs/gremlin/functions/comms.md @@ -0,0 +1,12 @@ + +### Comms + +#### `Gremlin.comms.displayMessageTo(_name, _text, _time)` + +Displays a message to a named Unit, Group, Country, or Coalition, or to everyone with the special name `all` + +--- + +#### `Gremlin.comms.playClipTo(_name, _path)` + +Plays a clip to a named Unit, Group, Country, or Coalition, or to everyone with the special name `all` diff --git a/docs/gremlin/functions/utils.md b/docs/gremlin/functions/utils.md index 319b3f0..803da1a 100644 --- a/docs/gremlin/functions/utils.md +++ b/docs/gremlin/functions/utils.md @@ -7,12 +7,6 @@ Counts the number of entries in a table, regardless of type --- -#### `Gremlin.utils.displayMessageTo(_name, _text, _time)` - -Displays a message to a named Unit, Group, Country, or Coalition, or to everyone with the special name `all` - ---- - #### `Gremlin.utils.getUnitZones(_unit)` Looks up a list of all the zones a unit is currently in diff --git a/docs/gremlin/usage.md b/docs/gremlin/usage.md index 5e5bdaf..780ea12 100644 --- a/docs/gremlin/usage.md +++ b/docs/gremlin/usage.md @@ -8,7 +8,7 @@ Gremlin:setup() Gremlin.log.info('My Cool DCS Script', 'Starting up!') -Gremlin.utils.displayMessageTo('test', 'Hullabaloo!', timer.getTime() + 1) +Gremlin.comms.displayMessageTo('test', 'Hullabaloo!', timer.getTime() + 1) local myArgs = Gremlin.utils.parseFuncArgs({ '{unit}:test', '{group}:test', timer.getTime() }, { unit = { diff --git a/mocks/DCS.lua b/mocks/DCS.lua index cae0350..a06948a 100644 --- a/mocks/DCS.lua +++ b/mocks/DCS.lua @@ -1872,6 +1872,11 @@ require("Scripts.ScriptingSystem") trigger.action.activateGroup = Mock() trigger.action.deactivateGroup = Mock() trigger.action.smoke = Mock() +trigger.action.outSound = Mock() +trigger.action.outSoundForCoalition = Mock() +trigger.action.outSoundForCountry = Mock() +trigger.action.outSoundForGroup = Mock() +trigger.action.outSoundForUnit = Mock() trigger.action.outText = Mock() trigger.action.outTextForCoalition = Mock() trigger.action.outTextForCountry = Mock() diff --git a/src/evac.lua b/src/evac.lua index fe5e833..affd950 100644 --- a/src/evac.lua +++ b/src/evac.lua @@ -324,19 +324,19 @@ Evac.units = { if _unitObj ~= nil then local _free = Evac.carryLimits[_unitObj:getTypeName()] or 0 if _free == 0 then - Gremlin.utils.displayMessageTo(_unit, "Your aircraft isn't rated for evacuees in this mission!", 1) + Gremlin.comms.displayMessageTo(_unit, "Your aircraft isn't rated for evacuees in this mission!", 1) return end _free = _free - Evac._internal.aircraft.countEvacuees(_unit) if _free <= 0 then - Gremlin.utils.displayMessageTo(_unit, 'Already full! Unload, first!', 1) + Gremlin.comms.displayMessageTo(_unit, 'Already full! Unload, first!', 1) return end Evac._internal.aircraft.loadEvacuees(_unit, _free) else - Gremlin.utils.displayMessageTo(_unit, "Your aircraft isn't rated for evacuees in this mission!", 1) + Gremlin.comms.displayMessageTo(_unit, "Your aircraft isn't rated for evacuees in this mission!", 1) end end, -- Starts the evacuee unloading process for a unit @@ -351,7 +351,7 @@ Evac.units = { local _count = Evac._internal.aircraft.countEvacuees(_unit) - Gremlin.utils.displayMessageTo(_unit, 'You are currently carrying ' .. _count .. ' evacuees.', 1) + Gremlin.comms.displayMessageTo(_unit, 'You are currently carrying ' .. _count .. ' evacuees.', 1) end, -- Count the number of units in a given zone count = function(_zone) @@ -513,20 +513,20 @@ Evac._internal.aircraft = { if Evac._state.extractableNow[_zone] == nil or ((Evac._state.zones.evac[_zone] == nil or Evac._state.zones.evac[_zone].active == false) and (Evac._state.zones.relay[_zone] == nil or Evac._state.zones.relay[_zone].active == false)) then Gremlin.log.debug(Evac.Id, string.format('Loading Evacuees : %s is not an active or registered zone\nextractable - %s\nevac zone - %s\nrelay zone - %s', _zone, mist.utils.tableShowSorted(Evac._state.extractableNow[_zone]), mist.utils.tableShowSorted(Evac._state.zones.evac[_zone]), mist.utils.tableShowSorted(Evac._state.zones.relay[_zone]))) - Gremlin.utils.displayMessageTo(_unit, 'Not in an active evac or relay zone! Try looking elsewhere.', 5) + Gremlin.comms.displayMessageTo(_unit, 'Not in an active evac or relay zone! Try looking elsewhere.', 5) return end if Evac._internal.aircraft.inAir(_unit) then Gremlin.log.debug(Evac.Id, string.format('Loading Evacuees : %s is not on the ground', _unit)) - Gremlin.utils.displayMessageTo(_unit, 'You need to land, first! Unless you have some magic way to teleport them up? And no, these folks are in no condition for the hoist, so put that back up.', 5) + Gremlin.comms.displayMessageTo(_unit, 'You need to land, first! Unless you have some magic way to teleport them up? And no, these folks are in no condition for the hoist, so put that back up.', 5) return end _number = math.min(_number, Gremlin.utils.countTableEntries(Evac._state.extractableNow[_zone])) if _number < 1 then Gremlin.log.debug(Evac.Id, string.format('Loading Evacuees : %s is empty', _zone)) - Gremlin.utils.displayMessageTo(_unit, 'No evacuees to load here, pilot! Try looking elsewhere.', 5) + Gremlin.comms.displayMessageTo(_unit, 'No evacuees to load here, pilot! Try looking elsewhere.', 5) return end @@ -577,7 +577,7 @@ Evac._internal.aircraft = { Gremlin.log.debug(Evac.Id, string.format('Loading Evacuees : Sending %s to %s', _message, tostring(_unit))) Gremlin.events.fire({ id = 'Evac:UnitLoaded', zone = _zone, unit = _unit, number = _number }) - Gremlin.utils.displayMessageTo(_unit, _message, _displayFor) + Gremlin.comms.displayMessageTo(_unit, _message, _displayFor) end, {_timeNow + 0.01}, _timeNow + 0.01, 1, _timeNow + _timeout + 0.02) end, countEvacuees = function(_unit) @@ -634,20 +634,20 @@ Evac._internal.aircraft = { if (Evac._state.zones.safe[_zone] == nil or Evac._state.zones.safe[_zone].active == false) and (Evac._state.zones.relay[_zone] == nil or Evac._state.zones.relay[_zone].active == false) then Gremlin.log.debug(Evac.Id, string.format('Unloading Evacuees : %s is not an active or registered zone\nrelay zone - %s\nsafe zone - %s', _zone, mist.utils.tableShowSorted(Evac._state.zones.relay[_zone]), mist.utils.tableShowSorted(Evac._state.zones.safe[_zone]))) - Gremlin.utils.displayMessageTo(_unit, 'Not in an active relay or safe zone! Try looking elsewhere.', 5) + Gremlin.comms.displayMessageTo(_unit, 'Not in an active relay or safe zone! Try looking elsewhere.', 5) return end if Evac._internal.aircraft.inAir(_unit) then Gremlin.log.debug(Evac.Id, string.format('Unloading Evacuees : %s is not on the ground', _unit)) - Gremlin.utils.displayMessageTo(_unit, "You need to land, first! Fastrope doesn't work with stretchers.", 5) + Gremlin.comms.displayMessageTo(_unit, "You need to land, first! Fastrope doesn't work with stretchers.", 5) return end local _number = Evac._internal.aircraft.countEvacuees(_unit) if _number < 1 then Gremlin.log.debug(Evac.Id, string.format('Unloading Evacuees : %s is empty', _unit)) - Gremlin.utils.displayMessageTo(_unit, 'No evacuees to unload?! Why are you even here, pilot?!', 5) + Gremlin.comms.displayMessageTo(_unit, 'No evacuees to unload?! Why are you even here, pilot?!', 5) return end @@ -697,7 +697,7 @@ Evac._internal.aircraft = { Gremlin.log.debug(Evac.Id, string.format('Unloading Evacuees : Sending %s to %s', _message, tostring(_unit))) Gremlin.events.fire({ id = 'Evac:UnitUnloaded', zone = _zone, unit = _unit, number = _number }) - Gremlin.utils.displayMessageTo(_unit, _message, _displayFor) + Gremlin.comms.displayMessageTo(_unit, _message, _displayFor) Evac._internal.utils.endIfEnoughGotOut() end, { _timeNow + 0.01 }, _timeNow + 0.01, 1, _timeNow + _timeout + 0.02) end @@ -834,9 +834,9 @@ Evac._internal.beacons = { Gremlin.log.debug(Evac.Id, string.format('Got Beacon List For Unit : %s, %s', tostring(_unit), _message or 'none')) if _message ~= nil and _message ~= '' then - Gremlin.utils.displayMessageTo(_unitObj:getGroup(), 'Evacuation Beacons:\n' .. _message, 15) + Gremlin.comms.displayMessageTo(_unitObj:getGroup(), 'Evacuation Beacons:\n' .. _message, 15) else - Gremlin.utils.displayMessageTo(_unitObj:getGroup(), 'No Active Evacuation Beacons', 15) + Gremlin.comms.displayMessageTo(_unitObj:getGroup(), 'No Active Evacuation Beacons', 15) end end end @@ -1658,7 +1658,7 @@ Evac._internal.handlers = { Gremlin.log.debug(Evac.Id, string.format('Lost Evacuee(s)! : %s', Evac._internal.aircraft.countEvacuees(_name))) - Gremlin.utils.displayMessageTo(Gremlin.SideToText[_side], string.format('We just lost %i evacuee(s)! Step it up, pilots!', Evac._internal.aircraft.countEvacuees(_name)), 15) + Gremlin.comms.displayMessageTo(Gremlin.SideToText[_side], string.format('We just lost %i evacuee(s)! Step it up, pilots!', Evac._internal.aircraft.countEvacuees(_name)), 15) Evac._state.extractionUnits[_name] = { [0] = Evac._state.extractionUnits[_name][0], diff --git a/src/gremlin.lua b/src/gremlin.lua index 01e8637..59575e2 100644 --- a/src/gremlin.lua +++ b/src/gremlin.lua @@ -29,6 +29,46 @@ Gremlin = { }, -- Methods + comms = { + displayMessageTo = function(_name, _text, _time) + if _name == 'all' or _name == 'Neutral' or _name == nil then + trigger.action.outText(_text, _time) + elseif type(_name) == 'string' and coalition.side[string.upper(_name)] ~= nil then + trigger.action.outTextForCoalition(coalition.side[string.upper(_name)], _text, _time) + elseif type(_name) == 'string' and country[string.upper(_name)] ~= nil then + trigger.action.outTextForCountry(country[string.upper(_name)], _text, _time) + elseif type(_name) == 'table' and _name.className_ == 'Group' then + trigger.action.outTextForGroup(_name:getID(), _text, _time) + elseif type(_name) == 'string' and Group.getByName(_name) ~= nil then + trigger.action.outTextForGroup(Group.getByName(_name):getID(), _text, _time) + elseif type(_name) == 'table' and _name.className_ == 'Unit' then + trigger.action.outTextForUnit(_name:getID(), _text, _time) + elseif type(_name) == 'string' and Unit.getByName(_name) ~= nil then + trigger.action.outTextForUnit(Unit.getByName(_name):getID(), _text, _time) + else + Gremlin.log.error(Gremlin.Id, string.format("Can't find object named %s to display message to!\nMessage was: %s", tostring(_name), _text)) + end + end, + playClipTo = function(_name, _path) + if _name == 'all' or _name == 'Neutral' or _name == nil then + trigger.action.outSound(_path) + elseif type(_name) == 'string' and coalition.side[string.upper(_name)] ~= nil then + trigger.action.outSoundForCoalition(coalition.side[string.upper(_name)], _path) + elseif type(_name) == 'string' and country[string.upper(_name)] ~= nil then + trigger.action.outSoundForCountry(country[string.upper(_name)], _path) + elseif type(_name) == 'table' and _name.className_ == 'Group' then + trigger.action.outSoundForGroup(_name:getID(), _path) + elseif type(_name) == 'string' and Group.getByName(_name) ~= nil then + trigger.action.outSoundForGroup(Group.getByName(_name):getID(), _path) + elseif type(_name) == 'table' and _name.className_ == 'Unit' then + trigger.action.outSoundForUnit(_name:getID(), _path) + elseif type(_name) == 'string' and Unit.getByName(_name) ~= nil then + trigger.action.outSoundForUnit(Unit.getByName(_name):getID(), _path) + else + Gremlin.log.error(Gremlin.Id, string.format("Can't find object named %s to play clip to!\nClip was: %s", tostring(_name), _path)) + end + end, + }, events = { _globalHandlers = { logEvents = { @@ -187,25 +227,6 @@ Gremlin = { end return _count end, - displayMessageTo = function(_name, _text, _time) - if _name == 'all' or _name == 'Neutral' or _name == nil then - trigger.action.outText(_text, _time) - elseif type(_name) == 'string' and coalition.side[string.upper(_name)] ~= nil then - trigger.action.outTextForCoalition(coalition.side[string.upper(_name)], _text, _time) - elseif type(_name) == 'string' and country[string.upper(_name)] ~= nil then - trigger.action.outTextForCountry(country[string.upper(_name)], _text, _time) - elseif type(_name) == 'table' and _name.className_ == 'Group' then - trigger.action.outTextForGroup(_name:getID(), _text, _time) - elseif type(_name) == 'string' and Group.getByName(_name) ~= nil then - trigger.action.outTextForGroup(Group.getByName(_name):getID(), _text, _time) - elseif type(_name) == 'table' and _name.className_ == 'Unit' then - trigger.action.outTextForUnit(_name:getID(), _text, _time) - elseif type(_name) == 'string' and Unit.getByName(_name) ~= nil then - trigger.action.outTextForUnit(Unit.getByName(_name):getID(), _text, _time) - else - Gremlin.log.error(Gremlin.Id, string.format("Can't find object named %s to display message to!\nMessage was: %s", tostring(_name), _text)) - end - end, getUnitZones = function(_unit) Gremlin.log.trace(Gremlin.Id, string.format('Grabbing Unit Zone Names : %s', _unit)) diff --git a/src/urgency.lua b/src/urgency.lua index 704d947..5809abd 100644 --- a/src/urgency.lua +++ b/src/urgency.lua @@ -119,7 +119,7 @@ Urgency._internal.doCountdowns = function() for _time, _message in pairs(_countdown.messages) do if (_time >= 0 and _time + _countdown.startedAt <= _now) or (_endTime ~= nil and _time < 0 and _time + _endTime <= _now) then Urgency._state.countdowns.active[_name].messages[_time] = nil - Gremlin.utils.displayMessageTo(_message.to, _message.text, _message.duration) + Gremlin.comms.displayMessageTo(_message.to, _message.text, _message.duration) Gremlin.log.trace(Urgency.Id, string.format('Sent Message : %s', _message.text)) end end diff --git a/test/gremlin.lua b/test/gremlin.lua index 5ef9b37..0fd2c55 100644 --- a/test/gremlin.lua +++ b/test/gremlin.lua @@ -104,6 +104,11 @@ local tearDown = function() Gremlin.log.trace:reset() trigger.action.setUnitInternalCargo:reset() trigger.action.setUserFlag:reset() + trigger.action.outSound:reset() + trigger.action.outSoundForCoalition:reset() + trigger.action.outSoundForCountry:reset() + trigger.action.outSoundForGroup:reset() + trigger.action.outSoundForUnit:reset() trigger.action.outText:reset() trigger.action.outTextForCoalition:reset() trigger.action.outTextForCountry:reset() @@ -121,6 +126,169 @@ local assertSpyCalledWith = function(_mock, _args) return lu.assertEquals(_status, true, string.format('%s\n%s', inspect(_result), inspect(_mock.calls))) end +TestGremlinComms = { + setUp = setUp, + testDisplayMessageToAll = function() + -- INIT + trigger.action.outText:whenCalled({ with = { 'test all', 1 }, thenReturn = nil }) + trigger.action.outText:whenCalled({ with = { 'test neutral', 1 }, thenReturn = nil }) + trigger.action.outText:whenCalled({ with = { 'test nil', 1 }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.displayMessageTo('all', 'test all', 1), nil) + lu.assertEquals(Gremlin.comms.displayMessageTo('Neutral', 'test neutral', 1), nil) + lu.assertEquals(Gremlin.comms.displayMessageTo(nil, 'test nil', 1), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outText, { 'test all', 1 }) + assertMockCalledWith(trigger.action.outText, { 'test neutral', 1 }) + assertMockCalledWith(trigger.action.outText, { 'test nil', 1 }) + end, + testDisplayMessageToCoalition = function() + -- INIT + trigger.action.outTextForCoalition:whenCalled({ with = { 1, 'test red', 1 }, thenReturn = nil }) + trigger.action.outTextForCoalition:whenCalled({ with = { 2, 'test blue', 1 }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.displayMessageTo('red', 'test red', 1), nil) + lu.assertEquals(Gremlin.comms.displayMessageTo('blue', 'test blue', 1), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outTextForCoalition, { 1, 'test red', 1 }) + assertMockCalledWith(trigger.action.outTextForCoalition, { 2, 'test blue', 1 }) + end, + testDisplayMessageToCountry = function() + -- INIT + trigger.action.outTextForCountry:whenCalled({ with = { 2, 'test USA', 1 }, thenReturn = nil }) + trigger.action.outTextForCountry:whenCalled({ with = { 0, 'test Russia', 1 }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.displayMessageTo('USA', 'test USA', 1), nil) + lu.assertEquals(Gremlin.comms.displayMessageTo('Russia', 'test Russia', 1), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outTextForCountry, { 2, 'test USA', 1 }) + assertMockCalledWith(trigger.action.outTextForCountry, { 0, 'test Russia', 1 }) + end, + testDisplayMessageToGroup = function() + -- INIT + trigger.action.outTextForGroup:whenCalled({ with = { 1, 'test group object', 1 }, thenReturn = nil }) + trigger.action.outTextForGroup:whenCalled({ with = { 2, 'test group name', 1 }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.displayMessageTo(_testGroup, 'test group object', 1), nil) + lu.assertEquals(Gremlin.comms.displayMessageTo(_testGroup2.groupName, 'test group name', 1), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outTextForGroup, { 1, 'test group object', 1 }) + assertMockCalledWith(trigger.action.outTextForGroup, { 2, 'test group name', 1 }) + end, + testDisplayMessageToUnit = function() + -- INIT + trigger.action.outTextForUnit:whenCalled({ with = { 1, 'test unit object', 1 }, thenReturn = nil }) + trigger.action.outTextForUnit:whenCalled({ with = { 1, 'test unit name', 1 }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.displayMessageTo(_testUnit, 'test unit object', 1), nil) + lu.assertEquals(Gremlin.comms.displayMessageTo(_testUnit2.unitName, 'test unit name', 1), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outTextForUnit, { 1, 'test unit object', 1 }) + assertMockCalledWith(trigger.action.outTextForUnit, { 1, 'test unit name', 1 }) + end, + testDisplayMessageToUnknown = function() + -- INIT + -- N/A? + + -- TEST + lu.assertEquals(Gremlin.comms.displayMessageTo('HammerTime', 'test unknown', 1), nil) + + -- SIDE EFFECTS + assertSpyCalledWith(Gremlin.log.error, + { Gremlin.Id, string.format("Can't find object named %s to display message to!\nMessage was: %s", + tostring('HammerTime'), 'test unknown') }) + end, + testPlayClipToAll = function() + -- INIT + trigger.action.outSound:whenCalled({ with = { 'test all' }, thenReturn = nil }) + trigger.action.outSound:whenCalled({ with = { 'test neutral' }, thenReturn = nil }) + trigger.action.outSound:whenCalled({ with = { 'test nil' }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.playClipTo('all', 'test all'), nil) + lu.assertEquals(Gremlin.comms.playClipTo('Neutral', 'test neutral'), nil) + lu.assertEquals(Gremlin.comms.playClipTo(nil, 'test nil'), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outSound, { 'test all' }) + assertMockCalledWith(trigger.action.outSound, { 'test neutral' }) + assertMockCalledWith(trigger.action.outSound, { 'test nil' }) + end, + testPlayClipToCoalition = function() + -- INIT + trigger.action.outSoundForCoalition:whenCalled({ with = { 1, 'test red' }, thenReturn = nil }) + trigger.action.outSoundForCoalition:whenCalled({ with = { 2, 'test blue' }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.playClipTo('red', 'test red'), nil) + lu.assertEquals(Gremlin.comms.playClipTo('blue', 'test blue'), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outSoundForCoalition, { 1, 'test red' }) + assertMockCalledWith(trigger.action.outSoundForCoalition, { 2, 'test blue' }) + end, + testPlayClipToCountry = function() + -- INIT + trigger.action.outSoundForCountry:whenCalled({ with = { 2, 'test USA' }, thenReturn = nil }) + trigger.action.outSoundForCountry:whenCalled({ with = { 0, 'test Russia' }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.playClipTo('USA', 'test USA'), nil) + lu.assertEquals(Gremlin.comms.playClipTo('Russia', 'test Russia'), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outSoundForCountry, { 2, 'test USA' }) + assertMockCalledWith(trigger.action.outSoundForCountry, { 0, 'test Russia' }) + end, + testPlayClipToGroup = function() + -- INIT + trigger.action.outSoundForGroup:whenCalled({ with = { 1, 'test group object' }, thenReturn = nil }) + trigger.action.outSoundForGroup:whenCalled({ with = { 2, 'test group name' }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.playClipTo(_testGroup, 'test group object'), nil) + lu.assertEquals(Gremlin.comms.playClipTo(_testGroup2.groupName, 'test group name'), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outSoundForGroup, { 1, 'test group object' }) + assertMockCalledWith(trigger.action.outSoundForGroup, { 2, 'test group name' }) + end, + testPlayClipToUnit = function() + -- INIT + trigger.action.outSoundForUnit:whenCalled({ with = { 1, 'test unit object' }, thenReturn = nil }) + trigger.action.outSoundForUnit:whenCalled({ with = { 1, 'test unit name' }, thenReturn = nil }) + + -- TEST + lu.assertEquals(Gremlin.comms.playClipTo(_testUnit, 'test unit object'), nil) + lu.assertEquals(Gremlin.comms.playClipTo(_testUnit2.unitName, 'test unit name'), nil) + + -- SIDE EFFECTS + assertMockCalledWith(trigger.action.outSoundForUnit, { 1, 'test unit object' }) + assertMockCalledWith(trigger.action.outSoundForUnit, { 1, 'test unit name' }) + end, + testPlayClipToUnknown = function() + -- INIT + -- N/A? + + -- TEST + lu.assertEquals(Gremlin.comms.playClipTo('HammerTime', 'test unknown'), nil) + + -- SIDE EFFECTS + assertSpyCalledWith(Gremlin.log.error, { Gremlin.Id, string.format("Can't find object named %s to play clip to!\nClip was: %s", tostring('HammerTime'), 'test unknown') }) + end, + tearDown = tearDown, +} + TestGremlinEvents = { setUp = setUp, testOn = function() @@ -236,84 +404,6 @@ TestGremlinUtils = { -- SIDE EFFECTS -- N/A? end, - testDisplayMessageToAll = function() - -- INIT - trigger.action.outText:whenCalled({ with = { 'test all', 1 }, thenReturn = nil }) - trigger.action.outText:whenCalled({ with = { 'test neutral', 1 }, thenReturn = nil }) - trigger.action.outText:whenCalled({ with = { 'test nil', 1 }, thenReturn = nil }) - - -- TEST - lu.assertEquals(Gremlin.utils.displayMessageTo('all', 'test all', 1), nil) - lu.assertEquals(Gremlin.utils.displayMessageTo('Neutral', 'test neutral', 1), nil) - lu.assertEquals(Gremlin.utils.displayMessageTo(nil, 'test nil', 1), nil) - - -- SIDE EFFECTS - assertMockCalledWith(trigger.action.outText, { 'test all', 1 }) - assertMockCalledWith(trigger.action.outText, { 'test neutral', 1 }) - assertMockCalledWith(trigger.action.outText, { 'test nil', 1 }) - end, - testDisplayMessageToCoalition = function() - -- INIT - trigger.action.outTextForCoalition:whenCalled({ with = { 1, 'test red', 1 }, thenReturn = nil }) - trigger.action.outTextForCoalition:whenCalled({ with = { 2, 'test blue', 1 }, thenReturn = nil }) - - -- TEST - lu.assertEquals(Gremlin.utils.displayMessageTo('red', 'test red', 1), nil) - lu.assertEquals(Gremlin.utils.displayMessageTo('blue', 'test blue', 1), nil) - - -- SIDE EFFECTS - assertMockCalledWith(trigger.action.outTextForCoalition, { 1, 'test red', 1 }) - assertMockCalledWith(trigger.action.outTextForCoalition, { 2, 'test blue', 1 }) - end, - testDisplayMessageToCountry = function() - -- INIT - trigger.action.outTextForCountry:whenCalled({ with = { 2, 'test USA', 1 }, thenReturn = nil }) - trigger.action.outTextForCountry:whenCalled({ with = { 0, 'test Russia', 1 }, thenReturn = nil }) - - -- TEST - lu.assertEquals(Gremlin.utils.displayMessageTo('USA', 'test USA', 1), nil) - lu.assertEquals(Gremlin.utils.displayMessageTo('Russia', 'test Russia', 1), nil) - - -- SIDE EFFECTS - assertMockCalledWith(trigger.action.outTextForCountry, { 2, 'test USA', 1 }) - assertMockCalledWith(trigger.action.outTextForCountry, { 0, 'test Russia', 1 }) - end, - testDisplayMessageToGroup = function() - -- INIT - trigger.action.outTextForGroup:whenCalled({ with = { 1, 'test group object', 1 }, thenReturn = nil }) - trigger.action.outTextForGroup:whenCalled({ with = { 2, 'test group name', 1 }, thenReturn = nil }) - - -- TEST - lu.assertEquals(Gremlin.utils.displayMessageTo(_testGroup, 'test group object', 1), nil) - lu.assertEquals(Gremlin.utils.displayMessageTo(_testGroup2.groupName, 'test group name', 1), nil) - - -- SIDE EFFECTS - assertMockCalledWith(trigger.action.outTextForGroup, { 1, 'test group object', 1 }) - assertMockCalledWith(trigger.action.outTextForGroup, { 2, 'test group name', 1 }) - end, - testDisplayMessageToUnit = function() - -- INIT - trigger.action.outTextForUnit:whenCalled({ with = { 1, 'test unit object', 1 }, thenReturn = nil }) - trigger.action.outTextForUnit:whenCalled({ with = { 1, 'test unit name', 1 }, thenReturn = nil }) - - -- TEST - lu.assertEquals(Gremlin.utils.displayMessageTo(_testUnit, 'test unit object', 1), nil) - lu.assertEquals(Gremlin.utils.displayMessageTo(_testUnit2.unitName, 'test unit name', 1), nil) - - -- SIDE EFFECTS - assertMockCalledWith(trigger.action.outTextForUnit, { 1, 'test unit object', 1 }) - assertMockCalledWith(trigger.action.outTextForUnit, { 1, 'test unit name', 1 }) - end, - testDisplayMessageToUnknown = function() - -- INIT - -- N/A? - - -- TEST - lu.assertEquals(Gremlin.utils.displayMessageTo('HammerTime', 'test unknown', 1), nil) - - -- SIDE EFFECTS - assertSpyCalledWith(Gremlin.log.error, { Gremlin.Id, string.format("Can't find object named %s to display message to!\nMessage was: %s", tostring('HammerTime'), 'test unknown') }) - end, testGetUnitZones = function() -- INIT -- N/A?