diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-20 13:01:14 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-21 23:38:18 +0200 |
commit | 3e47eec862ef9cdead4405e4b426417c497e3aa0 (patch) | |
tree | bfb697f67df894faf2e4b421faff7d7c7c0ee5bc | |
parent | 9440a3c280fbdfb32b6311a3a880384dca207579 (diff) | |
download | serenity-3e47eec862ef9cdead4405e4b426417c497e3aa0.zip |
Solitaire: Move cards functionality into LibCards
-rw-r--r-- | Base/res/icons/cards/buggie-deck.png (renamed from Base/res/icons/solitaire/buggie-deck.png) | bin | 5505 -> 5505 bytes | |||
-rw-r--r-- | Userland/Games/Solitaire/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Userland/Games/Solitaire/Game.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibCards/CMakeLists.txt | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibCards/Card.cpp (renamed from Userland/Games/Solitaire/Card.cpp) | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibCards/Card.h (renamed from Userland/Games/Solitaire/Card.h) | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibCards/CardStack.cpp (renamed from Userland/Games/Solitaire/CardStack.cpp) | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibCards/CardStack.h (renamed from Userland/Games/Solitaire/CardStack.h) | 16 |
9 files changed, 32 insertions, 23 deletions
diff --git a/Base/res/icons/solitaire/buggie-deck.png b/Base/res/icons/cards/buggie-deck.png Binary files differindex d08bb9e5f0..d08bb9e5f0 100644 --- a/Base/res/icons/solitaire/buggie-deck.png +++ b/Base/res/icons/cards/buggie-deck.png diff --git a/Userland/Games/Solitaire/CMakeLists.txt b/Userland/Games/Solitaire/CMakeLists.txt index 059356c3a9..084c776d24 100644 --- a/Userland/Games/Solitaire/CMakeLists.txt +++ b/Userland/Games/Solitaire/CMakeLists.txt @@ -1,12 +1,10 @@ compile_gml(Solitaire.gml SolitaireGML.h solitaire_gml) set(SOURCES - Card.cpp - CardStack.cpp Game.cpp main.cpp SolitaireGML.h ) serenity_app(Solitaire ICON app-solitaire) -target_link_libraries(Solitaire LibGUI LibGfx LibCore) +target_link_libraries(Solitaire LibCards LibGUI LibGfx LibCore) diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h index 24c1bfab05..fba4c1a39a 100644 --- a/Userland/Games/Solitaire/Game.h +++ b/Userland/Games/Solitaire/Game.h @@ -6,10 +6,13 @@ #pragma once -#include "CardStack.h" +#include <LibCards/CardStack.h> #include <LibGUI/Frame.h> #include <LibGUI/Painter.h> +using Cards::Card; +using Cards::CardStack; + namespace Solitaire { enum class Mode : u8 { diff --git a/Userland/Libraries/CMakeLists.txt b/Userland/Libraries/CMakeLists.txt index 548498ba85..99b72d1b0a 100644 --- a/Userland/Libraries/CMakeLists.txt +++ b/Userland/Libraries/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(LibArchive) add_subdirectory(LibAudio) add_subdirectory(LibC) +add_subdirectory(LibCards) add_subdirectory(LibChess) add_subdirectory(LibCompress) add_subdirectory(LibCore) diff --git a/Userland/Libraries/LibCards/CMakeLists.txt b/Userland/Libraries/LibCards/CMakeLists.txt new file mode 100644 index 0000000000..b9a6084719 --- /dev/null +++ b/Userland/Libraries/LibCards/CMakeLists.txt @@ -0,0 +1,7 @@ +set(SOURCES + Card.cpp + CardStack.cpp +) + +serenity_lib(LibCards cards) +target_link_libraries(LibCards LibC LibCore) diff --git a/Userland/Games/Solitaire/Card.cpp b/Userland/Libraries/LibCards/Card.cpp index 122abd6c14..ff39c57f2e 100644 --- a/Userland/Games/Solitaire/Card.cpp +++ b/Userland/Libraries/LibCards/Card.cpp @@ -9,7 +9,7 @@ #include <LibGfx/Font.h> #include <LibGfx/FontDatabase.h> -namespace Solitaire { +namespace Cards { static const NonnullRefPtr<Gfx::CharacterBitmap> s_diamond = Gfx::CharacterBitmap::create_from_ascii( " # " @@ -75,7 +75,7 @@ Card::Card(Type type, uint8_t value) Gfx::Painter bg_painter(*s_background); s_background->fill(Color::White); - auto image = Gfx::Bitmap::load_from_file("/res/icons/solitaire/buggie-deck.png"); + auto image = Gfx::Bitmap::load_from_file("/res/icons/cards/buggie-deck.png"); VERIFY(!image.is_null()); float aspect_ratio = image->width() / static_cast<float>(image->height()); diff --git a/Userland/Games/Solitaire/Card.h b/Userland/Libraries/LibCards/Card.h index a63c39749e..7c2fe41d0a 100644 --- a/Userland/Games/Solitaire/Card.h +++ b/Userland/Libraries/LibCards/Card.h @@ -15,7 +15,7 @@ #include <LibGfx/Rect.h> #include <ctype.h> -namespace Solitaire { +namespace Cards { class Card final : public Core::Object { C_OBJECT(Card) @@ -74,28 +74,28 @@ private: } template<> -struct AK::Formatter<Solitaire::Card> : Formatter<FormatString> { - void format(FormatBuilder& builder, const Solitaire::Card& card) +struct AK::Formatter<Cards::Card> : Formatter<FormatString> { + void format(FormatBuilder& builder, const Cards::Card& card) { StringView type; switch (card.type()) { - case Solitaire::Card::Type::Clubs: + case Cards::Card::Type::Clubs: type = "C"sv; break; - case Solitaire::Card::Type::Diamonds: + case Cards::Card::Type::Diamonds: type = "D"sv; break; - case Solitaire::Card::Type::Hearts: + case Cards::Card::Type::Hearts: type = "H"sv; break; - case Solitaire::Card::Type::Spades: + case Cards::Card::Type::Spades: type = "S"sv; break; default: VERIFY_NOT_REACHED(); } - Formatter<FormatString>::format(builder, "{:>2}{}", Solitaire::Card::labels[card.value()], type); + Formatter<FormatString>::format(builder, "{:>2}{}", Cards::Card::labels[card.value()], type); } }; diff --git a/Userland/Games/Solitaire/CardStack.cpp b/Userland/Libraries/LibCards/CardStack.cpp index 375264f226..5d62397fbe 100644 --- a/Userland/Games/Solitaire/CardStack.cpp +++ b/Userland/Libraries/LibCards/CardStack.cpp @@ -6,7 +6,7 @@ #include "CardStack.h" -namespace Solitaire { +namespace Cards { CardStack::CardStack() : m_position({ 0, 0 }) diff --git a/Userland/Games/Solitaire/CardStack.h b/Userland/Libraries/LibCards/CardStack.h index 2686bce8a4..36acc824df 100644 --- a/Userland/Games/Solitaire/CardStack.h +++ b/Userland/Libraries/LibCards/CardStack.h @@ -10,7 +10,7 @@ #include <AK/Format.h> #include <AK/Vector.h> -namespace Solitaire { +namespace Cards { class CardStack final { public: @@ -88,25 +88,25 @@ private: } template<> -struct AK::Formatter<Solitaire::CardStack> : Formatter<FormatString> { - void format(FormatBuilder& builder, const Solitaire::CardStack& stack) +struct AK::Formatter<Cards::CardStack> : Formatter<FormatString> { + void format(FormatBuilder& builder, const Cards::CardStack& stack) { StringView type; switch (stack.type()) { - case Solitaire::CardStack::Type::Stock: + case Cards::CardStack::Type::Stock: type = "Stock"sv; break; - case Solitaire::CardStack::Type::Normal: + case Cards::CardStack::Type::Normal: type = "Normal"sv; break; - case Solitaire::CardStack::Type::Foundation: + case Cards::CardStack::Type::Foundation: type = "Foundation"sv; break; - case Solitaire::CardStack::Type::Waste: + case Cards::CardStack::Type::Waste: type = "Waste"sv; break; - case Solitaire::CardStack::Type::Play: + case Cards::CardStack::Type::Play: type = "Play"sv; break; default: |