Allow override of system options by runners

This commit is contained in:
Xodetaetl 2015-08-11 12:22:33 +02:00
parent d99ed3906c
commit bc09b8f55e
4 changed files with 33 additions and 6 deletions

View file

@ -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)

View file

@ -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')

View file

@ -32,6 +32,7 @@ class Runner(object):
platform = NotImplemented
game_options = []
runner_options = []
system_options_override = []
context_menu_entries = []
def __init__(self, config=None):

View file

@ -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