From ac927114cb607a51f78b73049e936537364a5173 Mon Sep 17 00:00:00 2001 From: Yonokid <37304577+Yonokid@users.noreply.github.com> Date: Thu, 24 Apr 2025 23:25:10 -0400 Subject: [PATCH] basic result screen, fix empty balloon --- config.toml | 2 +- libs/tja.py | 4 ++++ libs/utils.py | 3 ++- scenes/game.py | 5 +++- scenes/result.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/config.toml b/config.toml index fdac99f..c89185e 100644 --- a/config.toml +++ b/config.toml @@ -13,7 +13,7 @@ right_don = ['J','D'] right_kat = ['I','U'] [audio] -device_type = 'ASIO' +device_type = 'WASAPI' asio_buffer = 6 [video] diff --git a/libs/tja.py b/libs/tja.py index 5c9ed8d..e914ef7 100644 --- a/libs/tja.py +++ b/libs/tja.py @@ -161,6 +161,8 @@ class TJAParser: if item != line: notes.append(bar) bar = [] + if len(self.course_data[diff]) < 2: + return notes, None return notes, self.course_data[diff][1] def get_se_note(self, play_note_list, ms_per_measure, note, note_ms): @@ -273,6 +275,8 @@ class TJAParser: if note in {'5', '6', '8'}: play_note_list[-1]['color'] = 255 if note == '8' and play_note_list[-2]['note'] in ('7', '9'): + if balloon is None: + raise Exception("Balloon note found, but no count was specified") if balloon_index >= len(balloon): play_note_list[-1]['balloon'] = 0 else: diff --git a/libs/utils.py b/libs/utils.py index 044ff3c..8f81ca6 100644 --- a/libs/utils.py +++ b/libs/utils.py @@ -98,8 +98,9 @@ def get_config() -> dict[str, Any]: class GlobalData: videos_cleared = False start_song: bool = False - selected_song: str = '' + selected_song: str = '' #Path selected_difficulty: int = -1 + song_title: str = '' result_good: int = -1 result_ok: int = -1 result_bad: int = -1 diff --git a/scenes/game.py b/scenes/game.py index eddfdd9..43cf708 100644 --- a/scenes/game.py +++ b/scenes/game.py @@ -156,10 +156,12 @@ class GameScreen: self.tja = TJAParser(song) self.tja.get_metadata() self.tja.distance = self.width - self.judge_x + self.start_delay = 0 + global_data.song_title = self.tja.title self.player_1 = Player(self, 1, difficulty, get_config()["general"]["judge_offset"]) self.song_music = audio.load_sound(self.tja.wave) - self.start_ms = get_current_ms() - self.tja.offset*1000 + self.start_ms = (get_current_ms() - self.tja.offset*1000) + self.start_delay audio.play_sound(self.song_music) @@ -169,6 +171,7 @@ class GameScreen: self.init_tja(global_data.selected_song, global_data.selected_difficulty) self.song_is_started = True + self.current_ms = get_current_ms() - self.start_ms self.player_1.update(self) diff --git a/scenes/result.py b/scenes/result.py index 8338ab5..3b08622 100644 --- a/scenes/result.py +++ b/scenes/result.py @@ -1,24 +1,83 @@ import pyray as ray from libs.audio import audio -from libs.utils import global_data +from libs.utils import ( + OutlinedText, + global_data, + load_all_textures_from_zip, + load_image_from_zip, +) +def draw_scaled_texture(texture, x: int, y: int, scale: float, color: ray.Color) -> None: + width = texture.width + height = texture.height + src_rect = ray.Rectangle(0, 0, width, height) + dst_rect = ray.Rectangle(x, y, width*scale, height*scale) + ray.draw_texture_pro(texture, src_rect, dst_rect, ray.Vector2(0, 0), 0, color) + class ResultScreen: def __init__(self, width, height): self.width = width self.height = height self.sound_don = audio.load_sound('Sounds\\inst_00_don.wav') + zip_file = 'Graphics\\lumendata\\enso_result.zip' + self.textures = load_all_textures_from_zip(zip_file) + + ray.unload_texture(self.textures['result'][327]) + image = load_image_from_zip(zip_file, 'result_img00327.png') + ray.image_resize(image, 1280, 144) + self.textures['result'][327] = ray.load_texture_from_image(image) + + self.text_generated = False + self.song_info = FontText(global_data.song_title, 40).texture + def update(self): if ray.is_key_pressed(ray.KeyboardKey.KEY_ENTER): global_data.songs_played += 1 audio.play_sound(self.sound_don) return "SONG_SELECT" + if not self.text_generated and global_data.song_title != '': + self.song_info = FontText(global_data.song_title, 40).texture + self.text_generated = True + def draw(self): + x = 0 + while x < self.width: + ray.draw_texture(self.textures['result'][326], x, 0 - self.textures['result'][326].height//2, ray.WHITE) + ray.draw_texture(self.textures['result'][326], x, self.height - self.textures['result'][326].height//2, ray.WHITE) + x += self.textures['result'][326].width + ray.draw_texture(self.textures['result'][327], 0, 0 - self.textures['result'][327].height//2, ray.WHITE) + ray.draw_texture(self.textures['result'][327], 0, self.height - self.textures['result'][327].height + self.textures['result'][327].height//2, ray.WHITE) + + ray.draw_text(f"{global_data.selected_song}", 100, 60, 20, ray.BLACK) ray.draw_text(f"SCORE: {global_data.result_score}", 100, 80, 20, ray.BLACK) ray.draw_text(f"GOOD: {global_data.result_good}", 100, 100, 20, ray.BLACK) ray.draw_text(f"OK: {global_data.result_ok}", 100, 120, 20, ray.BLACK) ray.draw_text(f"BAD: {global_data.result_bad}", 100, 140, 20, ray.BLACK) + + ray.draw_texture(self.textures['result'][330], -5, 3, ray.WHITE) + ray.draw_texture(self.textures['result'][(global_data.songs_played % 4) + 331], 232, 4, ray.WHITE) + ray.draw_texture(self.song_info, 1252 - self.song_info.width, int(35 - self.song_info.height / 2), ray.WHITE) + + ray.draw_texture(self.textures['result'][175], 532, 98, ray.fade(ray.WHITE, 0.75)) + + draw_scaled_texture(self.textures['result'][217], 554, 109, (10/11), ray.WHITE) + draw_scaled_texture(self.textures['result'][226], 554, 109, (10/11), ray.fade(ray.WHITE, 0.15)) + draw_scaled_texture(self.textures['result'][176], 1185, 116, (10/11), ray.WHITE) + draw_scaled_texture(self.textures['result'][187], 1058, 124, (10/11), ray.WHITE) + draw_scaled_texture(self.textures['result'][188], 1182, 115, (10/11), ray.WHITE) + +class FontText: + def __init__(self, text, font_size): + codepoint_count = ray.ffi.new('int *', 0) + codepoints_no_dup = set() + codepoints_no_dup.update(global_data.song_title) + codepoints = ray.load_codepoints(''.join(codepoints_no_dup), codepoint_count) + self.font = ray.load_font_ex('Graphics\\Modified-DFPKanteiryu-XB.ttf', 32, codepoints, 0) + self.text = OutlinedText(self.font, str(text), font_size, ray.WHITE, ray.BLACK, outline_thickness=5) + + self.texture = self.text.texture