Skip to content

Commit

Permalink
Revert "fix: remove is_user_event"
Browse files Browse the repository at this point in the history
This reverts commit 697da3d.
  • Loading branch information
Sequal32 committed Mar 27, 2023
1 parent 26c28f9 commit 950b8a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/yourcontrols/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ struct NumSetGenericEntry<T> {
#[serde(default)]
use_calculator: bool,
#[serde(default)]
is_user_event: bool,
#[serde(default)]
index_reversed: bool,
condition: Option<Condition>,
// The event to call after the number is set
Expand All @@ -313,6 +315,9 @@ struct NumIncrementEntry<T> {
#[serde(default)]
// If the difference of the values can be passed as a param in order to only make one event call
pass_difference: bool,
#[serde(default)]
// Whether to transmit the client event as a user/aircraft event
is_user_event: bool,
// Whether to use execute_calculator_code to transmit the event
#[serde(default)]
use_calculator: bool,
Expand Down Expand Up @@ -799,6 +804,8 @@ impl Definitions {
action.set_swap_event(swap_event_id);
}

action.set_is_user_event(var.is_user_event);

return Ok((Some(action), var_string));
}

Expand Down Expand Up @@ -859,7 +866,7 @@ impl Definitions {
let (var_string, _) =
self.add_var_string(category, &var.var_name, var.var_units.as_deref(), data_type)?;

let mut mapping = NumIncrement::new(var.increment_by);
let mut mapping = NumIncrement::new(var.is_user_event, var.increment_by);
mapping.set_pass_difference(var.pass_difference);

if let Some(up_event_param) = var.up_event_param {
Expand Down
25 changes: 18 additions & 7 deletions src/yourcontrols/src/syncdefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ pub struct NumSet<T> {
multiply_by: Option<T>,
add_by: Option<T>,
index_reversed: bool,
is_user_event: bool,

current: T,
}

Expand All @@ -189,6 +191,10 @@ where
}
}

pub fn set_is_user_event(&mut self, is_user_event: bool) {
self.is_user_event = is_user_event
}

pub fn set_swap_event(&mut self, event_id: u32) {
self.swap_event_id = Some(event_id)
}
Expand Down Expand Up @@ -227,6 +233,8 @@ where
return;
}

let object_id = if self.is_user_event { 0 } else { 1 };

let value = match self.multiply_by.as_ref() {
Some(multiply_by) => new * *multiply_by,
None => new,
Expand All @@ -252,7 +260,7 @@ where
lvar_transfer.set_unchecked(conn, event_name, None, &value_string);
} else {
conn.transmit_client_event(
1,
object_id,
self.event_id,
value.to_i32().unwrap() as u32,
GROUP_ID,
Expand All @@ -262,7 +270,7 @@ where

if let Some(swap_event_id) = self.swap_event_id {
conn.transmit_client_event(
1,
object_id,
swap_event_id,
0,
GROUP_ID,
Expand All @@ -279,6 +287,7 @@ pub struct NumIncrement<T> {
pub down_event_id: Option<u32>,
pub down_event_name: Option<String>,
pub down_event_param: Option<T>,
pub is_user_event: bool,
pub increment_amount: T,
pub current: T,
pub pass_difference: bool,
Expand All @@ -288,13 +297,14 @@ impl<T> NumIncrement<T>
where
T: Default + ToString,
{
pub fn new(increment_amount: T) -> Self {
pub fn new(is_user_event: bool, increment_amount: T) -> Self {
Self {
up_event_id: None,
down_event_id: None,
up_event_name: None,
down_event_name: None,
increment_amount,
is_user_event,
current: Default::default(),
pass_difference: false,
up_event_param: None,
Expand Down Expand Up @@ -341,14 +351,15 @@ where

fn set_new(&mut self, new: T, conn: &simconnect::SimConnector, lvar_transfer: &mut LVarSyncer) {
let mut working = self.current;
let object_id = if self.is_user_event { 0 } else { 1 };

if self.pass_difference {
if new > self.current {
let difference = (new - self.current).to_i32().unwrap() as u32;

if let Some(event_id) = self.up_event_id {
conn.transmit_client_event(
1,
object_id,
event_id,
difference,
GROUP_ID,
Expand All @@ -362,7 +373,7 @@ where

if let Some(event_id) = self.down_event_id {
conn.transmit_client_event(
1,
object_id,
event_id,
difference,
GROUP_ID,
Expand All @@ -378,7 +389,7 @@ where

if let Some(event_id) = self.down_event_id {
conn.transmit_client_event(
1,
object_id,
event_id,
self.down_event_param.and_then(|x| x.to_u32()).unwrap_or(0),
GROUP_ID,
Expand All @@ -403,7 +414,7 @@ where

if let Some(event_id) = self.up_event_id {
conn.transmit_client_event(
1,
object_id,
event_id,
self.up_event_param.and_then(|x| x.to_u32()).unwrap_or(0),
GROUP_ID,
Expand Down

0 comments on commit 950b8a2

Please sign in to comment.