CLI flag to give P2 the controller
This commit is contained in:
parent
d269082c8b
commit
9dfc942dfc
|
|
@ -74,7 +74,7 @@ impl Application {
|
|||
) -> Self {
|
||||
let wgpu = WgpuState::new();
|
||||
let icon = load_icon().ok().map(Arc::new);
|
||||
let mappings = MappingProvider::new(persistence.clone());
|
||||
let mappings = MappingProvider::new(persistence.clone(), args.player2_controller);
|
||||
let shortcuts = ShortcutProvider::new(persistence.clone());
|
||||
let controllers = ControllerManager::new(client.clone(), &mappings);
|
||||
let memory = Arc::new(MemoryClient::new(client.clone()));
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ pub struct CliArgs {
|
|||
/// Automatically open Player 2 for multiplayer
|
||||
#[arg(long)]
|
||||
pub player2: bool,
|
||||
/// Map the first connected controller to Player 2
|
||||
#[arg(long)]
|
||||
pub player2_controller: bool,
|
||||
}
|
||||
|
||||
pub const COLOR_PRESETS: [[Color32; 2]; 3] = [
|
||||
|
|
|
|||
11
src/input.rs
11
src/input.rs
|
|
@ -272,13 +272,14 @@ impl Mappings for InputMapping {
|
|||
#[derive(Clone)]
|
||||
pub struct MappingProvider {
|
||||
persistence: Persistence,
|
||||
first_gamepad_is_p2: bool,
|
||||
device_mappings: Arc<RwLock<HashMap<DeviceId, Arc<RwLock<GamepadMapping>>>>>,
|
||||
sim_mappings: HashMap<SimId, Arc<RwLock<InputMapping>>>,
|
||||
gamepad_info: Arc<RwLock<HashMap<GamepadId, GamepadInfo>>>,
|
||||
}
|
||||
|
||||
impl MappingProvider {
|
||||
pub fn new(persistence: Persistence) -> Self {
|
||||
pub fn new(persistence: Persistence, first_gamepad_is_p2: bool) -> Self {
|
||||
let mut sim_mappings = HashMap::new();
|
||||
let mut device_mappings = HashMap::new();
|
||||
|
||||
|
|
@ -307,6 +308,7 @@ impl MappingProvider {
|
|||
device_mappings: Arc::new(RwLock::new(device_mappings)),
|
||||
gamepad_info: Arc::new(RwLock::new(HashMap::new())),
|
||||
sim_mappings,
|
||||
first_gamepad_is_p2,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -338,7 +340,12 @@ impl MappingProvider {
|
|||
.clone();
|
||||
drop(lock);
|
||||
let mut lock = self.gamepad_info.write().unwrap();
|
||||
let bound_to = SimId::values()
|
||||
let players = if self.first_gamepad_is_p2 {
|
||||
vec![SimId::Player2, SimId::Player1]
|
||||
} else {
|
||||
vec![SimId::Player1, SimId::Player2]
|
||||
};
|
||||
let bound_to = players
|
||||
.into_iter()
|
||||
.find(|sim_id| lock.values().all(|info| info.bound_to != Some(*sim_id)));
|
||||
if let Entry::Vacant(entry) = lock.entry(gamepad.id()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue