SoundService & SoundInstance
Basic implementation. More work needs to be done.
This commit is contained in:
@@ -14,14 +14,15 @@
|
||||
using namespace std;
|
||||
using namespace rapidxml;
|
||||
|
||||
|
||||
DataModelInstance::DataModelInstance(void)
|
||||
{
|
||||
// Instances
|
||||
Instance::Instance();
|
||||
workspace = new WorkspaceInstance();
|
||||
guiRoot = new GuiRootInstance();
|
||||
level = new LevelInstance();
|
||||
thumbnailGenerator = new ThumbnailGeneratorInstance();
|
||||
soundService = new SoundService();
|
||||
|
||||
selectionService = new SelectionService();
|
||||
selectionService->setPropertyWindow(g_usableApp->_propWindow);
|
||||
@@ -31,6 +32,7 @@ DataModelInstance::DataModelInstance(void)
|
||||
_modY=0;
|
||||
workspace->setParent(this);
|
||||
level->setParent(this);
|
||||
|
||||
_loadedFileName="..//skooter.rbxm";
|
||||
listicon = 5;
|
||||
running = false;
|
||||
@@ -655,3 +657,8 @@ ThumbnailGeneratorInstance* DataModelInstance::getThumbnailGenerator()
|
||||
{
|
||||
return thumbnailGenerator;
|
||||
}
|
||||
|
||||
SoundService* DataModelInstance::getSoundService()
|
||||
{
|
||||
return soundService;
|
||||
}
|
||||
@@ -518,15 +518,17 @@ void PartInstance::onTouch()
|
||||
break;
|
||||
}
|
||||
|
||||
SoundService* sndService = g_dataModel->getSoundService();
|
||||
|
||||
switch(OnTouchSound)
|
||||
{
|
||||
case Enum::Sound::NoSound:
|
||||
break;
|
||||
case Enum::Sound::Victory:
|
||||
AudioPlayer::playSound(GetFileInPath("/content/sounds/victory.wav"));
|
||||
sndService->playSound(dynamic_cast<SoundInstance*>(sndService->findFirstChild("Victory")));
|
||||
break;
|
||||
case Enum::Sound::Boing:
|
||||
AudioPlayer::playSound(GetFileInPath("/content/sounds/boing.wav"));
|
||||
sndService->playSound(dynamic_cast<SoundInstance*>(sndService->findFirstChild("Boing")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
52
src/source/DataModelV2/SoundInstance.cpp
Normal file
52
src/source/DataModelV2/SoundInstance.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "DataModelV2/SoundInstance.h"
|
||||
#include "Globals.h"
|
||||
|
||||
SoundInstance::SoundInstance()
|
||||
{
|
||||
name = "Sound";
|
||||
className = "Sound";
|
||||
|
||||
soundVolume = 0.5;
|
||||
soundId = "";
|
||||
playOnRemove = false;
|
||||
looped = false;
|
||||
}
|
||||
|
||||
SoundInstance::~SoundInstance(void)
|
||||
{
|
||||
if(isPlayedOnRemove())
|
||||
play();
|
||||
}
|
||||
|
||||
// Functions
|
||||
void SoundInstance::play()
|
||||
{
|
||||
g_dataModel->getSoundService()->playSound(this);
|
||||
}
|
||||
|
||||
// Getters
|
||||
float SoundInstance::getSoundVolume()
|
||||
{
|
||||
return soundVolume;
|
||||
}
|
||||
|
||||
bool SoundInstance::isPlayedOnRemove()
|
||||
{
|
||||
return playOnRemove;
|
||||
}
|
||||
|
||||
std::string SoundInstance::getSoundId()
|
||||
{
|
||||
return soundId;
|
||||
}
|
||||
|
||||
bool SoundInstance::isLooped()
|
||||
{
|
||||
return looped;
|
||||
}
|
||||
|
||||
// Setters
|
||||
void SoundInstance::setSoundId(std::string newSoundId)
|
||||
{
|
||||
soundId = newSoundId;
|
||||
}
|
||||
83
src/source/DataModelV2/SoundService.cpp
Normal file
83
src/source/DataModelV2/SoundService.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "DataModelV2/SoundService.h"
|
||||
#include "StringFunctions.h"
|
||||
#include "AudioPlayer.h"
|
||||
#include "Globals.h"
|
||||
|
||||
SoundService::SoundService()
|
||||
{
|
||||
name = "SoundService";
|
||||
className = "SoundService";
|
||||
musicVolume = 0.3f;
|
||||
|
||||
// Create stock sounds
|
||||
SoundInstance* stockSound = new SoundInstance();
|
||||
|
||||
// Victory
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Victory");
|
||||
stockSound->setSoundId("/content/sounds/victory.wav");
|
||||
stockSound->setParent(this);
|
||||
|
||||
// Boing
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Boing");
|
||||
stockSound->setSoundId("/content/sounds/bass.wav");
|
||||
stockSound->setParent(this);
|
||||
|
||||
// Bomb
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Bomb");
|
||||
stockSound->setSoundId("/content/sounds/collide.wav");
|
||||
stockSound->setParent(this);
|
||||
|
||||
// Ping
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Ping");
|
||||
stockSound->setSoundId("/content/sounds/electronicpingshort.wav");
|
||||
stockSound->setParent(this);
|
||||
|
||||
// Break
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Break");
|
||||
stockSound->setSoundId("/content/sounds/glassbreak.wav");
|
||||
stockSound->setParent(this);
|
||||
|
||||
// Splat
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Splat");
|
||||
stockSound->setSoundId("/content/sounds/splat.wav");
|
||||
stockSound->setParent(this);
|
||||
|
||||
// Swoosh
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Swoosh");
|
||||
stockSound->setSoundId("/content/sounds/swoosh.wav");
|
||||
stockSound->setParent(this);
|
||||
|
||||
// Snap
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Snap");
|
||||
stockSound->setSoundId("/content/sounds/snap.wav");
|
||||
stockSound->setParent(this);
|
||||
|
||||
// Page
|
||||
stockSound = new SoundInstance();
|
||||
stockSound->setName("Page");
|
||||
stockSound->setSoundId("/content/sounds/pageturn.wav");
|
||||
stockSound->setParent(this);
|
||||
}
|
||||
|
||||
SoundService::~SoundService(void)
|
||||
{
|
||||
}
|
||||
|
||||
void SoundService::playSound(SoundInstance* sound)
|
||||
{
|
||||
std::string soundId = sound->getSoundId();
|
||||
AudioPlayer::playSound(GetFileInPath(soundId));
|
||||
}
|
||||
|
||||
float SoundService::getMusicVolume()
|
||||
{
|
||||
return musicVolume;
|
||||
}
|
||||
Reference in New Issue
Block a user