Added settings.ini
This commit is contained in:
34
src/main.cpp
34
src/main.cpp
@ -34,6 +34,7 @@
|
||||
#include "utils/ImagePathResolver.h"
|
||||
#include "graphics/renderers/GameRenderer.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/Settings.h"
|
||||
|
||||
// Debug logging removed: no-op in this build (previously LOG_DEBUG)
|
||||
|
||||
@ -534,6 +535,17 @@ int main(int, char **)
|
||||
// Initialize random seed for fireworks
|
||||
srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
// Load settings
|
||||
Settings::instance().load();
|
||||
|
||||
// Sync static variables with settings
|
||||
musicEnabled = Settings::instance().isMusicEnabled();
|
||||
playerName = Settings::instance().getPlayerName();
|
||||
if (playerName.empty()) playerName = "Player";
|
||||
|
||||
// Apply sound settings to manager
|
||||
SoundEffectManager::instance().setEnabled(Settings::instance().isSoundEnabled());
|
||||
|
||||
int sdlInitRes = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
||||
if (sdlInitRes < 0)
|
||||
{
|
||||
@ -547,7 +559,13 @@ int main(int, char **)
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
SDL_Window *window = SDL_CreateWindow("Tetris (SDL3)", LOGICAL_W, LOGICAL_H, SDL_WINDOW_RESIZABLE);
|
||||
|
||||
SDL_WindowFlags windowFlags = SDL_WINDOW_RESIZABLE;
|
||||
if (Settings::instance().isFullscreen()) {
|
||||
windowFlags |= SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
|
||||
SDL_Window *window = SDL_CreateWindow("Tetris (SDL3)", LOGICAL_W, LOGICAL_H, windowFlags);
|
||||
if (!window)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateWindow failed: %s", SDL_GetError());
|
||||
@ -711,7 +729,8 @@ int main(int, char **)
|
||||
AppState state = AppState::Loading;
|
||||
double loadingProgress = 0.0;
|
||||
Uint64 loadStart = SDL_GetTicks();
|
||||
bool running = true, isFullscreen = false;
|
||||
bool running = true;
|
||||
bool isFullscreen = Settings::instance().isFullscreen();
|
||||
bool leftHeld = false, rightHeld = false;
|
||||
double moveTimerMs = 0;
|
||||
const double DAS = 170.0, ARR = 40.0;
|
||||
@ -869,11 +888,13 @@ int main(int, char **)
|
||||
{
|
||||
Audio::instance().toggleMute();
|
||||
musicEnabled = !musicEnabled;
|
||||
Settings::instance().setMusicEnabled(musicEnabled);
|
||||
}
|
||||
if (e.key.scancode == SDL_SCANCODE_S)
|
||||
{
|
||||
// Toggle sound effects
|
||||
SoundEffectManager::instance().setEnabled(!SoundEffectManager::instance().isEnabled());
|
||||
Settings::instance().setSoundEnabled(SoundEffectManager::instance().isEnabled());
|
||||
}
|
||||
if (e.key.scancode == SDL_SCANCODE_N)
|
||||
{
|
||||
@ -884,6 +905,7 @@ int main(int, char **)
|
||||
{
|
||||
isFullscreen = !isFullscreen;
|
||||
SDL_SetWindowFullscreen(window, isFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
|
||||
Settings::instance().setFullscreen(isFullscreen);
|
||||
}
|
||||
}
|
||||
|
||||
@ -901,6 +923,7 @@ int main(int, char **)
|
||||
} else if (e.key.scancode == SDL_SCANCODE_RETURN || e.key.scancode == SDL_SCANCODE_KP_ENTER) {
|
||||
if (playerName.empty()) playerName = "PLAYER";
|
||||
scores.submit(game.score(), game.lines(), game.level(), game.elapsed(), playerName);
|
||||
Settings::instance().setPlayerName(playerName);
|
||||
isNewHighScore = false;
|
||||
SDL_StopTextInput(window);
|
||||
}
|
||||
@ -1169,6 +1192,9 @@ int main(int, char **)
|
||||
// Initialize audio system and start background loading on first frame
|
||||
if (!musicLoaded && currentTrackLoading == 0) {
|
||||
Audio::instance().init();
|
||||
// Apply audio settings
|
||||
Audio::instance().setMuted(!Settings::instance().isMusicEnabled());
|
||||
// Note: SoundEffectManager doesn't have a global mute yet, but we can add it or handle it in playSound
|
||||
|
||||
// Count actual music files first
|
||||
totalTracks = 0;
|
||||
@ -1686,6 +1712,10 @@ int main(int, char **)
|
||||
SDL_DestroyTexture(blocksTex);
|
||||
if (logoSmallTex)
|
||||
SDL_DestroyTexture(logoSmallTex);
|
||||
|
||||
// Save settings on exit
|
||||
Settings::instance().save();
|
||||
|
||||
lineEffect.shutdown();
|
||||
Audio::instance().shutdown();
|
||||
SoundEffectManager::instance().shutdown();
|
||||
|
||||
Reference in New Issue
Block a user