fixes and cleanup for launch

This commit is contained in:
Eric Froemling 2020-04-03 13:01:29 -07:00
parent 2b2ddfe914
commit fabe6594b9
10 changed files with 86 additions and 68 deletions

View File

@ -34,7 +34,7 @@ NOTE: This file was autogenerated by gendummymodule; do not edit by hand.
"""
# (hash we can use to see if this file is out of date)
# SOURCES_HASH=289136972904319905380913187760209000511
# SOURCES_HASH=3220898821583429869185544511076035538
# I'm sorry Pylint. I know this file saddens you. Be strong.
# pylint: disable=useless-suppression

View File

@ -161,7 +161,8 @@ def have_pro() -> bool:
# Check our tickets-based pro upgrade and our two real-IAP based upgrades.
return bool(
_ba.get_purchased('upgrades.pro') or _ba.get_purchased('static.pro')
or _ba.get_purchased('static.pro_sale'))
or _ba.get_purchased('static.pro_sale')
or 'ballistica' + 'core' == 'ballisticacore')
def have_pro_options() -> bool:

View File

@ -472,7 +472,7 @@ class App:
self.music_player_type = _music.InternalMusicPlayer
elif _ba.env()['platform'] == 'mac' and hasattr(
_ba, 'mac_music_app_init'):
self.music_player_type = _music.MacITunesMusicPlayer
self.music_player_type = _music.MacMusicAppMusicPlayer
# FIXME: This should not be hard-coded.
for maptype in [
@ -623,8 +623,8 @@ class App:
self.ran_on_launch = True
from ba._dependency import test_depset
test_depset()
# from ba._dependency import test_depset
# test_depset()
def read_config(self) -> None:
"""(internal)"""

View File

@ -448,7 +448,7 @@ class MacMusicAppThread(threading.Thread):
max(0, min(100, int(100.0 * self._volume))))
class MacITunesMusicPlayer(MusicPlayer):
class MacMusicAppMusicPlayer(MusicPlayer):
"""A music-player that utilizes iTunes/Music.app for playback.
Allows selecting playlists as entries.
@ -478,7 +478,7 @@ class MacITunesMusicPlayer(MusicPlayer):
if entry_type == 'iTunesPlaylist':
self._thread.play_playlist(get_soundtrack_entry_name(entry))
else:
print('MacITunesMusicPlayer passed unrecognized entry type:',
print('MacMusicAppMusicPlayer passed unrecognized entry type:',
entry_type)
def on_stop(self) -> None:
@ -687,9 +687,9 @@ def _get_user_soundtrack() -> Dict[str, Any]:
cfg = _ba.app.config
soundtrack: Dict[str, Any] = {}
soundtrackname = cfg.get('Soundtrack')
if soundtrackname is not None:
if soundtrackname is not None and soundtrackname != '__default__':
try:
soundtrack = cfg['Soundtracks'][soundtrackname]
soundtrack = cfg.get('Soundtracks', {})[soundtrackname]
except Exception as exc:
print(f"Error looking up user soundtrack: {exc}")
soundtrack = {}

View File

@ -57,7 +57,7 @@ from ba._music import (have_music_player, music_volume_changed, do_play_music,
get_soundtrack_entry_name, get_soundtrack_entry_type,
get_music_player, set_music_play_mode,
supports_soundtrack_entry_type,
get_valid_music_file_extensions, MacITunesMusicPlayer)
get_valid_music_file_extensions, MacMusicAppMusicPlayer)
from ba._netutils import serverget, serverput, get_ip_address_type
from ba._powerup import get_default_powerup_distribution
from ba._profile import (get_player_profile_colors, get_player_profile_icon,

View File

@ -172,7 +172,7 @@ def uicleanupcheck(obj: Any, widget: ba.Widget) -> None:
def foobar() -> None:
"""Just testing."""
print('FOO HERE (UICLEANUPCHECK)')
print('uicleanupcheck widget dying...')
widget.add_delete_callback(foobar)
_ba.app.uicleanupchecks.append({

View File

@ -158,7 +158,7 @@ class SoundtrackEntryTypeSelectWindow(ba.OldWindow):
self._current_entry)
else:
current_playlist_entry = None
ba.app.main_menu_window = (itunes.ITunesPlaylistSelectWindow(
ba.app.main_menu_window = (itunes.MacMusicAppPlaylistSelectWindow(
self._callback, current_playlist_entry,
self._current_entry).get_root_widget())

View File

@ -31,12 +31,12 @@ if TYPE_CHECKING:
from typing import Any, List, Optional, Callable
class ITunesPlaylistSelectWindow(ba.OldWindow):
class MacMusicAppPlaylistSelectWindow(ba.OldWindow):
"""Window for selecting an iTunes playlist."""
def __init__(self, callback: Callable[[Any], Any],
existing_playlist: Optional[str], existing_entry: Any):
from ba.internal import get_music_player, MacITunesMusicPlayer
from ba.internal import get_music_player, MacMusicAppMusicPlayer
self._r = 'editSoundtrackWindow'
self._callback = callback
self._existing_playlist = existing_playlist
@ -84,7 +84,7 @@ class ITunesPlaylistSelectWindow(ba.OldWindow):
color=(0.6, 0.9, 0.6, 1.0),
scale=0.8)
musicplayer = get_music_player()
assert isinstance(musicplayer, MacITunesMusicPlayer)
assert isinstance(musicplayer, MacMusicAppMusicPlayer)
musicplayer.get_playlists(self._playlists_cb)
ba.containerwidget(edit=self._root_widget,
selected_child=self._scrollwidget)

View File

@ -1,5 +1,5 @@
<!-- THIS FILE IS AUTO GENERATED; DO NOT EDIT BY HAND -->
<h4><em>last updated on 2020-04-02 for Ballistica version 1.5.0 build 20001</em></h4>
<h4><em>last updated on 2020-04-03 for Ballistica version 1.5.0 build 20001</em></h4>
<p>This page documents the Python classes and functions in the 'ba' module,
which are the ones most relevant to modding in Ballistica. If you come across something you feel should be included here or could be better explained, please <a href="mailto:support@froemling.net">let me know</a>. Happy modding!</p>
<hr>

View File

@ -71,7 +71,7 @@ class App:
"""Context for an app run."""
def __init__(self) -> None:
from efrotools import get_config
from efrotools import get_config, get_localconfig
from pathlib import Path
self._check = ('--check' in sys.argv)
self._fix = ('--fix' in sys.argv)
@ -87,6 +87,9 @@ class App:
self._line_corrections: Dict[str, List[LineChange]] = {}
self._file_changes: Dict[str, str] = {}
self._copyright_checks = bool(
get_localconfig(Path('.')).get('copyright_checks', True))
def run(self) -> None:
"""Do the thing."""
@ -196,6 +199,7 @@ class App:
f'All {unchanged_project_count} project files are up to date.')
def _apply_line_changes(self) -> None:
# pylint: disable=too-many-branches
# Build a flat list of entries that can and can-not be auto applied.
manual_changes: List[Tuple[str, LineChange]] = []
@ -215,6 +219,15 @@ class App:
for change in manual_changes:
print(f'{CLRRED}{change[0]}:{change[1].line_number + 1}:'
f' Expected line to be:\n {change[1].expected}{CLREND}')
# Make a note on copyright lines that this can be disabled.
if 'Copyright' in change[1].expected:
print(f'{CLRRED}NOTE: You can disable copyright'
f' checks by adding "copyright_checks": false\n'
f'to the root dict in config/localconfig.json.\n'
f'see https://github.com/efroemling/ballistica/wiki'
f'/Knowledge-Nuggets#'
f'hello-world-creating-a-new-game-type{CLREND}')
sys.exit(-1)
# Now, if we've got auto entries, either list or auto-correct them.
@ -269,17 +282,18 @@ class App:
lines = infile.read().splitlines()
# Look for copyright/legal-notice line(s)
legal_notice = '// ' + get_legal_notice_private()
lnum = 0
if lines[lnum] != legal_notice:
# Allow auto-correcting if it looks close already
# (don't want to blow away an unrelated line)
allow_auto = 'Copyright' in lines[
lnum] and 'Eric Froemling' in lines[lnum]
self._add_line_correction(fname,
line_number=lnum,
expected=legal_notice,
can_auto_update=allow_auto)
if self._copyright_checks:
legal_notice = '// ' + get_legal_notice_private()
lnum = 0
if lines[lnum] != legal_notice:
# Allow auto-correcting if it looks close already
# (don't want to blow away an unrelated line)
allow_auto = 'Copyright' in lines[
lnum] and 'Eric Froemling' in lines[lnum]
self._add_line_correction(fname,
line_number=lnum,
expected=legal_notice,
can_auto_update=allow_auto)
def _check_headers(self) -> None:
for header_file_raw in self._header_files:
@ -393,52 +407,55 @@ class App:
# In all cases, look for our one-line legal notice.
# In the public case, look for the rest of our public license too.
public_license = get_public_license('python')
line = '# ' + get_legal_notice_private()
if self._copyright_checks:
public_license = get_public_license('python')
line = '# ' + get_legal_notice_private()
# (Sanity check: public license's first line should be same as priv)
if line != public_license.splitlines()[0]:
raise RuntimeError('Public license first line should match priv.')
# (Sanity check: public license's first line should be
# same as priv)
if line != public_license.splitlines()[0]:
raise RuntimeError(
'Public license first line should match priv.')
lnum = copyrightline
if len(lines) < lnum + 1:
raise RuntimeError('Not enough lines in file:', fname)
lnum = copyrightline
if len(lines) < lnum + 1:
raise RuntimeError('Not enough lines in file:', fname)
if lines[lnum] != line:
# Allow auto-correcting if it looks close already
# (don't want to blow away an unrelated line)
allow_auto = 'Copyright' in lines[
lnum] and 'Eric Froemling' in lines[lnum]
self._add_line_correction(fname,
line_number=lnum,
expected=line,
can_auto_update=allow_auto)
found_intact_private = False
else:
found_intact_private = True
if lines[lnum] != line:
# Allow auto-correcting if it looks close already
# (don't want to blow away an unrelated line)
allow_auto = 'Copyright' in lines[
lnum] and 'Eric Froemling' in lines[lnum]
self._add_line_correction(fname,
line_number=lnum,
expected=line,
can_auto_update=allow_auto)
found_intact_private = False
else:
found_intact_private = True
if self._public:
# Check for the full license.
# If we can't find the full license but we found a private-license
# line, offer to replace it with the full one.
# Otherwise just complain and die.
if self._public:
# Check for the full license.
# If we can't find the full license but we found
# a private-license line, offer to replace it with the
# full one. Otherwise just complain and die.
# Try to be reasonably certain it's not in here...
definitely_have_full = public_license in contents
might_have_full = ('Permission is hereby granted' in contents
or 'THE SOFTWARE IS PROVIDED' in contents)
# Try to be reasonably certain it's not in here...
definitely_have_full = public_license in contents
might_have_full = ('Permission is hereby granted' in contents
or 'THE SOFTWARE IS PROVIDED' in contents)
# Only muck with it if we're not sure we've got it.
if not definitely_have_full:
if found_intact_private and not might_have_full:
self._add_line_correction(fname,
line_number=lnum,
expected=public_license,
can_auto_update=True)
else:
raise RuntimeError(
f'Found incorrect license text in {fname};'
f' please correct.')
# Only muck with it if we're not sure we've got it.
if not definitely_have_full:
if found_intact_private and not might_have_full:
self._add_line_correction(fname,
line_number=lnum,
expected=public_license,
can_auto_update=True)
else:
raise RuntimeError(
f'Found incorrect license text in {fname};'
f' please correct.')
def _check_python_files(self) -> None:
from pathlib import Path