# Released under the MIT License. See LICENSE for details.
#
"""Common shared Ballistica components.

For modding purposes, this package should generally not be used
directly. Instead one should use purpose-built packages such as
:mod:`bascenev1` or :mod:`bauiv1` which themselves import various
functionality from here and reexpose it in a more focused way.
"""

# pylint: disable=redefined-builtin

# ba_meta require api 9

# The stuff we expose here at the top level is our 'public' api for use
# from other modules/packages. Code *within* this package should import
# things from this package's submodules directly to reduce the chance of
# dependency loops. The exception is TYPE_CHECKING blocks and
# annotations - since those aren't evaluated at runtime, it is cleaner
# looking to use top level names directly.

import _babase
from _babase import (
    add_clean_frame_callback,
    allows_ticket_sales,
    android_get_external_files_dir,
    appname,
    appnameupper,
    apptime,
    apptimer,
    AppTimer,
    atexit,
    asset_loads_allowed,
    fullscreen_control_available,
    fullscreen_control_get,
    fullscreen_control_key_shortcut,
    fullscreen_control_set,
    can_display_chars,
    charstr,
    clipboard_get_text,
    clipboard_has_text,
    clipboard_is_supported,
    clipboard_set_text,
    ContextCall,
    ContextRef,
    crash,
    displaytime,
    displaytimer,
    DisplayTimer,
    do_once,
    env,
    Env,
    fade_screen,
    fatal_error,
    get_display_resolution,
    get_immediate_return_code,
    get_input_idle_time,
    get_max_graphics_quality,
    get_replays_dir,
    get_string_height,
    get_string_width,
    get_suppress_config_and_state_writes,
    get_ui_scale,
    get_virtual_safe_area_size,
    get_virtual_screen_size,
    apsimplesoundget,
    has_user_run_commands,
    have_permission,
    in_logic_thread,
    in_main_menu,
    increment_analytics_count,
    request_main_ui,
    is_os_playing_music,
    is_xcode_build,
    LangStr,
    lock_all_input,
    mac_music_app_get_playlists,
    mac_music_app_get_volume,
    mac_music_app_init,
    mac_music_app_play_playlist,
    mac_music_app_set_volume,
    mac_music_app_stop,
    menu_press,
    music_player_play,
    music_player_set_volume,
    music_player_shutdown,
    music_player_stop,
    native_review_request,
    native_review_request_supported,
    native_stack_trace,
    open_file_externally,
    open_url,
    overlay_web_browser_close,
    overlay_web_browser_is_open,
    overlay_web_browser_is_supported,
    overlay_web_browser_open_url,
    print_load_info,
    pushcall,
    quit,
    reload_hooks,
    reload_media,
    request_permission,
    resolve_legacy_asset_name,
    safecolor,
    screenmessage,
    set_analytics_screen,
    set_app_exit_code,
    set_asset_name_compat_versions,
    set_thread_name,
    set_main_ui_input_device,
    set_account_sign_in_state,
    set_ui_scale,
    show_progress_bar,
    split_text_into_lines,
    shutdown_suppress_begin,
    shutdown_suppress_end,
    shutdown_suppress_count,
    SimpleSound,
    suppress_config_and_state_writes,
    supports_max_fps,
    supports_vsync,
    supports_unicode_display,
    unlock_all_input,
    update_internal_logger_levels,
    user_agent_string,
    user_ran_commands,
    Vec3,
    workspaces_in_use,
)

