Compare commits
2 Commits
0aa5dbd899
...
be5a969600
| Author | SHA1 | Date | |
|---|---|---|---|
| be5a969600 | |||
| 02f7d391fc |
@ -6,7 +6,11 @@ definitely not a shameless untap clone
|
||||
|
||||
# todo
|
||||
+ Add drag-and-drop from hand and piles
|
||||
+ Add hotkeys for every zone
|
||||
+ Add untap all hotkey
|
||||
+ Add hotkeys for every zone (Almost done!)
|
||||
+ ~~Add untap all hotkey~~
|
||||
+ 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
|
||||
|
||||
52
src/game.rs
52
src/game.rs
@ -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,
|
||||
@ -53,8 +53,11 @@ enum Event {
|
||||
Bounce(Player),
|
||||
Tap(Uuid),
|
||||
Discard(Player),
|
||||
Undiscard(Player),
|
||||
Kill(Uuid, bool),
|
||||
Unkill(Uuid, bool),
|
||||
TransferDeadCard(Uuid, bool),
|
||||
UntapAll(Player),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
@ -298,6 +301,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) {
|
||||
let played_card = game_state.play.remove(&play_id).unwrap();
|
||||
game_state.events.push(CountedEvent {
|
||||
@ -334,3 +354,33 @@ 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),
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
94
src/main.rs
94
src/main.rs
@ -230,6 +230,74 @@ fn banish(
|
||||
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")]
|
||||
fn get_state(
|
||||
uuid: Uuid,
|
||||
@ -248,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,
|
||||
@ -389,7 +476,12 @@ fn rocket() -> _ {
|
||||
forget,
|
||||
banish,
|
||||
unkill,
|
||||
unbanish
|
||||
unbanish,
|
||||
shadow,
|
||||
unshadow,
|
||||
undiscard,
|
||||
remember,
|
||||
untap_all,
|
||||
],
|
||||
)
|
||||
.manage(ArcMutexGameState {
|
||||
|
||||
@ -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
|
||||
@ -264,18 +265,60 @@
|
||||
| \r =>
|
||||
if $current-mouse-node?.has-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 =>
|
||||
if $current-mouse-node?.has-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
|
||||
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 =>
|
||||
if $current-mouse-node?.has-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
|
||||
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 =>
|
||||
$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
|
||||
)!
|
||||
|
||||
@ -49,7 +49,7 @@ main {
|
||||
|
||||
#extra {
|
||||
transition: height 0.5s;
|
||||
overflow: hidden;
|
||||
overflow: auto;
|
||||
background-color: #222d;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user