Skip to content

Commit

Permalink
change type of pretty_name for ActionSets and Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmarni-Dev committed Dec 11, 2023
1 parent 7947dd0 commit b59e5be
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
26 changes: 13 additions & 13 deletions src/xr_input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,40 @@ pub fn setup_oxr_actions(world: &mut World) {
while let Some((set_name, set)) = a_iter.next() {
let mut actions: HashMap<&'static str, TypedAction> = default();
let oxr_action_set = instance
.create_action_set(set_name, set.pretty_name, set.priority)
.create_action_set(set_name, &set.pretty_name, set.priority)
.expect("Unable to create action set");
for (action_name, action) in set.actions.into_iter() {
let typed_action = match action.action_type {
ActionType::F32 => TypedAction::F32(match action.handednes {
ActionHandednes::Single => oxr_action_set
.create_action(action_name, action.pretty_name, &[])
.create_action(action_name, &action.pretty_name, &[])
.expect(&format!("Unable to create action: {}", action_name)),
ActionHandednes::Double => oxr_action_set
.create_action(action_name, action.pretty_name, &hands)
.create_action(action_name, &action.pretty_name, &hands)
.expect(&format!("Unable to create action: {}", action_name)),
}),
ActionType::Bool => TypedAction::Bool(match action.handednes {
ActionHandednes::Single => oxr_action_set
.create_action(action_name, action.pretty_name, &[])
.create_action(action_name, &action.pretty_name, &[])
.expect(&format!("Unable to create action: {}", action_name)),
ActionHandednes::Double => oxr_action_set
.create_action(action_name, action.pretty_name, &hands)
.create_action(action_name, &action.pretty_name, &hands)
.expect(&format!("Unable to create action: {}", action_name)),
}),
ActionType::PoseF => TypedAction::PoseF(match action.handednes {
ActionHandednes::Single => oxr_action_set
.create_action(action_name, action.pretty_name, &[])
.create_action(action_name, &action.pretty_name, &[])
.expect(&format!("Unable to create action: {}", action_name)),
ActionHandednes::Double => oxr_action_set
.create_action(action_name, action.pretty_name, &hands)
.create_action(action_name, &action.pretty_name, &hands)
.expect(&format!("Unable to create action: {}", action_name)),
}),
ActionType::Haptic => TypedAction::Haptic(match action.handednes {
ActionHandednes::Single => oxr_action_set
.create_action(action_name, action.pretty_name, &[])
.create_action(action_name, &action.pretty_name, &[])
.expect(&format!("Unable to create action: {}", action_name)),
ActionHandednes::Double => oxr_action_set
.create_action(action_name, action.pretty_name, &hands)
.create_action(action_name, &action.pretty_name, &hands)
.expect(&format!("Unable to create action: {}", action_name)),
}),
};
Expand Down Expand Up @@ -164,14 +164,14 @@ pub enum TypedAction {
}

pub struct SetupAction {
pretty_name: &'static str,
pretty_name: String,
action_type: ActionType,
handednes: ActionHandednes,
bindings: HashMap<&'static str, Vec<&'static str>>,
}

pub struct SetupActionSet {
pretty_name: &'static str,
pretty_name: String,
priority: u32,
actions: HashMap<&'static str, SetupAction>,
}
Expand All @@ -180,7 +180,7 @@ impl SetupActionSet {
pub fn new_action(
&mut self,
name: &'static str,
pretty_name: &'static str,
pretty_name: String,
action_type: ActionType,
handednes: ActionHandednes,
) {
Expand Down Expand Up @@ -230,7 +230,7 @@ impl SetupActionSets {
pub fn add_action_set(
&mut self,
name: &'static str,
pretty_name: &'static str,
pretty_name: String,
priority: u32,
) -> &mut SetupActionSet {
self.sets.insert(
Expand Down
28 changes: 14 additions & 14 deletions src/xr_input/hands/emulated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use openxr::{ActionTy, HandJoint};

use super::common::{get_bone_gizmo_style, HandBoneRadius};
use crate::{
xr_init::{xr_only, XrSetup},
resources::{XrInstance, XrSession},
xr_init::{xr_only, XrSetup},
xr_input::{
actions::{
ActionHandednes, ActionType, SetupActionSet, SetupActionSets, XrActionSets, XrBinding,
Expand All @@ -28,65 +28,63 @@ pub struct HandEmulationPlugin;

impl Plugin for HandEmulationPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
update_hand_skeleton_from_emulated.run_if(xr_only()),
);
app.add_systems(Update, update_hand_skeleton_from_emulated.run_if(xr_only()));
app.add_systems(XrSetup, setup_hand_emulation_action_set);
}
}

const HAND_ACTION_SET: &str = "hand_pose_approx";

fn setup_hand_emulation_action_set(mut action_sets: ResMut<SetupActionSets>) {
let mut action_set = action_sets.add_action_set(HAND_ACTION_SET, "Hand Pose Approximaiton", 0);
let action_set =
action_sets.add_action_set(HAND_ACTION_SET, "Hand Pose Approximaiton".into(), 0);
action_set.new_action(
"thumb_touch",
"Thumb Touched",
"Thumb Touched".into(),
ActionType::Bool,
ActionHandednes::Double,
);
action_set.new_action(
"thumb_x",
"Thumb X",
"Thumb X".into(),
ActionType::F32,
ActionHandednes::Double,
);
action_set.new_action(
"thumb_y",
"Thumb Y",
"Thumb Y".into(),
ActionType::F32,
ActionHandednes::Double,
);

action_set.new_action(
"index_touch",
"Index Finger Touched",
"Index Finger Touched".into(),
ActionType::Bool,
ActionHandednes::Double,
);
action_set.new_action(
"index_value",
"Index Finger Pull",
"Index Finger Pull".into(),
ActionType::F32,
ActionHandednes::Double,
);

action_set.new_action(
"middle_value",
"Middle Finger Pull",
"Middle Finger Pull".into(),
ActionType::F32,
ActionHandednes::Double,
);
action_set.new_action(
"ring_value",
"Ring Finger Pull",
"Ring Finger Pull".into(),
ActionType::F32,
ActionHandednes::Double,
);
action_set.new_action(
"little_value",
"Little Finger Pull",
"Little Finger Pull".into(),
ActionType::F32,
ActionHandednes::Double,
);
Expand Down Expand Up @@ -126,6 +124,7 @@ fn suggest_oculus_touch_profile(action_set: &mut SetupActionSet) {
);
}

#[allow(clippy::type_complexity)]
pub(crate) fn update_hand_skeleton_from_emulated(
session: Res<XrSession>,
instance: Res<XrInstance>,
Expand Down Expand Up @@ -546,5 +545,6 @@ fn get_bone_curl_angle(bone: HandJoint, curl: f32) -> f32 {
_ => 1.0,
};
let curl_angle = -((mul * curl * 80.0) + 5.0);
#[allow(clippy::needless_return)]
return curl_angle;
}
42 changes: 21 additions & 21 deletions src/xr_input/oculus_touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,124 +305,124 @@ pub struct OculusController {
impl OculusController {
pub fn new(mut action_sets: ResMut<SetupActionSets>) -> anyhow::Result<Self> {
let action_set =
action_sets.add_action_set("oculus_input", "Oculus Touch Controller Input", 0);
action_sets.add_action_set("oculus_input", "Oculus Touch Controller Input".into(), 0);
action_set.new_action(
"hand_pose",
"Hand Pose",
"Hand Pose".into(),
ActionType::PoseF,
ActionHandednes::Double,
);
action_set.new_action(
"pointer_pose",
"Pointer Pose",
"Pointer Pose".into(),
ActionType::PoseF,
ActionHandednes::Double,
);
action_set.new_action(
"squeeze",
"Grip Pull",
"Grip Pull".into(),
ActionType::F32,
ActionHandednes::Double,
);
action_set.new_action(
"trigger",
"Trigger Pull",
"Trigger Pull".into(),
ActionType::F32,
ActionHandednes::Double,
);
action_set.new_action(
"trigger_touched",
"Trigger Touch",
"Trigger Touch".into(),
ActionType::Bool,
ActionHandednes::Double,
);
action_set.new_action(
"haptic_feedback",
"Haptic Feedback",
"Haptic Feedback".into(),
ActionType::Haptic,
ActionHandednes::Double,
);
action_set.new_action(
"x_button",
"X Button",
"X Button".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"x_button_touch",
"X Button Touch",
"X Button Touch".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"y_button",
"Y Button",
"Y Button".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"y_button_touch",
"Y Button Touch",
"Y Button Touch".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"a_button",
"A Button",
"A Button".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"a_button_touch",
"A Button Touch",
"A Button Touch".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"b_button",
"B Button",
"B Button".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"b_button_touch",
"B Button Touch",
"B Button Touch".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"menu_button",
"Menu Button",
"Menu Button".into(),
ActionType::Bool,
ActionHandednes::Single,
);
action_set.new_action(
"thumbstick_x",
"Thumbstick X",
"Thumbstick X".into(),
ActionType::F32,
ActionHandednes::Double,
);
action_set.new_action(
"thumbstick_y",
"Thumbstick y",
"Thumbstick y".into(),
ActionType::F32,
ActionHandednes::Double,
);
action_set.new_action(
"thumbstick_touch",
"Thumbstick Touch",
"Thumbstick Touch".into(),
ActionType::Bool,
ActionHandednes::Double,
);
action_set.new_action(
"thumbstick_click",
"Thumbstick Click",
"Thumbstick Click".into(),
ActionType::Bool,
ActionHandednes::Double,
);
action_set.new_action(
"thumbrest_touch",
"Thumbrest Touch",
"Thumbrest Touch".into(),
ActionType::Bool,
ActionHandednes::Double,
);
Expand Down

0 comments on commit b59e5be

Please sign in to comment.