From 2eb39610dedbf11e82382e3f199355dfcaf95302 Mon Sep 17 00:00:00 2001 From: Yonokid <37304577+Yonokid@users.noreply.github.com> Date: Sat, 26 Apr 2025 02:09:18 -0400 Subject: [PATCH] update paths to pathlib for linux/mac support --- config.toml | 10 +++++----- install.bat | 1 + libs/tja.py | 12 +++++++----- libs/utils.py | 13 +++++++++---- scenes/game.py | 15 ++++++++------- scenes/result.py | 8 ++++++-- scenes/song_select.py | 6 ++++-- scenes/title.py | 11 +++++++---- 8 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 install.bat diff --git a/config.toml b/config.toml index fdac99f..4f5e81f 100644 --- a/config.toml +++ b/config.toml @@ -7,13 +7,13 @@ tja_path = 'Songs' video_path = 'Videos' [keybinds] -left_kat = ['E','R'] -left_don = ['F','K'] -right_don = ['J','D'] -right_kat = ['I','U'] +left_kat = ['D'] +left_don = ['F'] +right_don = ['J'] +right_kat = ['K'] [audio] -device_type = 'ASIO' +device_type = 'WASAPI' asio_buffer = 6 [video] diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..f6a0d65 --- /dev/null +++ b/install.bat @@ -0,0 +1 @@ +pip install -r requirements.txt diff --git a/libs/tja.py b/libs/tja.py index a546547..da2896b 100644 --- a/libs/tja.py +++ b/libs/tja.py @@ -1,5 +1,6 @@ import math from collections import deque +from pathlib import Path from libs.utils import get_pixels_per_frame, strip_comments @@ -28,9 +29,9 @@ def calculate_base_score(play_note_list: deque[dict]) -> int: class TJAParser: def __init__(self, path: str): #Defined on startup - self.folder_path = path - self.folder_name = self.folder_path.split('\\')[-1] - self.file_path = f'{self.folder_path}\\{self.folder_name}.tja' + self.folder_path = Path(path) + self.folder_name = self.folder_path.name + self.file_path = self.folder_path / f"{self.folder_name}.tja" #Defined on file_to_data() self.data = [] @@ -40,7 +41,7 @@ class TJAParser: self.title_ja = '' self.subtitle = '' self.subtitle_ja = '' - self.wave = f'{self.folder_path}\\' + self.wave = self.folder_path / "" self.offset = 0 self.demo_start = 0 self.course_data = dict() @@ -81,7 +82,8 @@ class TJAParser: elif 'BPM' in item: self.bpm = float(item.split(':')[1]) elif 'WAVE' in item: - self.wave += str(item.split(':')[1]) + filename = item.split(':')[1].strip() + self.wave = self.folder_path / filename elif 'OFFSET' in item: self.offset = float(item.split(':')[1]) elif 'DEMOSTART' in item: diff --git a/libs/utils.py b/libs/utils.py index 27a49f8..41198f7 100644 --- a/libs/utils.py +++ b/libs/utils.py @@ -3,6 +3,7 @@ import tempfile import time import zipfile from dataclasses import dataclass +from pathlib import Path from typing import Any import pyray as ray @@ -12,14 +13,16 @@ import tomllib def get_zip_filenames(zip_path: str) -> list[str]: result = [] - with zipfile.ZipFile(zip_path, 'r') as zip_ref: + new_path = Path(zip_path) + with zipfile.ZipFile(new_path, 'r') as zip_ref: file_list = zip_ref.namelist() for file_name in file_list: result.append(file_name) return result def load_image_from_zip(zip_path: str, filename: str) -> ray.Image: - with zipfile.ZipFile(zip_path, 'r') as zip_ref: + new_path = Path(zip_path) + with zipfile.ZipFile(new_path, 'r') as zip_ref: with zip_ref.open(filename) as image_file: with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file: temp_file.write(image_file.read()) @@ -29,7 +32,8 @@ def load_image_from_zip(zip_path: str, filename: str) -> ray.Image: return image def load_texture_from_zip(zip_path: str, filename: str) -> ray.Texture: - with zipfile.ZipFile(zip_path, 'r') as zip_ref: + new_path = Path(zip_path) + with zipfile.ZipFile(new_path, 'r') as zip_ref: with zip_ref.open(filename) as image_file: with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file: temp_file.write(image_file.read()) @@ -40,7 +44,8 @@ def load_texture_from_zip(zip_path: str, filename: str) -> ray.Texture: def load_all_textures_from_zip(zip_path: str) -> dict[str, list[ray.Texture]]: result_dict = dict() - with zipfile.ZipFile(zip_path, 'r') as zip_ref: + new_path = Path(zip_path) + with zipfile.ZipFile(new_path, 'r') as zip_ref: files = zip_ref.namelist() for file in files: with zip_ref.open(file) as image_file: diff --git a/scenes/game.py b/scenes/game.py index e6a2844..a8d26cd 100644 --- a/scenes/game.py +++ b/scenes/game.py @@ -1,6 +1,7 @@ import bisect import math from collections import deque +from pathlib import Path import pyray as ray @@ -139,11 +140,11 @@ class GameScreen: self.result_transition_2 = load_texture_from_zip('Graphics\\lumendata\\enso_result.zip', 'retry_game_img00126.png') def load_sounds(self): - self.sound_don = audio.load_sound('Sounds\\inst_00_don.wav') - self.sound_kat = audio.load_sound('Sounds\\inst_00_katsu.wav') - self.sound_balloon_pop = audio.load_sound('Sounds\\balloon_pop.wav') - - self.sound_result_transition = audio.load_sound('Sounds\\result\\VO_RESULT [1].ogg') + sounds_dir = Path("Sounds") + self.sound_don = audio.load_sound(str(sounds_dir / "inst_00_don.wav")) + self.sound_kat = audio.load_sound(str(sounds_dir / "inst_00_katsu.wav")) + self.sound_balloon_pop = audio.load_sound(str(sounds_dir / "balloon_pop.wav")) + self.sound_result_transition = audio.load_sound(str(sounds_dir / "result" / "VO_RESULT [1].ogg")) def init_tja(self, song: str, difficulty: int): self.load_textures() @@ -170,7 +171,7 @@ class GameScreen: 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.song_music = audio.load_sound(str(Path(self.tja.wave))) self.start_ms = (get_current_ms() - self.tja.offset*1000) + self.start_delay audio.play_sound(self.song_music) @@ -618,7 +619,7 @@ class Player: self.draw_balloon(game_screen, note, position, i) else: self.draw_note(game_screen, note_type, position, 255, note['se_note']) - ray.draw_text(str(i), position+64, 192, 25, ray.GREEN) + #ray.draw_text(str(i), position+64, 192, 25, ray.GREEN) def draw_gauge(self, game_screen: GameScreen): ray.draw_texture(game_screen.textures['gage_don_1p_hard'][0], 327, 128, ray.WHITE) diff --git a/scenes/result.py b/scenes/result.py index c015704..c430ef3 100644 --- a/scenes/result.py +++ b/scenes/result.py @@ -1,3 +1,5 @@ +from pathlib import Path + import pyray as ray from libs.animation import Animation @@ -21,8 +23,10 @@ class ResultScreen: def __init__(self, width: int, height: int): self.width = width self.height = height - self.sound_don = audio.load_sound('Sounds\\inst_00_don.wav') - self.bgm = audio.load_sound('Sounds\\result\\JINGLE_SEISEKI [1].ogg') + sounds_dir = Path("Sounds") + self.sound_don = audio.load_sound(str(sounds_dir / "inst_00_don.wav")) + self.sound_kat = audio.load_sound(str(sounds_dir / "inst_00_katsu.wav")) + self.bgm = audio.load_sound(str(sounds_dir / "result" / "JINGLE_SEISEKI [1].ogg")) zip_file = 'Graphics\\lumendata\\enso_result.zip' self.textures = load_all_textures_from_zip(zip_file) diff --git a/scenes/song_select.py b/scenes/song_select.py index 4fe0258..9733d3b 100644 --- a/scenes/song_select.py +++ b/scenes/song_select.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import pyray as ray @@ -17,8 +18,9 @@ class SongSelectScreen: self.selected_song = 0 self.selected_difficulty = 0 self.selected_index = 0 - self.sound_don = audio.load_sound('Sounds\\inst_00_don.wav') - self.sound_kat = audio.load_sound('Sounds\\inst_00_katsu.wav') + sounds_dir = Path("Sounds") + self.sound_don = audio.load_sound(str(sounds_dir / "inst_00_don.wav")) + self.sound_kat = audio.load_sound(str(sounds_dir / "inst_00_katsu.wav")) for dirpath, dirnames, filenames in os.walk(f'{get_config()["paths"]["tja_path"]}'): for filename in filenames: if filename.endswith(".tja"): diff --git a/scenes/title.py b/scenes/title.py index 197768b..3e9cc6f 100644 --- a/scenes/title.py +++ b/scenes/title.py @@ -36,10 +36,13 @@ class TitleScreen: def load_textures(self): self.textures = load_all_textures_from_zip('Graphics\\lumendata\\attract\\keikoku.zip') - self.sound_bachi_swipe = audio.load_sound('Sounds\\title\\SE_ATTRACT_2.ogg') - self.sound_bachi_hit = audio.load_sound('Sounds\\title\\SE_ATTRACT_3.ogg') - self.sound_warning_message = audio.load_sound('Sounds\\title\\VO_ATTRACT_3.ogg') - self.sound_warning_error = audio.load_sound('Sounds\\title\\SE_ATTRACT_1.ogg') + sounds_dir = Path("Sounds") + title_dir = sounds_dir / "title" + + self.sound_bachi_swipe = audio.load_sound(str(title_dir / "SE_ATTRACT_2.ogg")) + self.sound_bachi_hit = audio.load_sound(str(title_dir / "SE_ATTRACT_3.ogg")) + self.sound_warning_message = audio.load_sound(str(title_dir / "VO_ATTRACT_3.ogg")) + self.sound_warning_error = audio.load_sound(str(title_dir / "SE_ATTRACT_1.ogg")) self.texture_black = load_texture_from_zip('Graphics\\lumendata\\attract\\movie.zip', 'movie_img00000.png')