Skip to content

Commit

Permalink
Add generic inputs for left / right (absolute), use in shop
Browse files Browse the repository at this point in the history
  • Loading branch information
haihala committed Nov 12, 2024
1 parent f7f83bc commit 3a9c1b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
2 changes: 2 additions & 0 deletions client/input_parsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ fn generic_inputs() -> impl Iterator<Item = (ActionId, &'static str)> {
vec![
(ActionId::Up, "8|5"),
(ActionId::Down, "2|5"),
(ActionId::Left, "4|A5"),
(ActionId::Right, "6|A5"),
(ActionId::Back, "4|5"),
(ActionId::Forward, "6|5"),
(ActionId::Primary, "f"),
Expand Down
30 changes: 6 additions & 24 deletions client/lib/src/ui/shop/shop_inputs.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
use bevy::prelude::*;
use characters::{Character, Inventory};
use input_parsing::InputParser;
use wag_core::{ActionId, Facing, Owner, Player};
use wag_core::{ActionId, Owner, Player};

use super::{setup_shop::ShopItem, shops_resource::Shop, Shops, SHOP_COLUMNS};

pub fn navigate_shop(
mut parsers: Query<(
&mut InputParser,
&Player,
&mut Inventory,
&Character,
&Facing,
)>,
mut parsers: Query<(&mut InputParser, &Player, &mut Inventory, &Character)>,
slots: Query<(Entity, &Owner, Option<&ShopItem>)>,
mut shops: ResMut<Shops>,
) {
for (mut parser, player, mut inventory, character, facing) in &mut parsers {
for (mut parser, player, mut inventory, character) in &mut parsers {
let events = parser.get_events();
let shop = shops.get_mut_shop(player);

Expand All @@ -28,8 +22,8 @@ pub fn navigate_shop(
match event {
ActionId::Up => move_selection(shop, Up),
ActionId::Down => move_selection(shop, Down),
ActionId::Back => move_selection(shop, Left.mirror_if(facing.to_flipped())),
ActionId::Forward => move_selection(shop, Right.mirror_if(facing.to_flipped())),
ActionId::Left => move_selection(shop, Left),
ActionId::Right => move_selection(shop, Right),
ActionId::Primary => buy(shop, &mut inventory, character, &slots),
ActionId::Cancel => sell(shop, &mut inventory, character, &slots),
ActionId::Start => shop.closed = true,
Expand All @@ -47,19 +41,7 @@ enum CardinalDiretion {
Left,
Right,
}
impl CardinalDiretion {
fn mirror_if(self, condition: bool) -> Self {
if !condition {
self
} else {
match self {
Left => Right,
Right => Left,
other => other,
}
}
}
}

use CardinalDiretion::*;

fn move_selection(shop: &mut Shop, direction: CardinalDiretion) {
Expand Down
2 changes: 2 additions & 0 deletions client/wag_core/src/action_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum ActionId {
Default, // To satisfy Inspectable.
Up,
Down,
Left,
Right,
Back,
Forward,
Primary,
Expand Down

0 comments on commit 3a9c1b1

Please sign in to comment.