Added untap hotkey⍼

This commit is contained in:
Seoxi Ryouko
2025-02-28 03:45:25 -06:00
parent 02f7d391fc
commit be5a969600
4 changed files with 45 additions and 4 deletions

View File

@ -7,7 +7,7 @@ definitely not a shameless untap clone
# todo
+ Add drag-and-drop from hand and piles
+ Add hotkeys for every zone (Almost done!)
+ Add untap all hotkey
+ ~~Add untap all hotkey~~
+ Add viewing top of deck
+ Add score values (usable for life counters)

View File

@ -16,7 +16,7 @@ struct CardInfo {
count: usize,
}
#[derive(Deserialize, Serialize, Clone, Copy, Debug)]
#[derive(Deserialize, Serialize, Clone, Copy, Debug, PartialEq)]
pub enum Player {
A,
B,
@ -56,7 +56,8 @@ enum Event {
Undiscard(Player),
Kill(Uuid, bool),
Unkill(Uuid, bool),
TransferDeadCard(Uuid, bool)
TransferDeadCard(Uuid, bool),
UntapAll(Player),
}
#[derive(Serialize, Clone, Debug)]
@ -371,3 +372,15 @@ pub fn transfer_dead_card(game_state: &mut GameState, pile_index: usize, shadow_
event: Event::TransferDeadCard(card_id, shadow_to_discard),
});
}
pub fn untap_all(game_state: &mut GameState, player: Player) {
game_state.events.push(CountedEvent {
id: game_state.events.len(),
event: Event::UntapAll(player),
});
for (_, card) in game_state.play.iter_mut() {
if card.owner == player {
card.tapped = false;
}
}
}

View File

@ -316,6 +316,25 @@ fn get_state(
))
}
#[get("/<uuid>/untap_all")]
fn untap_all(
uuid: Uuid,
game_state_arc: &State<ArcMutexGameState>,
player_uuids: &State<PlayerUuids>,
) -> Result<String, BadRequest<String>> {
let game_state_mutex = Arc::clone(&game_state_arc.state);
let mut game_state = game_state_mutex.lock().unwrap();
let player = match player_uuids.map.get(&uuid) {
Some(player) => player,
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
};
game::untap_all(&mut game_state, player.clone());
Ok(format!(
"{}",
game::get_game_one_player(&game_state, player.clone())
))
}
#[get("/<uuid>/draw/<count>")]
fn draw(
uuid: Uuid,
@ -462,6 +481,7 @@ fn rocket() -> _ {
unshadow,
undiscard,
remember,
untap_all,
],
)
.manage(ArcMutexGameState {

View File

@ -11,6 +11,7 @@
const $view-card-container = document.query-selector '#view-card-container'
const $param = document.query-selector '#param'
const $play = document.query-selector '#play'
window.$play = play
const $discard-pile = document.query-selector '#discard-pile'
const $discard-pile-img = document.query-selector '#discard-pile-img'
const $discard-pile-count = document.query-selector '#discard-pile-count'
@ -232,7 +233,7 @@
$view-card-container.class-list.add \right
..add-event-listener \keyup ->
$current-mouse-node = [...document.query-selector-all \:hover][* - 1]
switch it.key
switch it.key.to-lower-case!
| \c => fetch-log "./draw/#{pop-param!}"
| \e => fetch-log "./pass"
| \0 \1 \2 \3 \4 \5 \6 \7 \8 \9 => push-param that
@ -313,4 +314,11 @@
| \q =>
$extra.class-list.add \hidden
$extra.remove-attribute \data-pile-type
| \x =>
console.log
if it.shift-key || state.player-state.turn_player == state.player-state.you
fetch-log \./untap_all
[...$play.children]
.filter -> \true == it.get-attribute \data-owned
.for-each -> it.set-attribute \data-tapped false
)!