1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3// 2018 Ingo Ruhnke <grumbel@gmail.com>
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18#include "object/music_object.hpp"
19
20#include "audio/sound_manager.hpp"
21#include "object/player.hpp"
22#include "util/reader_mapping.hpp"
23#include "util/writer.hpp"
24
25MusicObject::MusicObject() :
26 m_currentmusic(LEVEL_MUSIC),
27 m_music()
28{
29}
30
31MusicObject::MusicObject(const ReaderMapping& mapping) :
32 m_currentmusic(LEVEL_MUSIC),
33 m_music()
34{
35 mapping.get("file", m_music);
36}
37
38void
39MusicObject::update(float dt_sec)
40{
41}
42
43void
44MusicObject::draw(DrawingContext& context)
45{
46}
47
48void
49MusicObject::play_music(MusicType type)
50{
51 m_currentmusic = type;
52 switch (m_currentmusic)
53 {
54 case LEVEL_MUSIC:
55 SoundManager::current()->play_music(m_music);
56 break;
57
58 case HERRING_MUSIC:
59 SoundManager::current()->play_music("music/misc/invincible.ogg");
60 break;
61
62 case HERRING_WARNING_MUSIC:
63 SoundManager::current()->stop_music(TUX_INVINCIBLE_TIME_WARNING);
64 break;
65
66 default:
67 SoundManager::current()->play_music("");
68 break;
69 }
70}
71
72void
73MusicObject::resume_music()
74{
75 if (SoundManager::current()->get_current_music() == m_music)
76 {
77 SoundManager::current()->resume_music(3.2f);
78 }
79 else
80 {
81 SoundManager::current()->stop_music();
82 SoundManager::current()->play_music(m_music, true);
83 }
84}
85
86MusicType
87MusicObject::get_music_type() const
88{
89 return m_currentmusic;
90}
91
92void
93MusicObject::set_music(const std::string& music)
94{
95 m_music = music;
96}
97
98std::string
99MusicObject::get_music() const
100{
101 return m_music;
102}
103
104ObjectSettings
105MusicObject::get_settings()
106{
107 auto settings = GameObject::get_settings();
108
109 settings.add_music(_("File"), &m_music, "file");
110
111 return settings;
112}
113
114/* EOF */
115