Skip to content

Commit

Permalink
Good work Kevin
Browse files Browse the repository at this point in the history
  • Loading branch information
kkevlar committed Jun 14, 2024
1 parent ddeb559 commit af11500
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions mjoy_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gilrs = {path = "../vendored/gilrs/gilrs"}
serde = {version = "1.0.160", features = ["derive"]}
serde_json = "1.0.96"
mjoy_gui = {path = "../mjoy_gui"}
command_server = {path = "../command_server"}
regex = "1.5.4"
rand = "0.8.5"
tracing = "0.1.40"
Expand Down
10 changes: 9 additions & 1 deletion mjoy_core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,16 @@ fn main() {
&mut gilrs,
);
if changed {
let TopContext {
mut fbinfo,
mut all_joys,
} = top_context.replace(None).unwrap();

let fbinfo = update_gui_teams(&frozen);
let all_joys = outjoy::Outjoys::new(&frozen);
let all_joys = {
all_joys.overwrite(&frozen);
all_joys
};
let new_context = TopContext { fbinfo, all_joys };
top_context.replace(Some(new_context));

Expand Down
10 changes: 10 additions & 0 deletions mjoy_core/src/outjoy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl Outjoy {
Self { team, joy }
}

fn mutate_team(&mut self, team: Team) {
self.team = team;
}

fn inaxis_to_letter(a: &crate::injoy::NamedAxis, f: f32) -> Option<String> {
use crate::injoy::NamedAxis;
match a {
Expand Down Expand Up @@ -352,6 +356,12 @@ impl Outjoys {
Self { outjoys }
}

pub fn overwrite(&mut self, tl: &TeamLock) {
for (i, team) in tl.teams.iter().enumerate() {
self.outjoys.get_mut(i).unwrap().mutate_team(team.clone());
}
}

pub fn update<'b, 'c, 'd, 'e>(&self, context: &'d mut UpdateContext<'b, 'c, 'e>) {
for outjoy in self.outjoys.iter() {
outjoy.update(context);
Expand Down

0 comments on commit af11500

Please sign in to comment.