from babase._accountv2 import AccountV2Handle, AccountV2Subsystem
from babase._analytics import AnalyticsSubsystem
from babase._app import App, AppState
from babase._appcomponent import AppComponentSubsystem
from babase._appconfig import commit_app_config
from babase._appintent import AppIntent, AppIntentDefault, AppIntentExec
from babase._asset_packages import (
    check_asset_package_load,
    loaded_asset_package_apverids,
)
from babase._assetref import SimpleSoundHandle, getsimplesound
from babase._appmode import (
    AppMode,
    ControlPermission,
    ControlPermissionRequest,
)
from babase._appsubsystem import AppSubsystem
from babase._appmodeselector import AppModeSelector
from babase._appconfig import AppConfig
from babase._apputils import (
    AppHealthSubsystem,
    is_browser_likely_available,
    utc_now_cloud,
)
from babase._cloudloggercontrol import handle_cloud_logger_config_changed
from babase._logreporting import get_log_reporter
from babase._cloud import CloudSubscription
from babase._devconsole import (
    DevConsoleButtonDef,
    DevConsoleSubsystem,
    DevConsoleTab,
    DevConsoleTabEntry,
)
from babase._emptyappmode import EmptyAppMode
from babase._constructmode import ConstructAppMode
from babase._error import (
    ActivityNotFoundError,
    ActorNotFoundError,
    ContextError,
    DelegateNotFoundError,
    InputDeviceNotFoundError,
    MapNotFoundError,
    NodeNotFoundError,
    NotFoundError,
    PlayerNotFoundError,
    SessionNotFoundError,
    SessionPlayerNotFoundError,
    SessionTeamNotFoundError,
    TeamNotFoundError,
    WidgetNotFoundError,
)
from babase._gc import GarbageCollectionSubsystem
from babase._general import (
    AppTime,
    Call,
    CallPartial,
    CallStrict,
    DisplayTime,
    Existable,
    WeakCall,
    WeakCallPartial,
    WeakCallStrict,
    existing,
    get_type_name,
    getclass,
    storagename,
    verify_object_death,
)
from babase._language import (
    LangStrDir,
    LanguageSubsystem,
    Lstr,
    get_legacy_langdata,
    langstr_value,
    resolve_langstrs,
    translate_server_text,
)
from babase._locale import LocaleSubsystem
from babase._logging import (
    accountlog,
    applog,
    assetmanagerlog,
    balog,
    lifecyclelog,
    netlog,
    uilog,
    userlog,
)
from babase._login import LoginAdapter, LoginInfo, discord_sign_in
from babase._generated.enums import (
    InputType,
    Permission,
    QuitType,
    SpecialChar,
    UIScale,
)
from babase._math import normalized_color, is_point_in_box, vec3validate
from babase._meta import MetadataSubsystem
from babase._assetsubsystem import (
    AssetSubsystem,
    make_progress_reporter,
    ResolveResult,
    ResolveProgress,
    ResolvePhase,
    AssetResolveError,
)
from babase._env import DEFAULT_REQUEST_TIMEOUT_SECONDS
from babase._net import get_ip_address_type, NetworkSubsystem
from babase._plugin import PluginSpec, Plugin, PluginSubsystem
from babase._simpledialog import SimpleDialog
from babase._stringedit import StringEditAdapter, StringEditSubsystem
from babase._text import timestring
from babase._workspace import WorkspaceSubsystem

#: The :class:`~babase.App` singleton for the current process. Also
#: exposed at ``bauiv1.app``, ``bascenev1.app``, etc. — they all
#: refer to this same object.
app = App()
_babase.app = app

