1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-17 00:07:41 +02:00

Implement configurable object sounds: ambient, visit and removal

* If there more than one sound for visit or removal random is played
* At moment only the first ambient sound will be used
This commit is contained in:
Arseniy Shestakov
2017-09-13 03:35:58 +03:00
committed by DJWarmonger
parent e9bfbb70c1
commit f15cadc87b
22 changed files with 347 additions and 91 deletions

View File

@ -18,6 +18,7 @@
#include "../CGeneralTextHandler.h"
#include "../CModHandler.h"
#include "../JsonNode.h"
#include "../CSoundBase.h"
#include "CRewardableConstructor.h"
#include "CommonConstructors.h"
@ -201,6 +202,7 @@ CObjectClassesHandler::ObjectContainter * CObjectClassesHandler::loadFromJson(co
{
loadObjectEntry(entry.first, entry.second, obj);
}
return obj;
}
@ -348,6 +350,22 @@ std::string CObjectClassesHandler::getObjectName(si32 type, si32 subtype) const
return getObjectName(type);
}
SObjectSounds CObjectClassesHandler::getObjectSounds(si32 type) const
{
if(objects.count(type))
return objects.at(type)->sounds;
logGlobal->error("Access to non existing object of type %d", type);
return SObjectSounds();
}
SObjectSounds CObjectClassesHandler::getObjectSounds(si32 type, si32 subtype) const
{
if(knownSubObjects(type).count(subtype))
return getHandlerFor(type, subtype)->getSounds();
else
return getObjectSounds(type);
}
std::string CObjectClassesHandler::getObjectHandlerName(si32 type) const
{
return objects.at(type)->handlerName;
@ -414,6 +432,15 @@ void AObjectTypeHandler::init(const JsonNode & input, boost::optional<std::strin
else
objectName.reset(input["name"].String());
for(const JsonNode & node : input["sounds"]["ambient"].Vector())
sounds.ambient.push_back(node.String());
for(const JsonNode & node : input["sounds"]["visit"].Vector())
sounds.visit.push_back(node.String());
for(const JsonNode & node : input["sounds"]["removal"].Vector())
sounds.removal.push_back(node.String());
initTypeData(input);
}
@ -440,6 +467,11 @@ boost::optional<std::string> AObjectTypeHandler::getCustomName() const
return objectName;
}
SObjectSounds AObjectTypeHandler::getSounds() const
{
return sounds;
}
void AObjectTypeHandler::addTemplate(const ObjectTemplate & templ)
{
templates.push_back(templ);