Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ We also have a pr check for clippy and fmt, so if it fails, please use
### To run in debug mode with the wiz_debug feature enabled, run
`cargo run --features wiz_debug`
This will allow you to start the game with 1 player.

### build.sh usage
- Allows building release executable files for windows/linux/mac with `./build.sh -t <target>`, also allows to build with a `wiz_debug` feature flag with `./build.sh -t <target> -f`
- To build you would need to install targets first
- To correctly copy the assets, you would need to run the script from the root of the project
- The script copies the needed files as a release in your specified folder (in `DEST_PATH`)
59 changes: 59 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

TARGET="linux"
DEST_PATH="/mnt/c/Users/capos/Downloads"
BUILD_TYPE="release"
FEATURES=""

while getopts "t:fh" opt; do
case $opt in
t)
TARGET="$OPTARG"
;;
f)
FEATURES="wiz_debug $FEATURES"
;;
h)
echo "Usage: $0 [options]"
echo "Options:"
echo " -t <target> Build target (windows, linux, macos) [default: windows]"
echo " -f Enable debug features"
echo " -h Show help"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done

case $TARGET in
windows)
TARGET_NAME="x86_64-pc-windows-gnu"
EXE_EXT=".exe"
;;
linux)
TARGET_NAME="x86_64-unknown-linux-gnu"
EXE_EXT=""
;;
macos)
TARGET_NAME="aarch64-apple-darwin"
EXE_EXT=""
;;
*)
echo "Unknown target: $TARGET"
echo "Available targets: windows, linux, macos"
exit 1
;;
esac

BUILD_CMD="cargo build --target $TARGET_NAME --release"
if [ -n "$FEATURES" ]; then
BUILD_CMD="$BUILD_CMD --features $FEATURES"
fi


