-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into release_1.1
Create release 1.1
- Loading branch information
Showing
71 changed files
with
2,058 additions
and
718 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,16 @@ | ||
#include "file.h" | ||
|
||
// TODO: Windows path ? | ||
File::File(std::string &&file_name) { | ||
|
||
#ifdef RELEASE_LINUX | ||
std::string path = std::string(getenv("HOME")) + "/.kebb"; | ||
#else | ||
std::string path = "./files_kebb"; | ||
#endif | ||
|
||
if (!std::filesystem::exists(path)) | ||
std::filesystem::create_directory(path); | ||
|
||
_filename = path + "/" + std::move(file_name); | ||
} |
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,20 @@ | ||
#ifndef FILE_H | ||
#define FILE_H | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
|
||
/* | ||
* | ||
*/ | ||
class File { | ||
public: | ||
File(std::string &&file_name); | ||
|
||
protected: | ||
std::string _filename; | ||
}; | ||
|
||
#endif // !FILE_H |
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,42 @@ | ||
#include "option_file.h" | ||
|
||
OptionFile::OptionFile() : File("options.kebb") { | ||
|
||
std::ifstream f(_filename); // First launch | ||
if (!f.good()) | ||
save(); | ||
|
||
read(); | ||
} | ||
OptionFile::~OptionFile() { save(); } | ||
|
||
void OptionFile::save() const { | ||
std::ofstream ostrm(_filename); | ||
ostrm << _options.resolution << '\n' | ||
<< _options.layout << '\n' | ||
<< _options.timer_countdown << '\n' | ||
<< _options.timer_nb_targets << '\n' | ||
<< _options.timer_speed << '\n' | ||
<< _options.survival_nb_targets << '\n' | ||
<< _options.survival_speed << '\n' | ||
<< _options.last_mode << '\n' | ||
<< _options.letters << '\n' | ||
<< _options.capitals << '\n' | ||
<< _options.numbers << '\n' | ||
<< _options.symbols << '\n' | ||
<< _options.french_extras << '\n' | ||
<< _options.french_extra_caps; | ||
} | ||
|
||
void OptionFile::read() { | ||
std::ifstream istrm(_filename); | ||
istrm >> _options.resolution >> _options.layout >> _options.timer_countdown >> _options.timer_nb_targets >> | ||
_options.timer_speed >> _options.survival_nb_targets >> _options.survival_speed >> _options.last_mode >> | ||
_options.letters >> _options.capitals >> _options.numbers >> _options.symbols >> | ||
_options.french_extras >> _options.french_extra_caps; | ||
} | ||
|
||
// ---------------------------------------------------------------------------------------------------- | ||
// ACCESSORS ------------------------------------------------------------------------------------------ | ||
const Options &OptionFile::get() const { return _options; } | ||
Options &OptionFile::set() { return _options; } |
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,44 @@ | ||
#ifndef OPTION_FILE_H | ||
#define OPTION_FILE_H | ||
|
||
#include "file.h" | ||
#include <cstdint> | ||
|
||
struct Options { | ||
std::string resolution = "480-20"; | ||
std::string layout = "US"; | ||
uint16_t timer_countdown = 30; | ||
uint16_t timer_speed = 6; | ||
uint16_t timer_nb_targets = 5; | ||
uint16_t survival_nb_targets = 5; | ||
uint16_t survival_speed = 10; | ||
uint16_t last_mode = 10; | ||
bool letters = true; | ||
bool capitals = false; | ||
bool numbers = true; | ||
bool symbols = false; | ||
bool french_extras = false; | ||
bool french_extra_caps = false; | ||
}; | ||
|
||
/* | ||
* Allows to manage options which are stored in a struct. | ||
* The constructor reads the file to fill the struct. | ||
* Then the destructor write the file with the updated data. | ||
*/ | ||
class OptionFile : public File { | ||
public: | ||
OptionFile(); | ||
~OptionFile(); | ||
|
||
const Options &get() const; | ||
Options &set(); | ||
|
||
private: | ||
Options _options; | ||
|
||
void save() const; | ||
void read(); | ||
}; | ||
|
||
#endif // !OPTION_FILE_H |
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,45 @@ | ||
#include "record_file.h" | ||
|
||
RecordFile::RecordFile() : File("records.kebb"), _nb_max_records(15) { read(); } | ||
RecordFile::~RecordFile() { save(); } | ||
|
||
/* | ||
* Add a new record in the array beginnig. | ||
* And delete old record to limit the amount of data. | ||
*/ | ||
void RecordFile::add(Record r) { | ||
_records.insert(_records.begin(), r); | ||
while (_records.size() > _nb_max_records) | ||
_records.pop_back(); | ||
} | ||
|
||
/* | ||
* Write the array in the file. | ||
*/ | ||
void RecordFile::save() const { | ||
|
||
auto file = std::ofstream(_filename, std::ios::out | std::ios::trunc | std::ios::binary); | ||
for (const auto &r : _records) | ||
file.write((char *)&r, sizeof(Record)); | ||
} | ||
|
||
/* | ||
* Fill the array with the file's data. | ||
*/ | ||
void RecordFile::read() { | ||
|
||
auto file = std::ifstream(_filename, std::ios::in | std::ios::binary); | ||
|
||
while (true) { | ||
Record new_record; | ||
file.read((char *)&new_record, sizeof(Record)); | ||
if (new_record.mode != 999) | ||
_records.emplace_back(new_record); | ||
else | ||
break; | ||
} | ||
} | ||
|
||
// ---------------------------------------------------------------------------------------------------- | ||
// ACCESSORS ------------------------------------------------------------------------------------------ | ||
const std::vector<Record> &RecordFile::records() { return _records; } |
Oops, something went wrong.