Skip to content

Commit

Permalink
fix(Target Devices): Dynamically add Capability Mappings
Browse files Browse the repository at this point in the history
- Selecting different target devices will dynamically add capability maps and target devices, based on the target gamepad device, ensuring every feature works out of the box. These will only be applied if the source capability has not already been mapped in the device profile.
  • Loading branch information
pastaq committed Aug 8, 2024
1 parent ec0477b commit 04acf6a
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 45 deletions.
34 changes: 29 additions & 5 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func set_app_gamepad_profile(app: RunningApp) -> void:
logger.debug("No app available to set gamepad profile")
set_gamepad_profile("")
return

# Check to see if this game has any gamepad profiles. If so, set our
# gamepads to use them.
var section := ".".join(["game", app.launch_item.name.to_lower()])
Expand All @@ -297,18 +298,33 @@ func set_app_gamepad_profile(app: RunningApp) -> void:

## Sets the gamepad profile for the running app with the given profile
func set_gamepad_profile(path: String, target_gamepad: String = "") -> void:
# Discover the currently set gamepad to properly add additional capabilities based on that gamepad
var profile_modifier = target_gamepad
if target_gamepad.is_empty():
profile_modifier = settings_manager.get_value("input", "gamepad_profile_target", InputPlumber.DEFAULT_GLOBAL_PROFILE) as String

# If no profile was specified, unset the gamepad profiles
if path == "":
# Try check to see if there is a global gamepad setting
var profile_path := settings_manager.get_value("input", "gamepad_profile", InputPlumber.DEFAULT_GLOBAL_PROFILE) as String
if not profile_path.ends_with(".json") or not FileAccess.file_exists(profile_path):
profile_path = InputPlumber.DEFAULT_GLOBAL_PROFILE
logger.debug("Loading global gamepad profile: " + profile_path)

for gamepad in input_plumber.composite_devices:
gamepad.load_profile_path(profile_path)
gamepad.target_modify_profile(profile_path, profile_modifier)

# Set the target gamepad if one was specified
if not target_gamepad.is_empty():
gamepad.set_target_devices([target_gamepad, "keyboard", "mouse"])
var target_devices := [target_gamepad, "keyboard", "mouse"]
match target_gamepad:
"xb360", "xbox-series", "xbox-elite", "gamepad":
target_devices.append("touchpad")
_:
logger.debug(target_gamepad, "needs no additional target devices.")
logger.debug("Setting target devices to: ", target_devices)
gamepad.set_target_devices(target_devices)

return

logger.debug("Loading gamepad profile: " + path)
Expand All @@ -324,11 +340,19 @@ func set_gamepad_profile(path: String, target_gamepad: String = "") -> void:

# TODO: Save profiles for individual controllers?
for gamepad in input_plumber.composite_devices:
gamepad.load_profile_path(path)
gamepad.target_modify_profile(path, profile_modifier)

# Set the target gamepad if one was specified
if not target_gamepad.is_empty():
logger.debug("Setting target gamepad to: " + target_gamepad)
gamepad.set_target_devices([target_gamepad, "keyboard", "mouse"])
var target_devices := [target_gamepad, "keyboard", "mouse"]
match target_gamepad:
"xb360", "xbox-series", "xbox-elite", "gamepad":
target_devices.append("touchpad")
_:
logger.debug(target_gamepad, "needs no additional target devices.")
logger.debug("Setting target devices to: ", target_devices)
gamepad.set_target_devices(target_devices)

var notify := Notification.new("Using gamepad profile: " + profile.name)
NotificationManager.show(notify)

Expand Down
7 changes: 6 additions & 1 deletion core/global/platform.gd
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ func _read_dmi() -> PLATFORM:
return PLATFORM.AOKZOE_GEN2

# ASUS
elif product_name.contains("ROG Ally RC71L") and vendor_name == "ASUSTeK COMPUTER INC.":
elif product_name in [
"ROG Ally RC71L",
"ROG Ally RC71L_RC71L",
"ROG Ally X RC72LA",
"ROG Ally X RC72LA_RC72LA",
] and vendor_name == "ASUSTeK COMPUTER INC.":
logger.debug("Detected ROG Ally Gen 1 platform")
return PLATFORM.ALLY_GEN1

Expand Down
2 changes: 1 addition & 1 deletion core/platform/hardware/amd_apu_database.tres
Original file line number Diff line number Diff line change
Expand Up @@ -664,4 +664,4 @@ max_boost = 0.0
[resource]
script = ExtResource("2_pbguw")
apu_list = Array[ExtResource("1_a4rxd")]([SubResource("Resource_wio8w"), SubResource("Resource_tcfff"), SubResource("Resource_wmno8"), SubResource("Resource_b8fpu"), SubResource("Resource_1g34g"), SubResource("Resource_sp41q"), SubResource("Resource_h2si0"), SubResource("Resource_0pmlr"), SubResource("Resource_y8ihm"), SubResource("Resource_bvqtb"), SubResource("Resource_rk6b7"), SubResource("Resource_lnxua"), SubResource("Resource_0u6yf"), SubResource("Resource_6f80n"), SubResource("Resource_lbrm0"), SubResource("Resource_t5d1l"), SubResource("Resource_pnxln"), SubResource("Resource_e6tev"), SubResource("Resource_u52m2"), SubResource("Resource_uwui8"), SubResource("Resource_2ks23"), SubResource("Resource_yv37b"), SubResource("Resource_pwp6g"), SubResource("Resource_chr8q"), SubResource("Resource_2pyvv"), SubResource("Resource_3lvxu"), SubResource("Resource_rct3m"), SubResource("Resource_pps3c"), SubResource("Resource_5xvvv"), SubResource("Resource_pseh1"), SubResource("Resource_b2c3r"), SubResource("Resource_q76ve"), SubResource("Resource_xjgl8"), SubResource("Resource_n363j"), SubResource("Resource_bq0w7"), SubResource("Resource_5k7fn"), SubResource("Resource_msyku"), SubResource("Resource_8qb0g"), SubResource("Resource_ynh34"), SubResource("Resource_b6xme"), SubResource("Resource_soogm"), SubResource("Resource_t80ob"), SubResource("Resource_8p12x"), SubResource("Resource_duhig"), SubResource("Resource_20afn"), SubResource("Resource_cc6u3"), SubResource("Resource_fja1l"), SubResource("Resource_fmue3"), SubResource("Resource_wdxra"), SubResource("Resource_6o1lg"), SubResource("Resource_s24u0"), SubResource("Resource_nn84a"), SubResource("Resource_n0x5x"), SubResource("Resource_rj5oh"), SubResource("Resource_jnmf4"), SubResource("Resource_6crrv"), SubResource("Resource_a0hyt"), SubResource("Resource_4nd4h"), SubResource("Resource_fyb6g"), SubResource("Resource_bw227"), SubResource("Resource_u78ox"), SubResource("Resource_vyhi3"), SubResource("Resource_f4wf7"), SubResource("Resource_totkl"), SubResource("Resource_ip781"), SubResource("Resource_gwurq"), SubResource("Resource_4piv1"), SubResource("Resource_0buyr"), SubResource("Resource_i281s"), SubResource("Resource_tfm7x"), SubResource("Resource_6r8fs"), SubResource("Resource_r0vwt"), SubResource("Resource_flekc"), SubResource("Resource_087ib"), SubResource("Resource_aihsu"), SubResource("Resource_e2wwp"), SubResource("Resource_3mvmr"), SubResource("Resource_yqakw"), SubResource("Resource_ach5e"), SubResource("Resource_d5f1t"), SubResource("Resource_5hkqp"), SubResource("Resource_7mq4s"), SubResource("Resource_c8hi5"), SubResource("Resource_gabyr"), SubResource("Resource_dm5fp"), SubResource("Resource_i3yex"), SubResource("Resource_ydwb8"), SubResource("Resource_g7470"), SubResource("Resource_536ug"), SubResource("Resource_0rol5"), SubResource("Resource_xclq2"), SubResource("Resource_uujy8"), SubResource("Resource_m3pd4"), SubResource("Resource_t6ua1")])
database_name = "Intel"
database_name = "AMD APU Database"
3 changes: 2 additions & 1 deletion core/platform/hardware/apu_database.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func get_apu(apu_name: String) -> APUEntry:
if not loaded:
load_db()
if not apu_name in apu_map:
logger.info("APU " + apu_name + " not in APU Database")
logger.debug("APU " + apu_name + " not in " + database_name)
return null
logger.info("Found APU " + apu_name + " in " + database_name)
return apu_map[apu_name]
11 changes: 9 additions & 2 deletions core/platform/hardware/dmi_overrides_apu_database.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="APUDatabase" load_steps=8 format=3 uid="uid://jbsrng73ql4j"]
[gd_resource type="Resource" script_class="APUDatabase" load_steps=9 format=3 uid="uid://jbsrng73ql4j"]

[ext_resource type="Script" path="res://core/platform/hardware/apu_entry.gd" id="1_2ndxe"]
[ext_resource type="Script" path="res://core/platform/hardware/apu_database.gd" id="1_pyvkk"]
Expand Down Expand Up @@ -38,7 +38,14 @@ min_tdp = 8.0
max_tdp = 30.0
max_boost = 10.0

[sub_resource type="Resource" id="Resource_1iyim"]
script = ExtResource("1_2ndxe")
model_name = "ROG Ally X RC72LA_RC72LA"
min_tdp = 8.0
max_tdp = 30.0
max_boost = 10.0

