CLI flag to give P2 the controller

This commit is contained in:
Simon Gellis 2026-02-20 00:02:04 -05:00
parent d269082c8b
commit 9dfc942dfc
No known key found for this signature in database
GPG Key ID: DA576912FED9577B
3 changed files with 13 additions and 3 deletions

View File

@ -74,7 +74,7 @@ impl Application {
) -> Self { ) -> Self {
let wgpu = WgpuState::new(); let wgpu = WgpuState::new();
let icon = load_icon().ok().map(Arc::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 shortcuts = ShortcutProvider::new(persistence.clone());
let controllers = ControllerManager::new(client.clone(), &mappings); let controllers = ControllerManager::new(client.clone(), &mappings);
let memory = Arc::new(MemoryClient::new(client.clone())); let memory = Arc::new(MemoryClient::new(client.clone()));

View File

@ -43,6 +43,9 @@ pub struct CliArgs {
/// Automatically open Player 2 for multiplayer /// Automatically open Player 2 for multiplayer
#[arg(long)] #[arg(long)]
pub player2: bool, pub player2: bool,
/// Map the first connected controller to Player 2
#[arg(long)]
pub player2_controller: bool,
} }
pub const COLOR_PRESETS: [[Color32; 2]; 3] = [ pub const COLOR_PRESETS: [[Color32; 2]; 3] = [

View File

@ -272,13 +272,14 @@ impl Mappings for InputMapping {
#[derive(Clone)] #[derive(Clone)]
pub struct MappingProvider { pub struct MappingProvider {
persistence: Persistence, persistence: Persistence,
first_gamepad_is_p2: bool,
device_mappings: Arc<RwLock<HashMap<DeviceId, Arc<RwLock<GamepadMapping>>>>>, device_mappings: Arc<RwLock<HashMap<DeviceId, Arc<RwLock<GamepadMapping>>>>>,
sim_mappings: HashMap<SimId, Arc<RwLock<InputMapping>>>, sim_mappings: HashMap<SimId, Arc<RwLock<InputMapping>>>,
gamepad_info: Arc<RwLock<HashMap<GamepadId, GamepadInfo>>>, gamepad_info: Arc<RwLock<HashMap<GamepadId, GamepadInfo>>>,
} }
impl MappingProvider { 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 sim_mappings = HashMap::new();
let mut device_mappings = HashMap::new(); let mut device_mappings = HashMap::new();
@ -307,6 +308,7 @@ impl MappingProvider {
device_mappings: Arc::new(RwLock::new(device_mappings)), device_mappings: Arc::new(RwLock::new(device_mappings)),
gamepad_info: Arc::new(RwLock::new(HashMap::new())), gamepad_info: Arc::new(RwLock::new(HashMap::new())),
sim_mappings, sim_mappings,
first_gamepad_is_p2,
} }
} }
@ -338,7 +340,12 @@ impl MappingProvider {
.clone(); .clone();
drop(lock); drop(lock);
let mut lock = self.gamepad_info.write().unwrap(); 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() .into_iter()
.find(|sim_id| lock.values().all(|info| info.bound_to != Some(*sim_id))); .find(|sim_id| lock.values().all(|info| info.bound_to != Some(*sim_id)));
if let Entry::Vacant(entry) = lock.entry(gamepad.id()) { if let Entry::Vacant(entry) = lock.entry(gamepad.id()) {