mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
fix double free bug, add logging, update to python 3.14
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import copy
|
||||
from pathlib import Path
|
||||
from libs.tja import TJAParser
|
||||
@@ -8,15 +9,16 @@ from libs.video import VideoPlayer
|
||||
import pyray as ray
|
||||
from scenes.game import ClearAnimation, FCAnimation, FailAnimation, GameScreen, Player, Background, SCREEN_WIDTH, ResultTransition
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class TwoPlayerGameScreen(GameScreen):
|
||||
def on_screen_start(self):
|
||||
if not self.screen_init:
|
||||
super().on_screen_start()
|
||||
scene_preset = self.tja.metadata.scene_preset
|
||||
if self.background is not None:
|
||||
self.background.unload()
|
||||
self.background = Background(3, self.bpm, scene_preset=scene_preset)
|
||||
self.result_transition = ResultTransition(3)
|
||||
super().on_screen_start()
|
||||
scene_preset = self.tja.metadata.scene_preset
|
||||
if self.background is not None:
|
||||
self.background.unload()
|
||||
self.background = Background(3, self.bpm, scene_preset=scene_preset)
|
||||
self.result_transition = ResultTransition(3)
|
||||
|
||||
def load_hitsounds(self):
|
||||
"""Load the hit sounds"""
|
||||
@@ -26,12 +28,15 @@ class TwoPlayerGameScreen(GameScreen):
|
||||
if global_data.hit_sound[0] == -1:
|
||||
audio.load_sound(Path('none.wav'), 'hitsound_don_1p')
|
||||
audio.load_sound(Path('none.wav'), 'hitsound_kat_1p')
|
||||
logger.info("Loaded default (none) hit sounds for 1P")
|
||||
elif global_data.hit_sound[0] == 0:
|
||||
audio.load_sound(sounds_dir / "hit_sounds" / str(global_data.hit_sound[0]) / "don.wav", 'hitsound_don_1p')
|
||||
audio.load_sound(sounds_dir / "hit_sounds" / str(global_data.hit_sound[0]) / "ka.wav", 'hitsound_kat_1p')
|
||||
logger.info("Loaded wav hit sounds for 1P")
|
||||
else:
|
||||
audio.load_sound(sounds_dir / "hit_sounds" / str(global_data.hit_sound[0]) / "don.ogg", 'hitsound_don_1p')
|
||||
audio.load_sound(sounds_dir / "hit_sounds" / str(global_data.hit_sound[0]) / "ka.ogg", 'hitsound_kat_1p')
|
||||
logger.info("Loaded ogg hit sounds for 1P")
|
||||
audio.set_sound_pan('hitsound_don_1p', 1.0)
|
||||
audio.set_sound_pan('hitsound_kat_1p', 1.0)
|
||||
|
||||
@@ -39,12 +44,15 @@ class TwoPlayerGameScreen(GameScreen):
|
||||
if global_data.hit_sound[1] == -1:
|
||||
audio.load_sound(Path('none.wav'), 'hitsound_don_2p')
|
||||
audio.load_sound(Path('none.wav'), 'hitsound_kat_2p')
|
||||
logger.info("Loaded default (none) hit sounds for 2P")
|
||||
elif global_data.hit_sound[1] == 0:
|
||||
audio.load_sound(sounds_dir / "hit_sounds" / str(global_data.hit_sound[1]) / "don_2p.wav", 'hitsound_don_2p')
|
||||
audio.load_sound(sounds_dir / "hit_sounds" / str(global_data.hit_sound[1]) / "ka_2p.wav", 'hitsound_kat_2p')
|
||||
logger.info("Loaded wav hit sounds for 2P")
|
||||
else:
|
||||
audio.load_sound(sounds_dir / "hit_sounds" / str(global_data.hit_sound[1]) / "don.ogg", 'hitsound_don_2p')
|
||||
audio.load_sound(sounds_dir / "hit_sounds" / str(global_data.hit_sound[1]) / "ka.ogg", 'hitsound_kat_2p')
|
||||
logger.info("Loaded ogg hit sounds for 2P")
|
||||
audio.set_sound_pan('hitsound_don_2p', 0.0)
|
||||
audio.set_sound_pan('hitsound_kat_2p', 0.0)
|
||||
|
||||
@@ -55,10 +63,12 @@ class TwoPlayerGameScreen(GameScreen):
|
||||
self.init_tja(global_data.selected_song)
|
||||
audio.play_sound('restart', 'sound')
|
||||
self.song_started = False
|
||||
logger.info("F1 pressed: song restarted")
|
||||
|
||||
if ray.is_key_pressed(ray.KeyboardKey.KEY_ESCAPE):
|
||||
if self.song_music is not None:
|
||||
audio.stop_music_stream(self.song_music)
|
||||
logger.info("Escape pressed: returning to SONG_SELECT_2P")
|
||||
return self.on_screen_end('SONG_SELECT_2P')
|
||||
|
||||
def init_tja(self, song: Path):
|
||||
@@ -77,6 +87,7 @@ class TwoPlayerGameScreen(GameScreen):
|
||||
self.player_1 = Player(self.tja, 1, global_data.session_data[0].selected_difficulty, False, global_data.modifiers[0])
|
||||
self.player_2 = Player(tja_copy, 2, global_data.session_data[1].selected_difficulty, True, global_data.modifiers[1])
|
||||
self.start_ms = (get_current_ms() - self.tja.metadata.offset*1000)
|
||||
logger.info(f"TJA initialized for two-player song: {song}")
|
||||
|
||||
def spawn_ending_anims(self):
|
||||
if global_data.session_data[0].result_bad == 0:
|
||||
@@ -94,7 +105,7 @@ class TwoPlayerGameScreen(GameScreen):
|
||||
self.player_2.ending_anim = FailAnimation(self.player_2.is_2p)
|
||||
|
||||
def update(self):
|
||||
self.on_screen_start()
|
||||
super(GameScreen, self).update()
|
||||
current_time = get_current_ms()
|
||||
self.transition.update(current_time)
|
||||
self.current_ms = current_time - self.start_ms
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import logging
|
||||
from libs.utils import get_current_ms
|
||||
from scenes.result import Background, FadeIn, ResultPlayer, ResultScreen
|
||||
|
||||
class TwoPlayerResultScreen(ResultScreen):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class TwoPlayerResultScreen(ResultScreen):
|
||||
def on_screen_start(self):
|
||||
if not self.screen_init:
|
||||
super().on_screen_start()
|
||||
self.background = Background('3', self.width)
|
||||
self.fade_in = FadeIn('3')
|
||||
self.player_1 = ResultPlayer('1', True, False)
|
||||
self.player_2 = ResultPlayer('2', True, True)
|
||||
super().on_screen_start()
|
||||
self.background = Background('3', 1280)
|
||||
self.fade_in = FadeIn('3')
|
||||
self.player_1 = ResultPlayer('1', True, False)
|
||||
self.player_2 = ResultPlayer('2', True, True)
|
||||
logger.info("TwoPlayerResultScreen started, background and players initialized")
|
||||
|
||||
def update(self):
|
||||
self.on_screen_start()
|
||||
super(ResultScreen, self).update()
|
||||
current_time = get_current_ms()
|
||||
self.fade_in.update(current_time)
|
||||
self.player_1.update(current_time, self.fade_in.is_finished, self.is_skipped)
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
import logging
|
||||
from libs.file_navigator import SongFile
|
||||
from libs.transition import Transition
|
||||
from scenes.song_select import DiffSortSelect, SongSelectPlayer, SongSelectScreen, State
|
||||
from libs.utils import get_current_ms, global_data
|
||||
from libs.audio import audio
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class TwoPlayerSongSelectScreen(SongSelectScreen):
|
||||
def on_screen_start(self):
|
||||
if not self.screen_init:
|
||||
super().on_screen_start()
|
||||
self.player_1 = SongSelectPlayer('1', self.text_fade_in)
|
||||
self.player_2 = SongSelectPlayer('2', self.text_fade_in)
|
||||
super().on_screen_start()
|
||||
self.player_1 = SongSelectPlayer('1', self.text_fade_in)
|
||||
self.player_2 = SongSelectPlayer('2', self.text_fade_in)
|
||||
|
||||
def finalize_song(self):
|
||||
global_data.selected_song = self.navigator.get_current_item().path
|
||||
global_data.session_data[0].genre_index = self.navigator.get_current_item().box.name_texture_index
|
||||
logger.info(f"Finalized song selection: {global_data.selected_song}")
|
||||
|
||||
def handle_input_browsing(self):
|
||||
"""Handle input for browsing songs."""
|
||||
@@ -79,24 +82,25 @@ class TwoPlayerSongSelectScreen(SongSelectScreen):
|
||||
return
|
||||
p2_result = True
|
||||
if result is not None:
|
||||
print(result, p2_result)
|
||||
logger.info(f"Difficulty selection result: {result}, p2_result={p2_result}")
|
||||
if result == "cancel":
|
||||
self._cancel_selection()
|
||||
logger.info("Selection cancelled")
|
||||
elif result == "confirm":
|
||||
if p2_result:
|
||||
self._confirm_selection(2)
|
||||
else:
|
||||
self._confirm_selection(1)
|
||||
logger.info("Selection confirmed")
|
||||
elif result == "ura_toggle":
|
||||
if p2_result:
|
||||
self.ura_switch_animation.start(not self.player_2.is_ura)
|
||||
else:
|
||||
self.ura_switch_animation.start(not self.player_1.is_ura)
|
||||
logger.info("Ura toggled")
|
||||
|
||||
def handle_input_diff_sort(self):
|
||||
"""
|
||||
Handle input for sorting difficulty.
|
||||
"""
|
||||
"""Handle input for sorting difficulty."""
|
||||
if self.diff_sort_selector is None:
|
||||
raise Exception("Diff sort selector was not able to be created")
|
||||
|
||||
@@ -108,6 +112,7 @@ class TwoPlayerSongSelectScreen(SongSelectScreen):
|
||||
self.state = State.BROWSING
|
||||
self.text_fade_out.reset()
|
||||
self.text_fade_in.reset()
|
||||
logger.info(f"Diff sort selected: diff={diff}, level={level}")
|
||||
if diff != -1:
|
||||
if level != -1:
|
||||
self.navigator.diff_sort_diff = diff
|
||||
@@ -117,7 +122,7 @@ class TwoPlayerSongSelectScreen(SongSelectScreen):
|
||||
def _cancel_selection(self):
|
||||
"""Reset to browsing state"""
|
||||
super()._cancel_selection()
|
||||
self.player_2.selected_song = None
|
||||
self.player_2.selected_song = False
|
||||
|
||||
def _confirm_selection(self, player_selected: int):
|
||||
"""Confirm song selection and create game transition"""
|
||||
@@ -133,6 +138,7 @@ class TwoPlayerSongSelectScreen(SongSelectScreen):
|
||||
self.player_2.selected_diff_highlight_fade.start()
|
||||
self.player_2.selected_diff_text_resize.start()
|
||||
self.player_2.selected_diff_text_fadein.start()
|
||||
logger.info(f"Confirmed selection for player {player_selected}")
|
||||
|
||||
def check_for_selection(self):
|
||||
if (self.player_1.selected_diff_highlight_fade.is_finished and
|
||||
@@ -148,6 +154,7 @@ class TwoPlayerSongSelectScreen(SongSelectScreen):
|
||||
global_data.config['general']['language'], '')
|
||||
self.game_transition = Transition(title, subtitle)
|
||||
self.game_transition.start()
|
||||
logger.info(f"Game transition started for song: {title} - {subtitle}")
|
||||
|
||||
def update_players(self, current_time):
|
||||
self.player_1.update(current_time)
|
||||
@@ -155,7 +162,8 @@ class TwoPlayerSongSelectScreen(SongSelectScreen):
|
||||
if self.text_fade_out.is_finished:
|
||||
self.player_1.selected_song = True
|
||||
self.player_2.selected_song = True
|
||||
return "GAME_2P"
|
||||
next_screen = "GAME_2P"
|
||||
return next_screen
|
||||
|
||||
def draw_background_diffs(self):
|
||||
self.player_1.draw_background_diffs(self.state)
|
||||
|
||||
Reference in New Issue
Block a user