LCOV - code coverage report
Current view: top level - source/soundmanager/scripting - JSInterface_Sound.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 17 71 23.9 %
Date: 2023-01-19 00:18:29 Functions: 3 17 17.6 %

          Line data    Source code
       1             : /* Copyright (C) 2021 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : #include "precompiled.h"
      18             : 
      19             : #include "JSInterface_Sound.h"
      20             : 
      21             : #include "lib/config2.h"
      22             : #include "lib/utf8.h"
      23             : #include "maths/Vector3D.h"
      24             : #include "ps/Filesystem.h"
      25             : #include "scriptinterface/FunctionWrapper.h"
      26             : #include "scriptinterface/ScriptRequest.h"
      27             : #include "soundmanager/SoundManager.h"
      28             : 
      29             : #include <sstream>
      30             : 
      31             : namespace JSI_Sound
      32             : {
      33             : #if CONFIG2_AUDIO
      34             : 
      35           0 :     void StartMusic()
      36             :     {
      37           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      38           0 :             sndManager->SetMusicEnabled(true);
      39           0 :     }
      40             : 
      41           0 :     void StopMusic()
      42             :     {
      43           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      44           0 :             sndManager->SetMusicEnabled(false);
      45           0 :     }
      46             : 
      47           0 :     void ClearPlaylist()
      48             :     {
      49           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      50           0 :             sndManager->ClearPlayListItems();
      51           0 :     }
      52             : 
      53           0 :     void AddPlaylistItem(const std::wstring& filename)
      54             :     {
      55           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      56           0 :             sndManager->AddPlayListItem(VfsPath(filename));
      57           0 :     }
      58             : 
      59           0 :     void StartPlaylist(bool looping)
      60             :     {
      61           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      62           0 :             sndManager->StartPlayList(looping );
      63           0 :     }
      64             : 
      65           0 :     void PlayMusic(const std::wstring& filename, bool looping)
      66             :     {
      67           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      68           0 :             sndManager->PlayAsMusic(filename, looping);
      69           0 :     }
      70             : 
      71           0 :     void PlayUISound(const std::wstring& filename, bool looping)
      72             :     {
      73           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      74           0 :             sndManager->PlayAsUI(filename, looping);
      75           0 :     }
      76             : 
      77           0 :     void PlayAmbientSound(const std::wstring& filename, bool looping)
      78             :     {
      79           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      80           0 :             sndManager->PlayAsAmbient(filename, looping);
      81           0 :     }
      82             : 
      83           0 :     bool MusicPlaying()
      84             :     {
      85           0 :         return true;
      86             :     }
      87             : 
      88           0 :     void SetMasterGain(float gain)
      89             :     {
      90           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      91           0 :             sndManager->SetMasterGain(gain);
      92           0 :     }
      93             : 
      94           0 :     void SetMusicGain(float gain)
      95             :     {
      96           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
      97           0 :             sndManager->SetMusicGain(gain);
      98           0 :     }
      99             : 
     100           0 :     void SetAmbientGain(float gain)
     101             :     {
     102           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
     103           0 :             sndManager->SetAmbientGain(gain);
     104           0 :     }
     105             : 
     106           0 :     void SetActionGain(float gain)
     107             :     {
     108           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
     109           0 :             sndManager->SetActionGain(gain);
     110           0 :     }
     111             : 
     112           0 :     void SetUIGain(float gain)
     113             :     {
     114           0 :         if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager)
     115           0 :             sndManager->SetUIGain(gain);
     116           0 :     }
     117             : 
     118             : #else
     119             : 
     120             :     bool MusicPlaying( ){ return false; }
     121             :     void PlayAmbientSound(const std::wstring& UNUSED(filename), bool UNUSED(looping) ){}
     122             :     void PlayUISound(const std::wstring& UNUSED(filename), bool UNUSED(looping) ) {}
     123             :     void PlayMusic(const std::wstring& UNUSED(filename), bool UNUSED(looping) ) {}
     124             :     void StartPlaylist(bool UNUSED(looping) ){}
     125             :     void AddPlaylistItem(const std::wstring& UNUSED(filename) ){}
     126             :     void ClearPlaylist( ){}
     127             :     void StopMusic( ){}
     128             :     void StartMusic( ){}
     129             :     void SetMasterGain(float UNUSED(gain)){}
     130             :     void SetMusicGain(float UNUSED(gain)){}
     131             :     void SetAmbientGain(float UNUSED(gain)){}
     132             :     void SetActionGain(float UNUSED(gain)){}
     133             :     void SetUIGain(float UNUSED(gain)){}
     134             : 
     135             : #endif
     136             : 
     137          12 :     void RegisterScriptFunctions(const ScriptRequest& rq)
     138             :     {
     139          12 :         ScriptFunction::Register<&StartMusic>(rq, "StartMusic");
     140          12 :         ScriptFunction::Register<&StopMusic>(rq, "StopMusic");
     141          12 :         ScriptFunction::Register<&ClearPlaylist>(rq, "ClearPlaylist");
     142          12 :         ScriptFunction::Register<&AddPlaylistItem>(rq, "AddPlaylistItem");
     143          12 :         ScriptFunction::Register<&StartPlaylist>(rq, "StartPlaylist");
     144          12 :         ScriptFunction::Register<&PlayMusic>(rq, "PlayMusic");
     145          12 :         ScriptFunction::Register<&PlayUISound>(rq, "PlayUISound");
     146          12 :         ScriptFunction::Register<&PlayAmbientSound>(rq, "PlayAmbientSound");
     147          12 :         ScriptFunction::Register<&MusicPlaying>(rq, "MusicPlaying");
     148          12 :         ScriptFunction::Register<&SetMasterGain>(rq, "SetMasterGain");
     149          12 :         ScriptFunction::Register<&SetMusicGain>(rq, "SetMusicGain");
     150          12 :         ScriptFunction::Register<&SetAmbientGain>(rq, "SetAmbientGain");
     151          12 :         ScriptFunction::Register<&SetActionGain>(rq, "SetActionGain");
     152          12 :         ScriptFunction::Register<&SetUIGain>(rq, "SetUIGain");
     153          12 :     }
     154           3 : }

Generated by: LCOV version 1.13