def save_config(self): device_name = self.device_name.rsplit("#", 1)[0] device_type = self.device_type_ids[self.type_field.get_index()] # device_make = self.make_field.get_text().strip() device_model = self.model_field.get_text().strip() guid = DeviceManager.joystick_guid(self.device_name) buttons = DeviceManager.joystick_buttons(self.device_name) axes = DeviceManager.joystick_axes(self.device_name) hats = DeviceManager.joystick_hats(self.device_name) balls = DeviceManager.joystick_balls(self.device_name) config = [ "[fs-uae-controller]", "name = {}".format(device_name), "platform = {}".format(platform), "", "[device]", # "make = {}".format(device_make), "model = {}".format(device_model), "type = {}".format(device_type), "", "[sdl]", "guid = {}".format(guid), "buttons = {}".format(buttons), "hats = {}".format(hats), "axes = {}".format(axes), "balls = {}".format(balls), "", "[default]", "include = universal_gamepad", ] button_config = [] for i, button in enumerate(BUTTONS): panel = self.button_panels[i] if panel.event_name: button_config.append( "{0} = {1}".format(panel.event_name, button[3]) ) config.extend(sorted(button_config)) with open( self.get_save_path(self.get_joystick_id() + ".conf"), "w", encoding="UTF-8", ) as f: for line in config: f.write(line) f.write("\n") if len(guid) == 32: with open( self.get_save_path(guid + ".fs-uae-controller"), "w", encoding="UTF-8", ) as f: for line in config: f.write(line) f.write("\n")
def save_config(self): device_name = self.device_name.rsplit("#", 1)[0] device_type = self.device_type_ids[self.type_field.get_index()] device_make = self.make_field.get_text().strip() device_model = self.model_field.get_text().strip() guid = DeviceManager.joystick_guid(self.device_name) buttons = DeviceManager.joystick_buttons(self.device_name) axes = DeviceManager.joystick_axes(self.device_name) hats = DeviceManager.joystick_hats(self.device_name) balls = DeviceManager.joystick_balls(self.device_name) config = [ "[fs-uae-controller]", "name = {}".format(device_name), "platform = {}".format(platform), "", "[device]", "make = {}".format(device_make), "model = {}".format(device_model), "type = {}".format(device_type), "", "[sdl]", "guid = {}".format(guid), "buttons = {}".format(buttons), "hats = {}".format(hats), "axes = {}".format(axes), "balls = {}".format(balls), "", "[default]", "include = universal_gamepad", ] button_config = [] for i, button in enumerate(BUTTONS): panel = self.button_panels[i] if panel.event_name: button_config.append( "{0} = {1}".format(panel.event_name, button[3]) ) config.extend(sorted(button_config)) with open( self.get_save_path(self.get_joystick_id() + ".conf"), "w", encoding="UTF-8", ) as f: for line in config: f.write(line) f.write("\n") if len(guid) == 32: with open( self.get_save_path(guid + ".fs-uae-controller"), "w", encoding="UTF-8", ) as f: for line in config: f.write(line) f.write("\n")
def _create_sdl_gamecontroller_mapping(self): # The mapping to SDL game controller config here is not perfect. # The entire tool should be rewritten to register better what # range of axes is used, etc. fs_to_sdl_mapping = { "south_button": "a", "east_button": "b", "select_button": "back", "dpad_down": "dpdown", "dpad_left": "dpleft", "dpad_right": "dpright", "dpad_up": "dpup", "menu_button": "guide", "left_shoulder": "leftshoulder", "lstick_button": "leftstick", "left_trigger": "lefttrigger", "lstick_left": "leftx", "lstick_right": "leftx", "lstick_up": "lefty", "lstick_down": "lefty", "right_shoulder": "rightshoulder", "rstick_button": "rightstick", "right_trigger": "righttrigger", "rstick_left": "rightx", "rstick_right": "rightx", "rstick_up": "righty", "rstick_down": "righty", "start_button": "start", "west_button": "x", "north_button": "y", } device_name = self.device_name.rsplit("#", 1)[0] # device_make = self.make_field.get_text().strip() device_model = self.model_field.get_text().strip() guid = DeviceManager.joystick_guid(self.device_name) axes = DeviceManager.joystick_axes(self.device_name) balls = DeviceManager.joystick_balls(self.device_name) buttons = DeviceManager.joystick_buttons(self.device_name) hats = DeviceManager.joystick_hats(self.device_name) mapping = {} for i, button in enumerate(BUTTONS): panel = self.button_panels[i] fs_key = button[3] sdl_key = fs_to_sdl_mapping[fs_key] value = panel.event_name if not value: continue # if value.startswith("button_"): if value.startswith("axis_"): value = value.replace("axis_", "a") if value.endswith("_pos"): value = "+" + value[:-4] elif value.endswith("_neg"): value = "-" + value[:-4] # existing = mapping.get(sdl_key, "") # if existing: # if value.replace("+", "-") == existing: # # OK, same axis in correct order # value = value.replace("+", "") # else: # raise Exception("Unexpected axis ordering") elif value.startswith("hat_"): value = value.replace("hat_", "h") value = value.replace("_up", ".1") value = value.replace("_right", ".2") value = value.replace("_down", ".4") value = value.replace("_left", ".8") else: value = value.replace("button_", "b") existing = mapping.get(sdl_key, "") if existing: assert sdl_key in ["leftx", "lefty", "rightx", "righty"] if ( value.startswith("+a") and value.replace("+", "-") == existing ): # OK, same axis in correct order value = value.replace("+", "") else: # raise Exception("Unexpected axis ordering") # Split into half-axes del mapping[sdl_key] mapping["-" + sdl_key] = existing sdl_key = "+" + sdl_key mapping[sdl_key] = value lt = mapping.get("lefttrigger", "") rt = mapping.get("righttrigger", "") if lt.startswith("+") and rt.startswith("+"): # If both triggers have "positive axes", assume the entire axis # range is in use (from - to +). mapping["lefttrigger"] = lt[1:] mapping["righttrigger"] = rt[1:] sorted_mapping = [ "{}:{}".format(x[0], x[1]) for x in sorted(mapping.items()) ] name = self.get_joystick_sdl_name() # Escape escape character (%) name = name.replace("%", "%25") # Escape commas name = name.replace(",", "%2C") # if device_make or device_model: # name = "{} {}".format(device_make, device_model).strip() if platform == "linux": platform_str = "Linux" elif platform == "macos": platform_str = "Mac OS X" elif platform == "windows": platform_str = "Windows" else: platform_str = "Unknown" mapping_str = "{guid},{name}{comma}{mapping},platform:{platform},".format( guid=guid, name=name, comma=("," if mapping else ""), mapping=",".join(sorted_mapping), platform=platform_str, ) mapping_str_2 = "axes:{axes},balls:{balls},buttons:{buttons},hats:{hats},".format( axes=axes, balls=balls, buttons=buttons, hats=hats, platform=platform_str, ) # mapping_str = "{guid},{name}{comma}{mapping},axes:{axes},balls:{balls},buttons:{buttons},hats:{hats},platform:{platform},".format( # guid=guid, # name=name, # comma=("," if mapping else ""), # mapping=",".join(sorted_mapping), # axes=axes, # balls=balls, # buttons=buttons, # hats=hats, # platform=platform_str, # ) return mapping_str, mapping_str_2
def get_joystick_guid(self): return DeviceManager.joystick_guid(self.device_name)