JustAnotherDnDGame 0.1.0
Jeu de rôle tactique au d20, vue de dessus, en C++/Qt
Loading...
Searching...
No Matches
SoundCatalog.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Valentin Eloy
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#pragma once
5
6#include <filesystem>
7#include <map>
8#include <optional>
9#include <string>
10#include <string_view>
11#include <vector>
12
14
19
20namespace hmi {
21
33
34// Le resultat contient un SoundCatalog par valeur : il ne peut etre defini qu'apres la classe.
35struct SoundCatalogResult;
36
50public:
52 static constexpr int FORMAT_VERSION = 1;
53
59 [[nodiscard]] static SoundCatalogResult loadFromString(std::string_view json);
60
69 [[nodiscard]] static SoundCatalogResult loadFromFile(const std::filesystem::path& path);
70
71private:
79 [[nodiscard]] static SoundCatalogResult fromDocument(const core::JsonDocument& document);
80
81public:
89 [[nodiscard]] std::optional<std::string> resolve(std::string_view eventId) const;
90
92 [[nodiscard]] std::vector<std::string> eventIds() const;
93
95 void assign(const std::string& eventId, std::string file);
96
97private:
98 // std::map (et non unordered_map) : ordre de parcours deterministe, comme hmi::SkinCatalog.
99 std::map<std::string, std::string, std::less<>> _sounds;
100};
101
109 std::optional<SoundCatalog> catalog;
110 std::string error;
112
114 [[nodiscard]] bool ok() const noexcept {
115 return catalog.has_value();
116 }
117};
118
119} // namespace hmi
Brique de lecture JSON partagée par tous les catalogues (EX-CNT-012).
Catalogue des sons : nom d'événement → fichier (relatif à Source/Elements/Audio/).
Definition SoundCatalog.h:49
static constexpr int FORMAT_VERSION
Version du format écrite dans le fichier, et plus élevée qui soit lue.
Definition SoundCatalog.h:52
static SoundCatalogResult loadFromFile(const std::filesystem::path &path)
Lit un catalogue depuis un fichier.
Definition SoundCatalog.cpp:81
std::optional< std::string > resolve(std::string_view eventId) const
Résout le fichier assigné à un événement.
Definition SoundCatalog.cpp:85
std::vector< std::string > eventIds() const
Definition SoundCatalog.cpp:93
static SoundCatalogResult fromDocument(const core::JsonDocument &document)
Construit le catalogue depuis l'enveloppe déjà lue par core::readJsonObject.
Definition SoundCatalog.cpp:55
void assign(const std::string &eventId, std::string file)
Assigne un fichier à un événement, en écrasant une assignation existante.
Definition SoundCatalog.cpp:102
std::map< std::string, std::string, std::less<> > _sounds
Definition SoundCatalog.h:99
static SoundCatalogResult loadFromString(std::string_view json)
Lit un catalogue depuis une chaîne JSON.
Definition SoundCatalog.cpp:51
Definition AudioEngine.cpp:15
SoundCatalogError
Catégorie d'échec de lecture d'un sounds.json (même patron que hmi::SkinCatalogError/hmi::AnimationCa...
Definition SoundCatalog.h:26
@ UnsupportedVersion
Numéro de version supérieur à SoundCatalog::FORMAT_VERSION.
Definition SoundCatalog.h:30
@ FileNotFound
Fichier absent. Cas légitime (catalogue vide), pas une anomalie.
Definition SoundCatalog.h:28
@ None
Pas d'erreur.
Definition SoundCatalog.h:27
@ MalformedStructure
Structure inattendue (« sons » absent, entrée invalide…).
Definition SoundCatalog.h:31
@ ParseError
JSON malformé, ou racine qui n'est pas un objet.
Definition SoundCatalog.h:29
Résultat de la lecture de l'enveloppe commune d'un document JSON.
Definition JsonDocument.h:53
Résultat d'une lecture de catalogue : soit un SoundCatalog, soit une erreur décrite.
Definition SoundCatalog.h:108
std::optional< SoundCatalog > catalog
Definition SoundCatalog.h:109
std::string error
Definition SoundCatalog.h:110
bool ok() const noexcept
Definition SoundCatalog.h:114
SoundCatalogError errorCode
Definition SoundCatalog.h:111