Skip to content

Commit

Permalink
Merge branch 'main' into release_1.1
Browse files Browse the repository at this point in the history
Create release 1.1
  • Loading branch information
flinguenheld committed Aug 11, 2023
2 parents 17216b6 + dc0ef24 commit 398d90b
Show file tree
Hide file tree
Showing 71 changed files with 2,058 additions and 718 deletions.
26 changes: 19 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ set(CMAKE_CXX_FLAGS, "${CXX_FLAGS}")

# Options
option(RELEASE_LINUX "Use the final paths" OFF)
option(DEBUG "Print dev information" OFF)

if (RELEASE_LINUX)
add_definitions(-DRELEASE_LINUX)
endif()
if (DEBUG)
add_definitions(-DDEBUG)
endif()

# Add SDL2 CMake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
Expand All @@ -26,23 +30,31 @@ add_executable(${PROJECT_NAME} src/main.cpp
src/utils.cpp
src/renderer.cpp
src/about/window_about.cpp
src/file/file.cpp
src/file/option_file.cpp
src/file/record_file.cpp
src/game/target.cpp
src/game/dispatcher.cpp
src/game/window_game.cpp
src/game/score.cpp
src/game/window/window_game.cpp
src/game/window/window_gameover.cpp
src/game/window/widget_score.cpp
src/game/window/survival_mode/widget_gauge.cpp
src/game/window/survival_mode/window_survival_mode.cpp
src/game/window/survival_mode/window_welcome_survival.cpp
src/game/window/timer_mode/window_timer_mode.cpp
src/game/window/timer_mode/window_welcome_timer.cpp
src/option/window_option.cpp
src/option/option_file.cpp
src/pause/window_pause.cpp
src/score/score.cpp
src/score/widget_score.cpp
src/record/window_record.cpp
src/welcome/widget_logo.cpp
src/welcome/window_welcome.cpp
src/widget/button/widget_selection.cpp
src/widget/button/widget_boolean.cpp
src/widget/button/widget_list.cpp
src/widget/widget_base.cpp
src/widget/widget_menu.cpp
src/widget/widget_textbox.cpp
src/widget/widget_window.cpp)
src/widget/window/widget_bottom_menu.cpp
src/widget/window/widget_window.cpp)

find_package(Threads)
target_link_libraries(${PROJECT_NAME} Threads::Threads)
Expand Down
Binary file removed image/example_fast_1.gif
Binary file not shown.
Binary file removed image/example_fast_2.gif
Binary file not shown.
Binary file removed image/example_slow_1.gif
Binary file not shown.
Binary file removed image/example_slow_2.gif
Binary file not shown.
Binary file added image/example_survival_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/example_survival_2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/example_timer_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/example_timer_2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Go to options to select the amount of letters, the speed and try to press all of
It currently works with QWERTY, AZERTY and BÉPO layouts.

<div align="center">
<img src="./image/example_slow_1.gif" width="250" />
<img src="./image/example_slow_2.gif" width="250" />
<img src="./image/example_timer_1.gif" width="250" />
<img src="./image/example_timer_2.gif" width="250" />
</div>
<div align="center">
<img src="./image/example_fast_1.gif" width="250" />
<img src="./image/example_fast_2.gif" width="250" />
<img src="./image/example_survival_1.gif" width="250" />
<img src="./image/example_survival_2.gif" width="250" />
</div>

