Crossfire Server, Trunk
SoundFiles.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "SoundFiles.h"
14 #include "../CRESettings.h"
15 #include "SoundFile.h"
16 #include <QDir>
17 #include <QFile>
18 #include <QTextStream>
19 #include <QDebug>
20 #include "global.h"
21 
22 SoundFiles::SoundFiles(AssetWrapper *parent) : AssetWrapper(parent, "SoundFiles") {
23  setProperty(tipProperty, tr("Display all sound files."));
24  refreshSounds();
25 }
26 
29  QString path(settings.soundsDirectory());
30  if (path.isEmpty()) {
31  return;
32  }
33  QDir dir(path);
34  if (!dir.exists()) {
35  return;
36  }
37 
39 
40  for (auto sound : mySounds) {
41  delete sound;
42  }
43  mySounds.clear();
44 
45  std::map<std::string, std::string> soundConf;
46  QFile file(dir.filePath("sounds.conf"));
47  if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
48  QTextStream in(&file);
49  while (!in.atEnd()) {
50  QString line = in.readLine();
51  if (line.isEmpty() || line.startsWith('#')) {
52  continue;
53  }
54  auto split = line.split(':');
55  if (split.length() != 3) {
56  continue;
57  }
58  soundConf[split[0].toStdString()] = split[2].toStdString();
59  }
60  } else {
61  qDebug() << tr("Unable to open sound configuration file %1/sounds.conf").arg(path);
62  }
63 
64  auto files = dir.entryList(QDir::Files, QDir::SortFlag::IgnoreCase | QDir::Name);
65  for (auto file : files) {
66  if (file.endsWith(".ogg") || file.endsWith(".wav")) {
67  std::vector<std::string> events;
68  for (const auto &sc : soundConf) {
69  if (sc.second == file.toStdString()) {
70  events.push_back(sc.first);
71  }
72  }
73  mySounds.push_back(new SoundFile(events, this, file));
74  continue;
75  }
76  if (file.endsWith(".LICENSE")) {
77  auto name = file.left(file.length() - 8);
78  auto it = std::find_if(mySounds.cbegin(), mySounds.cend(), [&name] (const auto &sound) { return sound->displayName() == name; });
79  if (it != mySounds.cend()) {
80  auto br = bufferreader_init_from_file(nullptr, dir.filePath(file).toStdString().data(), "Failed to open LICENSE file %s: %s", llevError);
81  if (br) {
82  LicenseManager::parseLicenseFile(br, "", (*it)->license());
84  }
85  }
86  continue;
87  }
88  }
89 
91 }
92 
94  return mySounds[index];
95 }
96 
98  for (size_t i = 0; i < mySounds.size(); ++i) {
99  if (mySounds[i] == child) {
100  return static_cast<int>(i);
101  }
102  }
103  return -1;
104 }
105 
106 QString SoundFiles::licenseInformation() const {
107  if (mySounds.empty()) {
108  return tr("No sound file found");
109  }
110  size_t with = 0;
111  for (const auto &sound : mySounds) {
112  if (!sound->license().empty()) {
113  ++with;
114  }
115  }
116  size_t percent = 100 * with / mySounds.size();
117  if (percent == 100 && with < mySounds.size()) {
118  percent = 99;
119  }
120  return tr("%1 sound files with license information on %2 (%3%)").arg(with).arg(mySounds.size()).arg(percent);
121 }
global.h
line
Install Bug reporting Credits so make sure you have version or later There are files involved in the automatic convert convertall and filelist py GuildList has the list of guilds for the server GuildLocations is what is used by the install script for setting up the maps It has columns in the first is the name of the no spaces The second is the region of the the third is the destination folder for the the fourth is the exit the fifth and sixth are the x and y coords within the exit the seventh eighth and ninth are the exit location for the storage hall If field seven is then it uses the same exit map as for the guild hall itself filelist py has a list of which files to process for each guild hall convert py takes all the files in filelist py and customises them to the specific guild then outputs them into a in the same order that they are listed in GuildLocations convertall py reads the lines from GuildLocations and runs line by line
Definition: README.txt:12
settings
struct Settings settings
Definition: init.cpp:139
Files
Install Bug reporting Credits but rather whatever guild name you are using *With the current map and server there are three they and GreenGoblin *Whatever name you give the folder should but it will still use GUILD_TEMPLATE *You can change what guild it uses by editing the map files Modify Map Files
Definition: README.txt:17
AssetWrapper::tipProperty
static const char * tipProperty
Definition: AssetWrapper.h:34
llevError
@ llevError
Definition: logger.h:11
it
**Media tags please refer to the protocol file in doc Developers protocol Quick for your pleasure an example[/b][i] This is an old full of dirt and partially destroyed[hand] My dear as you two years i had to leave quickly Words have come to me of powerful magic scrolls discovered in an old temple by my uncle I have moved to study them I not forgot your knowledge in ancient languages I need your help for[print][b] Some parts of document are to damaged to be readable[/b][arcane] Arghis[color=Red] k h[color=dark slate blue] ark[color=#004000] fido[/color][hand] please come as fast as possible my friend[print][b] The bottom of letter seems deliberatly shredded What is it
Definition: media-tags.txt:28
SoundFiles::child
virtual AssetWrapper * child(int index) override
Definition: SoundFiles.cpp:93
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:55
arrest.Name
Name
Definition: arrest.py:40
SoundFiles.h
mad_mage_user.file
file
Definition: mad_mage_user.py:15
AssetWrapper::BeforeLayoutChange
@ BeforeLayoutChange
Definition: AssetWrapper.h:33
bufferreader_destroy
void bufferreader_destroy(BufferReader *br)
Definition: bufferreader.cpp:40
SoundFile.h
AssetWrapper
Definition: AssetWrapper.h:25
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
bufferreader_init_from_file
BufferReader * bufferreader_init_from_file(BufferReader *br, const char *filepath, const char *failureMessage, LogLevel failureLevel)
Definition: bufferreader.cpp:65
sc
Player Stats effect how well a character can survie and interact inside the crossfire world This section discusses the various what they and how they effect the player s actions Also in this section are the stat modifiers that specific classes professions bring Player and sps the current and maximum the Current and Maximum The Current Sp can go somewhat negative When Sp is negative not all spells can be and a more negative Sp makes spell casting less likey to succeed can affect Damage and how the characters as well as how often the character can attack this affects the prices when buying and selling items if this drops the player will start losing hit points wd Cleric or Dwarf sm Elf wd Fireborn sc
Definition: stats.txt:96
SoundFiles::licenseInformation
QString licenseInformation
Definition: SoundFiles.h:23
SoundFiles::SoundFiles
SoundFiles(AssetWrapper *parent)
Definition: SoundFiles.cpp:22
CRESettings
Definition: CRESettings.h:21
path
pluglist shows those as well as a short text describing each the list will simply appear empty The keyword for the Python plugin is Python plugout< keyword > Unloads a given identified by its _keyword_ So if you want to unload the Python you need to do plugout Python plugin< libname > Loads a given whose _filename_ is libname So in the case of you d have to do a plugin cfpython so Note that all filenames are relative to the default plugin path(SHARE/plugins). Console messages. ----------------- When Crossfire starts
SoundFiles::refreshSounds
void refreshSounds()
Definition: SoundFiles.cpp:27
SoundFiles::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition: SoundFiles.cpp:97
SoundFiles::mySounds
std::vector< SoundFile * > mySounds
Definition: SoundFiles.h:38
npc_dialog.index
int index
Definition: npc_dialog.py:102
split
static std::vector< std::string > split(const std::string &field, const std::string &by)
Definition: mapper.cpp:2608
LicenseManager::parseLicenseFile
static void parseLicenseFile(BufferReader *reader, const char *filename, std::vector< LicenseItem > &items)
Definition: LicenseManager.cpp:57
events
static QHash< QString, archetype * > events
Definition: CREMapPanel.cpp:24
SoundFile
Definition: SoundFile.h:19
AssetWrapper::AfterLayoutChange
@ AfterLayoutChange
Definition: AssetWrapper.h:33