예제 #1
0
def export_data() -> Dict[MusicChannel, Optional[Music]]:
    """Return the data used to export this."""
    base_id = WINDOWS[MusicChannel.BASE].chosen_id
    if base_id is not None:
        base_track = Music.by_id(base_id)
    else:
        base_track = None
    data: dict[MusicChannel, Optional[Music]] = {
        MusicChannel.BASE: base_track,
    }
    for channel, win in WINDOWS.items():
        if channel is MusicChannel.BASE:
            continue
        # If collapsed, use the suggested track. Otherwise use the chosen one.
        if is_collapsed:
            if base_track is not None:
                mus_id = base_track.get_suggestion(channel)
            else:
                mus_id = None
        else:
            mus_id = win.chosen_id
        if mus_id is not None:
            data[channel] = Music.by_id(mus_id)
        else:
            data[channel] = None
    return data
예제 #2
0
def load_selitems(loader: LoadScreen):
    """Load the selector items early, to correspond with the loadscreen order."""
    for item in Music.all():
        SEL_ITEMS[item.id] = SelItem.from_data(
            item.id,
            item.selitem_data,
            item.get_attrs()
        )
        loader.step('IMG')
예제 #3
0
def export_data():
    """Return the data used to export this."""
    return {
        channel:
            None if
            win.chosen_id is None
            else Music.by_id(win.chosen_id)
        for channel, win in WINDOWS.items()
    }
예제 #4
0
 def for_channel(channel: MusicChannel) -> List[SelItem]:
     """Get the items needed for a specific channel."""
     music_list = []
     for music in Music.all():
         if music.provides_channel(channel):
             selitem = SEL_ITEMS[music.id].copy()
             selitem.snd_sample = music.get_sample(channel)
             music_list.append(selitem)
     return music_list
예제 #5
0
def set_suggested(music_id: str, *, sel_item: bool = False) -> None:
    """Set the music ID that is suggested for the base.

    If sel_item is true, select the suggested item as well.
    """
    if music_id is None or music_id.casefold() == '<none>':
        # No music, special.
        for channel in MusicChannel:
            if channel is MusicChannel.BASE:
                continue
            WINDOWS[channel].set_suggested()
    else:
        music = Music.by_id(music_id)
        for channel in MusicChannel:
            if channel is MusicChannel.BASE:
                continue

            sugg = music.get_suggestion(channel)
            WINDOWS[channel].set_suggested({sugg} if sugg else set())
예제 #6
0
def selwin_callback(music_id: Optional[str], channel: MusicChannel):
    """Callback for the selector windows.

    This saves into the config file the last selected item.
    """
    if music_id is None:
        music_id = '<NONE>'
    GEN_OPTS['Last_Selected']['music_' + channel.name.casefold()] = music_id
    # If collapsed, the hidden ones follow the base always.
    if channel is channel.BASE:
        set_suggested(music_id, sel_item=is_collapsed)

        # If we have an instance, it's "custom" behaviour, and so disable
        # all the subparts.
        try:
            has_inst = bool(Music.by_id(music_id).inst)
        except KeyError:  # <none>
            has_inst = False

        for win_chan, win in WINDOWS.items():
            if win_chan is not channel.BASE:
                win.readonly = has_inst