Skip to content

Commit

Permalink
merge: Merge pull request #48 from G-Epitech/47-add-ncurse
Browse files Browse the repository at this point in the history
feat: add ncurse
  • Loading branch information
Yann-Masson authored Apr 7, 2024
2 parents 6bc0278 + b8ab83b commit 74c14bf
Show file tree
Hide file tree
Showing 23 changed files with 961 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ lib
*.gcda
*.o
scores.txt
*.zip
4 changes: 2 additions & 2 deletions assets/nibbler/tail.ascii
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
║═
|-
~~~~
╝╚╗╔
~~~~
4 changes: 2 additions & 2 deletions assets/snake/tail.ascii
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
║═
|-
~~~~
╝╚╗╔
~~~~
3 changes: 3 additions & 0 deletions core/src/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ void Core::_initWindow()
this->_graphicsProvider = this->_getGraphicsProvider(0);
std::cerr << "No graphic provider selected, using default provider" << std::endl;
}
this->_textures.clear();
this->_fonts.clear();
this->_sounds.clear();
this->_window = this->_graphicsProvider->createWindow(windowInitProps);
this->_sceneStage = PLAY;
}
Expand Down
16 changes: 13 additions & 3 deletions core/src/menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ void Menu::_initTexts()

void Menu::_clearLists()
{
this->_nameField.reset();
this->_font.reset();
this->_music.reset();
this->_hiddenAuthors.clear();
this->_hiddenTexts.clear();
this->_texts.clear();
Expand Down Expand Up @@ -303,8 +306,8 @@ void Menu::_initWindow()
};

try {
this->_window = this->_graphicsProvider->createWindow(windowInitProps);
this->_clearLists();
this->_window = this->_graphicsProvider->createWindow(windowInitProps);
this->_preventGraphicsProvider();
this->_initTexts();
this->_initTextures();
Expand Down Expand Up @@ -410,7 +413,7 @@ void Menu::_selectGame()
if (this->_checkBoxType == GAME_CHECKBOX) {
for (auto checkBox : this->_gamesCheckBoxes) {
if (checkBox->isHovered() && checkBox->isChecked())
this->_exitWithNewGame();
return this->_exitWithNewGame();
if (checkBox->isHovered())
checkBox->check();
else
Expand All @@ -419,7 +422,7 @@ void Menu::_selectGame()
} else {
for (auto checkBox : this->_graphicsCheckBoxes) {
if (checkBox->isHovered() && checkBox->isChecked())
this->_changeGraphics(checkBox);
return this->_changeGraphics(checkBox);
if (checkBox->isHovered())
checkBox->check();
else
Expand All @@ -436,6 +439,8 @@ void Menu::_changeGraphics(std::shared_ptr<CheckBox> checkBox)
this->_graphicsProvider = graphicsProvider;
this->_window->close();
this->_initWindow();
this->_previousSelectedGame();
this->_previousSelectedGraphics();
}
}

Expand Down Expand Up @@ -511,6 +516,11 @@ void Menu::_handleMouseButtonEvents(std::shared_ptr<events::IMouseButtonEvent> m
this->_selectGame();
}
}
for (auto checkBox : this->_graphicsCheckBoxes) {
if (checkBox->isHovered(position)) {
this->_selectGame();
}
}
}

void Menu::_handleEvents()
Expand Down
2 changes: 1 addition & 1 deletion graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#add_subdirectory(ncurses)
add_subdirectory(ncurses)
add_subdirectory(sfml)
21 changes: 21 additions & 0 deletions graphics/ncurses/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
project(ncurses)
add_library(ncurses SHARED
export.cpp
src/GraphicsProvider.cpp
src/GraphicsProvider.hpp
src/window/Window.cpp
src/window/Window.hpp
src/window/EventsHandler.cpp
src/window/EventsHandler.hpp
src/sound/Sound.cpp
src/sound/Sound.hpp
src/texture/Texture.cpp
src/texture/Texture.hpp
src/font/Font.cpp
src/font/Font.hpp
src/window/Renderer.cpp
src/window/Renderer.hpp
)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../common PRIVATE)

target_include_directories(ncurses PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src)
target_include_directories(ncurses PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../..)
target_include_directories(ncurses PUBLIC ${CMAKE_CURRENT_LIST_DIR}/..)

find_package(Curses REQUIRED)
target_link_libraries(ncurses ${CURSES_LIBRARIES})
15 changes: 10 additions & 5 deletions graphics/ncurses/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@

#include "shared/games/IGameProvider.hpp"
#include "shared/types/Libraries.hpp"
#include "src/GraphicsProvider.hpp"

using namespace arcade::graphics;
using namespace shared::graphics;
using namespace shared::types;

extern "C" {
shared::types::LibraryType SHARED_LIBRARY_TYPE_GETTER_NAME(void)
LibraryType SHARED_LIBRARY_TYPE_GETTER_NAME(void)
{
return shared::types::LibraryType::GRAPHIC;
return LibraryType::GRAPHIC;
}

/* std::shared_ptr<shared::graphics::IGraphicsProvider> SHARED_GRAPHICS_PROVIDER_LOADER_NAME(void)
IGraphicsProvider *SHARED_GRAPHICS_PROVIDER_GETTER_NAME(void)
{
return std::make_shared<RendererClass>(...);
}*/
return new ncurses::GraphicsProvider();
}
}

