summaryrefslogtreecommitdiff
path: root/platforms/tortuise-script-compiled/src/input.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-10-31 12:19:17 -0400
committerMica White <botahamec@outlook.com>2026-10-31 12:19:17 -0400
commitc2dfde109b8cd59946081ff2665bd1e75a6d116f (patch)
tree9a889a42b9a67fba8851318a79d33a956f8afad1 /platforms/tortuise-script-compiled/src/input.rs
parentec40f6e3acc7874b82709ab81b254c741529fdff (diff)
Fix import
Diffstat (limited to 'platforms/tortuise-script-compiled/src/input.rs')
-rw-r--r--platforms/tortuise-script-compiled/src/input.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/platforms/tortuise-script-compiled/src/input.rs b/platforms/tortuise-script-compiled/src/input.rs
index a7d7340..da197b9 100644
--- a/platforms/tortuise-script-compiled/src/input.rs
+++ b/platforms/tortuise-script-compiled/src/input.rs
@@ -102,6 +102,7 @@ pub enum PowerInfo {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Gamepad(usize);
+#[cfg(feature = "gamepad")]
impl From<Button> for gilrs::Button {
fn from(value: Button) -> Self {
match value {
@@ -128,6 +129,7 @@ impl From<Button> for gilrs::Button {
}
}
+#[cfg(feature = "gamepad")]
impl From<Axis> for gilrs::Axis {
fn from(value: Axis) -> Self {
match value {
@@ -143,6 +145,7 @@ impl From<Axis> for gilrs::Axis {
}
}
+#[cfg(feature = "gamepad")]
impl From<Option<gilrs::PowerInfo>> for PowerInfo {
fn from(value: Option<gilrs::PowerInfo>) -> Self {
match value {
@@ -181,6 +184,7 @@ impl From<KeyCode> for crossterm::event::KeyCode {
}
}
+#[cfg(feature = "gamepad")]
impl Gamepad {
pub fn is_button_pressed_this_frame(&self, context: &ScriptContext, button: Button) -> bool {
context
@@ -217,43 +221,86 @@ impl Gamepad {
}
}
+#[cfg(not(feature = "gamepad"))]
+impl Gamepad {
+ pub fn is_button_pressed_this_frame(&self, _context: &ScriptContext, _button: Button) -> bool {
+ false
+ }
+
+ pub fn is_button_released_this_frame(&self, _context: &ScriptContext, _button: Button) -> bool {
+ false
+ }
+
+ pub fn is_button_down(&self, _context: &ScriptContext, _button: Button) -> bool {
+ false
+ }
+
+ pub fn axis_value(&self, _context: &ScriptContext, _axis: Axis) -> f32 {
+ 0.0
+ }
+
+ pub fn is_connected(&self, _context: &ScriptContext) -> bool {
+ false
+ }
+
+ pub fn power_info(&self, _context: &ScriptContext) -> PowerInfo {
+ PowerInfo::Unknown
+ }
+}
+
impl ScriptContext<'_> {
pub fn is_key_pressed_this_frame(&self, key_code: KeyCode) -> bool {
+ #[cfg(feature = "profiling")]
puffin::profile_function!();
self.0.input.is_key_pressed_this_frame(key_code.into())
}
pub fn is_mouse_clicked_this_frame(&self) -> bool {
+ #[cfg(feature = "profiling")]
puffin::profile_function!();
self.0.input.is_mouse_clicked_this_frame()
}
pub fn mouse_location(&self) -> Option<Position> {
+ #[cfg(feature = "profiling")]
puffin::profile_function!();
self.0.input.mouse_location()
}
pub fn scroll_direction_this_frame(&self) -> Option<Direction> {
+ #[cfg(feature = "profiling")]
puffin::profile_function!();
self.0.input.scroll_direction_this_frame()
}
+ #[cfg(feature = "gamepad")]
pub fn is_gamepad_connected_this_frame(&self) -> Option<Gamepad> {
+ #[cfg(feature = "profiling")]
puffin::profile_function!();
self.0.input.is_gamepad_connected_this_frame().map(Gamepad)
}
+ #[cfg(not(feature = "gamepad"))]
+ pub fn is_gamepad_connected_this_frame(&self) -> Option<Gamepad> {
+ #[cfg(feature = "profiling")]
+ puffin::profile_function!();
+ None
+ }
+
pub fn is_focused(&self) -> bool {
+ #[cfg(feature = "profiling")]
puffin::profile_function!();
self.0.input.is_focused()
}
pub fn was_focused_this_frame(&self) -> bool {
+ #[cfg(feature = "profiling")]
puffin::profile_function!();
self.0.input.was_focused_this_frame()
}
pub fn was_unfocused_this_frame(&self) -> bool {
+ #[cfg(feature = "profiling")]
puffin::profile_function!();
self.0.input.was_unfocused_this_frame()
}