Skip to content

Commit

Permalink
Merge pull request #1 from X-R-G-B/merge_rtype
Browse files Browse the repository at this point in the history
BLUGA: Fix conflicts
  • Loading branch information
guillaumeAbel authored Nov 2, 2023
2 parents b11b780 + ba18ddc commit 589d1b1
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 54 deletions.
3 changes: 2 additions & 1 deletion libs/B-luga-graphics/include/B-luga-graphics/AnimRect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Types {
{LEFT, "left" },
});

enum RectListType { UNDEFINED, DEFAULT_RECT, MOVE, ATTACK, DEAD };
enum RectListType { UNDEFINED, DEFAULT_RECT, MOVE, ATTACK, DEAD, HOVER };

NLOHMANN_JSON_SERIALIZE_ENUM(
RectListType,
Expand All @@ -35,6 +35,7 @@ namespace Types {
{MOVE, "move" },
{ATTACK, "attack" },
{DEAD, "dead" },
{HOVER, "hover" }
});

class AnimRect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,55 @@ namespace Types {
float size;
};

struct Button {
Button(std::function<void()> &fct) : callback(fct) {};
std::function<void()> callback;
};

struct InputBox {
InputBox(
std::string &textStr,
std::string &boxName,
std::size_t &maxCharacters,
bool isSelected = false)
: name(boxName),
text(textStr),
maxChar(maxCharacters),
selected(isSelected) {};
std::string name;
std::string text;
std::size_t maxChar;
bool selected;
};

struct Color {
Raylib::Color color;
};