$BUILD_CMD && \
cp "target/$TARGET_NAME/$BUILD_TYPE/wizard$EXE_EXT" "$DEST_PATH/" && \
cp assets/ "$DEST_PATH/" -r
8 changes: 4 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub enum B {
RoundStarted {
round: usize,
cards_per_player: usize,
trump: Option<Suit>,
trump: Option<Card>,
},
DealerMustSetTrump {
dealer: PlayerId,
Expand Down Expand Up @@ -130,7 +130,7 @@ pub enum B {
ServerShutdown,
}

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub struct Card {
pub value: Value,
pub suit: Suit,
Expand All @@ -142,15 +142,15 @@ impl Card {
}
}

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, EnumIter)]
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, Hash, EnumIter)]
pub enum Suit {
Red,
Yellow,
Green,
Blue,
}

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, EnumIter)]
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, Hash, EnumIter)]
pub enum Value {
Jester,
Number(u8), // 1-13
Expand Down
57 changes: 55 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use crate::client::views::Button;
use crate::gameplay_ui::hand::{HandMessage, ViewableHand};
use crate::gameplay_ui::table::{TableMessage, ViewableTable};
use crate::ui_element_traits::Message;
use iced::{time, window, Size, Subscription, Task};
use iced::{time, widget::image, window, Size, Subscription, Task};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use strum::IntoEnumIterator;

pub use update::update;
pub use views::view;
Expand Down Expand Up @@ -92,7 +93,7 @@ pub struct App {
pub game_log: Vec<String>,
pub hand: Vec<Card>,
pub current_trick: Vec<(PlayerId, Card)>,
pub trump: Option<Suit>,
pub trump: Option<Card>,
pub round_number: usize,
pub is_my_turn: bool,
pub is_bidding_phase: bool,
Expand Down Expand Up @@ -127,6 +128,16 @@ pub struct App {
pub btn_back_to_menu: crate::client::views::Button,

pub btn_ready_owned: crate::client::views::Button,
pub btn_submit_bid: crate::client::views::Button,

pub img_main_menu: image::Handle,
pub img_lobby_menu: image::Handle,
pub img_background: image::Handle,
pub img_ingame_background: image::Handle,
pub img_menu_container: image::Handle,

#[allow(dead_code)]
pub card_images: HashMap<Card, image::Handle>,
}

impl Default for App {
Expand Down Expand Up @@ -195,7 +206,49 @@ impl Default for App {
btn_back_to_menu: Button::new_back_to_menu_button(15, 160, 40),

btn_ready_owned: Button::new_ready_owned_button(20, 100, 36),
btn_submit_bid: Button::new_submit_bid_button(21, 110, 36),

img_main_menu: image::Handle::from_path("assets/wizard_main_menu.png"),
img_lobby_menu: image::Handle::from_path("assets/wizard_lobby_menu.png"),
img_background: image::Handle::from_path("assets/background_forall.png"),
img_ingame_background: image::Handle::from_path("assets/ingame_background.png"),
img_menu_container: image::Handle::from_path("assets/menu_container.png"),

card_images: Self::preload_card_images(),
}
}
}

impl App {
fn preload_card_images() -> HashMap<Card, image::Handle> {
let mut map = HashMap::new();

map.insert(
Card::new(Suit::Red, crate::api::Value::Jester),
image::Handle::from_path("assets/cards/variations/jester.png"),
);
map.insert(
Card::new(Suit::Red, crate::api::Value::Wizard),
image::Handle::from_path("assets/cards/variations/wizard.png"),
);

for suit in Suit::iter() {
for num in 1..=13 {
let card = Card::new(suit, crate::api::Value::Number(num));
let path = crate::api::get_card_path(card);
map.insert(card, image::Handle::from_path(path));
}
}

map
}

#[allow(dead_code)]
pub fn get_card_image(&self, card: Card) -> image::Handle {
self.card_images.get(&card).cloned().unwrap_or_else(|| {
//just in case
image::Handle::from_path(crate::api::get_card_path(card))
})
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/client/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;
use super::{connect_ws, App, AppMessage, MenuState, PlayerCount};
use crate::api::{Card, Lobby, PlayerId, ServerMessage, Value, B, C, S};
use crate::client::TaskBatcher;
use crate::gameplay_ui::hand::ViewableHand;
use crate::ui_element_traits::{Animated, Notifiable, Resizable};

/// Get player name from ID using lobby data
Expand Down Expand Up @@ -304,7 +305,8 @@ pub fn update(state: &mut App, msg: AppMessage) -> Task<AppMessage> {
state.btn_send_chat.update_with_msg(btn_msg.clone()),
state.btn_start_game.update_with_msg(btn_msg.clone()),
state.btn_back_to_menu.update_with_msg(btn_msg.clone()),
state.btn_ready_owned.update_with_msg(btn_msg),
state.btn_ready_owned.update_with_msg(btn_msg.clone()),
state.btn_submit_bid.update_with_msg(btn_msg.clone()),
]);
}
AppMessage::AnimationTick => {
Expand All @@ -323,6 +325,7 @@ pub fn update(state: &mut App, msg: AppMessage) -> Task<AppMessage> {
state.btn_start_game.update_animations(),
state.btn_back_to_menu.update_animations(),
state.btn_ready_owned.update_animations(),
state.btn_submit_bid.update_animations(),
]);
}
AppMessage::WindowResized(window_size) => {
Expand Down Expand Up @@ -403,7 +406,15 @@ fn handle_server_message(state: &mut App, msg: ServerMessage) {
}
state.game_log.push(log.clone());
state.last_msg = log;
state.hand = cards;
state.hand = cards.clone();

// Create viewable cards with preloaded images
let viewable_cards = ViewableHand::create_viewable_cards_static(
&cards,
&state.valid_cards,
state.window_size,
);
state.viewable_hand.set_cards(viewable_cards);
}
S::TrumpRequest => {
let log = "[SERVER] You must set the trump suit!".to_string();
Expand Down Expand Up @@ -548,7 +559,10 @@ fn handle_server_message(state: &mut App, msg: ServerMessage) {
println!("{}", log);
state.game_log.push(log.clone());
state.last_msg = log;
state.trump = Some(suit);
state.trump = Some(Card {
suit,
value: Value::Number(1),
});
state.must_set_trump = false;
}
B::BiddingStarted {
Expand Down
11 changes: 11 additions & 0 deletions src/client/views/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ impl Button {
)
}

pub fn new_submit_bid_button(id: usize, width: u16, height: u16) -> Self {
Self::new(
id,
"Bet",
BUTTON1_PATH,
width,
height,
AppMessage::SubmitBid,
)
}

pub fn set_on_click(&mut self, on_click: AppMessage) {
self.on_click = on_click;
}
Expand Down
Loading