Skip to content

Commit

Permalink
highlighting looks okay
Browse files Browse the repository at this point in the history
  • Loading branch information
r3w0p committed May 30, 2024
1 parent b5a76f8 commit 778ef4d
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 54 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ jobs:
strategy:
matrix:
include:
- name: Linux GCC
- name: Linux GCC x64
os: ubuntu-latest
compiler_cc: gcc
compiler_cpp: g++
asset: caravan_linux_x64

steps:
- name: Checkout
Expand All @@ -37,10 +38,10 @@ jobs:

- name: Rename Executable
working-directory: ./build
run: mv caravan caravan_linux_x64
run: mv caravan ${{matrix.asset}}

- name: Upload Executable to Release
uses: AButler/[email protected]
with:
files: ./build/caravan_linux_x64
files: ./build/${{matrix.asset}}
repo-token: ${{ secrets.GITHUB_TOKEN }}
27 changes: 12 additions & 15 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
name: MacOS

#on:
# release:
# types: [ created ]

on:
push:
branches: [ "1.2.0" ]
release:
types: [ created ]

env:
BUILD_TYPE: Release
Expand All @@ -18,10 +14,11 @@ jobs:
strategy:
matrix:
include:
- name: MacOS Clang
- name: MacOS Clang x64
os: macos-latest
compiler_cc: clang
compiler_cpp: clang++
asset: caravan_macos_x64

steps:
- name: Checkout
Expand All @@ -39,12 +36,12 @@ jobs:
- name: CMake Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target caravan

#- name: Rename Executable
# working-directory: ./build
# run: mv caravan caravan_macos_x64
- name: Rename Executable
working-directory: ./build
run: mv caravan ${{matrix.asset}}

#- name: Upload Executable to Release
# uses: AButler/[email protected]
# with:
# files: ./build/caravan_macos_x64
# repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Executable to Release
uses: AButler/[email protected]
with:
files: ./build/${{matrix.asset}}
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
include:
- name: Linux GCC
- name: Linux GCC x64
os: ubuntu-latest
compiler_cc: gcc
compiler_cpp: g++
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ jobs:
strategy:
matrix:
include:
- name: Windows GCC
- name: Windows GCC x64
os: windows-latest
compiler_cc: gcc
compiler_cpp: g++
asset: caravan_windows_x64.exe

steps:
- name: Checkout
Expand All @@ -37,10 +38,10 @@ jobs:

- name: Rename Executable
working-directory: ./build
run: mv caravan.exe caravan_windows_x64.exe
run: mv caravan.exe ${{matrix.asset}}

- name: Upload Executable to Release
uses: AButler/[email protected]
with:
files: ./build/caravan_windows_x64.exe
files: ./build/${{matrix.asset}}
repo-token: ${{ secrets.GITHUB_TOKEN }}
48 changes: 32 additions & 16 deletions src/caravan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@

const std::string OPTS_HELP = "h,help";
const std::string OPTS_VERSION = "v,version";
const std::string OPTS_PVP = "pvp";
const std::string OPTS_BVB = "bvb";
const std::string OPTS_BOT = "b,bot";
const std::string OPTS_DELAY = "d,delay";
const std::string OPTS_FIRST = "f,first";
const std::string OPTS_CARDS = "c,cards";
const std::string OPTS_SAMPLES = "s,samples";
const std::string OPTS_IMBALANCED = "i,imbalanced";

const std::string KEY_HELP = "help";
const std::string KEY_VERSION = "version";
const std::string KEY_PVP = "pvp";
const std::string KEY_BVB = "bvb";
const std::string KEY_BOT = "bot";
const std::string KEY_DELAY = "delay";
const std::string KEY_FIRST = "first";
const std::string KEY_CARDS = "cards";
const std::string KEY_SAMPLES = "samples";
const std::string KEY_IMBALANCED = "imbalanced";

