forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speech.cpp
42 lines (33 loc) · 1015 Bytes
/
speech.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "speech.h"
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "json.h"
#include "rng.h"
static std::map<std::string, std::vector<SpeechBubble>> speech;
static SpeechBubble nullSpeech = { no_translation( "INVALID SPEECH" ), 0 };
void load_speech( const JsonObject &jo )
{
translation sound;
jo.read( "sound", sound );
const int volume = jo.get_int( "volume" );
for( const std::string &label : jo.get_tags( "speaker" ) ) {
speech[label].emplace_back( SpeechBubble{ sound, volume } );
}
}
void reset_speech()
{
speech.clear();
}
const SpeechBubble &get_speech( const std::string &label )
{
const std::map<std::string, std::vector<SpeechBubble> >::iterator speech_type = speech.find(
label );
if( speech_type == speech.end() || speech_type->second.empty() ) {
// Bad lookup, return a fake sound, also warn?
return nullSpeech;
}
return random_entry_ref( speech_type->second );
}