From 0b4732befaaf4a742acb319256c535eb449668a7 Mon Sep 17 00:00:00 2001 From: Nemrav <> Date: Thu, 1 Aug 2024 18:17:24 -0300 Subject: Music and Sound Effect define loading sound and music pr feedback more sound and music style fixes check lookup path --- src/openvic-simulation/misc/SoundEffect.cpp | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/openvic-simulation/misc/SoundEffect.cpp (limited to 'src/openvic-simulation/misc/SoundEffect.cpp') 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 -- cgit v1.2.3-56-ga3b1