-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:vmbatlle/super-mario-kart
- Loading branch information
Showing
7 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,6 @@ super_mario_kart | |
*.app | ||
|
||
#VScode | ||
.vscode | ||
.vscode | ||
|
||
settings.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "settings.h" | ||
|
||
void applySetting(const std::string key, std::string value) { | ||
if (key.compare(MUSIC_VOLUME) == 0) { | ||
Audio::setVolume(std::stof(value), Audio::getSfxVolume()); | ||
} else if (key.compare(SFX_VOLUME) == 0) { | ||
Audio::setVolume(Audio::getMusicVolume(), std::stof(value)); | ||
} | ||
} | ||
|
||
|
||
void Settings::loadSettings() { | ||
std::string line; | ||
std::ifstream file(FILE_NAME, std::fstream::in); | ||
|
||
while(file.is_open() && std::getline(file, line)) { | ||
std::string key = line.substr(0, line.find('=')); | ||
std::string value = line.substr(line.find('=')+1); | ||
applySetting(key, value); | ||
} | ||
|
||
file.close(); | ||
|
||
} | ||
|
||
void Settings::saveSettings(sf::Vector2u resolution) { | ||
std::string line; | ||
std::ofstream file; | ||
file.open(FILE_NAME, std::fstream::out); | ||
|
||
file << MUSIC_VOLUME << "=" << Audio::getMusicVolume() << std::endl; | ||
file << SFX_VOLUME << "=" << Audio::getSfxVolume() << std::endl; | ||
file << RESOLUTION_X << "=" << resolution.x << std::endl; | ||
file << RESOLUTION_Y << "=" << resolution.y << std::endl; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
class Settings; | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include "audio/audio.h" | ||
#include "input/input.h" | ||
#include <SFML/Graphics.hpp> | ||
|
||
static const std::string FILE_NAME = "settings.txt"; | ||
|
||
static const std::string MUSIC_VOLUME = "MUSIC_VOLUME"; | ||
static const std::string SFX_VOLUME = "SFX_VOLUME"; | ||
static const std::string RESOLUTION_Y = "RESOLUTION_Y"; | ||
static const std::string RESOLUTION_X = "RESOLUTION_X"; | ||
|
||
class Settings { | ||
private: | ||
Settings(); | ||
static Settings inst; | ||
|
||
public: | ||
static void loadSettings(); | ||
static void saveSettings(sf::Vector2u resolution); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters