1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

It is now possible to define custom battle opening sound and custom music

for a battlefield
This commit is contained in:
Ivan Savenko 2024-07-15 21:46:23 +00:00
parent 358008fca9
commit 9c5d5d7c5a
5 changed files with 46 additions and 7 deletions

View File

@ -35,6 +35,7 @@
#include "../adventureMap/AdventureMapInterface.h" #include "../adventureMap/AdventureMapInterface.h"
#include "../../CCallback.h" #include "../../CCallback.h"
#include "../../lib/BattleFieldHandler.h"
#include "../../lib/CStack.h" #include "../../lib/CStack.h"
#include "../../lib/CConfigHandler.h" #include "../../lib/CConfigHandler.h"
#include "../../lib/CGeneralTextHandler.h" #include "../../lib/CGeneralTextHandler.h"
@ -113,6 +114,9 @@ void BattleInterface::playIntroSoundAndUnlockInterface()
onIntroSoundPlayed(); onIntroSoundPlayed();
}; };
auto bfieldType = getBattle()->battleGetBattlefieldType();
const auto & battlefieldSound = bfieldType.getInfo()->musicFilename;
std::vector<soundBase::soundID> battleIntroSounds = std::vector<soundBase::soundID> battleIntroSounds =
{ {
soundBase::battle00, soundBase::battle01, soundBase::battle00, soundBase::battle01,
@ -120,7 +124,13 @@ void BattleInterface::playIntroSoundAndUnlockInterface()
soundBase::battle05, soundBase::battle06, soundBase::battle07 soundBase::battle05, soundBase::battle06, soundBase::battle07
}; };
int battleIntroSoundChannel = CCS->soundh->playSoundFromSet(battleIntroSounds); int battleIntroSoundChannel = -1;
if (!battlefieldSound.empty())
battleIntroSoundChannel = CCS->soundh->playSound(battlefieldSound);
else
battleIntroSoundChannel = CCS->soundh->playSoundFromSet(battleIntroSounds);
if (battleIntroSoundChannel != -1) if (battleIntroSoundChannel != -1)
{ {
CCS->soundh->setCallback(battleIntroSoundChannel, onIntroPlayed); CCS->soundh->setCallback(battleIntroSoundChannel, onIntroPlayed);
@ -144,6 +154,12 @@ void BattleInterface::onIntroSoundPlayed()
if (openingPlaying()) if (openingPlaying())
openingEnd(); openingEnd();
auto bfieldType = getBattle()->battleGetBattlefieldType();
const auto & battlefieldMusic = bfieldType.getInfo()->musicFilename;
if (!battlefieldMusic.empty())
CCS->musich->playMusic(battlefieldMusic, true, true);
else
CCS->musich->playMusicFromSet("battle", true, true); CCS->musich->playMusicFromSet("battle", true, true);
} }

View File

@ -24,6 +24,18 @@
"format" : "imageFile", "format" : "imageFile",
"description" : "Background image for this battlefield" "description" : "Background image for this battlefield"
}, },
"music" :
{
"description" : "Optional, filename for custom music to play during combat on this terrain",
"type" : "string",
"format" : "musicFile"
},
"openingSound" :
{
"description" : "Optional, filename for custom sound to play during combat opening on this terrain",
"type" : "string",
"format" : "musicFile"
},
"impassableHexes" : { "impassableHexes" : {
"type" : "array", "type" : "array",
"description" : "List of battle hexes that will be always blocked on this battlefield (e.g. ship to ship battles)", "description" : "List of battle hexes that will be always blocked on this battlefield (e.g. ship to ship battles)",

View File

@ -1,17 +1,23 @@
```jsonc ```jsonc
// Human-readable name of the battlefield // Human-readable name of the battlefield
"name" : "" "name" : "",
// If set to true, obstacles will be taken from "specialBattlefields" property of an obstacle // If set to true, obstacles will be taken from "specialBattlefields" property of an obstacle
// If set to false, obstacles will be taken from "allowedTerrains" instead // If set to false, obstacles will be taken from "allowedTerrains" instead
"isSpecial" : false "isSpecial" : false,
// List of bonuses that will affect all battles on this battlefield // List of bonuses that will affect all battles on this battlefield
"bonuses" : { BONUS_FORMAT } "bonuses" : { BONUS_FORMAT },
// Background image for this battlefield // Background image for this battlefield
"graphics" : "" "graphics" : "",
// Optional, filename for custom music to play during combat on this terrain
"music" : "",
// Optional, filename for custom sound to play during combat opening on this terrain
"openingSound" : "",
// List of battle hexes that will be always blocked on this battlefield (e.g. ship to ship battles) // List of battle hexes that will be always blocked on this battlefield (e.g. ship to ship battles)
"impassableHexes" : [ 10, 20, 50 ] "impassableHexes" : [ 10, 20, 50 ],
``` ```

View File

@ -40,6 +40,9 @@ std::shared_ptr<BattleFieldInfo> BattleFieldHandler::loadFromJson(const std::str
for(auto node : json["impassableHexes"].Vector()) for(auto node : json["impassableHexes"].Vector())
info->impassableHexes.emplace_back(node.Integer()); info->impassableHexes.emplace_back(node.Integer());
info->openingSoundFilename = AudioPath::fromJson(json["openingSound"]);
info->musicFilename = AudioPath::fromJson(json["music"]);
return info; return info;
} }

View File

@ -32,6 +32,8 @@ public:
std::string icon; std::string icon;
si32 iconIndex; si32 iconIndex;
std::vector<BattleHex> impassableHexes; std::vector<BattleHex> impassableHexes;
AudioPath openingSoundFilename;
AudioPath musicFilename;
BattleFieldInfo() BattleFieldInfo()
: BattleFieldInfo(BattleField::NONE, "") : BattleFieldInfo(BattleField::NONE, "")