Skip to content

Commit

Permalink
feat(junowen): dynamic delay change on all scene
Browse files Browse the repository at this point in the history
  • Loading branch information
progre committed Oct 4, 2023
1 parent 7542963 commit 1b2b7ef
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
6 changes: 6 additions & 0 deletions junowen/src/helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use junowen_lib::DevicesInput;

pub fn inputed_number(input: &DevicesInput) -> Option<u8> {
let raw_keys = &input.input_device_array[0].raw_keys;
(0..=9).find(|i| raw_keys[(b'0' + i) as usize] & 0x80 != 0)
}
1 change: 1 addition & 0 deletions junowen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod cui;
mod helper;
mod interprocess;
mod session;
mod state;
Expand Down
13 changes: 11 additions & 2 deletions junowen/src/state/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::sync::mpsc::RecvError;
use anyhow::Result;
use junowen_lib::{Input, Th19};

use crate::session::{RoundInitial, Session};
use crate::{
helper::inputed_number,
session::{RoundInitial, Session},
};

pub fn on_input_players(session: &mut Session, th19: &mut Th19) -> Result<(), RecvError> {
// -1フレーム目、0フレーム目は複数回呼ばれ、回数が不定なのでスキップする
Expand All @@ -12,7 +15,13 @@ pub fn on_input_players(session: &mut Session, th19: &mut Th19) -> Result<(), Re
input.set_p1_input(Input(0));
input.set_p2_input(Input(0));
} else {
let (p1, p2) = session.enqueue_input_and_dequeue(th19.input().p1_input().0 as u8, None)?;
let input = th19.input();
let delay = if session.host() {
inputed_number(input)
} else {
None
};
let (p1, p2) = session.enqueue_input_and_dequeue(input.p1_input().0 as u8, delay)?;
let input = th19.input_mut();
input.set_p1_input(Input(p1 as u32));
input.set_p2_input(Input(p2 as u32));
Expand Down
22 changes: 15 additions & 7 deletions junowen/src/state/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::sync::mpsc::RecvError;
use anyhow::Result;
use junowen_lib::{th19_helpers::reset_cursors, Input, Menu, ScreenId, Th19};

use crate::session::{MatchInitial, RoundInitial, Session};
use crate::{
helper::inputed_number,
session::{MatchInitial, RoundInitial, Session},
};

pub fn on_input_players(
first_time: bool,
Expand Down Expand Up @@ -55,13 +58,13 @@ pub fn on_input_players(
return Ok(());
}

let delay = if !session.host() {
None
let input = th19.input();
let delay = if session.host() {
inputed_number(input)
} else {
let raw_keys = &th19.input().input_device_array[0].raw_keys;
(0..=9).find(|i| raw_keys[(b'0' + i) as usize] & 0x80 != 0)
None
};
let (p1, p2) = session.enqueue_input_and_dequeue(th19.input().p1_input().0 as u8, delay)?;
let (p1, p2) = session.enqueue_input_and_dequeue(input.p1_input().0 as u8, delay)?;
let input = th19.input_mut();
input.set_p1_input(Input(p1 as u32));
input.set_p2_input(Input(p2 as u32));
Expand All @@ -75,13 +78,18 @@ pub fn on_input_menu(session: &mut Session, th19: &mut Th19) -> Result<(), RecvE
return Ok(());
}

let delay = if session.host() {
inputed_number(th19.input())
} else {
None
};
let (p1, _p2) = session.enqueue_input_and_dequeue(
if session.host() {
th19.menu_input().0 as u8
} else {
Input::NULL as u8
},
None,
delay,
)?;
*th19.menu_input_mut() = Input(p1 as u32);
Ok(())
Expand Down

0 comments on commit 1b2b7ef

Please sign in to comment.