diff --git a/card_stuffs/src/lib.rs b/card_stuffs/src/lib.rs index b3090fc..1786130 100644 --- a/card_stuffs/src/lib.rs +++ b/card_stuffs/src/lib.rs @@ -171,7 +171,7 @@ impl Default for Deck { } } -enum Seed { +pub enum Seed { Unseeded, SeedVal(u64), } @@ -188,7 +188,7 @@ impl Deck { } } -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] enum NumPassesThroughDeck { Unlimited, Limited(u64), @@ -196,15 +196,27 @@ enum NumPassesThroughDeck { pub const NUM_PILES_KLONDIKE: usize = 7; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Klondike { pub piles: [Vec; NUM_PILES_KLONDIKE], - pub deck: Vec, + pub deck: Vec, // this term is a bit overloaded pub waste: Vec, pub foundation: [Vec; 4], // 4 = len of num suits - max_num_passes_through_deck: NumPassesThroughDeck, - current_num_passes_through_deck: u64, - num_cards_turned: u8, + _max_num_passes_through_deck: NumPassesThroughDeck, + _current_num_passes_through_deck: u64, + _num_cards_turned: u8, +} + +impl Klondike { + pub fn draw(self: &mut Self) { + // completely temporary + let c1 = self.deck.pop().unwrap(); + let c2 = self.deck.pop().unwrap(); + let c3 = self.deck.pop().unwrap(); + self.waste.push(c1); + self.waste.push(c2); + self.waste.push(c3); + } } impl Default for Klondike { @@ -226,9 +238,9 @@ impl Default for Klondike { deck: deck.cards, waste: Vec::new(), foundation: [Vec::new(), Vec::new(), Vec::new(), Vec::new()], // is this really the best way? - max_num_passes_through_deck: NumPassesThroughDeck::Unlimited, - current_num_passes_through_deck: 0, - num_cards_turned: 3, + _max_num_passes_through_deck: NumPassesThroughDeck::Unlimited, + _current_num_passes_through_deck: 0, + _num_cards_turned: 3, } } } diff --git a/card_stuffs/src/main.rs b/card_stuffs/src/main.rs index b63570b..9dbc243 100644 --- a/card_stuffs/src/main.rs +++ b/card_stuffs/src/main.rs @@ -24,43 +24,50 @@ pub struct App { const CARD_HEIGHT: u16 = 11; const CARD_WIDTH: u16 = 15; -fn waste_widget(cards_in_waste: &Vec) -> List { - let mut cards_to_display = Vec::new(); +fn draw_waste(cards_in_waste: &Vec, area: Rect, frame: &mut Frame) { + if cards_in_waste.len() == 0 { + frame.render_widget( + // TODO something different here to show empty stack - also it's too tall for some reason + facedown_card(false), + area + ); + } + let horizontal = Layout::horizontal([ + Constraint::Length(3), + Constraint::Length(3), + Constraint::Length(CARD_WIDTH), + ]); + let [w1, w2, top_waste] = horizontal.areas(area); + // There must be a better way to do this if cards_in_waste.len() >= 3 { - cards_to_display.push(cards_in_waste.windows(3).last()); + frame.render_widget( + partially_covered_card(&cards_in_waste[cards_in_waste.len() - 1]), + w1 + ); + frame.render_widget( + partially_covered_card(&cards_in_waste[cards_in_waste.len() - 2]), + w2 + ); + frame.render_widget( + card_widget(&cards_in_waste[cards_in_waste.len() - 3], true, false, false), + top_waste + ); } else if cards_in_waste.len() == 2 { - cards_to_display.push(cards_in_waste.windows(2).last()); + frame.render_widget( + partially_covered_card(&cards_in_waste[cards_in_waste.len() - 1]), + w2 + ); + frame.render_widget( + card_widget(&cards_in_waste[cards_in_waste.len() - 2], true, false, false), + top_waste + ); } else if cards_in_waste.len() == 1 { - cards_to_display.push(cards_in_waste.windows(1).last()); + frame.render_widget( + card_widget(&cards_in_waste[cards_in_waste.len() - 1], true, false, false), + top_waste + ); } - // Eeeek - we're no longer a basic "List"... I think maybe I need - // a new widget I've make myself... I probably should do that for all cards - // to be toootaly honest - - - // This (and the rest) probably shouldn't be ListItems - let hidden_card = [ - format!("#############"), - format!("#############"), - format!("#############"), - format!("#####TODO####"), - format!("#############"), - format!("#############"), - format!("#############"), - format!("#############"), - format!("#############"), - ]; - - let card_image: Vec = hidden_card.iter().map(|m| { - ListItem::new(m.to_string()) - }) - .collect(); - - List::new(card_image) - .block(Block::new() - .borders(Borders::ALL) - .border_type(BorderType::Rounded)) } fn deck_widget(cards_in_deck: &Vec) -> Paragraph<'static> { @@ -138,6 +145,7 @@ fn partially_covered_card(card: &card_stuffs::Card) -> Paragraph { .border_type(BorderType::Rounded)) } +/* struct CardWidget { card: card_stuffs::Card, // put display stuff in here? @@ -149,6 +157,7 @@ impl Widget for CardWidget { } } +*/ fn facedown_card(top: bool) -> Paragraph<'static> { let hidden_card = format!( @@ -218,29 +227,12 @@ impl App { let [deck_area, waste_area, fa, fb, fc, fd] = horizontal.areas(dwf_area); let foundation_areas = [fa, fb, fc, fd]; - let horizontal = Layout::horizontal([ - Constraint::Length(3), - Constraint::Length(3), - Constraint::Length(CARD_WIDTH), - ]); - let [w1, w2, waste_area] = horizontal.areas(waste_area); - frame.render_widget( deck_widget(&self.cards.deck), deck_area ); - frame.render_widget( - partially_covered_card(&self.cards.piles[0][0]), - w1 - ); - frame.render_widget( - partially_covered_card(&self.cards.piles[1][0]), - w2 - ); - frame.render_widget( - waste_widget(&self.cards.waste), - waste_area - ); + + draw_waste(&self.cards.waste, waste_area, frame); for fa in foundation_areas { frame.render_widget( @@ -318,6 +310,7 @@ impl App { fn handle_key_event(&mut self, key_event: KeyEvent) { match key_event.code { KeyCode::Char('q') => self.exit(), + KeyCode::Char('d') => self.cards.draw(), _ => {} } }