-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the ability to store, load, read, save global game settings
- Loading branch information
Showing
8 changed files
with
88 additions
and
14 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
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,4 @@ | ||
# fpslock | ||
false | ||
# gamespeed | ||
.10f |
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,16 @@ | ||
#pragma once | ||
|
||
class Settings | ||
{ | ||
public: | ||
Settings(); | ||
~Settings() = default; | ||
bool getFpsLock() { return fpsLock; }; | ||
float getGameSpeed() { return gameSpeed; }; | ||
void setFpsLock(bool temp) { fpsLock = temp; }; | ||
void setGameSpeed(float temp) { gameSpeed = temp; }; | ||
void saveToFile(); | ||
private: | ||
bool fpsLock; | ||
float gameSpeed; | ||
}; |
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,46 @@ | ||
#include "Settings.hpp" | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
|
||
Settings::Settings() { | ||
std::fstream file; | ||
file.open("assets/settings.txt", std::ios::in); | ||
std::string line; | ||
if (!file.fail()) { | ||
std::getline(file, line, '\n'); | ||
std::cout << line << std::endl; | ||
std::getline(file, line, '\n'); | ||
std::cout << line << std::endl; | ||
if (line == "true") { | ||
fpsLock = true; | ||
} else { | ||
fpsLock = false; | ||
} | ||
std::getline(file, line, '\n'); | ||
std::cout << line << std::endl; | ||
std::getline(file, line, '\n'); | ||
std::cout << line << std::endl; | ||
gameSpeed = std::stof(line); | ||
} else { | ||
file.open("assets/settings.txt", std::ios::out); | ||
file << "# fpslock\n" << "false\n" << "# gamespeed\n" << ".10f\n"; | ||
fpsLock = false; | ||
gameSpeed = .10f; // | ||
} | ||
file.close(); | ||
} | ||
|
||
void Settings::saveToFile() { | ||
std::fstream file; | ||
file.open("assets/settings.txt", std::ios::out); | ||
file << "# fpslock\n"; | ||
if (fpsLock) { | ||
file << "true\n"; | ||
} else { | ||
file << "false\n"; | ||
} | ||
file << "# gamespeed\n"; | ||
file << std::to_string(gameSpeed); | ||
file.close(); | ||
} |
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