Brunot
Loading...
Searching...
No Matches
Player.h
Go to the documentation of this file.
1
12// ____ __ __ __
13// /\__ _\/\ \ /\ \/\ \
14// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
15// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
16// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
17// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
18// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
19#pragma once
20
21#include "Framework/Component.h"
22#include "Component/Card.h"
23#include "Deck.h"
24#include <vector>
25
30class Player : public Component
31{
32public:
33 static auto bindLuaTypes(sol::state& lua) -> void;
34 static auto getEnum() -> ComponentTypeEnum
35 {
36 return cPlayer;
37 }
38 Player();
39 Player(const Player& other) = default;
40 Player(Player&& other) noexcept = default;
41 ~Player() override = default;
42
43 auto operator=(const Player& other) -> Player& = default;
44 auto operator=(Player&& other) -> Player& = default;
45
46 auto clone() const -> std::unique_ptr<GameObject> override;
47
48 auto onUpdate(float dt) -> void override;
49 auto onRender() -> void override;
50 auto componentShowMenu() -> void override;
51
52 auto onEnterEngine() -> void override;
53 auto endWindow() -> void override
54 {
55 } // for debug ImGUI
56 auto load(const Stream& stream) -> void override;
57 auto save(Stream& stream) const -> void override;
58
59 friend auto to_json(json& j, const Player& p) -> void;
60 friend auto from_json(const json& j, Player& p) -> void;
61
69 auto addCardToHand(std::unique_ptr<Card> drawnCard) -> Entity*;
70
80 auto moveCardToHand(std::unique_ptr<Card> drawnCard) -> void;
81
89 auto fillHand(Deck* deck, float drawDuration, float initialDelay) -> void;
90
96 auto drawCardToHand(Deck* deck, float drawDuration) -> void;
97
99 auto getNumberOfCardsInHand() const -> int;
100
102 auto clearHand() -> void;
103
105 auto decrementNumberOfCards() -> void;
106
108 auto hasCards() const -> bool;
109
111 auto getMaxCards() const -> int;
112
114 auto getFirstCard() -> Entity*;
115
117 auto getLastCard() -> Entity*;
118
119private:
120
126 auto createCardToMenu(std::unique_ptr<Card> cardToAdd) -> Entity*;
127
129 auto addCardLua(std::unique_ptr<Card>& drawnCard) -> void;
130
133
136
137};
sys::Json Stream
Definition AudioObject.h:20
The card component that is moved around on the board.
The base class for components, holding all of their shared All components should inherit from this.
Component that represents a deck of playing cards.
nlohmann::json json
Definition Json.cpp:19
Definition Card.h:34
ComponentTypeEnum
This enum lists out every type of component we have.
Definition Component.h:39
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
Component that represents a deck of playing cards.
Definition Deck.h:31
Definition Entity.h:41
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
The component responsible for storing information relevant to the player.
Definition Player.h:31
auto decrementNumberOfCards() -> void
Public function so Table can tell the player when they lose a card.
Definition Player.cpp:290
auto fillHand(Deck *deck, float drawDuration, float initialDelay) -> void
Draws cards from the deck until the hand is full or until the deck is empty.
Definition Player.cpp:164
~Player() override=default
auto drawCardToHand(Deck *deck, float drawDuration) -> void
Draws a single card from the deck and adds it to the hand.
Definition Player.cpp:215
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Player.cpp:87
auto componentShowMenu() -> void override
Definition Player.cpp:112
static auto getEnum() -> ComponentTypeEnum
Definition Player.h:34
auto hasCards() const -> bool
Returns if the player has any cards in their hand or not.
Definition Player.cpp:295
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Player.cpp:82
static auto bindLuaTypes(sol::state &lua) -> void
Definition Player.cpp:51
auto moveCardToHand(std::unique_ptr< Card > drawnCard) -> void
Creates a card entity and adds it to the hand.
Definition Player.cpp:136
auto addCardToHand(std::unique_ptr< Card > drawnCard) -> Entity *
Creates a card entity and adds it to the hand, but does not visually move it You would want to use th...
Definition Player.cpp:131
auto operator=(const Player &other) -> Player &=default
auto createCardToMenu(std::unique_ptr< Card > cardToAdd) -> Entity *
Actually handles the logic of adding a card to the player's hand.
Definition Player.cpp:319
int maxNumberOfCards
The maximum number of cards the player can hold.
Definition Player.h:135
auto getLastCard() -> Entity *
Returns the first card Entity in the players hand.
Definition Player.cpp:311
auto getNumberOfCardsInHand() const -> int
Returns the number of cards the player is holding.
Definition Player.cpp:267
auto getFirstCard() -> Entity *
Returns the first card Entity in the players hand.
Definition Player.cpp:305
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Player.h:53
Player(const Player &other)=default
auto clearHand() -> void
Gets rid of all the cards in the players hand.
Definition Player.cpp:272
int numberOfCardsInHand
The number of cards the player is holding.
Definition Player.h:132
auto getMaxCards() const -> int
Returns the max number cards the player can hold in their hand.
Definition Player.cpp:300
auto addCardLua(std::unique_ptr< Card > &drawnCard) -> void
wrapper around addCard so that it can be bound to lua
Definition Player.cpp:262
auto onUpdate(float dt) -> void override
called once every frame.
Definition Player.cpp:78
friend auto to_json(json &j, const Player &p) -> void
Definition Player.cpp:98
Player(Player &&other) noexcept=default
auto operator=(Player &&other) -> Player &=default
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Player.cpp:121
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Player.cpp:92
friend auto from_json(const json &j, Player &p) -> void
Definition Player.cpp:106
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Player.cpp:73
Player()
Definition Player.cpp:63