Changeset View
Changeset View
Standalone View
Standalone View
source/soundmanager/scripting/JSInterface_Sound.cpp
Show All 16 Lines | |||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "JSInterface_Sound.h" | #include "JSInterface_Sound.h" | ||||
#include "lib/config2.h" | #include "lib/config2.h" | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "maths/Vector3D.h" | #include "maths/Vector3D.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | |||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "soundmanager/SoundManager.h" | #include "soundmanager/SoundManager.h" | ||||
#include <sstream> | #include <sstream> | ||||
namespace JSI_Sound | namespace JSI_Sound | ||||
{ | { | ||||
#if CONFIG2_AUDIO | #if CONFIG2_AUDIO | ||||
void StartMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void StartMusic() | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->SetMusicEnabled(true); | sndManager->SetMusicEnabled(true); | ||||
} | } | ||||
void StopMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void StopMusic() | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->SetMusicEnabled(false); | sndManager->SetMusicEnabled(false); | ||||
} | } | ||||
void ClearPlaylist(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void ClearPlaylist() | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->ClearPlayListItems(); | sndManager->ClearPlayListItems(); | ||||
} | } | ||||
void AddPlaylistItem(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename) | void AddPlaylistItem(const std::wstring& filename) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->AddPlayListItem(VfsPath(filename)); | sndManager->AddPlayListItem(VfsPath(filename)); | ||||
} | } | ||||
void StartPlaylist(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool looping) | void StartPlaylist(bool looping) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->StartPlayList(looping ); | sndManager->StartPlayList(looping ); | ||||
} | } | ||||
void PlayMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename, bool looping) | void PlayMusic(const std::wstring& filename, bool looping) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->PlayAsMusic(filename, looping); | sndManager->PlayAsMusic(filename, looping); | ||||
} | } | ||||
void PlayUISound(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename, bool looping) | void PlayUISound(const std::wstring& filename, bool looping) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->PlayAsUI(filename, looping); | sndManager->PlayAsUI(filename, looping); | ||||
} | } | ||||
void PlayAmbientSound(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename, bool looping) | void PlayAmbientSound(const std::wstring& filename, bool looping) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->PlayAsAmbient(filename, looping); | sndManager->PlayAsAmbient(filename, looping); | ||||
} | } | ||||
bool MusicPlaying(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | bool MusicPlaying() | ||||
{ | { | ||||
return true; | return true; | ||||
} | } | ||||
void SetMasterGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) | void SetMasterGain(float gain) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->SetMasterGain(gain); | sndManager->SetMasterGain(gain); | ||||
} | } | ||||
void SetMusicGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) | void SetMusicGain(float gain) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->SetMusicGain(gain); | sndManager->SetMusicGain(gain); | ||||
} | } | ||||
void SetAmbientGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) | void SetAmbientGain(float gain) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->SetAmbientGain(gain); | sndManager->SetAmbientGain(gain); | ||||
} | } | ||||
void SetActionGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) | void SetActionGain(float gain) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->SetActionGain(gain); | sndManager->SetActionGain(gain); | ||||
} | } | ||||
void SetUIGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) | void SetUIGain(float gain) | ||||
{ | { | ||||
if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) | ||||
sndManager->SetUIGain(gain); | sndManager->SetUIGain(gain); | ||||
} | } | ||||
#else | #else | ||||
bool MusicPlaying(ScriptInterface::CxPrivate* UNUSED(pCxPrivate) ){ return false; } | bool MusicPlaying(){ return false; } | ||||
void PlayAmbientSound(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& UNUSED(filename), bool UNUSED(looping) ){} | void PlayAmbientSound(const std::wstring& UNUSED(filename), bool UNUSED(looping) ){} | ||||
void PlayUISound(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& UNUSED(filename), bool UNUSED(looping) ) {} | void PlayUISound(const std::wstring& UNUSED(filename), bool UNUSED(looping) ) {} | ||||
void PlayMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& UNUSED(filename), bool UNUSED(looping) ) {} | void PlayMusic(const std::wstring& UNUSED(filename), bool UNUSED(looping) ) {} | ||||
void StartPlaylist(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool UNUSED(looping) ){} | void StartPlaylist(bool UNUSED(looping) ){} | ||||
void AddPlaylistItem(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& UNUSED(filename) ){} | void AddPlaylistItem(const std::wstring& UNUSED(filename) ){} | ||||
void ClearPlaylist(ScriptInterface::CxPrivate* UNUSED(pCxPrivate) ){} | void ClearPlaylist(){} | ||||
void StopMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate) ){} | void StopMusic(){} | ||||
void StartMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate) ){} | void StartMusic(){} | ||||
void SetMasterGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain){} | void SetMasterGain(float gain){} | ||||
void SetMusicGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain){} | void SetMusicGain(float gain){} | ||||
void SetAmbientGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain){} | void SetAmbientGain(float gain){} | ||||
void SetActionGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain){} | void SetActionGain(float gain){} | ||||
void SetUIGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain){} | void SetUIGain(float gain){} | ||||
#endif | #endif | ||||
void RegisterScriptFunctions(const ScriptInterface& scriptInterface) | void RegisterScriptFunctions(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.RegisterFunction<void, &StartMusic>("StartMusic"); | #define Register(name) ScriptWrapper::WrapAndRegister<decltype(&name), &name>(scriptInterface, #name) | ||||
scriptInterface.RegisterFunction<void, &StopMusic>("StopMusic"); | Register(StartMusic); | ||||
scriptInterface.RegisterFunction<void, &ClearPlaylist>("ClearPlaylist"); | Register(StopMusic); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &AddPlaylistItem>("AddPlaylistItem"); | Register(ClearPlaylist); | ||||
scriptInterface.RegisterFunction<void, bool, &StartPlaylist>("StartPlaylist"); | Register(AddPlaylistItem); | ||||
scriptInterface.RegisterFunction<void, std::wstring, bool, &PlayMusic>("PlayMusic"); | Register(StartPlaylist); | ||||
scriptInterface.RegisterFunction<void, std::wstring, bool, &PlayUISound>("PlayUISound"); | Register(PlayMusic); | ||||
scriptInterface.RegisterFunction<void, std::wstring, bool, &PlayAmbientSound>("PlayAmbientSound"); | Register(PlayUISound); | ||||
scriptInterface.RegisterFunction<bool, &MusicPlaying>("MusicPlaying"); | Register(PlayAmbientSound); | ||||
scriptInterface.RegisterFunction<void, float, &SetMasterGain>("SetMasterGain"); | Register(MusicPlaying); | ||||
scriptInterface.RegisterFunction<void, float, &SetMusicGain>("SetMusicGain"); | Register(SetMasterGain); | ||||
scriptInterface.RegisterFunction<void, float, &SetAmbientGain>("SetAmbientGain"); | Register(SetMusicGain); | ||||
scriptInterface.RegisterFunction<void, float, &SetActionGain>("SetActionGain"); | Register(SetAmbientGain); | ||||
scriptInterface.RegisterFunction<void, float, &SetUIGain>("SetUIGain"); | Register(SetActionGain); | ||||
Register(SetUIGain); | |||||
#undef Register | |||||
} | } | ||||
} | } |
Wildfire Games · Phabricator