mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
make bootup faster
This commit is contained in:
@@ -105,7 +105,7 @@ class EntryScreen:
|
||||
self.selected_box = max(0, self.selected_box - 1)
|
||||
if is_r_kat_pressed():
|
||||
audio.play_sound(self.sound_kat)
|
||||
self.selected_box = min(self.num_boxes, self.selected_box + 1)
|
||||
self.selected_box = min(self.num_boxes - 1, self.selected_box + 1)
|
||||
|
||||
def update(self):
|
||||
self.on_screen_start()
|
||||
|
||||
@@ -40,9 +40,9 @@ class ResultScreen:
|
||||
self.load_textures()
|
||||
self.load_sounds()
|
||||
self.screen_init = True
|
||||
self.song_info = FontText(session_data.song_title, 40).texture
|
||||
self.song_info = OutlinedText(session_data.song_title, 40, ray.Color(255, 255, 255, 255), ray.Color(0, 0, 0, 255), outline_thickness=5)
|
||||
audio.play_sound(self.bgm)
|
||||
self.fade_in = FadeIn(get_current_ms())
|
||||
self.fade_in = FadeIn()
|
||||
self.fade_out = None
|
||||
self.gauge = None
|
||||
self.score_delay = None
|
||||
@@ -165,7 +165,9 @@ class ResultScreen:
|
||||
|
||||
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)
|
||||
src = ray.Rectangle(0, 0, self.song_info.texture.width, self.song_info.texture.height)
|
||||
dest = ray.Rectangle(1252 - self.song_info.texture.width, 35 - self.song_info.texture.height / 2, self.song_info.texture.width, self.song_info.texture.height)
|
||||
self.song_info.draw(src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
|
||||
ray.draw_texture(self.textures['result'][175], 532, 98, ray.fade(ray.WHITE, 0.75))
|
||||
|
||||
@@ -189,7 +191,7 @@ class ResultScreen:
|
||||
|
||||
|
||||
class FadeIn:
|
||||
def __init__(self, current_ms: float):
|
||||
def __init__(self):
|
||||
self.fadein = Animation.create_fade(450, initial_opacity=1.0, final_opacity=0.0, delay=100)
|
||||
self.fade = ray.fade(ray.WHITE, self.fadein.attribute)
|
||||
|
||||
@@ -212,12 +214,6 @@ class FadeIn:
|
||||
ray.draw_texture(texture_2, x, screen_height - texture_2.height + texture_2.height//2, self.fade)
|
||||
x += texture_2.width
|
||||
|
||||
class FontText:
|
||||
def __init__(self, text, font_size):
|
||||
self.text = OutlinedText(str(text), font_size, ray.Color(255, 255, 255, 255), ray.Color(0, 0, 0, 255), outline_thickness=5)
|
||||
|
||||
self.texture = self.text.texture
|
||||
|
||||
class ScoreAnimator:
|
||||
def __init__(self, target_score):
|
||||
self.target_score = str(target_score)
|
||||
|
||||
@@ -5,7 +5,6 @@ from typing import Optional, Union
|
||||
|
||||
import pyray as ray
|
||||
|
||||
from libs import song_hash
|
||||
from libs.animation import Animation
|
||||
from libs.audio import audio
|
||||
from libs.tja import TJAParser
|
||||
@@ -418,20 +417,8 @@ class SongBox:
|
||||
def get_scores(self):
|
||||
if self.tja is None:
|
||||
return
|
||||
|
||||
with sqlite3.connect('scores.db') as con:
|
||||
cursor = con.cursor()
|
||||
|
||||
diffs_to_compute = []
|
||||
for diff in self.tja.metadata.course_data:
|
||||
if diff not in self.hash:
|
||||
diffs_to_compute.append(diff)
|
||||
|
||||
if diffs_to_compute:
|
||||
for diff in diffs_to_compute:
|
||||
notes, _, bars = TJAParser.notes_to_position(TJAParser(self.tja.file_path), diff)
|
||||
self.hash[diff] = self.tja.hash_note_data(notes, bars)
|
||||
|
||||
# Batch database query for all diffs at once
|
||||
if self.tja.metadata.course_data:
|
||||
hash_values = [self.hash[diff] for diff in self.tja.metadata.course_data]
|
||||
@@ -1004,17 +991,15 @@ class SongFile(FileSystemItem):
|
||||
if self.is_recent:
|
||||
self.tja.ex_data.new = True
|
||||
title = self.tja.metadata.title.get(global_data.config['general']['language'].lower(), self.tja.metadata.title['en'])
|
||||
self.hash = global_data.song_paths[path]
|
||||
self.box = SongBox(title, texture_index, False, tja=self.tja, name_texture_index=name_texture_index if name_texture_index is not None else texture_index)
|
||||
self.box.hash = global_data.song_hashes[self.hash][0]["diff_hashes"]
|
||||
self.box.get_scores()
|
||||
|
||||
class FileNavigator:
|
||||
"""Manages navigation through pre-generated Directory and SongFile objects"""
|
||||
def __init__(self, root_dirs: list[str]):
|
||||
# Handle both single path and list of paths
|
||||
if isinstance(root_dirs, (list, tuple)):
|
||||
self.root_dirs = [Path(p) if not isinstance(p, Path) else p for p in root_dirs]
|
||||
else:
|
||||
self.root_dirs = [Path(root_dirs) if not isinstance(root_dirs, Path) else root_dirs]
|
||||
self.root_dirs = [Path(p) if not isinstance(p, Path) else p for p in root_dirs]
|
||||
|
||||
# Pre-generated objects storage
|
||||
self.all_directories: dict[str, Directory] = {} # path -> Directory
|
||||
@@ -1118,14 +1103,10 @@ class FileNavigator:
|
||||
for i, tja_path in enumerate(sorted(tja_files)):
|
||||
song_key = str(tja_path)
|
||||
if song_key not in self.all_song_files:
|
||||
try:
|
||||
song_obj = SongFile(tja_path, tja_path.name, texture_index)
|
||||
if song_obj.is_recent:
|
||||
self.new_items.append(SongFile(tja_path, tja_path.name, 620, name_texture_index=texture_index))
|
||||
self.all_song_files[song_key] = song_obj
|
||||
except Exception as e:
|
||||
print(f"Error creating SongFile for {tja_path}: {e}")
|
||||
continue
|
||||
song_obj = SongFile(tja_path, tja_path.name, texture_index)
|
||||
if song_obj.is_recent:
|
||||
self.new_items.append(SongFile(tja_path, tja_path.name, 620, name_texture_index=texture_index))
|
||||
self.all_song_files[song_key] = song_obj
|
||||
|
||||
content_items.append(self.all_song_files[song_key])
|
||||
|
||||
@@ -1302,19 +1283,20 @@ class FileNavigator:
|
||||
hash_val, title, subtitle = parts[0], parts[1], parts[2]
|
||||
original_hash = hash_val
|
||||
|
||||
if song_hash.song_hashes is not None:
|
||||
if hash_val in song_hash.song_hashes:
|
||||
file_path = Path(song_hash.song_hashes[hash_val]["file_path"])
|
||||
if file_path.exists():
|
||||
tja_files.append(file_path)
|
||||
else:
|
||||
# Try to find by title and subtitle
|
||||
for key, value in song_hash.song_hashes.items():
|
||||
if (value["title"]["en"] == title and
|
||||
value["subtitle"]["en"][2:] == subtitle and
|
||||
Path(value["file_path"]).exists()):
|
||||
if hash_val in global_data.song_hashes:
|
||||
file_path = Path(global_data.song_hashes[hash_val][0]["file_path"])
|
||||
if file_path.exists():
|
||||
tja_files.append(file_path)
|
||||
else:
|
||||
# Try to find by title and subtitle
|
||||
for key, value in global_data.song_hashes.items():
|
||||
for i in range(len(value)):
|
||||
song = value[i]
|
||||
if (song["title"]["en"] == title and
|
||||
song["subtitle"]["en"][2:] == subtitle and
|
||||
Path(song["file_path"]).exists()):
|
||||
hash_val = key
|
||||
tja_files.append(Path(song_hash.song_hashes[hash_val]["file_path"]))
|
||||
tja_files.append(Path(global_data.song_hashes[hash_val][i]["file_path"]))
|
||||
break
|
||||
|
||||
if hash_val != original_hash:
|
||||
@@ -1523,17 +1505,3 @@ class FileNavigator:
|
||||
self.current_root_dir = Path()
|
||||
self.history.clear()
|
||||
self.load_root_directories()
|
||||
|
||||
def get_stats(self):
|
||||
"""Get statistics about the pre-generated objects"""
|
||||
song_count_by_dir = {}
|
||||
for dir_path, items in self.directory_contents.items():
|
||||
song_count_by_dir[dir_path] = len([item for item in items if isinstance(item, SongFile)])
|
||||
|
||||
return {
|
||||
'total_directories': len(self.all_directories),
|
||||
'total_songs': len(self.all_song_files),
|
||||
'root_items': len(self.root_items),
|
||||
'directories_with_content': len(self.directory_contents),
|
||||
'songs_by_directory': song_count_by_dir
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user