Implemented more hotkeys🌶️
This commit is contained in:
@ -6,7 +6,11 @@ definitely not a shameless untap clone
|
|||||||
|
|
||||||
# todo
|
# todo
|
||||||
+ Add drag-and-drop from hand and piles
|
+ Add drag-and-drop from hand and piles
|
||||||
+ Add hotkeys for every zone
|
+ Add hotkeys for every zone (Almost done!)
|
||||||
+ Add untap all hotkey
|
+ Add untap all hotkey
|
||||||
+ Add viewing top of deck
|
+ Add viewing top of deck
|
||||||
|
+ Add score values (usable for life counters)
|
||||||
|
|
||||||
|
# maybe todo
|
||||||
|
+ Make deck information, piles, and score info json-configurable
|
||||||
+ Use cookies instead of hardcoded url uuid
|
+ Use cookies instead of hardcoded url uuid
|
||||||
|
|||||||
37
src/game.rs
37
src/game.rs
@ -53,8 +53,10 @@ enum Event {
|
|||||||
Bounce(Player),
|
Bounce(Player),
|
||||||
Tap(Uuid),
|
Tap(Uuid),
|
||||||
Discard(Player),
|
Discard(Player),
|
||||||
|
Undiscard(Player),
|
||||||
Kill(Uuid, bool),
|
Kill(Uuid, bool),
|
||||||
Unkill(Uuid, bool),
|
Unkill(Uuid, bool),
|
||||||
|
TransferDeadCard(Uuid, bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Clone, Debug)]
|
#[derive(Serialize, Clone, Debug)]
|
||||||
@ -298,6 +300,23 @@ pub fn discard(game_state: &mut GameState, hand_index: usize, player: Player, sh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn undiscard(game_state: &mut GameState, pile_index: usize, player: Player, shadow: bool) {
|
||||||
|
let player_hand = match player {
|
||||||
|
Player::A => &mut game_state.hands[0],
|
||||||
|
Player::B => &mut game_state.hands[1],
|
||||||
|
};
|
||||||
|
game_state.events.push(CountedEvent {
|
||||||
|
id: game_state.events.len(),
|
||||||
|
event: Event::Undiscard(player.clone()),
|
||||||
|
});
|
||||||
|
let card = if shadow {
|
||||||
|
game_state.shadow_realm.remove(pile_index)
|
||||||
|
} else {
|
||||||
|
game_state.discard_pile.remove(pile_index)
|
||||||
|
};
|
||||||
|
player_hand.cards.push(card);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn kill(game_state: &mut GameState, play_id: Uuid, shadow: bool) {
|
pub fn kill(game_state: &mut GameState, play_id: Uuid, shadow: bool) {
|
||||||
let played_card = game_state.play.remove(&play_id).unwrap();
|
let played_card = game_state.play.remove(&play_id).unwrap();
|
||||||
game_state.events.push(CountedEvent {
|
game_state.events.push(CountedEvent {
|
||||||
@ -334,3 +353,21 @@ pub fn unkill(game_state: &mut GameState, player: Player, pile_index: usize, sha
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn transfer_dead_card(game_state: &mut GameState, pile_index: usize, shadow_to_discard: bool) {
|
||||||
|
let card_id = if shadow_to_discard {
|
||||||
|
let card = game_state.shadow_realm.remove(pile_index);
|
||||||
|
let ret = card.clone();
|
||||||
|
game_state.discard_pile.push(card);
|
||||||
|
ret
|
||||||
|
} else {
|
||||||
|
let card = game_state.discard_pile.remove(pile_index);
|
||||||
|
let ret = card.clone();
|
||||||
|
game_state.shadow_realm.push(card);
|
||||||
|
ret
|
||||||
|
};
|
||||||
|
game_state.events.push(CountedEvent {
|
||||||
|
id: game_state.events.len(),
|
||||||
|
event: Event::TransferDeadCard(card_id, shadow_to_discard),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
74
src/main.rs
74
src/main.rs
@ -230,6 +230,74 @@ fn banish(
|
|||||||
Ok(format!("{}", game::get_events(&game_state)))
|
Ok(format!("{}", game::get_events(&game_state)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/<uuid>/unshadow/<index>")]
|
||||||
|
fn unshadow(
|
||||||
|
uuid: Uuid,
|
||||||
|
index: usize,
|
||||||
|
game_state_arc: &State<ArcMutexGameState>,
|
||||||
|
player_uuids: &State<PlayerUuids>,
|
||||||
|
) -> Result<String, BadRequest<String>> {
|
||||||
|
match player_uuids.map.get(&uuid) {
|
||||||
|
Some(_) => (),
|
||||||
|
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
|
||||||
|
};
|
||||||
|
let game_state_mutex = Arc::clone(&game_state_arc.state);
|
||||||
|
let mut game_state = game_state_mutex.lock().unwrap();
|
||||||
|
game::transfer_dead_card(&mut game_state, index, true);
|
||||||
|
Ok(format!("{}", game::get_events(&game_state)))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/<uuid>/undiscard/<index>")]
|
||||||
|
fn undiscard(
|
||||||
|
uuid: Uuid,
|
||||||
|
index: usize,
|
||||||
|
game_state_arc: &State<ArcMutexGameState>,
|
||||||
|
player_uuids: &State<PlayerUuids>,
|
||||||
|
) -> Result<String, BadRequest<String>> {
|
||||||
|
let player = match player_uuids.map.get(&uuid) {
|
||||||
|
Some(player) => player,
|
||||||
|
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
|
||||||
|
};
|
||||||
|
let game_state_mutex = Arc::clone(&game_state_arc.state);
|
||||||
|
let mut game_state = game_state_mutex.lock().unwrap();
|
||||||
|
game::undiscard(&mut game_state, index, player.clone(), false);
|
||||||
|
Ok(format!("{}", game::get_events(&game_state)))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/<uuid>/remember/<index>")]
|
||||||
|
fn remember(
|
||||||
|
uuid: Uuid,
|
||||||
|
index: usize,
|
||||||
|
game_state_arc: &State<ArcMutexGameState>,
|
||||||
|
player_uuids: &State<PlayerUuids>,
|
||||||
|
) -> Result<String, BadRequest<String>> {
|
||||||
|
let player = match player_uuids.map.get(&uuid) {
|
||||||
|
Some(player) => player,
|
||||||
|
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
|
||||||
|
};
|
||||||
|
let game_state_mutex = Arc::clone(&game_state_arc.state);
|
||||||
|
let mut game_state = game_state_mutex.lock().unwrap();
|
||||||
|
game::undiscard(&mut game_state, index, player.clone(), true);
|
||||||
|
Ok(format!("{}", game::get_events(&game_state)))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/<uuid>/shadow/<index>")]
|
||||||
|
fn shadow(
|
||||||
|
uuid: Uuid,
|
||||||
|
index: usize,
|
||||||
|
game_state_arc: &State<ArcMutexGameState>,
|
||||||
|
player_uuids: &State<PlayerUuids>,
|
||||||
|
) -> Result<String, BadRequest<String>> {
|
||||||
|
match player_uuids.map.get(&uuid) {
|
||||||
|
Some(_) => (),
|
||||||
|
None => return Err(BadRequest(format!("Invalid player {}.", uuid))),
|
||||||
|
};
|
||||||
|
let game_state_mutex = Arc::clone(&game_state_arc.state);
|
||||||
|
let mut game_state = game_state_mutex.lock().unwrap();
|
||||||
|
game::transfer_dead_card(&mut game_state, index, false);
|
||||||
|
Ok(format!("{}", game::get_events(&game_state)))
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/<uuid>/get_state")]
|
#[get("/<uuid>/get_state")]
|
||||||
fn get_state(
|
fn get_state(
|
||||||
uuid: Uuid,
|
uuid: Uuid,
|
||||||
@ -389,7 +457,11 @@ fn rocket() -> _ {
|
|||||||
forget,
|
forget,
|
||||||
banish,
|
banish,
|
||||||
unkill,
|
unkill,
|
||||||
unbanish
|
unbanish,
|
||||||
|
shadow,
|
||||||
|
unshadow,
|
||||||
|
undiscard,
|
||||||
|
remember,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.manage(ArcMutexGameState {
|
.manage(ArcMutexGameState {
|
||||||
|
|||||||
@ -264,18 +264,53 @@
|
|||||||
| \r =>
|
| \r =>
|
||||||
if $current-mouse-node?.has-attribute \data-play-id
|
if $current-mouse-node?.has-attribute \data-play-id
|
||||||
fetch-log "./bounce/#{$current-mouse-node.get-attribute \data-play-id}"
|
fetch-log "./bounce/#{$current-mouse-node.get-attribute \data-play-id}"
|
||||||
|
else if $current-mouse-node?.has-attribute \data-list-type
|
||||||
|
switch $current-mouse-node.get-attribute \data-list-type
|
||||||
|
| \discard
|
||||||
|
fetch-log "./undiscard/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
| \deck
|
||||||
|
void #fetch-log "./unshadow/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
| \shadow
|
||||||
|
fetch-log "./remember/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
$current-mouse-node.parent-element.remove-child $current-mouse-node
|
||||||
|
if !$extra.child-element-count
|
||||||
|
$extra.class-list.add \hidden
|
||||||
|
$extra.remove-attribute \data-pile-type
|
||||||
| \d =>
|
| \d =>
|
||||||
if $current-mouse-node?.has-attribute \data-hand-index
|
if $current-mouse-node?.has-attribute \data-hand-index
|
||||||
fetch-log "./discard/#{$current-mouse-node.get-attribute \data-hand-index}"
|
fetch-log "./discard/#{$current-mouse-node.get-attribute \data-hand-index}"
|
||||||
else if $current-mouse-node?.has-attribute \data-play-id
|
else if $current-mouse-node?.has-attribute \data-play-id
|
||||||
fetch-log "./kill/#{$current-mouse-node.get-attribute \data-play-id}"
|
fetch-log "./kill/#{$current-mouse-node.get-attribute \data-play-id}"
|
||||||
|
else if $current-mouse-node?.has-attribute \data-list-type
|
||||||
|
switch $current-mouse-node.get-attribute \data-list-type
|
||||||
|
| \discard
|
||||||
|
return #fetch-log "./unkill/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
| \deck
|
||||||
|
void #fetch-log "./unkill/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
| \shadow
|
||||||
|
fetch-log "./unshadow/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
$current-mouse-node.parent-element.remove-child $current-mouse-node
|
||||||
|
if !$extra.child-element-count
|
||||||
|
$extra.class-list.add \hidden
|
||||||
|
$extra.remove-attribute \data-pile-type
|
||||||
| \s =>
|
| \s =>
|
||||||
if $current-mouse-node?.has-attribute \data-hand-index
|
if $current-mouse-node?.has-attribute \data-hand-index
|
||||||
fetch-log "./forget/#{$current-mouse-node.get-attribute \data-hand-index}"
|
fetch-log "./forget/#{$current-mouse-node.get-attribute \data-hand-index}"
|
||||||
else if $current-mouse-node?.has-attribute \data-play-id
|
else if $current-mouse-node?.has-attribute \data-play-id
|
||||||
fetch-log "./banish/#{$current-mouse-node.get-attribute \data-play-id}"
|
fetch-log "./banish/#{$current-mouse-node.get-attribute \data-play-id}"
|
||||||
|
else if $current-mouse-node?.has-attribute \data-list-type
|
||||||
|
switch $current-mouse-node.get-attribute \data-list-type
|
||||||
|
| \discard
|
||||||
|
fetch-log "./shadow/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
| \deck
|
||||||
|
void #fetch-log "./unbanish/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
| \shadow
|
||||||
|
return #fetch-log "./unshadow/#{$current-mouse-node.get-attribute \data-index}"
|
||||||
|
$current-mouse-node.parent-element.remove-child $current-mouse-node
|
||||||
|
if !$extra.child-element-count
|
||||||
|
$extra.class-list.add \hidden
|
||||||
|
$extra.remove-attribute \data-pile-type
|
||||||
| \q =>
|
| \q =>
|
||||||
$extra.class-list.add \hidden
|
$extra.class-list.add \hidden
|
||||||
$extra.remove-attribute \data-pile-type
|
$extra.remove-attribute \data-pile-type
|
||||||
|
|
||||||
)!
|
)!
|
||||||
|
|||||||
@ -49,7 +49,7 @@ main {
|
|||||||
|
|
||||||
#extra {
|
#extra {
|
||||||
transition: height 0.5s;
|
transition: height 0.5s;
|
||||||
overflow: hidden;
|
overflow: auto;
|
||||||
background-color: #222d;
|
background-color: #222d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user