1 /* Copyright (C) 2017 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
17 #include "precompiled.h"
18 #include "scriptinterface/ScriptInterface.h"
20 #include "JSInterface_Sound.h"
22 #include "lib/config2.h"
24 #include "maths/Vector3D.h"
25 #include "ps/Filesystem.h"
26 #include "ps/Profile.h"
27 #include "soundmanager/SoundManager.h"
35 void StartMusic(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
))
37 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
38 sndManager
->SetMusicEnabled(true);
41 void StopMusic(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
))
43 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
44 sndManager
->SetMusicEnabled(false);
47 void ClearPlaylist(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
))
49 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
50 sndManager
->ClearPlayListItems();
53 void AddPlaylistItem(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& filename
)
55 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
56 sndManager
->AddPlayListItem(VfsPath(filename
));
59 void StartPlaylist(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), bool looping
)
61 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
62 sndManager
->StartPlayList( looping
);
65 void PlayMusic(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& filename
, bool looping
)
67 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
68 sndManager
->PlayAsMusic( filename
, looping
);
71 void PlayUISound(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& filename
, bool looping
)
73 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
74 sndManager
->PlayAsUI( filename
, looping
);
77 void PlayAmbientSound(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& filename
, bool looping
)
79 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
80 sndManager
->PlayAsAmbient( filename
, looping
);
83 bool MusicPlaying(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
))
88 void SetMasterGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
)
90 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
91 sndManager
->SetMasterGain(gain
);
94 void SetMusicGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
)
96 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
97 sndManager
->SetMusicGain(gain
);
100 void SetAmbientGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
)
102 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
103 sndManager
->SetAmbientGain(gain
);
106 void SetActionGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
)
108 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
109 sndManager
->SetActionGain(gain
);
112 void SetUIGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
)
114 if ( CSoundManager
* sndManager
= (CSoundManager
*)g_SoundManager
)
115 sndManager
->SetUIGain(gain
);
120 bool MusicPlaying(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
) ){ return false; }
121 void PlayAmbientSound(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& UNUSED(filename
), bool UNUSED(looping
) ){}
122 void PlayUISound(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& UNUSED(filename
), bool UNUSED(looping
) ) {}
123 void PlayMusic(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& UNUSED(filename
), bool UNUSED(looping
) ) {}
124 void StartPlaylist(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), bool UNUSED(looping
) ){}
125 void AddPlaylistItem(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), const std::wstring
& UNUSED(filename
) ){}
126 void ClearPlaylist(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
) ){}
127 void StopMusic(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
) ){}
128 void StartMusic(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
) ){}
129 void SetMasterGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
){}
130 void SetMusicGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
){}
131 void SetAmbientGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
){}
132 void SetActionGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
){}
133 void SetUIGain(ScriptInterface::CxPrivate
* UNUSED(pCxPrivate
), float gain
){}
138 void RegisterScriptFunctions(const ScriptInterface
& scriptInterface
)
140 scriptInterface
.RegisterFunction
<void, &StartMusic
>("StartMusic");
141 scriptInterface
.RegisterFunction
<void, &StopMusic
>("StopMusic");
142 scriptInterface
.RegisterFunction
<void, &ClearPlaylist
>("ClearPlaylist");
143 scriptInterface
.RegisterFunction
<void, std::wstring
, &AddPlaylistItem
>("AddPlaylistItem");
144 scriptInterface
.RegisterFunction
<void, bool, &StartPlaylist
>("StartPlaylist");
145 scriptInterface
.RegisterFunction
<void, std::wstring
, bool, &PlayMusic
>("PlayMusic");
146 scriptInterface
.RegisterFunction
<void, std::wstring
, bool, &PlayUISound
>("PlayUISound");
147 scriptInterface
.RegisterFunction
<void, std::wstring
, bool, &PlayAmbientSound
>("PlayAmbientSound");
148 scriptInterface
.RegisterFunction
<bool, &MusicPlaying
>("MusicPlaying");
149 scriptInterface
.RegisterFunction
<void, float, &SetMasterGain
>("SetMasterGain");
150 scriptInterface
.RegisterFunction
<void, float, &SetMusicGain
>("SetMusicGain");
151 scriptInterface
.RegisterFunction
<void, float, &SetAmbientGain
>("SetAmbientGain");
152 scriptInterface
.RegisterFunction
<void, float, &SetActionGain
>("SetActionGain");
153 scriptInterface
.RegisterFunction
<void, float, &SetUIGain
>("SetUIGain");