const uint8_t FIRST_ABC = 1;
const uint8_t FIRST_DEF = 2;
Expand All @@ -29,14 +45,14 @@ int main(int argc, char *argv[]) {
options.add_options()
(OPTS_HELP, "Print help instructions.")
(OPTS_VERSION, "Print software version.")
("pvp", "A Player vs Player game.")
("bvb", "A Bot vs Bot game.")
("b,bot", "Which bot to play with (normal, friendly).", cxxopts::value<std::string>()->default_value("normal"))
("d,delay", "Delay before bot makes its move (in seconds).", cxxopts::value<float>()->default_value("1.0"))
("f,first", "Which player goes first (1 or 2).", cxxopts::value<uint8_t>()->default_value("1"))
("c,cards", "Number of cards for each caravan deck (30-162, inclusive).", cxxopts::value<uint8_t>()->default_value("54"))
("s,samples", "Number of traditional decks to sample when building caravan decks (1-3, inclusive).", cxxopts::value<uint8_t>()->default_value("1"))
("i,imbalanced",
(OPTS_PVP, "A Player vs Player game.")
(OPTS_BVB, "A Bot vs Bot game.")
(OPTS_BOT, "Which bot to play with (normal, friendly).", cxxopts::value<std::string>()->default_value("normal"))
(OPTS_DELAY, "Delay before bot makes its move (in seconds).", cxxopts::value<float>()->default_value("1.0"))
(OPTS_FIRST, "Which player goes first (1 or 2).", cxxopts::value<uint8_t>()->default_value("1"))
(OPTS_CARDS, "Number of cards for each caravan deck (30-162, inclusive).", cxxopts::value<uint8_t>()->default_value("54"))
(OPTS_SAMPLES, "Number of traditional decks to sample when building caravan decks (1-3, inclusive).", cxxopts::value<uint8_t>()->default_value("1"))
(OPTS_IMBALANCED,
"An imbalanced caravan deck is built by taking as many "
"cards from one shuffled sample deck before moving to the next. "
"A balanced deck randomly samples cards across all sample decks.")
Expand All @@ -59,14 +75,14 @@ int main(int argc, char *argv[]) {
exit(EXIT_SUCCESS);
}

bool pvp = result["pvp"].as<bool>();
bool bots = result["bvb"].as<bool>();
std::string bot = result["bot"].as<std::string>();
float delay = result["delay"].as<float>();
uint8_t first = result["first"].as<uint8_t>();
uint8_t cards = result["cards"].as<uint8_t>();
uint8_t samples = result["samples"].as<uint8_t>();
bool imbalanced = result["imbalanced"].as<bool>();
bool pvp = result[KEY_PVP].as<bool>();
bool bots = result[KEY_BVB].as<bool>();
std::string bot = result[KEY_BOT].as<std::string>();
float delay = result[KEY_DELAY].as<float>();
uint8_t first = result[KEY_FIRST].as<uint8_t>();
uint8_t cards = result[KEY_CARDS].as<uint8_t>();
uint8_t samples = result[KEY_SAMPLES].as<uint8_t>();
bool imbalanced = result[KEY_IMBALANCED].as<bool>();

if (pvp && bots) {
printf("Game cannot be both Player vs Player and Bot vs Bot.\n");
Expand Down
62 changes: 46 additions & 16 deletions src/caravan/view/view_tui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ void push_card(ViewConfig *vc, ftxui::Elements *e, Card card, bool lead) {
using namespace ftxui;

if (card.rank == JOKER) {
// Push lead then "JO" to compensate for lack of suit
if(lead) { e->push_back(text(L" ")); }
e->push_back(text(rank_to_wstr(card.rank, lead)));
e->push_back(text(rank_to_wstr(card.rank, lead)) | color(Color::Default));

} else {
e->push_back(text(rank_to_wstr(card.rank, lead)));
// Push rank then suit
e->push_back(text(rank_to_wstr(card.rank, lead)) | color(Color::Default));
e->push_back(suit_to_text(vc, card.suit));
}
}
Expand Down Expand Up @@ -415,7 +417,7 @@ GameCommand ViewTUI::parse_user_input(std::string input, bool confirmed) {

std::shared_ptr<ftxui::Node> gen_position(uint8_t position, bool blank = false) {
using namespace ftxui;
return text(blank ? "" : std::to_string(position)) | borderEmpty | size(WIDTH, EQUAL, WIDTH_POSITION) | size(HEIGHT, EQUAL, HEIGHT_POSITION);
return text(blank ? "" : std::to_string(position)) | borderEmpty | color(Color::Default) | size(WIDTH, EQUAL, WIDTH_POSITION) | size(HEIGHT, EQUAL, HEIGHT_POSITION);
}

std::shared_ptr<ftxui::Node> gen_position_blank() {
Expand All @@ -440,7 +442,7 @@ std::shared_ptr<ftxui::Node> gen_card(ViewConfig *vc, Card card, bool hide, bool
if(blank) {
ret = ret | borderEmpty;
} else if(highlight) {
ret = ret | borderHeavy | (vc->colour ? color(Color::Palette16::YellowLight) : color(Color::Default));
ret = ret | borderHeavy | (vc->colour ? color(Color::Palette16::MagentaLight) : color(Color::Default));
} else {
ret = ret | borderDouble;
}
Expand Down Expand Up @@ -476,9 +478,9 @@ std::shared_ptr<ftxui::Node> gen_faces(ViewConfig *vc, Slot slot, bool blank = f
}

return vbox({
text(ranks),
hbox(suits)
}) | borderEmpty | size(WIDTH, EQUAL, WIDTH_FACES) | size(HEIGHT, EQUAL, HEIGHT_FACES);
text(ranks) | color(Color::Default),
hbox(suits)
}) | borderEmpty | size(WIDTH, EQUAL, WIDTH_FACES) | size(HEIGHT, EQUAL, HEIGHT_FACES);
}

std::shared_ptr<ftxui::Node> gen_faces_blank() {
Expand All @@ -487,11 +489,23 @@ std::shared_ptr<ftxui::Node> gen_faces_blank() {

std::shared_ptr<ftxui::Node> gen_caravan_slot(ViewConfig *vc, uint8_t position, Slot slot, bool highlight, bool blank = false) {
using namespace ftxui;
return hbox({
blank ? gen_position_blank() : gen_position(position),
blank ? gen_card_blank() : gen_card(vc, slot.card, false, highlight),
blank ? gen_faces_blank() : gen_faces(vc, slot),
}) | hcenter | size(WIDTH, EQUAL, WIDTH_CARAVAN_SLOT) | size(HEIGHT, EQUAL, HEIGHT_CARAVAN_SLOT);
std::shared_ptr<Node> ret;
Elements e;
e.push_back(blank ? gen_position_blank() : gen_position(position));

if(blank) {
e.push_back(gen_card_blank());
} else if(highlight) {
e.push_back(gen_card(vc, slot.card, false, highlight));
} else {
e.push_back(gen_card(vc, slot.card, false, highlight) | color(Color::Default));
}

e.push_back(blank ? gen_faces_blank() : gen_faces(vc, slot));

ret = hbox(e) | hcenter | size(WIDTH, EQUAL, WIDTH_CARAVAN_SLOT) | size(HEIGHT, EQUAL, HEIGHT_CARAVAN_SLOT);

return ret;
}

std::shared_ptr<ftxui::Node> gen_caravan_slot_blank() {
Expand All @@ -500,6 +514,7 @@ std::shared_ptr<ftxui::Node> gen_caravan_slot_blank() {

std::shared_ptr<ftxui::Node> gen_caravan(ViewConfig *vc, Game *game, CaravanName cn, bool top) {
using namespace ftxui;
std::shared_ptr<Node> ret;
std::shared_ptr<Node> content;
Elements e;
Elements title;
Expand All @@ -511,7 +526,11 @@ std::shared_ptr<ftxui::Node> gen_caravan(ViewConfig *vc, Game *game, CaravanName
if ((top && (TRACK_NUMERIC_MAX - i) <= caravan_size) || (!top && i + 1 <= caravan_size)) {
uint8_t position = top ? TRACK_NUMERIC_MAX - i : i + 1;

bool highlight = false; // TODO
// Highlight caravan slot if selected for placement of face card
bool highlight =
vc->highlight.option != NO_OPTION &&
vc->highlight.caravan_name == cn &&
vc->highlight.pos_caravan == position;

e.push_back(gen_caravan_slot(vc, position, caravan->get_slot(position), highlight));

Expand Down Expand Up @@ -550,10 +569,21 @@ std::shared_ptr<ftxui::Node> gen_caravan(ViewConfig *vc, Game *game, CaravanName
title.push_back(text(L" "));
}

return window(
ret = window(
hbox({title}) | hcenter | bold,
content
) | center | size(WIDTH, EQUAL, WIDTH_CARAVAN) | size(HEIGHT, EQUAL, HEIGHT_CARAVAN);

// Highlight card if caravan selected in unconfirmed command
bool highlight =
vc->highlight.option != NO_OPTION &&
vc->highlight.caravan_name == cn;

if(highlight) {
ret = ret | (vc->colour ? color(Color::Palette16::MagentaLight) : color(Color::Default));
}

return ret;
}

std::shared_ptr<ftxui::Node> gen_deck_card(ViewConfig *vc, Game *game, uint8_t position, Card card, bool hide, bool highlight, bool blank = false) {
Expand Down Expand Up @@ -615,10 +645,10 @@ std::shared_ptr<ftxui::Node> gen_deck(ViewConfig *vc, Game *game, bool top) {
Card card = player_this->get_hand()[position - 1];

// Highlight card if it is this player's turn and unconfirmed
// command wants to play or discard this card
// command wants to use this hand card
bool highlight =
vc->user_turn->get_name() == player_this->get_name() &&
vc->highlight.option == OPTION_DISCARD &&
vc->highlight.option != NO_OPTION &&
vc->highlight.pos_hand == position;

e.push_back(gen_deck_card(vc, game, position, card, hide, highlight));
Expand Down

0 comments on commit 778ef4d

Please sign in to comment.