---
Expand Down
14 changes: 7 additions & 7 deletions src/about/window_about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ WindowAbout::WindowAbout(kebb::boxsize screen_size, std::shared_ptr<kebb::Window
std::shared_ptr<Renderer> renderer)
: WidgetWindow(next_window, renderer) {

_widget_menu = std::make_unique<WidgetMenu>(screen_size, renderer, "<ESC> Quit");
_widget_menu = std::make_unique<WidgetBottomMenu>(screen_size, renderer, "<ESC> Quit");

// Geometry
kebb::boxsize char_size = _renderer->font_char_size(FontName::F_Menu); // NOTE: Use font menu ?
kebb::boxsize char_size = _renderer->font_char_size(FontName::F_Menu);
kebb::boxsize bs;
kebb::point pt;

// ------------------------------------------------------------------------
// Title ------------------------------------------------------------------
// Catppuccin: Mocha
char_size.set_scale(3);
bs.w = char_size.w * 4;
bs.w = char_size.w * 5;
bs.h = char_size.h;

pt.x = screen_size.w / 2 - bs.w / 2;
Expand All @@ -34,7 +34,7 @@ WindowAbout::WindowAbout(kebb::boxsize screen_size, std::shared_ptr<kebb::Window
pt.x = screen_size.w / 2 - bs.w / 2;
pt.y += bs.h * 1.4;
_widget_version = std::make_unique<WidgetTextBox>(pt, bs);
_widget_version->set_text("Kebb 1.0");
_widget_version->set_text("Kebb 1.1");
_widget_version->set_color_text(kebb::color(kebb::ColorName::C_Yellow));

char_size.set_scale(0.5);
Expand All @@ -44,10 +44,10 @@ WindowAbout::WindowAbout(kebb::boxsize screen_size, std::shared_ptr<kebb::Window
pt.x = screen_size.w / 2 - bs.w / 2;
pt.y += bs.h * 2;
_widget_date = std::make_unique<WidgetTextBox>(pt, bs);
_widget_date->set_text("2023-07-27");
_widget_date->set_text("2023-08-11");
_widget_date->set_color_text(kebb::color(kebb::ColorName::C_Yellow));

char_size = _renderer->font_char_size(FontName::F_Menu); // NOTE: Use font menu ?
char_size = _renderer->font_char_size(FontName::F_Menu);

bs.w = char_size.w * 36;
bs.h = char_size.h;
Expand All @@ -68,7 +68,7 @@ WindowAbout::WindowAbout(kebb::boxsize screen_size, std::shared_ptr<kebb::Window

WindowAbout::~WindowAbout() {}

void WindowAbout::render() {
void WindowAbout::render() const {

_renderer->clear_screen();
_widget_title->render(_renderer->renderer(), _renderer->font(FontName::F_Menu));
Expand Down
8 changes: 4 additions & 4 deletions src/about/window_about.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define WINDOW_ABOUT

#include "utils.h"
#include "widget/widget_menu.h"
#include "widget/widget_window.h"
#include "widget/window/widget_bottom_menu.h"
#include "widget/window/widget_window.h"
#include <memory>

class WindowAbout : public WidgetWindow {
Expand All @@ -13,7 +13,7 @@ class WindowAbout : public WidgetWindow {
virtual ~WindowAbout() override;

virtual void control_escape() override;
virtual void render() override;
virtual void render() const override;

private:
std::unique_ptr<WidgetTextBox> _widget_title;
Expand All @@ -22,7 +22,7 @@ class WindowAbout : public WidgetWindow {
std::unique_ptr<WidgetTextBox> _widget_github;
std::unique_ptr<WidgetTextBox> _widget_email;

std::unique_ptr<WidgetMenu> _widget_menu;
std::unique_ptr<WidgetBottomMenu> _widget_menu;
};

#endif // !WINDOW_ABOUT
12 changes: 6 additions & 6 deletions src/controller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "controller.h"
#include "option/option_file.h"
#include <SDL_keycode.h>
#include <SDL_video.h>

Controller::Controller(std::shared_ptr<OptionFile> options)
: _options(options), _circumflex(false), _grave(false), _diaeresis(false), _mask_mod(0x3FF) {}
Expand All @@ -9,8 +8,9 @@ void Controller::handle_input(bool &running, std::shared_ptr<WidgetWindow> windo
SDL_Event e;
while (SDL_PollEvent(&e)) {

if (e.type == SDL_QUIT) {
if (e.type == SDL_QUIT || e.window.event == SDL_WINDOWEVENT_CLOSE) { // TODO: Confirm mouse click on X
running = false;

} else if (e.type == SDL_KEYDOWN) {

switch (e.key.keysym.sym) {
Expand All @@ -20,7 +20,7 @@ void Controller::handle_input(bool &running, std::shared_ptr<WidgetWindow> windo
break;

case SDLK_RETURN:
case SDLK_RETURN2: // NOTE: What is that ?
case SDLK_RETURN2:
case SDLK_KP_ENTER:
window->control_enter();
break;
Expand Down Expand Up @@ -52,9 +52,9 @@ void Controller::handle_input(bool &running, std::shared_ptr<WidgetWindow> windo
break;

default:
if (_options->get(OptionName::Layout) == "US")
if (_options->get().layout == "US")
window->control_others(convert_us(e));
else if (_options->get(OptionName::Layout) == "FR")
else if (_options->get().layout == "FR")
window->control_others(convert_fr(e));
else
window->control_others(convert_bepo(e));
Expand Down
5 changes: 3 additions & 2 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include "SDL_keyboard.h"
#include "SDL_keycode.h"
#include "SDL_stdinc.h"
#include "file/option_file.h"
#include "game/target.h"
#include "option/option_file.h"
#include "widget/widget_window.h"
#include "widget/window/widget_window.h"
#include <SDL_keycode.h>
#include <iostream>
#include <memory>
#include <vector>
Expand Down
16 changes: 16 additions & 0 deletions src/file/file.cpp
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);
}
20 changes: 20 additions & 0 deletions src/file/file.h
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
42 changes: 42 additions & 0 deletions src/file/option_file.cpp
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; }
44 changes: 44 additions & 0 deletions src/file/option_file.h
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
45 changes: 45 additions & 0 deletions src/file/record_file.cpp
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; }
Loading

0 comments on commit 398d90b

Please sign in to comment.