예제 #1
0
def get_game_settings(arcade: Arcade) -> List[Dict[str, Any]]:
    game_lut: Dict[str, Dict[int, str]] = {}
    settings_lut: Dict[str, Dict[int, Dict[str, Any]]] = {}
    all_settings = []

    for (game, version, name) in Base.all_games():
        if game not in game_lut:
            game_lut[game] = {}
            settings_lut[game] = {}
        game_lut[game][version] = name
        settings_lut[game][version] = {}

    for (game, version, settings) in Base.all_settings():
        if not settings:
            continue

        # First, set up the basics
        game_settings: Dict[str, Any] = {
            'game': game,
            'version': version,
            'name': game_lut[game][version],
            'bools': [],
            'ints': [],
            'strs': [],
            'longstrs': [],
        }

        # Now, look up the current setting for each returned setting
        for setting_type, setting_unpacker in [
            ('bools', "get_bool"),
            ('ints', "get_int"),
            ('strs', "get_str"),
            ('longstrs', "get_str"),
        ]:
            for setting in settings.get(setting_type, []):
                if setting['category'] not in settings_lut[game][version]:
                    cached_setting = g.data.local.machine.get_settings(
                        arcade.id, game, version, setting['category'])
                    if cached_setting is None:
                        cached_setting = ValidatedDict()
                    settings_lut[game][version][
                        setting['category']] = cached_setting

                current_settings = settings_lut[game][version][
                    setting['category']]
                setting['value'] = getattr(current_settings, setting_unpacker)(
                    setting['setting'])
                game_settings[setting_type].append(setting)

        # Now, include it!
        all_settings.append(game_settings)

    return sorted(
        all_settings,
        key=lambda setting: (setting['game'], setting['version']),
    )
예제 #2
0
def get_game_settings(arcade: Arcade) -> List[Dict[str, Any]]:
    game_lut: Dict[str, Dict[int, str]] = {}
    settings_lut: Dict[str, Dict[int, Dict[str, Any]]] = {}
    all_settings = []

    for (game, version, name) in Base.all_games():
        if game not in game_lut:
            game_lut[game] = {}
            settings_lut[game] = {}
        game_lut[game][version] = name
        settings_lut[game][version] = {}

    for (game, version, settings) in Base.all_settings():
        if not settings:
            continue

        # First, set up the basics
        game_settings: Dict[str, Any] = {
            'game': game,
            'version': version,
            'name': game_lut[game][version],
            'bools': [],
            'ints': [],
        }

        # Now, look up the current setting for each returned setting
        for bool_setting in settings.get('bools', []):
            if bool_setting['category'] not in settings_lut[game][version]:
                cached_setting = g.data.local.machine.get_settings(
                    arcade.id, game, version, bool_setting['category'])
                if cached_setting is None:
                    cached_setting = ValidatedDict()
                settings_lut[game][version][
                    bool_setting['category']] = cached_setting

            current_settings = settings_lut[game][version][
                bool_setting['category']]
            bool_setting['value'] = current_settings.get_bool(
                bool_setting['setting'])
            game_settings['bools'].append(bool_setting)

        # Now, look up the current setting for each returned setting
        for int_setting in settings.get('ints', []):
            if int_setting['category'] not in settings_lut[game][version]:
                cached_setting = g.data.local.machine.get_settings(
                    arcade.id, game, version, int_setting['category'])
                if cached_setting is None:
                    cached_setting = ValidatedDict()
                settings_lut[game][version][
                    int_setting['category']] = cached_setting

            current_settings = settings_lut[game][version][
                int_setting['category']]
            int_setting['value'] = current_settings.get_int(
                int_setting['setting'])
            game_settings['ints'].append(int_setting)

        # Now, include it!
        all_settings.append(game_settings)

    return all_settings