52 changes: 52 additions & 0 deletions graphics/ncurses/src/GraphicsProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
** EPITECH PROJECT, 2024
** GraphicsProvider.cpp
** File description:
** GraphicsProvider class
*/

#include <iostream>
#include "GraphicsProvider.hpp"
#include "utils/compiler.hpp"
#include "window/Window.hpp"
#include "font/Font.hpp"
#include "sound/Sound.hpp"
#include "texture/Texture.hpp"

using namespace shared::graphics;
using namespace arcade::graphics::ncurses;

const shared::graphics::GraphicsManifest GraphicsProvider::_manifest = {
.name = "ncurses",
.description = "NCURSES Library",
.version = "1.0",
.authors = {
{
.name = "Yann Masson",
.email = "yann.masson@epitech.eu",
.website = "yannmasson.fr"
}
}
};

GraphicsProvider::GraphicsProvider() = default;

const GraphicsManifest &GraphicsProvider::getManifest() const noexcept {
return GraphicsProvider::_manifest;
}

std::unique_ptr<IWindow> GraphicsProvider::createWindow(const IWindow::WindowInitProps &props) {
return std::make_unique<window::Window>(props);
}

std::shared_ptr<ISound> GraphicsProvider::createSound(const std::string &path) {
return std::make_shared<sound::Sound>(path);
}

std::shared_ptr<ITexture> GraphicsProvider::createTexture(unused const std::string &bin, const std::string &ascii) {
return std::make_shared<texture::Texture>(ascii);
}

std::shared_ptr<IFont> GraphicsProvider::createFont(const std::string &path) {
return std::make_shared<font::Font>(path);
}
68 changes: 68 additions & 0 deletions graphics/ncurses/src/GraphicsProvider.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
** EPITECH PROJECT, 2024
** GraphicsProvider.hpp
** File description:
** GraphicsProvider class
*/

#pragma once

#include "shared/graphics/ITexture.hpp"
#include "shared/graphics/IGraphicsProvider.hpp"

using namespace shared::graphics;

namespace arcade::graphics::ncurses
{
class GraphicsProvider;
}

class arcade::graphics::ncurses::GraphicsProvider : public shared::graphics::IGraphicsProvider
{
public:
GraphicsProvider();
~GraphicsProvider() override = default;

/**
* @brief Get the manifest of the graphics library
*
* @return Manifest of the graphics library
*/
const shared::graphics::GraphicsManifest &getManifest() const noexcept override;

/**
* @brief Create a renderer object
*
* @param windowProps Properties to use to init the window
* @return Created renderer object
*/
std::unique_ptr<IWindow> createWindow(const IWindow::WindowInitProps &windowProps) override;

/**
* @brief Create a sound object
*
* @param path Path of the sound file
* @return Created sound object
*/
std::shared_ptr<ISound> createSound(const std::string &path) override;

/**
* @brief Create a texture object
*
* @param bin Path of the binary texture file
* @param ascii Path of the ascii texture file
* @return Created texture object
*/
std::shared_ptr<ITexture> createTexture(const std::string &bin, const std::string &ascii) override;

/**
* @brief Create a font object
*
* @param path Path of the font file
* @return Created font object
*/
std::shared_ptr<IFont> createFont(const std::string &path) override;

protected:
static const shared::graphics::GraphicsManifest _manifest;
};
13 changes: 13 additions & 0 deletions graphics/ncurses/src/font/Font.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** Font.cpp
*/

#include "Font.hpp"
#include "common/exceptions/FontException.hpp"

using namespace arcade::graphics::ncurses::font;

Font::Font(const std::string &path) {}
22 changes: 22 additions & 0 deletions graphics/ncurses/src/font/Font.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** Font.hpp
*/

#pragma once

#include <string>
#include "shared/graphics/IFont.hpp"
#include "utils/compiler.hpp"

namespace arcade::graphics::ncurses::font {
class Font;
}

class arcade::graphics::ncurses::font::Font : public shared::graphics::IFont {
public:
explicit Font(const std::string &path);
~Font() override = default;
};
32 changes: 32 additions & 0 deletions graphics/ncurses/src/sound/Sound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** Sound.cpp
*/

#include "Sound.hpp"
#include "common/exceptions/SoundException.hpp"

using namespace arcade::graphics::ncurses::sound;
using namespace arcade::graphics::common::exceptions;

Sound::Sound(const std::string &path, SoundState state) {}

Sound::SoundVolume Sound::getVolume() const {
return 100;
}

void Sound::setVolume(SoundVolume volume) {}

void Sound::setState(SoundState state) {}

Sound::SoundState Sound::getState() const {
return SoundState::STOP;
}

void Sound::setLoopState(bool loop) {}

bool Sound::getLoopState() const {
return false;
}
31 changes: 31 additions & 0 deletions graphics/ncurses/src/sound/Sound.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** Sound.hpp
*/

#pragma once

#include <string>

#include "shared/graphics/ISound.hpp"

namespace arcade::graphics::ncurses::sound {
class Sound;
}

class arcade::graphics::ncurses::sound::Sound : public shared::graphics::ISound {
public:
explicit Sound(const std::string &path, SoundState state = STOP);
~Sound() override = default;

SoundVolume getVolume() const override;
SoundState getState() const override;
void setVolume(SoundVolume volume) override;
void setState(SoundState state) override;
void setLoopState(bool loop) override;
bool getLoopState() const override;

private:
};
Loading

0 comments on commit 74c14bf

Please sign in to comment.