refactor jail_audio: namespace Ja, enum class, tipus sense prefix JA_
This commit is contained in:
+31
-37
@@ -20,7 +20,7 @@
|
||||
// clang-format on
|
||||
|
||||
#include "core/audio/audio_adapter.hpp" // Para AudioResource::getMusic/getSound
|
||||
#include "core/audio/jail_audio.hpp" // Para JA_*
|
||||
#include "core/audio/jail_audio.hpp" // Para Ja namespace
|
||||
#include "game/options.hpp" // Para Options::audio
|
||||
|
||||
// Singleton
|
||||
@@ -43,15 +43,15 @@ Audio::Audio() { initSDLAudio(); }
|
||||
|
||||
// Destructor
|
||||
Audio::~Audio() {
|
||||
JA_Quit();
|
||||
Ja::quit();
|
||||
}
|
||||
|
||||
// Método principal
|
||||
void Audio::update() {
|
||||
JA_Update();
|
||||
Ja::update();
|
||||
|
||||
// Sincronizar estado: detectar cuando la música se para (ej. fade-out completado)
|
||||
if ((instance != nullptr) && instance->music_.state == MusicState::PLAYING && JA_GetMusicState() != JA_MUSIC_PLAYING) {
|
||||
if (instance != nullptr && instance->music_.state == MusicState::PLAYING && Ja::getMusicState() != Ja::MusicState::PLAYING) {
|
||||
instance->music_.state = MusicState::STOPPED;
|
||||
}
|
||||
}
|
||||
@@ -65,22 +65,18 @@ void Audio::playMusic(const std::string& name, const int loop, const int crossfa
|
||||
return;
|
||||
}
|
||||
|
||||
if (!music_enabled_) {
|
||||
return;
|
||||
}
|
||||
if (!music_enabled_) { return; }
|
||||
|
||||
auto* resource = AudioResource::getMusic(name);
|
||||
if (resource == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (resource == nullptr) { return; }
|
||||
|
||||
if (crossfade_ms > 0 && music_.state == MusicState::PLAYING) {
|
||||
JA_CrossfadeMusic(resource, crossfade_ms, loop);
|
||||
Ja::crossfadeMusic(resource, crossfade_ms, loop);
|
||||
} else {
|
||||
if (music_.state == MusicState::PLAYING) {
|
||||
JA_StopMusic();
|
||||
Ja::stopMusic();
|
||||
}
|
||||
JA_PlayMusic(resource, loop);
|
||||
Ja::playMusic(resource, loop);
|
||||
}
|
||||
|
||||
music_.name = name;
|
||||
@@ -89,18 +85,16 @@ void Audio::playMusic(const std::string& name, const int loop, const int crossfa
|
||||
}
|
||||
|
||||
// Reproduce la música por puntero (con crossfade opcional)
|
||||
void Audio::playMusic(JA_Music_t* music, const int loop, const int crossfade_ms) {
|
||||
if (!music_enabled_ || music == nullptr) {
|
||||
return;
|
||||
}
|
||||
void Audio::playMusic(Ja::Music* music, const int loop, const int crossfade_ms) {
|
||||
if (!music_enabled_ || music == nullptr) { return; }
|
||||
|
||||
if (crossfade_ms > 0 && music_.state == MusicState::PLAYING) {
|
||||
JA_CrossfadeMusic(music, crossfade_ms, loop);
|
||||
Ja::crossfadeMusic(music, crossfade_ms, loop);
|
||||
} else {
|
||||
if (music_.state == MusicState::PLAYING) {
|
||||
JA_StopMusic();
|
||||
Ja::stopMusic();
|
||||
}
|
||||
JA_PlayMusic(music, loop);
|
||||
Ja::playMusic(music, loop);
|
||||
}
|
||||
|
||||
music_.name.clear(); // nom desconegut quan es passa per punter
|
||||
@@ -111,7 +105,7 @@ void Audio::playMusic(JA_Music_t* music, const int loop, const int crossfade_ms)
|
||||
// Pausa la música
|
||||
void Audio::pauseMusic() {
|
||||
if (music_enabled_ && music_.state == MusicState::PLAYING) {
|
||||
JA_PauseMusic();
|
||||
Ja::pauseMusic();
|
||||
music_.state = MusicState::PAUSED;
|
||||
}
|
||||
}
|
||||
@@ -119,7 +113,7 @@ void Audio::pauseMusic() {
|
||||
// Continua la música pausada
|
||||
void Audio::resumeMusic() {
|
||||
if (music_enabled_ && music_.state == MusicState::PAUSED) {
|
||||
JA_ResumeMusic();
|
||||
Ja::resumeMusic();
|
||||
music_.state = MusicState::PLAYING;
|
||||
}
|
||||
}
|
||||
@@ -127,7 +121,7 @@ void Audio::resumeMusic() {
|
||||
// Detiene la música
|
||||
void Audio::stopMusic() {
|
||||
if (music_enabled_) {
|
||||
JA_StopMusic();
|
||||
Ja::stopMusic();
|
||||
music_.state = MusicState::STOPPED;
|
||||
}
|
||||
}
|
||||
@@ -135,42 +129,42 @@ void Audio::stopMusic() {
|
||||
// Reproduce un sonido por nombre
|
||||
void Audio::playSound(const std::string& name, Group group) const {
|
||||
if (sound_enabled_) {
|
||||
JA_PlaySound(AudioResource::getSound(name), 0, static_cast<int>(group));
|
||||
Ja::playSound(AudioResource::getSound(name), 0, static_cast<int>(group));
|
||||
}
|
||||
}
|
||||
|
||||
// Reproduce un sonido por puntero directo
|
||||
void Audio::playSound(JA_Sound_t* sound, Group group) const {
|
||||
void Audio::playSound(Ja::Sound* sound, Group group) const {
|
||||
if (sound_enabled_ && sound != nullptr) {
|
||||
JA_PlaySound(sound, 0, static_cast<int>(group));
|
||||
Ja::playSound(sound, 0, static_cast<int>(group));
|
||||
}
|
||||
}
|
||||
|
||||
// Detiene todos los sonidos
|
||||
void Audio::stopAllSounds() const {
|
||||
if (sound_enabled_) {
|
||||
JA_StopChannel(-1);
|
||||
Ja::stopChannel(-1);
|
||||
}
|
||||
}
|
||||
|
||||
// Realiza un fundido de salida de la música
|
||||
void Audio::fadeOutMusic(int milliseconds) const {
|
||||
if (music_enabled_ && getRealMusicState() == MusicState::PLAYING) {
|
||||
JA_FadeOutMusic(milliseconds);
|
||||
Ja::fadeOutMusic(milliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
// Consulta directamente el estado real de la música en jailaudio
|
||||
auto Audio::getRealMusicState() -> MusicState {
|
||||
JA_Music_state ja_state = JA_GetMusicState();
|
||||
Ja::MusicState ja_state = Ja::getMusicState();
|
||||
switch (ja_state) {
|
||||
case JA_MUSIC_PLAYING:
|
||||
case Ja::MusicState::PLAYING:
|
||||
return MusicState::PLAYING;
|
||||
case JA_MUSIC_PAUSED:
|
||||
case Ja::MusicState::PAUSED:
|
||||
return MusicState::PAUSED;
|
||||
case JA_MUSIC_STOPPED:
|
||||
case JA_MUSIC_INVALID:
|
||||
case JA_MUSIC_DISABLED:
|
||||
case Ja::MusicState::STOPPED:
|
||||
case Ja::MusicState::INVALID:
|
||||
case Ja::MusicState::DISABLED:
|
||||
default:
|
||||
return MusicState::STOPPED;
|
||||
}
|
||||
@@ -181,7 +175,7 @@ void Audio::setSoundVolume(float sound_volume, Group group) const {
|
||||
if (sound_enabled_) {
|
||||
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
const float CONVERTED_VOLUME = sound_volume * Options::audio.volume;
|
||||
JA_SetSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||
Ja::setSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +184,7 @@ void Audio::setMusicVolume(float music_volume) const {
|
||||
if (music_enabled_) {
|
||||
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
const float CONVERTED_VOLUME = music_volume * Options::audio.volume;
|
||||
JA_SetMusicVolume(CONVERTED_VOLUME);
|
||||
Ja::setMusicVolume(CONVERTED_VOLUME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +206,7 @@ void Audio::initSDLAudio() {
|
||||
if (!SDL_Init(SDL_INIT_AUDIO)) {
|
||||
std::cout << "SDL_AUDIO could not initialize! SDL Error: " << SDL_GetError() << '\n';
|
||||
} else {
|
||||
JA_Init(FREQUENCY, SDL_AUDIO_S16LE, 2);
|
||||
Ja::init(FREQUENCY, SDL_AUDIO_S16LE, 2);
|
||||
enable(Options::audio.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-10
@@ -1,8 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath> // Para lround
|
||||
#include <cmath> // Para std::lround
|
||||
#include <cstdint> // Para int8_t, uint8_t
|
||||
#include <string> // Para string
|
||||
#include <utility> // Para move
|
||||
|
||||
namespace Ja {
|
||||
struct Music;
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
// --- Clase Audio: gestor de audio (singleton) ---
|
||||
// Implementació canònica, byte-idèntica entre projectes.
|
||||
@@ -41,17 +47,17 @@ class Audio {
|
||||
static void update(); // Actualización del sistema de audio
|
||||
|
||||
// --- Control de música ---
|
||||
void playMusic(const std::string& name, int loop = -1, int crossfade_ms = 0); // Reproducir música por nombre (con crossfade opcional)
|
||||
void playMusic(struct JA_Music_t* music, int loop = -1, int crossfade_ms = 0); // Reproducir música por puntero (con crossfade opcional)
|
||||
void pauseMusic(); // Pausar reproducción de música
|
||||
void resumeMusic(); // Continua la música pausada
|
||||
void stopMusic(); // Detener completamente la música
|
||||
void fadeOutMusic(int milliseconds) const; // Fundido de salida de la música
|
||||
void playMusic(const std::string& name, int loop = -1, int crossfade_ms = 0); // Reproducir música por nombre (con crossfade opcional)
|
||||
void playMusic(Ja::Music* music, int loop = -1, int crossfade_ms = 0); // Reproducir música por puntero (con crossfade opcional)
|
||||
void pauseMusic(); // Pausar reproducción de música
|
||||
void resumeMusic(); // Continua la música pausada
|
||||
void stopMusic(); // Detener completamente la música
|
||||
void fadeOutMusic(int milliseconds) const; // Fundido de salida de la música
|
||||
|
||||
// --- Control de sonidos ---
|
||||
void playSound(const std::string& name, Group group = Group::GAME) const; // Reproducir sonido puntual por nombre
|
||||
void playSound(struct JA_Sound_t* sound, Group group = Group::GAME) const; // Reproducir sonido puntual por puntero
|
||||
void stopAllSounds() const; // Detener todos los sonidos
|
||||
void playSound(const std::string& name, Group group = Group::GAME) const; // Reproducir sonido puntual por nombre
|
||||
void playSound(Ja::Sound* sound, Group group = Group::GAME) const; // Reproducir sonido puntual por puntero
|
||||
void stopAllSounds() const; // Detener todos los sonidos
|
||||
|
||||
// --- Control de volumen (API interna: float 0.0..1.0) ---
|
||||
void setSoundVolume(float volume, Group group = Group::ALL) const; // Ajustar volumen de efectos
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include "core/resources/resource.h"
|
||||
|
||||
namespace AudioResource {
|
||||
auto getMusic(const std::string& name) -> JA_Music_t* {
|
||||
auto getMusic(const std::string& name) -> Ja::Music* {
|
||||
return Resource::get()->getMusic(name);
|
||||
}
|
||||
|
||||
auto getSound(const std::string& name) -> JA_Sound_t* {
|
||||
auto getSound(const std::string& name) -> Ja::Sound* {
|
||||
return Resource::get()->getSound(name);
|
||||
}
|
||||
} // namespace AudioResource
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// --- Audio Resource Adapter ---
|
||||
// Aquest fitxer exposa una interfície comuna a Audio per obtenir JA_Music_t* /
|
||||
// JA_Sound_t* per nom. Cada projecte la implementa en audio_adapter.cpp
|
||||
// Aquest fitxer exposa una interfície comuna a Audio per obtenir Ja::Music* /
|
||||
// Ja::Sound* per nom. Cada projecte la implementa en audio_adapter.cpp
|
||||
// delegant al seu singleton de recursos (Resource::get(), Resource::Cache::get(),
|
||||
// etc.). Això permet que audio.hpp/audio.cpp siguin idèntics entre projectes.
|
||||
|
||||
#include <string> // Para string
|
||||
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
namespace Ja {
|
||||
struct Music;
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
namespace AudioResource {
|
||||
auto getMusic(const std::string& name) -> JA_Music_t*;
|
||||
auto getSound(const std::string& name) -> JA_Sound_t*;
|
||||
auto getMusic(const std::string& name) -> Ja::Music*;
|
||||
auto getSound(const std::string& name) -> Ja::Sound*;
|
||||
} // namespace AudioResource
|
||||
|
||||
+614
-719
File diff suppressed because it is too large
Load Diff
@@ -64,12 +64,12 @@ Resource::~Resource() {
|
||||
textures_.clear();
|
||||
|
||||
for (auto &[name, s] : sounds_) {
|
||||
JA_DeleteSound(s);
|
||||
Ja::deleteSound(s);
|
||||
}
|
||||
sounds_.clear();
|
||||
|
||||
for (auto &[name, m] : musics_) {
|
||||
JA_DeleteMusic(m);
|
||||
Ja::deleteMusic(m);
|
||||
}
|
||||
musics_.clear();
|
||||
}
|
||||
@@ -103,14 +103,14 @@ void Resource::preloadResources() {
|
||||
break;
|
||||
}
|
||||
case Asset::Type::SOUND: {
|
||||
JA_Sound_t *s = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
Ja::Sound *s = Ja::loadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
if (s != nullptr) {
|
||||
sounds_[BASE_NAME] = s;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Asset::Type::MUSIC: {
|
||||
JA_Music_t *m = JA_LoadMusic(bytes.data(), (Uint32)bytes.size());
|
||||
Ja::Music *m = Ja::loadMusic(bytes.data(), (Uint32)bytes.size());
|
||||
if (m != nullptr) {
|
||||
musics_[BASE_NAME] = m;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ void Resource::preloadFonts() {
|
||||
// Pass 2b: construye los Menu (dependen de Text+sonidos cargados antes)
|
||||
//
|
||||
// NOTA: Menu::loadFromBytes aún llama internamente a asset->get() y Text/
|
||||
// JA_LoadSound por path. Funciona en modo fallback; en pack estricto requiere
|
||||
// Ja::loadSound por path. Funciona en modo fallback; en pack estricto requiere
|
||||
// que Menu se adapte a cargar desde ResourceHelper. Migración pendiente.
|
||||
void Resource::preloadMenus() {
|
||||
const auto &items = Asset::get()->getAll();
|
||||
@@ -218,7 +218,7 @@ auto Resource::getTexture(const std::string &name) -> Texture * {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
auto Resource::getSound(const std::string &name) -> JA_Sound_t * {
|
||||
auto Resource::getSound(const std::string &name) -> Ja::Sound * {
|
||||
auto it = sounds_.find(name);
|
||||
if (it == sounds_.end()) {
|
||||
std::cerr << "Resource::getSound: missing " << name << '\n';
|
||||
@@ -227,7 +227,7 @@ auto Resource::getSound(const std::string &name) -> JA_Sound_t * {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
auto Resource::getMusic(const std::string &name) -> JA_Music_t * {
|
||||
auto Resource::getMusic(const std::string &name) -> Ja::Music * {
|
||||
auto it = musics_.find(name);
|
||||
if (it == musics_.end()) {
|
||||
std::cerr << "Resource::getMusic: missing " << name << '\n';
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
class Menu;
|
||||
class Text;
|
||||
class Texture;
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
namespace Ja {
|
||||
struct Music;
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
// Precarga y posee todos los recursos del juego durante toda la vida de la app.
|
||||
// Singleton inicializado desde Director; las escenas consultan handles via get*().
|
||||
@@ -22,8 +24,8 @@ class Resource {
|
||||
static auto get() -> Resource *;
|
||||
|
||||
auto getTexture(const std::string &name) -> Texture *;
|
||||
auto getSound(const std::string &name) -> JA_Sound_t *;
|
||||
auto getMusic(const std::string &name) -> JA_Music_t *;
|
||||
auto getSound(const std::string &name) -> Ja::Sound *;
|
||||
auto getMusic(const std::string &name) -> Ja::Music *;
|
||||
auto getAnimationLines(const std::string &name) -> std::vector<std::string> &;
|
||||
auto getText(const std::string &name) -> Text *; // name sin extensión: "smb2", "nokia2", ...
|
||||
auto getMenu(const std::string &name) -> Menu *; // name sin extensión: "title", "options", ...
|
||||
@@ -44,8 +46,8 @@ class Resource {
|
||||
SDL_Renderer *renderer_;
|
||||
|
||||
std::unordered_map<std::string, Texture *> textures_;
|
||||
std::unordered_map<std::string, JA_Sound_t *> sounds_;
|
||||
std::unordered_map<std::string, JA_Music_t *> musics_;
|
||||
std::unordered_map<std::string, Ja::Sound *> sounds_;
|
||||
std::unordered_map<std::string, Ja::Music *> musics_;
|
||||
std::unordered_map<std::string, std::vector<std::string>> animation_lines_;
|
||||
std::unordered_map<std::string, Text *> texts_;
|
||||
std::unordered_map<std::string, Menu *> menus_;
|
||||
|
||||
@@ -168,7 +168,7 @@ Director::~Director() {
|
||||
Options::saveToFile();
|
||||
|
||||
// Libera las secciones primero: sus destructores tocan audio/render SDL
|
||||
// (p.ej. Intro::~Intro llama a JA_DeleteMusic) y deben ejecutarse antes
|
||||
// (p.ej. Intro::~Intro llama a Ja::deleteMusic) y deben ejecutarse antes
|
||||
// de SDL_Quit().
|
||||
logo_.reset();
|
||||
intro_.reset();
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
#include "game/entities/player.h" // for Player
|
||||
#include "game/options.hpp" // for Options
|
||||
#include "game/ui/menu.h" // for Menu
|
||||
struct JA_Sound_t;
|
||||
namespace Ja {
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
namespace {
|
||||
// Constantes geométricas y temporales compartidas por los helpers de initEnemyFormations
|
||||
@@ -1521,7 +1523,7 @@ void Game::updateDeath() {
|
||||
// Hace sonar aleatoriamente uno de los 4 sonidos de burbujas
|
||||
if (!demo_.enabled) {
|
||||
const Uint8 INDEX = rand() % 4;
|
||||
JA_Sound_t *sound[4] = {bubble1_sound_, bubble2_sound_, bubble3_sound_, bubble4_sound_};
|
||||
Ja::Sound *sound[4] = {bubble1_sound_, bubble2_sound_, bubble3_sound_, bubble4_sound_};
|
||||
Audio::get()->playSound(sound[INDEX]);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-18
@@ -18,8 +18,10 @@ class SmartSprite;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
namespace Ja {
|
||||
struct Music;
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
// Clase Game
|
||||
class Game {
|
||||
@@ -315,23 +317,23 @@ class Game {
|
||||
Sprite *game_over_sprite_; // Sprite para dibujar los graficos del game over
|
||||
Sprite *game_over_end_sprite_; // Sprite para dibujar los graficos del game over de acabar el juego
|
||||
|
||||
JA_Sound_t *balloon_sound_; // Sonido para la explosión del globo
|
||||
JA_Sound_t *bullet_sound_; // Sonido para los disparos
|
||||
JA_Sound_t *player_collision_sound_; // Sonido para la colisión del jugador con un enemigo
|
||||
JA_Sound_t *hi_score_sound_; // Sonido para cuando se alcanza la máxima puntuación
|
||||
JA_Sound_t *item_drop_sound_; // Sonido para cuando se genera un item
|
||||
JA_Sound_t *item_pick_up_sound_; // Sonido para cuando se recoge un item
|
||||
JA_Sound_t *coffee_out_sound_; // Sonido para cuando el jugador pierde el café al recibir un impacto
|
||||
JA_Sound_t *stage_change_sound_; // Sonido para cuando se cambia de fase
|
||||
JA_Sound_t *bubble1_sound_; // Sonido para cuando el jugador muere
|
||||
JA_Sound_t *bubble2_sound_; // Sonido para cuando el jugador muere
|
||||
JA_Sound_t *bubble3_sound_; // Sonido para cuando el jugador muere
|
||||
JA_Sound_t *bubble4_sound_; // Sonido para cuando el jugador muere
|
||||
JA_Sound_t *clock_sound_; // Sonido para cuando se detiene el tiempo con el item reloj
|
||||
JA_Sound_t *power_ball_sound_; // Sonido para cuando se explota una Power Ball
|
||||
JA_Sound_t *coffee_machine_sound_; // Sonido para cuando la máquina de café toca el suelo
|
||||
Ja::Sound *balloon_sound_; // Sonido para la explosión del globo
|
||||
Ja::Sound *bullet_sound_; // Sonido para los disparos
|
||||
Ja::Sound *player_collision_sound_; // Sonido para la colisión del jugador con un enemigo
|
||||
Ja::Sound *hi_score_sound_; // Sonido para cuando se alcanza la máxima puntuación
|
||||
Ja::Sound *item_drop_sound_; // Sonido para cuando se genera un item
|
||||
Ja::Sound *item_pick_up_sound_; // Sonido para cuando se recoge un item
|
||||
Ja::Sound *coffee_out_sound_; // Sonido para cuando el jugador pierde el café al recibir un impacto
|
||||
Ja::Sound *stage_change_sound_; // Sonido para cuando se cambia de fase
|
||||
Ja::Sound *bubble1_sound_; // Sonido para cuando el jugador muere
|
||||
Ja::Sound *bubble2_sound_; // Sonido para cuando el jugador muere
|
||||
Ja::Sound *bubble3_sound_; // Sonido para cuando el jugador muere
|
||||
Ja::Sound *bubble4_sound_; // Sonido para cuando el jugador muere
|
||||
Ja::Sound *clock_sound_; // Sonido para cuando se detiene el tiempo con el item reloj
|
||||
Ja::Sound *power_ball_sound_; // Sonido para cuando se explota una Power Ball
|
||||
Ja::Sound *coffee_machine_sound_; // Sonido para cuando la máquina de café toca el suelo
|
||||
|
||||
JA_Music_t *game_music_; // Musica de fondo
|
||||
Ja::Music *game_music_; // Musica de fondo
|
||||
|
||||
// Variables
|
||||
int num_players_; // Numero de jugadores
|
||||
|
||||
@@ -7,8 +7,10 @@ class SmartSprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
class Writer;
|
||||
struct JA_Music_t;
|
||||
struct Section;
|
||||
namespace Ja {
|
||||
struct Music;
|
||||
} // namespace Ja
|
||||
|
||||
// Clase Intro
|
||||
class Intro {
|
||||
@@ -36,7 +38,7 @@ class Intro {
|
||||
// Variables
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint8 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||
JA_Music_t *music_; // Musica para la intro
|
||||
Ja::Music *music_; // Musica para la intro
|
||||
int scene_; // Indica que escena está activa
|
||||
|
||||
void update(); // Actualiza las variables del objeto
|
||||
|
||||
@@ -15,8 +15,10 @@ class SmartSprite;
|
||||
class Sprite;
|
||||
class Text;
|
||||
class Texture;
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
namespace Ja {
|
||||
struct Music;
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
class Title {
|
||||
public:
|
||||
@@ -70,8 +72,8 @@ class Title {
|
||||
Fade *fade_; // Objeto para realizar fundidos en pantalla
|
||||
|
||||
// Variables
|
||||
JA_Music_t *title_music_; // Musica para el titulo
|
||||
JA_Sound_t *crash_sound_; // Sonido con el impacto del título
|
||||
Ja::Music *title_music_; // Musica para el titulo
|
||||
Ja::Sound *crash_sound_; // Sonido con el impacto del título
|
||||
int background_counter_; // Temporizador para el fondo de tiles de la pantalla de titulo
|
||||
int counter_; // Temporizador para la pantalla de titulo
|
||||
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||
|
||||
+14
-14
@@ -6,7 +6,7 @@
|
||||
#include <sstream> // for basic_stringstream
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio::get (playSound)
|
||||
#include "core/audio/jail_audio.hpp" // for JA_LoadSound, JA_DeleteSound (propietat local)
|
||||
#include "core/audio/jail_audio.hpp" // for Ja::loadSound, Ja::deleteSound (propietat local)
|
||||
#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction
|
||||
#include "core/rendering/text.h" // for Text
|
||||
#include "core/resources/asset.h" // for Asset
|
||||
@@ -40,7 +40,7 @@ Menu::Menu(SDL_Renderer *renderer, const std::string &file)
|
||||
center_x_ = 0;
|
||||
center_y_ = 0;
|
||||
widest_item_ = 0;
|
||||
default_action_when_cancel = 0;
|
||||
default_action_when_cancel_ = 0;
|
||||
|
||||
// Selector
|
||||
selector_.origin_y = 0;
|
||||
@@ -73,15 +73,15 @@ Menu::~Menu() {
|
||||
renderer_ = nullptr;
|
||||
|
||||
if (sound_move_ != nullptr) {
|
||||
JA_DeleteSound(sound_move_);
|
||||
Ja::deleteSound(sound_move_);
|
||||
}
|
||||
|
||||
if (sound_accept_ != nullptr) {
|
||||
JA_DeleteSound(sound_accept_);
|
||||
Ja::deleteSound(sound_accept_);
|
||||
}
|
||||
|
||||
if (sound_cancel_ != nullptr) {
|
||||
JA_DeleteSound(sound_cancel_);
|
||||
Ja::deleteSound(sound_cancel_);
|
||||
}
|
||||
|
||||
delete text_;
|
||||
@@ -229,21 +229,21 @@ auto Menu::setVars(const std::string &var, const std::string &value) -> bool {
|
||||
else if (var == "sound_cancel") {
|
||||
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||
if (!bytes.empty()) {
|
||||
sound_cancel_ = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
sound_cancel_ = Ja::loadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "sound_accept") {
|
||||
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||
if (!bytes.empty()) {
|
||||
sound_accept_ = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
sound_accept_ = Ja::loadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "sound_move") {
|
||||
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||
if (!bytes.empty()) {
|
||||
sound_move_ = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
sound_move_ = Ja::loadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ auto Menu::setVars(const std::string &var, const std::string &value) -> bool {
|
||||
}
|
||||
|
||||
else if (var == "defaultActionWhenCancel") {
|
||||
default_action_when_cancel = std::stoi(value);
|
||||
default_action_when_cancel_ = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var.empty()) {
|
||||
@@ -341,15 +341,15 @@ auto Menu::setVars(const std::string &var, const std::string &value) -> bool {
|
||||
void Menu::loadAudioFile(const std::string &file, int sound) {
|
||||
switch (sound) {
|
||||
case SOUND_ACCEPT:
|
||||
sound_accept_ = JA_LoadSound(file.c_str());
|
||||
sound_accept_ = Ja::loadSound(file.c_str());
|
||||
break;
|
||||
|
||||
case SOUND_CANCEL:
|
||||
sound_cancel_ = JA_LoadSound(file.c_str());
|
||||
sound_cancel_ = Ja::loadSound(file.c_str());
|
||||
break;
|
||||
|
||||
case SOUND_MOVE:
|
||||
sound_move_ = JA_LoadSound(file.c_str());
|
||||
sound_move_ = Ja::loadSound(file.c_str());
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -770,7 +770,7 @@ void Menu::setItemCaption(int index, const std::string &text) {
|
||||
|
||||
// Establece el indice del itemm que se usará por defecto al cancelar el menu
|
||||
void Menu::setDefaultActionWhenCancel(int item) {
|
||||
default_action_when_cancel = item;
|
||||
default_action_when_cancel_ = item;
|
||||
}
|
||||
|
||||
// Gestiona la entrada de teclado y mando durante el menu
|
||||
@@ -797,7 +797,7 @@ void Menu::checkInput() {
|
||||
}
|
||||
|
||||
if (Input::get()->checkInput(CANCEL, REPEAT_FALSE)) {
|
||||
item_selected_ = default_action_when_cancel;
|
||||
item_selected_ = default_action_when_cancel_;
|
||||
if (sound_cancel_ != nullptr) {
|
||||
Audio::get()->playSound(sound_cancel_);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
|
||||
#include "utils/utils.h" // for Color
|
||||
class Text;
|
||||
struct JA_Sound_t;
|
||||
namespace Ja {
|
||||
struct Sound;
|
||||
} // namespace Ja
|
||||
|
||||
// Tipos de fondos para el menú
|
||||
constexpr int MENU_BACKGROUND_TRANSPARENT = 0;
|
||||
@@ -140,9 +142,9 @@ class Menu {
|
||||
bool is_centered_on_y_; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y
|
||||
bool are_elements_centered_on_x_; // Variable para saber si los elementos van centrados en el eje X
|
||||
int widest_item_; // Anchura del elemento más ancho
|
||||
JA_Sound_t *sound_accept_; // Sonido al aceptar o elegir una opción del menu
|
||||
JA_Sound_t *sound_cancel_; // Sonido al cancelar el menu
|
||||
JA_Sound_t *sound_move_; // Sonido al mover el selector
|
||||
Ja::Sound *sound_accept_; // Sonido al aceptar o elegir una opción del menu
|
||||
Ja::Sound *sound_cancel_; // Sonido al cancelar el menu
|
||||
Ja::Sound *sound_move_; // Sonido al mover el selector
|
||||
Color color_greyed_; // Color para los elementos agrisados
|
||||
Rectangle rect_bg_; // Rectangulo de fondo del menu
|
||||
std::vector<Item> items_; // Estructura para cada elemento del menu
|
||||
|
||||
Reference in New Issue
Block a user