__all__ = [
    'accountlog',
    'AccountV2Handle',
    'AccountV2Subsystem',
    'ActivityNotFoundError',
    'ActorNotFoundError',
    'allows_ticket_sales',
    'add_clean_frame_callback',
    'AnalyticsSubsystem',
    'android_get_external_files_dir',
    'app',
    'App',
    'AppComponentSubsystem',
    'AppConfig',
    'AppHealthSubsystem',
    'AppIntent',
    'AppIntentDefault',
    'AppIntentExec',
    'AppMode',
    'ControlPermission',
    'ControlPermissionRequest',
    'AppState',
    'applog',
    'appname',
    'appnameupper',
    'AppModeSelector',
    'AppSubsystem',
    'apptime',
    'AppTime',
    'apptime',
    'apptimer',
    'AppTimer',
    'asset_loads_allowed',
    'assetmanagerlog',
    'AssetSubsystem',
    'AssetResolveError',
    'atexit',
    'balog',
    'Call',
    'CallPartial',
    'CallStrict',
    'fullscreen_control_available',
    'fullscreen_control_get',
    'fullscreen_control_key_shortcut',
    'fullscreen_control_set',
    'can_display_chars',
    'charstr',
    'clipboard_get_text',
    'clipboard_has_text',
    'clipboard_is_supported',
    'CloudSubscription',
    'clipboard_set_text',
    'commit_app_config',
    'ContextCall',
    'ContextError',
    'ContextRef',
    'crash',
    'DelegateNotFoundError',
    'DevConsoleButtonDef',
    'DevConsoleTab',
    'DevConsoleTabEntry',
    'DevConsoleSubsystem',
    'DisplayTime',
    'displaytime',
    'displaytimer',
    'DisplayTimer',
    'discord_sign_in',
    'do_once',
    'ConstructAppMode',
    'EmptyAppMode',
    'env',
    'Env',
    'Existable',
    'existing',
    'fade_screen',
    'fatal_error',
    'GarbageCollectionSubsystem',
    'get_display_resolution',
    'get_immediate_return_code',
    'get_input_idle_time',
    'get_ip_address_type',
    'get_legacy_langdata',
    'get_max_graphics_quality',
    'get_replays_dir',
    'get_string_height',
    'get_string_width',
    'get_suppress_config_and_state_writes',
    'get_type_name',
    'get_ui_scale',
    'get_virtual_safe_area_size',
    'get_virtual_screen_size',
    'getclass',
    'apsimplesoundget',
    'getsimplesound',
    'get_log_reporter',
    'handle_cloud_logger_config_changed',
    'has_user_run_commands',
    'have_permission',
    'in_logic_thread',
    'in_main_menu',
    'increment_analytics_count',
    'InputDeviceNotFoundError',
    'InputType',
    'request_main_ui',
    'is_browser_likely_available',
    'is_browser_likely_available',
    'is_os_playing_music',
    'is_point_in_box',
    'is_xcode_build',
    'LanguageSubsystem',
    'check_asset_package_load',
    'loaded_asset_package_apverids',
    'LocaleSubsystem',
    'lifecyclelog',
    'LangStr',
    'LangStrDir',
    'lock_all_input',
    'LoginAdapter',
    'LoginInfo',
    'Lstr',
    'make_progress_reporter',
    'mac_music_app_get_playlists',
    'mac_music_app_get_volume',
    'mac_music_app_init',
    'mac_music_app_play_playlist',
    'mac_music_app_set_volume',
    'mac_music_app_stop',
    'MapNotFoundError',
    'menu_press',
    'MetadataSubsystem',
    'music_player_play',
    'music_player_set_volume',
    'music_player_shutdown',
    'music_player_stop',
    'native_review_request',
    'native_review_request_supported',
    'native_stack_trace',
    'netlog',
    'NetworkSubsystem',
    'NodeNotFoundError',
    'normalized_color',
    'NotFoundError',
    'open_file_externally',
    'open_url',
    'overlay_web_browser_close',
    'overlay_web_browser_is_open',
    'overlay_web_browser_is_supported',
    'overlay_web_browser_open_url',
    'Permission',
    'PlayerNotFoundError',
    'Plugin',
    'PluginSubsystem',
    'PluginSpec',
    'print_load_info',
    'pushcall',
    'quit',
    'QuitType',
    'reload_hooks',
    'langstr_value',
    'reload_media',
    'request_permission',
    'resolve_langstrs',
    'translate_server_text',
    'ResolveResult',
    'ResolveProgress',
    'ResolvePhase',
    'resolve_legacy_asset_name',
    'safecolor',
    'screenmessage',
    'SessionNotFoundError',
    'SessionPlayerNotFoundError',
    'SessionTeamNotFoundError',
    'set_analytics_screen',
    'set_app_exit_code',
    'set_asset_name_compat_versions',
    'set_main_ui_input_device',
    'set_thread_name',
    'set_account_sign_in_state',
    'set_ui_scale',
    'show_progress_bar',
    'split_text_into_lines',
    'shutdown_suppress_begin',
    'shutdown_suppress_end',
    'shutdown_suppress_count',
    'SimpleDialog',
    'SimpleSound',
    'SimpleSoundHandle',
    'suppress_config_and_state_writes',
    'SpecialChar',
    'storagename',
    'StringEditAdapter',
    'StringEditSubsystem',
    'supports_max_fps',
    'supports_vsync',
    'supports_unicode_display',
    'TeamNotFoundError',
    'timestring',
    'uilog',
    'userlog',
    'UIScale',
    'unlock_all_input',
    'update_internal_logger_levels',
    'user_agent_string',
    'user_ran_commands',
    'utc_now_cloud',
    'Vec3',
    'vec3validate',
    'verify_object_death',
    'WeakCall',
    'WeakCallPartial',
    'WeakCallStrict',
    'WidgetNotFoundError',
    'workspaces_in_use',
    'WorkspaceSubsystem',
    'DEFAULT_REQUEST_TIMEOUT_SECONDS',
]

# We want stuff to show up as babase.Foo instead of babase._sub.Foo.
# UPDATE: Trying without this for now. Seems like this might cause more
# harm than good. Can flip it back on if it is missed.
# set_canonical_module_names(globals())

# Allow the native layer to wrap a few things up.
_babase.reached_end_of_babase()

# Marker we pop down at the very end so other modules can run sanity
# checks to make sure we aren't importing them reciprocally when they
# import us.
_REACHED_END_OF_MODULE = True
