From 5c7e759385dcf0c14bd16c0ad36bdd521b384b37 Mon Sep 17 00:00:00 2001 From: Anthony Samms Date: Tue, 23 Dec 2025 21:02:56 -0500 Subject: [PATCH] fix skin loading --- config.toml | 4 +--- libs/audio.py | 2 +- libs/config.py | 3 +-- libs/texture.py | 14 ++++++-------- libs/utils.py | 2 +- scenes/game.py | 2 +- scenes/loading.py | 2 +- scenes/title.py | 11 +++-------- scenes/two_player/game.py | 2 +- 9 files changed, 16 insertions(+), 26 deletions(-) diff --git a/config.toml b/config.toml index e1ecb43..c28f1d4 100644 --- a/config.toml +++ b/config.toml @@ -29,9 +29,7 @@ rainbow = false [paths] tja_path = ['Songs'] -video_path = ['Videos'] -#You can change this path to Graphics/GreenVer1080 for the 1080p skin -graphics_path = 'Graphics/GreenVer' +skin = 'PyTaikoGreen' [keys] exit_key = 'Q' diff --git a/libs/audio.py b/libs/audio.py index 0643e6e..a9229aa 100644 --- a/libs/audio.py +++ b/libs/audio.py @@ -131,7 +131,7 @@ class AudioEngine: self.audio_device_ready = False self.volume_presets = volume_presets - self.sounds_path = Path("Sounds") + self.sounds_path = Path(f"Skins/{get_config()["paths"]["skin"]}/Sounds") def set_log_level(self, level: int): lib.set_log_level(level) # type: ignore diff --git a/libs/config.py b/libs/config.py index f07a7b4..3ac46c8 100644 --- a/libs/config.py +++ b/libs/config.py @@ -30,8 +30,7 @@ class NameplateConfig(TypedDict): class PathsConfig(TypedDict): tja_path: list[Path] - video_path: list[Path] - graphics_path: Path + skin: Path class KeysConfig(TypedDict): exit_key: int diff --git a/libs/texture.py b/libs/texture.py index 614b9ac..300287b 100644 --- a/libs/texture.py +++ b/libs/texture.py @@ -1,9 +1,7 @@ import copy import json -import os import logging import sys -import tempfile from pathlib import Path from typing import Any, Optional @@ -73,8 +71,8 @@ class TextureWrapper: self.textures: dict[str, dict[str, Texture | FramedTexture]] = dict() self.animations: dict[int, BaseAnimation] = dict() self.skin_config: dict[str, SkinInfo] = dict() - self.graphics_path = Path(get_config()['paths']['graphics_path']) - self.parent_graphics_path = Path(get_config()['paths']['graphics_path']) + self.graphics_path = Path(f'Skins/{get_config()['paths']['skin']}/Graphics') + self.parent_graphics_path = Path(f'Skins/{get_config()['paths']['skin']}/Graphics') if not (self.graphics_path / "skin_config.json").exists(): raise Exception("skin is missing a skin_config.json") @@ -87,7 +85,7 @@ class TextureWrapper: self.screen_scale = self.screen_width / 1280 if "parent" in data["screen"]: parent = data["screen"]["parent"] - self.parent_graphics_path = Path("Graphics") / parent + self.parent_graphics_path = Path("Skins") / parent parent_data = json.loads((self.parent_graphics_path / "skin_config.json").read_text()) for k, v in parent_data.items(): self.skin_config[k] = SkinInfo(v.get('x', 0) * self.screen_scale, v.get('y', 0) * self.screen_scale, v.get('font_size', 0) * self.screen_scale, v.get('width', 0) * self.screen_scale, v.get('height', 0) * self.screen_scale) @@ -189,7 +187,7 @@ class TextureWrapper: if screen_name in self.textures and subset in self.textures[screen_name]: return try: - if not os.path.isfile(folder / 'texture.json'): + if not (folder / 'texture.json').exists(): raise Exception(f"texture.json file missing from {folder}") with open(folder / 'texture.json') as json_file: @@ -205,7 +203,7 @@ class TextureWrapper: if tex_dir.is_dir(): frames = [ray.LoadTexture(str(frame).encode(encoding)) for frame in sorted(tex_dir.iterdir(), key=lambda x: int(x.stem)) if frame.is_file()] - self.textures[folder.stem][tex_name] = Texture(tex_name, frames, tex_mapping) + self.textures[folder.stem][tex_name] = FramedTexture(tex_name, frames, tex_mapping) self._read_tex_obj_data(tex_mapping, self.textures[folder.stem][tex_name]) elif tex_file.is_file(): tex = ray.LoadTexture(str(tex_file).encode(encoding)) @@ -230,7 +228,7 @@ class TextureWrapper: # Load zip files from child screen path only for zip_file in screen_path.iterdir(): - if zip_file.is_file() and zip_file.suffix == ".zip": + if zip_file.is_dir(): self.load_zip(screen_name, zip_file.stem) logger.info(f"Screen textures loaded for: {screen_name}") diff --git a/libs/utils.py b/libs/utils.py index 71826e4..cc6a98e 100644 --- a/libs/utils.py +++ b/libs/utils.py @@ -200,7 +200,7 @@ class OutlinedText: if reload_font: codepoint_count = ray.ffi.new('int *', 0) codepoints = ray.load_codepoints(''.join(global_data.font_codepoints), codepoint_count) - global_data.font = ray.load_font_ex(str(Path('Graphics/Modified-DFPKanteiryu-XB.ttf')), 40, codepoints, len(global_data.font_codepoints)) + global_data.font = ray.load_font_ex(str(Path(f'Skins/{global_data.config["paths"]["skin"]}/Modified-DFPKanteiryu-XB.ttf')), 40, codepoints, len(global_data.font_codepoints)) logger.info(f"Reloaded font with {len(global_data.font_codepoints)} codepoints") return global_data.font diff --git a/scenes/game.py b/scenes/game.py index ceed97e..c44b838 100644 --- a/scenes/game.py +++ b/scenes/game.py @@ -116,7 +116,7 @@ class GameScreen(Screen): def load_hitsounds(self): """Load the hit sounds""" - sounds_dir = Path("Sounds") + sounds_dir = Path(f"Skins/{global_data.config["paths"]["skin"]}/Sounds") if global_data.hit_sound == -1: audio.load_sound(Path('none.wav'), 'hitsound_don_1p') audio.load_sound(Path('none.wav'), 'hitsound_kat_1p') diff --git a/scenes/loading.py b/scenes/loading.py index ca636e7..f5a0ed6 100644 --- a/scenes/loading.py +++ b/scenes/loading.py @@ -58,7 +58,7 @@ class LoadScreen(Screen): global_data.font_codepoints.add(character) codepoint_count = ray.ffi.new('int *', 0) codepoints = ray.load_codepoints(''.join(global_data.font_codepoints), codepoint_count) - global_data.font = ray.load_font_ex(str(Path('Graphics/Modified-DFPKanteiryu-XB.ttf')), 40, codepoints, len(global_data.font_codepoints)) + global_data.font = ray.load_font_ex(str(Path(f'Skins/{global_data.config["paths"]["skin"]}/Graphics/Modified-DFPKanteiryu-XB.ttf')), 40, codepoints, len(global_data.font_codepoints)) def _load_navigator(self): """Background thread function to load navigator""" diff --git a/scenes/title.py b/scenes/title.py index 1f366b4..3a2abca 100644 --- a/scenes/title.py +++ b/scenes/title.py @@ -25,16 +25,11 @@ class State: class TitleScreen(Screen): def __init__(self, name: str): super().__init__(name) - #normalize to accept both stings and lists in toml - #maybe normalize centrally? but it's used only here - vp = global_data.config["paths"]["video_path"] - video_paths = [vp] if isinstance(vp, str) else vp self.op_video_list = [] self.attract_video_list = [] - for base in video_paths: - base = Path(base) - self.op_video_list += list((base/"op_videos").glob("**/*.mp4")) - self.attract_video_list += list((base/"attract_videos").glob("**/*.mp4")) + base = Path(f"Skins/{global_data.config["paths"]["skin"]}/Videos") + self.op_video_list += list((base/"op_videos").glob("**/*.mp4")) + self.attract_video_list += list((base/"attract_videos").glob("**/*.mp4")) self.coin_overlay = CoinOverlay() self.allnet_indicator = AllNetIcon() self.entry_overlay = EntryOverlay() diff --git a/scenes/two_player/game.py b/scenes/two_player/game.py index 91aae48..6389f38 100644 --- a/scenes/two_player/game.py +++ b/scenes/two_player/game.py @@ -23,7 +23,7 @@ class TwoPlayerGameScreen(GameScreen): def load_hitsounds(self): """Load the hit sounds""" - sounds_dir = Path("Sounds") + sounds_dir = Path(f"Skins/{global_data.config["paths"]["skin"]}/Sounds") # Load hitsounds for 1P if global_data.hit_sound[PlayerNum.P1] == -1: