mirror of
https://github.com/lutris/lutris
synced 2024-09-15 22:09:55 +00:00
Allow override of system options by runners
This commit is contained in:
parent
d99ed3906c
commit
bc09b8f55e
|
@ -276,12 +276,15 @@ class LutrisConfig(object):
|
|||
def options_as_dict(self, options_type):
|
||||
"""Convert the option list to a dict with option name as keys"""
|
||||
options = {}
|
||||
runner = (import_runner(self.runner_slug)()
|
||||
if self.runner_slug
|
||||
else None)
|
||||
if options_type == 'system':
|
||||
options = sysoptions.system_options
|
||||
elif options_type == 'runner' and self.runner_slug:
|
||||
runner = import_runner(self.runner_slug)()
|
||||
options = (sysoptions.with_runner_overrides(runner)
|
||||
if runner
|
||||
else sysoptions.system_options)
|
||||
elif options_type == 'runner' and runner:
|
||||
options = runner.runner_options
|
||||
elif options_type == 'game' and self.runner_slug:
|
||||
runner = import_runner(self.runner_slug)()
|
||||
elif options_type == 'game' and runner:
|
||||
options = runner.game_options
|
||||
return dict((opt['option'], opt) for opt in options)
|
||||
|
|
|
@ -455,5 +455,12 @@ class SystemBox(ConfigBox):
|
|||
def __init__(self, lutris_config):
|
||||
ConfigBox.__init__(self)
|
||||
self.lutris_config = lutris_config
|
||||
self.options = sysoptions.system_options
|
||||
|
||||
if self.lutris_config.runner_slug:
|
||||
runner = import_runner(self.lutris_config.runner_slug)
|
||||
self.options = sysoptions.with_runner_overrides(runner)
|
||||
else:
|
||||
self.options = sysoptions.system_options
|
||||
|
||||
self.generate_widgets('system')
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ class Runner(object):
|
|||
platform = NotImplemented
|
||||
game_options = []
|
||||
runner_options = []
|
||||
system_options_override = []
|
||||
context_menu_entries = []
|
||||
|
||||
def __init__(self, config=None):
|
||||
|
|
|
@ -141,3 +141,19 @@ system_options = [
|
|||
"controllers. Requires the xboxdrv package installed.")
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def with_runner_overrides(runner):
|
||||
"""Return system options updated with overrides from given runner."""
|
||||
options = system_options
|
||||
if runner.system_options_override:
|
||||
opts_dict = dict((opt['option'], opt) for opt in options)
|
||||
for option in runner.system_options_override:
|
||||
key = option['option']
|
||||
if opts_dict.get(key):
|
||||
opts_dict[key] = opts_dict[key].copy()
|
||||
opts_dict[key].update(option)
|
||||
else:
|
||||
opts_dict[key] = option
|
||||
options = [opt for opt in opts_dict.values()]
|
||||
return options
|
||||
|
|
Loading…
Reference in a new issue