From 3a9c1b161e727ad51e6ed336a1207834f9065b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eero=20H=C3=A4ih=C3=A4l=C3=A4?= Date: Tue, 12 Nov 2024 11:14:12 +0200 Subject: [PATCH] Add generic inputs for left / right (absolute), use in shop --- client/input_parsing/src/lib.rs | 2 ++ client/lib/src/ui/shop/shop_inputs.rs | 30 ++++++--------------------- client/wag_core/src/action_id.rs | 2 ++ 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/client/input_parsing/src/lib.rs b/client/input_parsing/src/lib.rs index 32f96264..a2a9861a 100644 --- a/client/input_parsing/src/lib.rs +++ b/client/input_parsing/src/lib.rs @@ -54,6 +54,8 @@ fn generic_inputs() -> impl Iterator { 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"), diff --git a/client/lib/src/ui/shop/shop_inputs.rs b/client/lib/src/ui/shop/shop_inputs.rs index b0e5271c..387fa51b 100644 --- a/client/lib/src/ui/shop/shop_inputs.rs +++ b/client/lib/src/ui/shop/shop_inputs.rs @@ -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, ) { - 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); @@ -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, @@ -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) { diff --git a/client/wag_core/src/action_id.rs b/client/wag_core/src/action_id.rs index 7babf696..1c6cdd9c 100644 --- a/client/wag_core/src/action_id.rs +++ b/client/wag_core/src/action_id.rs @@ -13,6 +13,8 @@ pub enum ActionId { Default, // To satisfy Inspectable. Up, Down, + Left, + Right, Back, Forward, Primary,