1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2013-2019 The ManaPlus Developers |
4 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
5 |
|
|
* |
6 |
|
|
* This file is part of The ManaPlus Client. |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
11 |
|
|
* any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "resources/db/sounddb.h" |
23 |
|
|
|
24 |
|
|
#include "configuration.h" |
25 |
|
|
#include "logger.h" |
26 |
|
|
#include "notifymanager.h" |
27 |
|
|
|
28 |
|
|
#include "enums/resources/notifytypes.h" |
29 |
|
|
|
30 |
|
|
#include "resources/beingcommon.h" |
31 |
|
|
|
32 |
|
|
#include "debug.h" |
33 |
|
|
|
34 |
|
|
namespace |
35 |
|
|
{ |
36 |
|
1 |
std::string mDefault; |
37 |
|
1 |
STD_VECTOR<std::string> mSounds; |
38 |
|
|
} // namespace |
39 |
|
|
|
40 |
|
|
void SoundDB::load() |
41 |
|
|
{ |
42 |
|
|
unload(); |
43 |
|
|
logger->log1("Initializing sound database..."); |
44 |
|
|
loadXmlFile(paths.getStringValue("soundsFile"), SkipError_false); |
45 |
|
|
loadXmlFile(paths.getStringValue("soundsPatchFile"), SkipError_true); |
46 |
|
|
loadXmlDir("soundsPatchDir", loadXmlFile) |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
void SoundDB::loadXmlFile(const std::string &fileName, |
50 |
|
|
const SkipError skipError) |
51 |
|
|
{ |
52 |
|
|
XML::Document *doc = new XML::Document(fileName, |
53 |
|
|
UseVirtFs_true, |
54 |
|
|
skipError); |
55 |
|
|
XmlNodeConstPtrConst root = doc->rootNode(); |
56 |
|
|
|
57 |
|
|
if ((root == nullptr) || !xmlNameEqual(root, "sounds")) |
58 |
|
|
{ |
59 |
|
|
delete doc; |
60 |
|
|
return; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
for_each_xml_child_node(node, root) |
64 |
|
|
{ |
65 |
|
|
if (xmlNameEqual(node, "include")) |
66 |
|
|
{ |
67 |
|
|
const std::string name = XML::getProperty(node, "name", ""); |
68 |
|
|
if (!name.empty()) |
69 |
|
|
loadXmlFile(name, skipError); |
70 |
|
|
continue; |
71 |
|
|
} |
72 |
|
|
else if (xmlNameEqual(node, "sound")) |
73 |
|
|
{ |
74 |
|
|
const std::string name = XML::getProperty(node, "name", ""); |
75 |
|
|
const int id = NotifyManager::getIndexBySound(name); |
76 |
|
|
if (id != 0) |
77 |
|
|
{ |
78 |
|
|
const std::string value = XML::getProperty(node, "value", ""); |
79 |
|
|
mSounds[id] = value; |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
delete doc; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
215 |
void SoundDB::unload() |
88 |
|
|
{ |
89 |
|
215 |
logger->log1("Unloading sound database..."); |
90 |
|
215 |
mSounds.resize(NotifyTypes::TYPE_END); |
91 |
✓✓ |
47945 |
for (int f = 0; f < NotifyTypes::TYPE_END; f ++) |
92 |
|
143190 |
mSounds[f].clear(); |
93 |
|
215 |
} |
94 |
|
|
|
95 |
|
|
std::string &SoundDB::getSound(const int id) |
96 |
|
|
{ |
97 |
|
|
if (id < 0 || id >= NotifyTypes::TYPE_END) |
98 |
|
|
return mDefault; |
99 |
|
|
return mSounds[id]; |
100 |
✓✗✓✗
|
3 |
} |