aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/SoundEffect.cpp
diff options
context:
space:
mode:
author Nemrav <50055236+Nemrav@users.noreply.github.com>2024-08-03 21:38:25 +0200
committer GitHub <noreply@github.com>2024-08-03 21:38:25 +0200
commitadc7eb8ad07170ba8da18f684321a92d01447c2c (patch)
treeeedd074580ff5a81b4eff4b8bc43163b7cf59f0e /src/openvic-simulation/misc/SoundEffect.cpp
parent1f42a6255226b79d271df5060a8391f4ea00fc0a (diff)
parent0b4732befaaf4a742acb319256c535eb449668a7 (diff)
Merge pull request #181 from OpenVicProject/sim_music
Music and Sound Effect define loading
Diffstat (limited to 'src/openvic-simulation/misc/SoundEffect.cpp')
-rw-r--r--src/openvic-simulation/misc/SoundEffect.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/openvic-simulation/misc/SoundEffect.cpp b/src/openvic-simulation/misc/SoundEffect.cpp
new file mode 100644
index 0000000..df3196b
--- /dev/null
+++ b/src/openvic-simulation/misc/SoundEffect.cpp
@@ -0,0 +1,38 @@
+#include "SoundEffect.hpp"
+
+using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+
+SoundEffect::SoundEffect (
+ std::string_view new_identifier, std::string_view new_file, fixed_point_t new_volume
+) : HasIdentifier { new_identifier }, file { new_file }, volume { new_volume } {}
+
+bool SoundEffectManager::_load_sound_define(std::string_view sfx_identifier, ast::NodeCPtr root) {
+ std::string_view file {};
+ fixed_point_t volume = 1;
+ bool ret = expect_dictionary_keys(
+ "file", ONE_EXACTLY, expect_string(assign_variable_callback(file)),
+ "volume", ZERO_OR_ONE,
+ expect_fixed_point(assign_variable_callback(volume))
+ )(root);
+
+ if (sfx_identifier.empty()) {
+ Logger::error("Invalid sound identifier - empty!");
+ return false;
+ }
+ if(file.empty()) {
+ Logger::error("Invalid sound file name - empty!");
+ return false;
+ }
+
+ ret &= sound_effects.add_item({sfx_identifier,file,volume});
+ return ret;
+}
+
+bool SoundEffectManager::load_sound_defines_file(ast::NodeCPtr root) {
+ return expect_dictionary_reserve_length(sound_effects,
+ [this](std::string_view key, ast::NodeCPtr value) -> bool {
+ return _load_sound_define(key,value);
+ }
+ )(root);
+} \ No newline at end of file