[resource]
script = ExtResource("1_pyvkk")
apu_list = Array[ExtResource("1_2ndxe")]([SubResource("Resource_42d24"), SubResource("Resource_3vns2"), SubResource("Resource_w0hoe"), SubResource("Resource_5sfce"), SubResource("Resource_4wd0b")])
apu_list = Array[ExtResource("1_2ndxe")]([SubResource("Resource_42d24"), SubResource("Resource_3vns2"), SubResource("Resource_w0hoe"), SubResource("Resource_5sfce"), SubResource("Resource_4wd0b"), SubResource("Resource_1iyim")])
database_name = ""
35 changes: 34 additions & 1 deletion core/systems/input/events/event.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class_name InputPlumberEvent
@export var mouse: InputPlumberMouseEvent
@export var dbus: String
@export var gamepad: InputPlumberGamepadEvent
@export var touchpad: InputPlumberTouchpadEvent


## Create a new InputPlumberEvent from the given capability string
Expand Down Expand Up @@ -32,6 +33,8 @@ static func from_event(godot_event: InputEvent) -> InputPlumberEvent:
return null
elif godot_event is InputEventAction:
return null
elif godot_event is InputEventAction:
return null

return null

Expand All @@ -47,6 +50,8 @@ static func from_dict(dict: Dictionary) -> InputPlumberEvent:
event.dbus = dict["dbus"]
if "gamepad" in dict:
event.gamepad = InputPlumberGamepadEvent.from_dict(dict["gamepad"] as Dictionary)
if "touchpad" in dict:
event.touchpad = InputPlumberTouchpadEvent.from_dict(dict["touchpad"] as Dictionary)

return event

Expand All @@ -62,6 +67,8 @@ func to_dict() -> Dictionary:
dict["dbus"] = self.dbus
if self.gamepad:
dict["gamepad"] = self.gamepad.to_dict()
if self.touchpad:
dict["touchpad"] = self.touchpad.to_dict()

return dict

Expand Down Expand Up @@ -102,7 +109,17 @@ func to_capability() -> String:
capability += "Motion"
return capability
return ""

if touchpad:
capability += "Touchpad:"
if touchpad.name:
capability += touchpad.name + ":"
else:
return ""
if touchpad.touch and touchpad.touch.button:
capability += "Button:" + touchpad.touch.button
return capability
if touchpad.touch and touchpad.touch.motion:
capability += "Motion"
return capability


Expand Down Expand Up @@ -142,7 +159,23 @@ func set_capability(capability: String) -> int:
gyro.name = "Gyro"
gamepad.gyro = gyro
return OK
if capability.begins_with("Touchpad"):
touchpad = InputPlumberTouchpadEvent.new()
var parts := capability.split(":")
if not parts.size() in [3, 4]:
return ERR_CANT_CREATE
touchpad.name = parts[1]
var touch := InputPlumberTouchEvent.new()
if parts[2] == "Button":
touch.button = parts[3]
if parts[2] == "Motion":
var motion := InputPlumberTouchMotionEvent.new()
touch.motion = motion
touchpad.touch = touch

return OK


return ERR_DOES_NOT_EXIST


Expand Down
25 changes: 25 additions & 0 deletions core/systems/input/events/touch_event.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extends Resource
class_name InputPlumberTouchEvent

@export var button: String
@export var motion: InputPlumberTouchMotionEvent


static func from_dict(dict: Dictionary) -> InputPlumberTouchEvent:
var event := InputPlumberTouchEvent.new()
if "button" in dict:
event.button = dict["button"]
if "motion" in dict:
event.motion = InputPlumberTouchMotionEvent.from_dict(dict["motion"])

return event


func to_dict() -> Dictionary:
var dict := {}
if self.button:
dict["button"] = self.button
if self.motion:
dict["motion"] = self.motion.to_dict()

return dict
25 changes: 25 additions & 0 deletions core/systems/input/events/touch_motion_event.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extends Resource
class_name InputPlumberTouchMotionEvent

@export var region: String
@export var speed_pps: int


static func from_dict(dict: Dictionary) -> InputPlumberTouchMotionEvent:
var event := InputPlumberTouchMotionEvent.new()
if "region" in dict:
event.region = dict["region"]
if "speed_pps" in dict:
event.speed_pps = dict["speed_pps"]

return event


func to_dict() -> Dictionary:
var dict := {}
if self.region:
dict["region"] = self.region
if self.speed_pps:
dict["speed_pps"] = self.speed_pps

return dict
26 changes: 26 additions & 0 deletions core/systems/input/events/touchpad_event.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extends Resource
class_name InputPlumberTouchpadEvent

@export var name: String
@export var touch: InputPlumberTouchEvent


static func from_dict(dict: Dictionary) -> InputPlumberTouchpadEvent:
var event := InputPlumberTouchpadEvent.new()
if "name" in dict:
event.name = dict["name"]
if "touch" in dict:
var touch = InputPlumberTouchEvent.from_dict(dict["touch"])
event.touch = touch

return event


func to_dict() -> Dictionary:
var dict := {}
if self.name:
dict["name"] = self.name
if self.touch:
dict["touch"] = self.touch.to_dict()

return dict
Loading

0 comments on commit 04acf6a

Please sign in to comment.