static const std::unordered_map<std::string, Raylib::Color> colorMatchStrings({
{"darkgray", Raylib::DarkGray },
{"yellow", Raylib::Yellow },
{"gold", Raylib::Gold },
{"orange", Raylib::Orange },
{"pink", Raylib::Pink },
{"red", Raylib::Red },
{"maroon", Raylib::Maroon },
{"green", Raylib::Green },
{"lime", Raylib::Lime },
{"darkgreen", Raylib::DarkGreen },
{"skyblue", Raylib::SkyBlue },
{"blue", Raylib::Blue },
{"darkblue", Raylib::DarkBlue },
{"purple", Raylib::Purple },
{"violet", Raylib::Violet },
{"darkpurple", Raylib::DarkPurple},
{"beige", Raylib::Beige },
{"brown", Raylib::Brown },
{"darkbrown", Raylib::DarkBrown },
{"white", Raylib::White },
{"black", Raylib::Black },
{"blank", Raylib::Blank },
{"magenta", Raylib::Magenta },
{"white", Raylib::RayWhite }
});
} // namespace Types
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace Systems::GraphicsSystems {
{
Raylib::Audio::closeAudioDevice();
Raylib::Window::closeWindow();
Raylib::TextureManager::unloadTextures();
}

static void checkRaylibStop(std::size_t /*unused*/, std::size_t /*unused*/)
Expand All @@ -61,7 +62,6 @@ namespace Systems::GraphicsSystems {
public:
void initPlugin() override
{
Logger::fatal("initplugin");
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry::getInstance().addEventCallback(Events::REMOVE_ENTITY, UnloadRaylib::unloadRaylibComponents);
Registry::getInstance().addEventCallback(Events::CLEAR, UnloadRaylib::unloadRaylibComponents);
Expand All @@ -72,7 +72,6 @@ namespace Systems::GraphicsSystems {
}
std::vector<std::function<void(std::size_t, std::size_t)>> getSystems() override
{
Logger::fatal("getSystems graphics");
std::vector<std::function<void(std::size_t, std::size_t)>> graphicsSystems = {
checkRaylibStop
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ namespace Raylib {
// Sounds
class Sound {
public:
static std::unique_ptr<Sound> fromFile(const std::string& fileName, float volume);
static std::unique_ptr<Sound> fromFile(const std::string &fileName, float volume);

virtual ~Sound() = default;

virtual bool isReady() const = 0;
[[nodiscard]] virtual bool isReady() const = 0;

virtual void unload() = 0;

Expand All @@ -39,19 +39,19 @@ namespace Raylib {

virtual void resume() const = 0;

virtual bool isPlaying() const = 0;
[[nodiscard]] virtual bool isPlaying() const = 0;

virtual void setVolume(float volume) const = 0;

virtual void setPitch(float pitch) const = 0;

virtual void setPan(float pan) const = 0;

virtual bool NeedToPlay() const = 0;
[[nodiscard]] virtual bool NeedToPlay() const = 0;

virtual void setNeedToPlay(bool needToPlay) = 0;

virtual const std::string &getPath() const = 0;
[[nodiscard]] virtual const std::string &getPath() const = 0;
};

class Music {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,24 @@ namespace Raylib {
default : return -1;
}
}

KeyboardKey Inputs::getRaylibKey(int equivalent)
{
for (int i = 0; i < static_cast<int>(KeyboardKey::KB_MAX_MAX); i++) {
if (equivalent == getEquivalentRaylibKey(static_cast<KeyboardKey>(i))) {
return static_cast<KeyboardKey>(i);
}
}
return KeyboardKey::KB_MAX_MAX;
}

MouseButton Inputs::getRaylibMouse(int equivalent)
{
for (int i = 0; i < static_cast<int>(MouseButton::MOUSE_MAX_MAX); i++) {
if (equivalent == getEquivalentRaylibMouse(static_cast<MouseButton>(i))) {
return static_cast<MouseButton>(i);
}
}
return MouseButton::MOUSE_MAX_MAX;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Raylib {

enum class KeyboardKey : int {
KB_NULL ,
KB_NULL = 0,
KB_APOSTROPHE ,
KB_COMMA ,
KB_MINUS ,
Expand Down Expand Up @@ -99,21 +99,25 @@ namespace Raylib {
KB_RIGHT_ALT ,
KB_RIGHT_SUPER ,
KB_MENU ,
KB_MAX_MAX ,
};

enum class MouseButton : int {
MOUSE_BTN_LEFT ,
MOUSE_BTN_LEFT = 0,
MOUSE_BTN_RIGHT ,
MOUSE_BTN_MIDDLE ,
MOUSE_BTN_SIDE ,
MOUSE_BTN_EXTRA ,
MOUSE_BTN_FORWARD ,
MOUSE_BTN_BACK ,
MOUSE_MAX_MAX ,
};

class Inputs {
public:
static int getEquivalentRaylibKey(KeyboardKey key);
static int getEquivalentRaylibMouse(MouseButton button);
static KeyboardKey getRaylibKey(int equivalent);
static MouseButton getRaylibMouse(int equivalent);
};
} // namespace Raylib
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extern "C" {
#include "raylib.h"
}
#include "RaylibImpl/Graphics/Graphics.hpp"
#include "B-luga-graphics/Raylib/Events/Inputs.hpp"
#include "Graphics.hpp"

namespace Raylib {
Expand Down Expand Up @@ -104,29 +105,35 @@ namespace Raylib {
TakeScreenshot(fileName.c_str());
}

// Collision check functions
bool checkCollisionPointRec(Vector2 point, Rectangle rec)
{
return (CheckCollisionPointRec({point.x, point.y}, {rec.x, rec.y, rec.width, rec.height}));
}

bool KeyboardInput::isKeyPressed(KeyboardKey key)
{
return IsKeyPressed(static_cast<int>(key));
return IsKeyPressed(static_cast<int>(Inputs::getEquivalentRaylibKey(key)));
}

bool KeyboardInput::isKeyDown(KeyboardKey key)
{
return IsKeyDown(static_cast<int>(key));
return IsKeyDown(static_cast<int>(Inputs::getEquivalentRaylibKey(key)));
}

bool KeyboardInput::isKeyReleased(KeyboardKey key)
{
return IsKeyReleased(static_cast<int>(key));
return IsKeyReleased(static_cast<int>(Inputs::getEquivalentRaylibKey(key)));
}

bool KeyboardInput::isKeyUp(KeyboardKey key)
{
return IsKeyUp(static_cast<int>(key));
return IsKeyUp(static_cast<int>(Inputs::getEquivalentRaylibKey(key)));
}

void KeyboardInput::setExitKey(KeyboardKey key)
{
SetExitKey(static_cast<int>(key));
SetExitKey(static_cast<int>(Inputs::getEquivalentRaylibKey(key)));
}

int KeyboardInput::getKeyPressed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <mutex>
#include <memory>
#include <string>
#include "B-luga-graphics/Raylib/Geometry/Geometry.hpp"
Expand Down Expand Up @@ -83,6 +84,8 @@ namespace Raylib {
static void takeScreenshot(const std::string &fileName);
};

bool checkCollisionPointRec(Vector2 point, Rectangle rec);

class KeyboardInput {
public:
static bool isKeyPressed(KeyboardKey key);
Expand Down Expand Up @@ -153,26 +156,47 @@ namespace Raylib {
static Color getColor(unsigned int hexValue);
};

class TextureManager {
public:
TextureManager(const TextureManager &) = delete;
TextureManager(TextureManager &&) = delete;
void operator=(const TextureManager &) = delete;
void operator=(TextureManager &&) = delete;

static TextureManager &getInstance();
~TextureManager();
::Texture2D &getTexture(const std::string &fileName);
void unloadTextures();

private:
TextureManager() = default;
std::map<std::string, ::Texture2D> _textures;
std::mutex _mutex;
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
static TextureManager _instance;
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
};

class RayImage {
public:
static std::unique_ptr<RayImage> fromFile(const std::string &fileName);
static std::unique_ptr<RayImage> fromColor(int width, int height, Color color);

virtual ~RayImage() = default;

virtual bool isImageReady() = 0;
[[nodiscard]] virtual bool isImageReady() = 0;

virtual void unloadImage() = 0;

virtual int getWidth() const = 0;
[[nodiscard]] virtual int getWidth() const = 0;

virtual int getHeight() const = 0;
[[nodiscard]] virtual int getHeight() const = 0;

virtual int getMipmaps() const = 0;
[[nodiscard]] virtual int getMipmaps() const = 0;

virtual int getFormat() const = 0;
[[nodiscard]] virtual int getFormat() const = 0;

virtual void *getData() = 0;
[[nodiscard]] virtual void *getData() = 0;
};

class Sprite {
Expand All @@ -182,19 +206,17 @@ namespace Raylib {

virtual ~Sprite() = default;

virtual void unloadSprite() = 0;

virtual unsigned int getId() const = 0;
[[nodiscard]] virtual unsigned int getId() const = 0;

virtual float getWidth() const = 0;
[[nodiscard]] virtual float getWidth() const = 0;

virtual float getHeight() const = 0;
[[nodiscard]] virtual float getHeight() const = 0;

virtual int getTextureWidth() const = 0;
[[nodiscard]] virtual int getTextureWidth() const = 0;

virtual int getTextureHeight() const = 0;
[[nodiscard]] virtual int getTextureHeight() const = 0;

virtual int getMipmaps() const = 0;
[[nodiscard]] virtual int getMipmaps() const = 0;

virtual int getFormat() const = 0;

Expand Down Expand Up @@ -290,21 +312,21 @@ namespace Raylib {

virtual void drawPro(Vector2 origin, float rotation, float spacing) = 0;

virtual float x() const = 0;
[[nodiscard] virtual float x() const = 0;

virtual float y() const = 0;
[[nodiscard] virtual float y() const = 0;

virtual float getFontSize() const = 0;
[[nodiscard] virtual float getFontSize() const = 0;

virtual void setFontSize(float fontSize) = 0;

virtual Vector2 getPosition() const = 0;
[[nodiscard] virtual Vector2 getPosition() const = 0;

virtual void setPixelPosition(Vector2 position) = 0;

virtual void setColor(Color color) = 0;

virtual Color getColor() const = 0;
[[nodiscard] virtual Color getColor() const = 0;

virtual void setCurrentFontSize(float fontSize) = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ static void unloadMusic(std::size_t id)
}
}

static void unloadSprite(std::size_t id)
{
Registry::components<Raylib::SpriteShared> arrSprite =
Registry::getInstance().getComponents<Raylib::SpriteShared>();

if (arrSprite.exist(id)) {
arrSprite[id]->unloadSprite();
}
}

static void unloadImage(std::size_t id)
{
Registry::components<Raylib::RayImageShared> arrImage = Registry::getInstance().getComponents<Raylib::RayImageShared>();
Expand All @@ -51,6 +41,5 @@ void UnloadRaylib::unloadRaylibComponents(std::size_t id)
{
unloadSounds(id);
unloadMusic(id);
unloadSprite(id);
unloadImage(id);
}
Loading

0 comments on commit 589d1b1

Please sign in to comment.