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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
fetch-depth: 1

- name: Cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
22 changes: 13 additions & 9 deletions truncate_client/src/lil_bits/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ impl<'a> BoardUI<'a> {
interactions.selected_tile_on_board = None;
}

if let Some((tile, _)) =
if let Some((tile_index, tile)) =
interactions.selected_tile_in_hand
{
msg = Some(PlayerMessage::Place(
msg = Some(PlayerMessage::Place {
coord,
*hand.get(tile).unwrap(),
));
slot: Some(tile_index),
tile,
});

interactions.selected_tile_in_hand = None;
interactions.selected_square_on_board = None;
Expand All @@ -197,12 +198,15 @@ impl<'a> BoardUI<'a> {
}
}

if let Some(tile) = interactions.released_tile {
if tile.1 == coord {
msg = Some(PlayerMessage::Place(
if let Some((tile_index, tile, released_coord)) =
interactions.released_tile
{
if released_coord == coord {
msg = Some(PlayerMessage::Place {
coord,
*hand.get(tile.0).unwrap(),
));
slot: Some(tile_index),
tile,
});
interactions.selected_tile_in_hand = None;
interactions.selected_tile_on_board = None;
interactions.released_tile = None;
Expand Down
2 changes: 1 addition & 1 deletion truncate_client/src/lil_bits/hand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a> HandUI<'a> {
coord: Some(coord), ..
}) = depot.interactions.hovered_unoccupied_square_on_board
{
depot.interactions.released_tile = Some((i, coord));
depot.interactions.released_tile = Some((i, *char, coord));
}
}

Expand Down
16 changes: 2 additions & 14 deletions truncate_client/src/regions/active_game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl ActiveGame {
player_number: _,
next_player_number,
board,
hand: _,
hand,
changes,
game_ends_at,
paused,
Expand Down Expand Up @@ -334,19 +334,7 @@ impl ActiveGame {
.insert(board_change.detail.coordinate, board_change.clone());
}

for hand_change in changes.iter().filter_map(|c| match c {
Change::Hand(change) => Some(change),
_ => None,
}) {
for removed in &hand_change.removed {
if let Some(pos) = self.hand.iter().position(|t| t == removed) {
self.hand.remove(pos);
}
}
let reduced_length = self.hand.len();
self.hand.0.extend(&hand_change.added);
self.new_hand_tiles = (reduced_length..self.hand.len()).collect();
}
self.hand = hand;

self.time_changes = changes
.iter()
Expand Down
5 changes: 3 additions & 2 deletions truncate_client/src/regions/single_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,11 @@ impl SinglePlayerState {
}

let next_move = match next_msg {
Some((player, PlayerMessage::Place(position, tile))) => Some(Move::Place {
Some((player, PlayerMessage::Place { coord, slot, tile })) => Some(Move::Place {
player,
slot,
tile,
position,
position: coord,
}),
Some((player, PlayerMessage::Swap(from, to))) => Some(Move::Swap {
player,
Expand Down
7 changes: 5 additions & 2 deletions truncate_client/src/regions/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn action_to_move(player: usize, action: &str) -> Move {
} else if from.len() == 1 {
Move::Place {
player,
slot: None,
tile: from.chars().next().unwrap(),
position: to_pos,
}
Expand Down Expand Up @@ -296,6 +297,7 @@ impl TutorialState {
// TODO: Use some special infinite bag?
bag: TileBag::latest(None).1,
judge: Judge::new(vec![]),
move_sequence: vec![],
battle_count: 0,
turn_count: 0,
player_turn_count: vec![0, 0],
Expand Down Expand Up @@ -547,10 +549,11 @@ impl TutorialState {
}

let Some(game_move) = (match msg {
PlayerMessage::Place(position, tile) => Some(Move::Place {
PlayerMessage::Place { coord, slot, tile } => Some(Move::Place {
player: 0,
slot,
tile,
position,
position: coord,
}),
PlayerMessage::Swap(from, to) => Some(Move::Swap {
player: 0,
Expand Down
15 changes: 10 additions & 5 deletions truncate_client/src/utils/control_devices/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ pub fn handle_input(
let current_selection = ensure_board_selection(depot);

if let Some(char) = hand.get(key) {
msg = Some(PlayerMessage::Place(current_selection, *char))
msg = Some(PlayerMessage::Place {
coord: current_selection,
slot: Some(key),
tile: *char,
});
}
}
}
Expand All @@ -143,10 +147,11 @@ pub fn handle_input(
) {
let current_selection = ensure_board_selection(depot);

msg = Some(PlayerMessage::Place(
current_selection,
letter.chars().next().unwrap(),
))
msg = Some(PlayerMessage::Place {
coord: current_selection,
slot: None,
tile: letter.chars().next().unwrap(),
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion truncate_client/src/utils/depot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct HoveredRegion {
#[derive(Clone, Default)]
pub struct InteractionDepot {
pub view_only: bool,
pub released_tile: Option<(usize, Coordinate)>,
pub released_tile: Option<(usize, char, Coordinate)>,
pub dragging_tile_on_board: Option<(Coordinate, Square)>,
pub selected_tile_on_board: Option<(Coordinate, Square)>,
pub hovered_tile_on_board: Option<(Coordinate, Square)>,
Expand Down
7 changes: 7 additions & 0 deletions truncate_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ pub enum GamePlayError {

#[error("Player {player:?} doesn't have a '{tile:?}' tile")]
PlayerDoesNotHaveTile { player: usize, tile: char },

#[error("Player {player:?} doesn't have a '{tile:?}' tile in slot {slot}")]
PlayerDoesNotHaveTileInSlot {
player: usize,
tile: char,
slot: usize,
},
}
26 changes: 22 additions & 4 deletions truncate_core/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Game {
pub board: Board,
pub bag: TileBag,
pub judge: Judge,
pub move_sequence: Vec<Move>,
pub battle_count: u32,
pub turn_count: u32,
pub player_turn_count: Vec<u32>,
Expand Down Expand Up @@ -72,6 +73,7 @@ impl Game {
board,
bag: TileBag::generation(rules.tile_generation, tile_seed),
judge: Judge::default(),
move_sequence: vec![],
battle_count: 0,
turn_count: 0,
player_turn_count: Vec::with_capacity(2),
Expand Down Expand Up @@ -104,6 +106,7 @@ impl Game {
board,
bag: TileBag::generation(rules.tile_generation, tile_seed),
judge: Judge::default(),
move_sequence: vec![],
battle_count: 0,
turn_count: 0,
player_turn_count: Vec::with_capacity(2),
Expand Down Expand Up @@ -412,7 +415,7 @@ impl Game {
}

self.recent_changes = match self.make_move(
next_move,
next_move.clone(),
attacker_dictionary,
defender_dictionary,
cached_word_judgements,
Expand All @@ -423,6 +426,7 @@ impl Game {
return Err(format!("{msg}"));
}
};
self.move_sequence.push(next_move);

// Track any new tiles that the player may have gained vision of from this turn
{
Expand Down Expand Up @@ -548,6 +552,7 @@ impl Game {
match game_move {
Move::Place {
player,
slot,
tile,
position: player_reported_position,
} => {
Expand Down Expand Up @@ -579,8 +584,21 @@ impl Game {
return Err(GamePlayError::NonAdjacentPlace);
}

if !self.players[player].has_tile(tile) {
return Err(GamePlayError::PlayerDoesNotHaveTile { player, tile });
match slot {
Some(slot) => {
if !self.players[player].has_tile_in_slot(tile, slot) {
return Err(GamePlayError::PlayerDoesNotHaveTileInSlot {
player,
tile,
slot,
});
}
}
None => {
if !self.players[player].has_tile(tile) {
return Err(GamePlayError::PlayerDoesNotHaveTile { player, tile });
}
}
}

changes.push(Change::Board(BoardChange {
Expand All @@ -589,7 +607,7 @@ impl Game {
.set(position, player, tile, attacker_dictionary)?,
action: BoardChangeAction::Added,
}));
changes.push(self.players[player].use_tile(tile, &mut self.bag)?);
changes.push(self.players[player].use_tile(tile, slot, &mut self.bag)?);

self.resolve_attack(
player,
Expand Down
10 changes: 8 additions & 2 deletions truncate_core/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ pub enum PlayerMessage {
EditName(String),
StartGame,
Resign,
Place(Coordinate, char),
Place {
coord: Coordinate,
slot: Option<usize>,
tile: char,
},
Swap(Coordinate, Coordinate),
Rematch,
Pause,
Expand Down Expand Up @@ -103,7 +107,9 @@ impl fmt::Display for PlayerMessage {
PlayerMessage::EditName(name) => write!(f, "Set name to {name}"),
PlayerMessage::StartGame => write!(f, "Start the game"),
PlayerMessage::Resign => write!(f, "Resign"),
PlayerMessage::Place(coord, tile) => write!(f, "Place {} at {}", tile, coord),
PlayerMessage::Place { coord, slot, tile } => {
write!(f, "Place slot {:?} ({}) at {}", slot, tile, coord)
}
PlayerMessage::Swap(a, b) => write!(f, "Swap the tiles at {} and {}", a, b),
PlayerMessage::Rematch => write!(f, "Rematch!"),
PlayerMessage::Pause => write!(f, "Pause!"),
Expand Down
Loading
Loading