add reverse animations, zip up graphics files

This commit is contained in:
Yonokid
2024-09-23 17:44:38 -04:00
parent 9f96204a6f
commit 1bc72cd128
5 changed files with 198 additions and 276 deletions

View File

@@ -1,11 +1,12 @@
import pyray as ray import pyray as ray
from global_funcs import load_texture_from_zip
class EntryScreen: class EntryScreen:
def __init__(self, width, height): def __init__(self, width, height):
self.width = width self.width = width
self.height = height self.height = height
self.texture_footer = ray.load_texture('Graphics\\lumendata\\entry\\entry_img00375.png') self.texture_footer = load_texture_from_zip('Graphics\\lumendata\\entry.zip', 'entry_img00375.png')
def update(self): def update(self):
if ray.is_key_pressed(ray.KeyboardKey.KEY_ENTER): if ray.is_key_pressed(ray.KeyboardKey.KEY_ENTER):

229
game.py
View File

@@ -14,152 +14,152 @@ class GameScreen:
self.current_ms = 0 self.current_ms = 0
def load_textures(self): def load_textures(self):
folder_path = 'Graphics\\lumendata\\enso_system\\common\\' zip_file = 'Graphics\\lumendata\\enso_system\\common.zip'
self.texture_judge_circle = ray.load_texture(folder_path + 'lane_hit_img00017.png') self.texture_judge_circle = load_texture_from_zip(zip_file, 'lane_hit_img00017.png')
self.image_lane = ray.load_image(folder_path + 'lane_img00000.png') self.image_lane = load_image_from_zip(zip_file, 'lane_img00000.png')
ray.image_resize(self.image_lane, 948, 176) ray.image_resize(self.image_lane, 948, 176)
self.texture_lane = ray.load_texture_from_image(self.image_lane) self.texture_lane = ray.load_texture_from_image(self.image_lane)
self.texture_lane_cover = ray.load_texture(folder_path + 'lane_obi_img00000.png') self.texture_lane_cover = load_texture_from_zip(zip_file, 'lane_obi_img00000.png')
self.texture_score_cover = ray.load_texture(folder_path + 'lane_obi_img00003.png') self.texture_score_cover = load_texture_from_zip(zip_file, 'lane_obi_img00003.png')
self.texture_don = [ray.load_texture(folder_path + 'onp_don_img00000.png'), self.texture_don = [load_texture_from_zip(zip_file, 'onp_don_img00000.png'),
ray.load_texture(folder_path + 'onp_don_img00001.png')] load_texture_from_zip(zip_file, 'onp_don_img00001.png')]
self.texture_kat = [ray.load_texture(folder_path + 'onp_katsu_img00000.png'), self.texture_kat = [load_texture_from_zip(zip_file, 'onp_katsu_img00000.png'),
ray.load_texture(folder_path + 'onp_katsu_img00001.png')] load_texture_from_zip(zip_file, 'onp_katsu_img00001.png')]
self.texture_dai_don = [ray.load_texture(folder_path + 'onp_don_dai_img00000.png'), self.texture_dai_don = [load_texture_from_zip(zip_file, 'onp_don_dai_img00000.png'),
ray.load_texture(folder_path + 'onp_don_dai_img00001.png')] load_texture_from_zip(zip_file, 'onp_don_dai_img00001.png')]
self.texture_dai_kat = [ray.load_texture(folder_path + 'onp_katsu_dai_img00000.png'), self.texture_dai_kat = [load_texture_from_zip(zip_file, 'onp_katsu_dai_img00000.png'),
ray.load_texture(folder_path + 'onp_katsu_dai_img00001.png')] load_texture_from_zip(zip_file, 'onp_katsu_dai_img00001.png')]
self.texture_balloon_head = [ray.load_texture(folder_path + 'onp_fusen_img00001.png'), self.texture_balloon_head = [load_texture_from_zip(zip_file, 'onp_fusen_img00001.png'),
ray.load_texture(folder_path + 'onp_fusen_img00002.png')] load_texture_from_zip(zip_file, 'onp_fusen_img00002.png')]
self.texture_balloon_tail = [ray.load_texture(folder_path + 'onp_fusen_img00000.png'), self.texture_balloon_tail = [load_texture_from_zip(zip_file, 'onp_fusen_img00000.png'),
ray.load_texture(folder_path + 'onp_fusen_img00000.png')] load_texture_from_zip(zip_file, 'onp_fusen_img00000.png')]
self.texture_drumroll_head = [ray.load_texture(folder_path + 'onp_renda_img00002.png'), self.texture_drumroll_head = [load_texture_from_zip(zip_file, 'onp_renda_img00002.png'),
ray.load_texture(folder_path + 'onp_renda_img00003.png')] load_texture_from_zip(zip_file, 'onp_renda_img00003.png')]
self.texture_drumroll_body = [ray.load_texture(folder_path + 'onp_renda_img00000.png'), self.texture_drumroll_body = [load_texture_from_zip(zip_file, 'onp_renda_img00000.png'),
ray.load_texture(folder_path + 'onp_renda_img00000.png')] load_texture_from_zip(zip_file, 'onp_renda_img00000.png')]
self.texture_drumroll_tail = [ray.load_texture(folder_path + 'onp_renda_img00001.png'), self.texture_drumroll_tail = [load_texture_from_zip(zip_file, 'onp_renda_img00001.png'),
ray.load_texture(folder_path + 'onp_renda_img00001.png')] load_texture_from_zip(zip_file, 'onp_renda_img00001.png')]
self.texture_dai_drumroll_head = [ray.load_texture(folder_path + 'onp_renda_dai_img00002.png'), self.texture_dai_drumroll_head = [load_texture_from_zip(zip_file, 'onp_renda_dai_img00002.png'),
ray.load_texture(folder_path + 'onp_renda_dai_img00003.png')] load_texture_from_zip(zip_file, 'onp_renda_dai_img00003.png')]
self.texture_dai_drumroll_body = [ray.load_texture(folder_path + 'onp_renda_dai_img00000.png'), self.texture_dai_drumroll_body = [load_texture_from_zip(zip_file, 'onp_renda_dai_img00000.png'),
ray.load_texture(folder_path + 'onp_renda_dai_img00000.png')] load_texture_from_zip(zip_file, 'onp_renda_dai_img00000.png')]
self.texture_dai_drumroll_tail = [ray.load_texture(folder_path + 'onp_renda_dai_img00001.png'), self.texture_dai_drumroll_tail = [load_texture_from_zip(zip_file, 'onp_renda_dai_img00001.png'),
ray.load_texture(folder_path + 'onp_renda_dai_img00001.png')] load_texture_from_zip(zip_file, 'onp_renda_dai_img00001.png')]
self.texture_drumroll_count = ray.load_texture(folder_path + 'renda_num_img00000.png') self.texture_drumroll_count = load_texture_from_zip(zip_file, 'renda_num_img00000.png')
self.texture_drumroll_number = [] self.texture_drumroll_number = []
for i in range(1, 11): for i in range(1, 11):
filename = f'renda_num_img{str(i).zfill(5)}.png' filename = f'renda_num_img{str(i).zfill(5)}.png'
self.texture_drumroll_number.append(ray.load_texture(folder_path + filename)) self.texture_drumroll_number.append(load_texture_from_zip(zip_file, filename))
self.texture_barline = ray.load_texture(folder_path + 'lane_syousetsu_img00000.png') self.texture_barline = load_texture_from_zip(zip_file, 'lane_syousetsu_img00000.png')
self.texture_good = ray.load_texture(folder_path + 'lane_hit_effect_img00009.png') self.texture_good = load_texture_from_zip(zip_file, 'lane_hit_effect_img00009.png')
self.texture_good_hit_center = ray.load_texture(folder_path + 'lane_hit_img00019.png') self.texture_good_hit_center = load_texture_from_zip(zip_file, 'lane_hit_img00019.png')
self.texture_good_hit_center_big = ray.load_texture(folder_path + 'lane_hit_img00021.png') self.texture_good_hit_center_big = load_texture_from_zip(zip_file, 'lane_hit_img00021.png')
self.texture_good_hit_effect = [ray.load_texture(folder_path + 'lane_hit_effect_img00005.png'), self.texture_good_hit_effect = [load_texture_from_zip(zip_file, 'lane_hit_effect_img00005.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00006.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00006.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00007.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00007.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00008.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00008.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00008.png')] load_texture_from_zip(zip_file, 'lane_hit_effect_img00008.png')]
self.texture_good_hit_effect_big = [ray.load_texture(folder_path + 'lane_hit_effect_img00011.png'), self.texture_good_hit_effect_big = [load_texture_from_zip(zip_file, 'lane_hit_effect_img00011.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00012.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00012.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00013.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00013.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00014.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00014.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00015.png')] load_texture_from_zip(zip_file, 'lane_hit_effect_img00015.png')]
self.texture_ok = ray.load_texture(folder_path + 'lane_hit_effect_img00004.png') self.texture_ok = load_texture_from_zip(zip_file, 'lane_hit_effect_img00004.png')
self.texture_ok_hit_center = ray.load_texture(folder_path + 'lane_hit_img00018.png') self.texture_ok_hit_center = load_texture_from_zip(zip_file, 'lane_hit_img00018.png')
self.texture_ok_hit_center_big = ray.load_texture(folder_path + 'lane_hit_img00020.png') self.texture_ok_hit_center_big = load_texture_from_zip(zip_file, 'lane_hit_img00020.png')
self.texture_ok_hit_effect = [ray.load_texture(folder_path + 'lane_hit_effect_img00000.png'), self.texture_ok_hit_effect = [load_texture_from_zip(zip_file, 'lane_hit_effect_img00000.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00001.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00001.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00002.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00002.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00003.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00003.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00003.png')] load_texture_from_zip(zip_file, 'lane_hit_effect_img00003.png')]
self.texture_ok_hit_effect_big = [ray.load_texture(folder_path + 'lane_hit_effect_img00016.png'), self.texture_ok_hit_effect_big = [load_texture_from_zip(zip_file, 'lane_hit_effect_img00016.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00017.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00017.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00018.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00018.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00019.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00019.png'),
ray.load_texture(folder_path + 'lane_hit_effect_img00020.png')] load_texture_from_zip(zip_file, 'lane_hit_effect_img00020.png')]
self.texture_bad = ray.load_texture(folder_path + 'lane_hit_effect_img00010.png') self.texture_bad = load_texture_from_zip(zip_file, 'lane_hit_effect_img00010.png')
self.image_lane_effect_good = ray.load_image(folder_path + 'lane_hit_img00007.png') self.image_lane_effect_good = load_image_from_zip(zip_file, 'lane_hit_img00007.png')
ray.image_resize(self.image_lane_effect_good, 951, 130) ray.image_resize(self.image_lane_effect_good, 951, 130)
self.image_lane_effect_don = ray.load_image(folder_path + 'lane_hit_img00005.png') self.image_lane_effect_don = load_image_from_zip(zip_file, 'lane_hit_img00005.png')
ray.image_resize(self.image_lane_effect_don, 951, 130) ray.image_resize(self.image_lane_effect_don, 951, 130)
self.image_lane_effect_kat = ray.load_image(folder_path + 'lane_hit_img00006.png') self.image_lane_effect_kat = load_image_from_zip(zip_file, 'lane_hit_img00006.png')
ray.image_resize(self.image_lane_effect_kat, 951, 130) ray.image_resize(self.image_lane_effect_kat, 951, 130)
self.texture_lane_effect_good = ray.load_texture_from_image(self.image_lane_effect_good) self.texture_lane_effect_good = ray.load_texture_from_image(self.image_lane_effect_good)
self.texture_lane_effect_don = ray.load_texture_from_image(self.image_lane_effect_don) self.texture_lane_effect_don = ray.load_texture_from_image(self.image_lane_effect_don)
self.texture_lane_effect_kat = ray.load_texture_from_image(self.image_lane_effect_kat) self.texture_lane_effect_kat = ray.load_texture_from_image(self.image_lane_effect_kat)
self.texture_drum = ray.load_texture(folder_path + 'lane_obi_img00014.png') self.texture_drum = load_texture_from_zip(zip_file, 'lane_obi_img00014.png')
self.texture_don_R = ray.load_texture(folder_path + 'lane_obi_img00015.png') self.texture_don_R = load_texture_from_zip(zip_file, 'lane_obi_img00015.png')
self.texture_don_L = ray.load_texture(folder_path + 'lane_obi_img00016.png') self.texture_don_L = load_texture_from_zip(zip_file, 'lane_obi_img00016.png')
self.texture_kat_R = ray.load_texture(folder_path + 'lane_obi_img00017.png') self.texture_kat_R = load_texture_from_zip(zip_file, 'lane_obi_img00017.png')
self.texture_kat_L = ray.load_texture(folder_path + 'lane_obi_img00018.png') self.texture_kat_L = load_texture_from_zip(zip_file, 'lane_obi_img00018.png')
self.texture_1p_emblem = ray.load_texture(folder_path + 'lane_obi_img00019.png') self.texture_1p_emblem = load_texture_from_zip(zip_file, 'lane_obi_img00019.png')
self.texture_difficulty = [ray.load_texture(folder_path + 'lane_obi_img00021.png'), self.texture_difficulty = [load_texture_from_zip(zip_file, 'lane_obi_img00021.png'),
ray.load_texture(folder_path + 'lane_obi_img00022.png'), load_texture_from_zip(zip_file, 'lane_obi_img00022.png'),
ray.load_texture(folder_path + 'lane_obi_img00023.png'), load_texture_from_zip(zip_file, 'lane_obi_img00023.png'),
ray.load_texture(folder_path + 'lane_obi_img00024.png'), load_texture_from_zip(zip_file, 'lane_obi_img00024.png'),
ray.load_texture(folder_path + 'lane_obi_img00025.png'), load_texture_from_zip(zip_file, 'lane_obi_img00025.png'),
ray.load_texture(folder_path + 'lane_obi_img00025.png'), load_texture_from_zip(zip_file, 'lane_obi_img00025.png'),
ray.load_texture(folder_path + 'lane_obi_img00025.png')] load_texture_from_zip(zip_file, 'lane_obi_img00025.png')]
self.texture_combo_text = [ray.load_texture(folder_path + 'lane_obi_img00035.png'), self.texture_combo_text = [load_texture_from_zip(zip_file, 'lane_obi_img00035.png'),
ray.load_texture(folder_path + 'lane_obi_img00046.png')] load_texture_from_zip(zip_file, 'lane_obi_img00046.png')]
self.texture_combo_numbers = [] self.texture_combo_numbers = []
for i in range(36, 58): for i in range(36, 58):
if i not in [46, 48]: if i not in [46, 48]:
filename = f'lane_obi_img{str(i).zfill(5)}.png' filename = f'lane_obi_img{str(i).zfill(5)}.png'
self.texture_combo_numbers.append(ray.load_texture(folder_path + filename)) self.texture_combo_numbers.append(load_texture_from_zip(zip_file, filename))
self.texture_combo_glimmer = ray.load_texture(folder_path + 'lane_obi_img00048.png') self.texture_combo_glimmer = load_texture_from_zip(zip_file, 'lane_obi_img00048.png')
self.texture_score_numbers = [] self.texture_score_numbers = []
for i in range(4, 14): for i in range(4, 14):
filename = f'lane_obi_img{str(i).zfill(5)}.png' filename = f'lane_obi_img{str(i).zfill(5)}.png'
self.texture_score_numbers.append(ray.load_texture(folder_path + filename)) self.texture_score_numbers.append(load_texture_from_zip(zip_file, filename))
self.texture_se_moji = [] self.texture_se_moji = []
for i in range(0, 17): for i in range(0, 17):
filename = f'onp_moji_img{str(i).zfill(5)}.png' filename = f'onp_moji_img{str(i).zfill(5)}.png'
if i == 8: if i == 8:
filename = 'onp_renda_moji_img00001.png' filename = 'onp_renda_moji_img00001.png'
self.texture_se_moji.append(ray.load_texture(folder_path + filename)) self.texture_se_moji.append(load_texture_from_zip(zip_file, filename))
folder_path = 'Graphics\\lumendata\\enso_system\\base1p\\' zip_file = 'Graphics\\lumendata\\enso_system\\base1p.zip'
self.texture_balloon_speech_bubble_p1 = ray.load_texture(folder_path + 'action_fusen_1p_img00000.png') self.texture_balloon_speech_bubble_p1 = load_texture_from_zip(zip_file, 'action_fusen_1p_img00000.png')
self.texture_balloon = [ray.load_texture(folder_path + 'action_fusen_1p_img00011.png'), self.texture_balloon = [load_texture_from_zip(zip_file, 'action_fusen_1p_img00011.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00012.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00012.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00013.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00013.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00014.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00014.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00015.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00015.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00016.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00016.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00017.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00017.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00018.png')] load_texture_from_zip(zip_file, 'action_fusen_1p_img00018.png')]
self.texture_balloon_number = [ray.load_texture(folder_path + 'action_fusen_1p_img00001.png'), self.texture_balloon_number = [load_texture_from_zip(zip_file, 'action_fusen_1p_img00001.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00002.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00002.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00003.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00003.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00004.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00004.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00005.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00005.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00006.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00006.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00007.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00007.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00008.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00008.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00009.png'), load_texture_from_zip(zip_file, 'action_fusen_1p_img00009.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00010.png')] load_texture_from_zip(zip_file, 'action_fusen_1p_img00010.png')]
self.texture_base_score_numbers = [] self.texture_base_score_numbers = []
for i in range(0, 10): for i in range(0, 10):
filename = f'score_add_1p_img{str(i).zfill(5)}.png' filename = f'score_add_1p_img{str(i).zfill(5)}.png'
self.texture_base_score_numbers.append(ray.load_texture(folder_path + filename)) self.texture_base_score_numbers.append(load_texture_from_zip(zip_file, filename))
def load_sounds(self): def load_sounds(self):
self.sound_don = ray.load_sound('Sounds\\inst_00_don.wav') self.sound_don = ray.load_sound('Sounds\\inst_00_don.wav')
@@ -172,18 +172,18 @@ class GameScreen:
#Map notes to textures #Map notes to textures
self.note_type_dict = {'1': self.texture_don, self.note_type_dict = {'1': self.texture_don,
'2': self.texture_kat, '2': self.texture_kat,
'3': self.texture_dai_don, '3': self.texture_dai_don,
'4': self.texture_dai_kat, '4': self.texture_dai_kat,
'5': self.texture_drumroll_head, '5': self.texture_drumroll_head,
'6': self.texture_dai_drumroll_head, '6': self.texture_dai_drumroll_head,
'7': self.texture_balloon_head, '7': self.texture_balloon_head,
'drumroll_body': self.texture_drumroll_body, 'drumroll_body': self.texture_drumroll_body,
'drumroll_tail': self.texture_drumroll_tail, 'drumroll_tail': self.texture_drumroll_tail,
'dai_drumroll_body': self.texture_dai_drumroll_body, 'dai_drumroll_body': self.texture_dai_drumroll_body,
'dai_drumroll_tail': self.texture_dai_drumroll_tail, 'dai_drumroll_tail': self.texture_dai_drumroll_tail,
'balloon_tail': self.texture_balloon_tail} 'balloon_tail': self.texture_balloon_tail}
self.tja = tja_parser(f'Songs\\{song}') self.tja = TJAParser(f'Songs\\{song}')
self.tja.get_metadata() self.tja.get_metadata()
self.tja.distance = self.width - self.judge_x self.tja.distance = self.width - self.judge_x
@@ -509,7 +509,6 @@ class Player:
self.animation_manager(game_screen, self.base_score_list) self.animation_manager(game_screen, self.base_score_list)
self.score_manager(game_screen) self.score_manager(game_screen)
self.key_manager(game_screen) self.key_manager(game_screen)
return None
def draw_animation_list(self, game_screen, animation_list): def draw_animation_list(self, game_screen, animation_list):
for animation in animation_list: for animation in animation_list:

View File

@@ -2,107 +2,32 @@ import time
import os import os
import pyray as ray import pyray as ray
import cv2 import cv2
import zipfile
import tempfile
from collections import deque from collections import deque
#TJA Format creator is unknown. I did not create the format, but I did write the parser though. #TJA Format creator is unknown. I did not create the format, but I did write the parser though.
import cProfile def load_image_from_zip(zip_path, filename):
import pstats with zipfile.ZipFile(zip_path, 'r') as zip_ref:
import io with zip_ref.open(filename) as image_file:
import sys with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
temp_file.write(image_file.read())
temp_file_path = temp_file.name
image = ray.load_image(temp_file_path)
os.remove(temp_file_path)
return image
class Profiler: def load_texture_from_zip(zip_path, filename):
def __init__(self): with zipfile.ZipFile(zip_path, 'r') as zip_ref:
self.profiler = cProfile.Profile() with zip_ref.open(filename) as image_file:
self.stats = None with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
self.calls = 0 temp_file.write(image_file.read())
self.profiled_functions = set() # Track profiled functions temp_file_path = temp_file.name
self.previous_order = [] # Track previous order of functions texture = ray.load_texture(temp_file_path)
os.remove(temp_file_path)
def profile(self, func, *args, **kwargs): return texture
func_name = func.__name__
self.calls += 1
# Start profiling
self.profiler.enable()
func(*args, **kwargs)
self.profiler.disable()
# Collect and update stats
if self.stats is None:
self.stats = pstats.Stats(self.profiler)
else:
self.stats.add(self.profiler)
# Get current order of functions
current_order = self.get_current_function_order()
# Check if a new function is added or if order has changed
if func_name not in self.profiled_functions or self.previous_order != current_order:
self.profiled_functions.add(func_name)
self.clear_screen()
# Update the previous order to the current one
self.previous_order = current_order
# Print the averaged stats
self.print_averaged_stats()
def clear_screen(self):
sys.stdout.write('\033[2J\033[H') # Clear screen and move cursor to the top
sys.stdout.flush()
def get_current_function_order(self):
# Capture stats output to determine the current order of functions
stream = io.StringIO()
stats = pstats.Stats(self.profiler, stream=stream)
stats.sort_stats(pstats.SortKey.TIME)
stats.print_stats()
# Extract function names from the stats output
content = stream.getvalue().splitlines()[5:] # Skip header lines
function_order = [line.split()[-1] for line in content if line.strip()]
return function_order
def print_averaged_stats(self):
# Prepare the output stream to capture stats
stream = io.StringIO()
stats = pstats.Stats(self.profiler, stream=stream)
stats.sort_stats(pstats.SortKey.TIME)
# Print the stats, but suppress the raw counts
stats.print_stats()
# Extract and process stats to average them
content = stream.getvalue().splitlines()
header = content[:5] # Keep the header
data = content[5:] # Data lines
if data:
# Update the total calls and times
avg_data = []
for line in data:
parts = line.split()
if len(parts) >= 6:
ncalls = int(parts[0].replace('/', '')) # Total calls
tottime = float(parts[1]) # Total time
percall = tottime / ncalls if ncalls > 0 else 0
cumtime = float(parts[3]) # Cumulative time
cumpercall = cumtime / ncalls if ncalls > 0 else 0
# Format and add the line
avg_data.append(
f"{ncalls:>9} {tottime / self.calls:>9.3f} {percall:>9.3f} "
f"{ncalls:>9} {cumtime / self.calls:>9.3f} {cumpercall:>9.3f} {line[90:]}"
)
# Move cursor to the start of the line before printing
sys.stdout.write('\033[F' * (len(header) + len(avg_data))) # Move cursor up to overwrite
# Print the header and averaged data
sys.stdout.write('\n'.join(header + avg_data) + '\n')
sys.stdout.flush()
def rounded(d): def rounded(d):
sign = 1 if (d >= 0) else -1 sign = 1 if (d >= 0) else -1
@@ -137,7 +62,7 @@ def get_pixels_per_frame(bpm, fps, time_signature, distance):
total_frames = fps * total_time total_frames = fps * total_time
return (distance / total_frames) * (fps/60) return (distance / total_frames) * (fps/60)
class tja_parser: class TJAParser:
def __init__(self, path): def __init__(self, path):
#Defined on startup #Defined on startup
self.folder_path = path self.folder_path = path
@@ -341,7 +266,7 @@ class tja_parser:
if len(play_note_list) > 1: if len(play_note_list) > 1:
prev_note = play_note_list[-2] prev_note = play_note_list[-2]
if prev_note['note'] in {'1', '2'}: if prev_note['note'] in {'1', '2'}:
if note_ms - prev_note['ms'] < (ms_per_measure/8): if note_ms - prev_note['ms'] <= (ms_per_measure/8) - 1:
prev_note['se_note'] = se_notes[prev_note['note']][1] prev_note['se_note'] = se_notes[prev_note['note']][1]
else: else:
prev_note['se_note'] = se_notes[prev_note['note']][0] prev_note['se_note'] = se_notes[prev_note['note']][0]
@@ -398,6 +323,14 @@ class Animation:
delay=self.params.get('delay', 0.0), delay=self.params.get('delay', 0.0),
ease_in=self.params.get('ease_in', None), ease_in=self.params.get('ease_in', None),
ease_out=self.params.get('ease_out', None)) ease_out=self.params.get('ease_out', None))
if self.params.get('reverse', None) is not None and current_ms - self.start_ms >= self.duration + self.params.get('delay', 0.0):
self.fade(current_ms,
self.duration,
final_opacity=self.params.get('initial_opacity', 1.0),
initial_opacity=self.params.get('final_opacity', 0.0),
delay=self.params.get('delay', 0.0) + self.duration + self.params.get('reverse'),
ease_in=self.params.get('ease_in', None),
ease_out=self.params.get('ease_out', None))
elif self.type == 'move': elif self.type == 'move':
self.move(current_ms, self.move(current_ms,
self.duration, self.duration,
@@ -417,6 +350,12 @@ class Animation:
initial_size=self.params.get('initial_size', 1.0), initial_size=self.params.get('initial_size', 1.0),
final_size=self.params.get('final_size', 1.0), final_size=self.params.get('final_size', 1.0),
delay=self.params.get('delay', 0.0)) delay=self.params.get('delay', 0.0))
if self.params.get('reverse', None) is not None and current_ms - self.start_ms >= self.duration + self.params.get('delay', 0.0):
self.texture_resize(current_ms,
self.duration,
final_size=self.params.get('initial_size', 1.0),
initial_size=self.params.get('final_size', 1.0),
delay=self.params.get('delay', 0.0) + self.duration)
def fade(self, current_ms, duration, initial_opacity, final_opacity, delay, ease_in, ease_out): def fade(self, current_ms, duration, initial_opacity, final_opacity, delay, ease_in, ease_out):
def ease_out_progress(progress, ease): def ease_out_progress(progress, ease):

View File

@@ -22,7 +22,8 @@ def main():
ray.set_window_max_size(screen_width, screen_height) ray.set_window_max_size(screen_width, screen_height)
ray.set_window_min_size(screen_width, screen_height) ray.set_window_min_size(screen_width, screen_height)
ray.init_window(screen_width, screen_height, "PyTaiko") ray.init_window(screen_width, screen_height, "PyTaiko")
ray.toggle_borderless_windowed() #ray.toggle_borderless_windowed()
ray.clear_window_state(ray.ConfigFlags.FLAG_WINDOW_TOPMOST)
#ray.maximize_window() #ray.maximize_window()
current_screen = Screens.TITLE current_screen = Screens.TITLE
@@ -42,11 +43,13 @@ def main():
#Screens.RESULT: result_screen #Screens.RESULT: result_screen
} }
#Drawing as a render texture causes some weird issue with the notes having an extra shadow, $50 bounty for whoever fixes it
target = ray.load_render_texture(screen_width, screen_height) target = ray.load_render_texture(screen_width, screen_height)
ray.set_texture_filter(target.texture, ray.TextureFilter.TEXTURE_FILTER_TRILINEAR) ray.set_texture_filter(target.texture, ray.TextureFilter.TEXTURE_FILTER_TRILINEAR)
start_song = False start_song = False
ray.set_exit_key(ray.KeyboardKey.KEY_A) ray.set_exit_key(ray.KeyboardKey.KEY_A)
while not ray.window_should_close(): while not ray.window_should_close():
ray.begin_texture_mode(target) ray.begin_texture_mode(target)
screen = screen_mapping[current_screen] screen = screen_mapping[current_screen]
if screen == title_screen: if screen == title_screen:
@@ -56,6 +59,7 @@ def main():
if ray.is_key_pressed(ray.KeyboardKey.KEY_F11): if ray.is_key_pressed(ray.KeyboardKey.KEY_F11):
ray.toggle_fullscreen() ray.toggle_fullscreen()
ray.is_window_fullscreen()
elif ray.is_key_pressed(ray.KeyboardKey.KEY_F12): elif ray.is_key_pressed(ray.KeyboardKey.KEY_F12):
ray.toggle_borderless_windowed() ray.toggle_borderless_windowed()

103
title.py
View File

@@ -3,7 +3,7 @@ import numpy as np
import cv2 import cv2
import os import os
import random import random
from global_funcs import Animation, VideoPlayer, get_current_ms from global_funcs import Animation, VideoPlayer, get_current_ms, load_texture_from_zip
class TitleScreen: class TitleScreen:
def __init__(self, width, height): def __init__(self, width, height):
@@ -26,27 +26,28 @@ class TitleScreen:
self.load_textures() self.load_textures()
def load_textures(self): def load_textures(self):
self.texture_bg = ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00000.png') zip_file = 'Graphics\\lumendata\\attract\\keikoku.zip'
self.texture_warning = ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00001.png') self.texture_bg = load_texture_from_zip(zip_file, 'keikoku_img00000.png')
self.texture_warning_ch1 = [ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00004.png'), self.texture_warning = load_texture_from_zip(zip_file, 'keikoku_img00001.png')
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00009.png'), self.texture_warning_ch1 = [load_texture_from_zip(zip_file, 'keikoku_img00004.png'),
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00016.png')] load_texture_from_zip(zip_file, 'keikoku_img00009.png'),
self.texture_warning_ch1_base = ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00002.png') load_texture_from_zip(zip_file, 'keikoku_img00016.png')]
self.texture_warning_ch2 = [ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00005.png'), self.texture_warning_ch1_base = load_texture_from_zip(zip_file, 'keikoku_img00002.png')
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00006.png'), self.texture_warning_ch2 = [load_texture_from_zip(zip_file, 'keikoku_img00005.png'),
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00007.png'), load_texture_from_zip(zip_file, 'keikoku_img00006.png'),
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00008.png'), load_texture_from_zip(zip_file, 'keikoku_img00007.png'),
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00010.png'), load_texture_from_zip(zip_file, 'keikoku_img00008.png'),
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00011.png'), load_texture_from_zip(zip_file, 'keikoku_img00010.png'),
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00012.png'), load_texture_from_zip(zip_file, 'keikoku_img00011.png'),
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00013.png'), load_texture_from_zip(zip_file, 'keikoku_img00012.png'),
ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00017.png')] load_texture_from_zip(zip_file, 'keikoku_img00013.png'),
self.texture_warning_ch2_base = ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00003.png') load_texture_from_zip(zip_file, 'keikoku_img00017.png')]
self.texture_warning_bachi = ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00019.png') self.texture_warning_ch2_base = load_texture_from_zip(zip_file, 'keikoku_img00003.png')
self.texture_warning_bachi_hit = ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00018.png') self.texture_warning_bachi = load_texture_from_zip(zip_file, 'keikoku_img00019.png')
self.texture_warning_bachi_hit = load_texture_from_zip(zip_file, 'keikoku_img00018.png')
self.texture_warning_x_1 = ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00014.png') self.texture_warning_x_1 = load_texture_from_zip(zip_file, 'keikoku_img00014.png')
self.texture_warning_x_2 = ray.load_texture('Graphics\\lumendata\\attract\\keikoku\\keikoku_img00015.png') self.texture_warning_x_2 = load_texture_from_zip(zip_file, 'keikoku_img00015.png')
self.sound_bachi_swipe = ray.load_sound('Sounds\\title\\SE_ATTRACT_2.ogg') self.sound_bachi_swipe = ray.load_sound('Sounds\\title\\SE_ATTRACT_2.ogg')
@@ -54,7 +55,7 @@ class TitleScreen:
self.sound_warning_message = ray.load_sound('Sounds\\title\\VO_ATTRACT_3.ogg') self.sound_warning_message = ray.load_sound('Sounds\\title\\VO_ATTRACT_3.ogg')
self.sound_warning_error = ray.load_sound('Sounds\\title\\SE_ATTRACT_1.ogg') self.sound_warning_error = ray.load_sound('Sounds\\title\\SE_ATTRACT_1.ogg')
self.texture_black = ray.load_texture('Graphics\\lumendata\\attract\\movie\\movie_img00000.png') self.texture_black = load_texture_from_zip('Graphics\\lumendata\\attract\\movie.zip', 'movie_img00000.png')
def scene_manager(self): def scene_manager(self):
if self.current_op_video is not None: if self.current_op_video is not None:
@@ -100,15 +101,19 @@ class WarningBoard:
def __init__(self, current_ms, title_screen): def __init__(self, current_ms, title_screen):
self.start_ms = current_ms self.start_ms = current_ms
self.error_time = 4250 self.error_time = 4250
#Move warning board down from top of screen
self.move_animation_1 = Animation(current_ms, 266.67, 'move') self.move_animation_1 = Animation(current_ms, 266.67, 'move')
self.move_animation_1.params['start_position'] = -720 self.move_animation_1.params['start_position'] = -720
self.move_animation_1.params['total_distance'] = title_screen.height + ((title_screen.height - title_screen.texture_warning.height)//2) + 20 self.move_animation_1.params['total_distance'] = title_screen.height + ((title_screen.height - title_screen.texture_warning.height)//2) + 20
#Move warning board up a little bit
self.move_animation_2 = Animation(current_ms, 116.67, 'move') self.move_animation_2 = Animation(current_ms, 116.67, 'move')
self.move_animation_2.params['start_position'] = 92 + 20 self.move_animation_2.params['start_position'] = 92 + 20
self.move_animation_2.params['delay'] = 266.67 self.move_animation_2.params['delay'] = 266.67
self.move_animation_2.params['total_distance'] = -30 self.move_animation_2.params['total_distance'] = -30
#And finally into its correct position
self.move_animation_3 = Animation(current_ms, 116.67, 'move') self.move_animation_3 = Animation(current_ms, 116.67, 'move')
self.move_animation_3.params['start_position'] = 82 self.move_animation_3.params['start_position'] = 82
self.move_animation_3.params['delay'] = 383.34 self.move_animation_3.params['delay'] = 383.34
@@ -119,6 +124,7 @@ class WarningBoard:
self.fade_animation_1.params['initial_opacity'] = 0.0 self.fade_animation_1.params['initial_opacity'] = 0.0
self.fade_animation_1.params['final_opacity'] = 1.0 self.fade_animation_1.params['final_opacity'] = 1.0
#Fade to black
self.fade_animation_2 = Animation(current_ms, 500, 'fade') self.fade_animation_2 = Animation(current_ms, 500, 'fade')
self.fade_animation_2.params['initial_opacity'] = 0.0 self.fade_animation_2.params['initial_opacity'] = 0.0
self.fade_animation_2.params['final_opacity'] = 1.0 self.fade_animation_2.params['final_opacity'] = 1.0
@@ -132,39 +138,29 @@ class WarningBoard:
self.resize_animation_1.params['initial_size'] = 1.0 self.resize_animation_1.params['initial_size'] = 1.0
self.resize_animation_1.params['final_size'] = 1.5 self.resize_animation_1.params['final_size'] = 1.5
self.resize_animation_1.params['delay'] = self.error_time self.resize_animation_1.params['delay'] = self.error_time
self.resize_animation_1.params['reverse'] = 0
self.resize_animation_2 = Animation(current_ms, 166.67, 'texture_resize')
self.resize_animation_2.params['initial_size'] = 1.5
self.resize_animation_2.params['final_size'] = 1.0
self.resize_animation_2.params['delay'] = self.error_time + 166.67
self.fade_animation_4 = Animation(current_ms, 166.67, 'fade') self.fade_animation_4 = Animation(current_ms, 166.67, 'fade')
self.fade_animation_4.params['delay'] = self.error_time self.fade_animation_4.params['delay'] = self.error_time
self.fade_animation_4.params['initial_opacity'] = 0.0 self.fade_animation_4.params['initial_opacity'] = 0.0
self.fade_animation_4.params['final_opacity'] = 1.0 self.fade_animation_4.params['final_opacity'] = 1.0
self.fade_animation_4.params['reverse'] = 166.67
self.fade_animation_5 = Animation(current_ms, 166.67, 'fade')
self.fade_animation_5.params['delay'] = self.error_time + 166.67 + 166.67
self.fade_animation_5.params['initial_opacity'] = 1.0
self.fade_animation_5.params['final_opacity'] = 0.0
self.fade_animation_6 = Animation(current_ms, 166.67, 'fade') self.fade_animation_6 = Animation(current_ms, 166.67, 'fade')
self.fade_animation_6.params['delay'] = self.error_time + 166.67 + 166.67 self.fade_animation_6.params['delay'] = self.error_time + 166.67 + 166.67
self.fade_animation_6.params['initial_opacity'] = 0.0 self.fade_animation_6.params['initial_opacity'] = 0.0
self.fade_animation_6.params['final_opacity'] = 1.0 self.fade_animation_6.params['final_opacity'] = 1.0
#Bachi hit
self.resize_animation_3 = Animation(current_ms, 233.34, 'texture_resize') self.resize_animation_3 = Animation(current_ms, 233.34, 'texture_resize')
self.resize_animation_3.params['initial_size'] = 0.5 self.resize_animation_3.params['initial_size'] = 0.5
self.resize_animation_3.params['final_size'] = 1.5 self.resize_animation_3.params['final_size'] = 1.5
#Bachi hit
self.fade_animation_7 = Animation(current_ms, 116.67, 'fade') self.fade_animation_7 = Animation(current_ms, 116.67, 'fade')
self.fade_animation_7.params['initial_opacity'] = 0.0 self.fade_animation_7.params['initial_opacity'] = 0.0
self.fade_animation_7.params['final_opacity'] = 1.0 self.fade_animation_7.params['final_opacity'] = 1.0
self.fade_animation_7.params['reverse'] = 0
self.fade_animation_8 = Animation(current_ms, 116.67, 'fade')
self.fade_animation_8.params['delay'] = 116.67
self.fade_animation_8.params['initial_opacity'] = 1.0
self.fade_animation_8.params['final_opacity'] = 0.0
self.source_rect = ray.Rectangle(0, 0, title_screen.texture_black.width, title_screen.texture_black.height) self.source_rect = ray.Rectangle(0, 0, title_screen.texture_black.width, title_screen.texture_black.height)
self.dest_rect = ray.Rectangle(0, 0, title_screen.width, title_screen.height) self.dest_rect = ray.Rectangle(0, 0, title_screen.width, title_screen.height)
@@ -190,10 +186,8 @@ class WarningBoard:
self.fade_animation_2.update(current_ms) self.fade_animation_2.update(current_ms)
self.fade_animation_3.update(current_ms) self.fade_animation_3.update(current_ms)
self.fade_animation_4.update(current_ms) self.fade_animation_4.update(current_ms)
self.fade_animation_5.update(current_ms)
self.fade_animation_6.update(current_ms) self.fade_animation_6.update(current_ms)
self.resize_animation_1.update(current_ms) self.resize_animation_1.update(current_ms)
self.resize_animation_2.update(current_ms)
delay = 566.67 delay = 566.67
elapsed_time = current_ms - self.start_ms elapsed_time = current_ms - self.start_ms
if self.character_index(1) != 8: if self.character_index(1) != 8:
@@ -206,10 +200,9 @@ class WarningBoard:
self.hit_played = True self.hit_played = True
ray.play_sound(title_screen.sound_bachi_hit) ray.play_sound(title_screen.sound_bachi_hit)
self.resize_animation_3.start_ms = current_ms self.resize_animation_3.start_ms = current_ms
self.fade_animation_8.start_ms = current_ms self.fade_animation_7.start_ms = current_ms
self.resize_animation_3.update(current_ms) self.resize_animation_3.update(current_ms)
self.fade_animation_7.update(current_ms) self.fade_animation_7.update(current_ms)
self.fade_animation_8.update(current_ms)
if self.error_time + 166.67 <= elapsed_time and not self.error_played: if self.error_time + 166.67 <= elapsed_time and not self.error_played:
self.error_played = True self.error_played = True
@@ -262,23 +255,14 @@ class WarningBoard:
if self.character_index(1) == 8: if self.character_index(1) == 8:
ray.draw_texture(title_screen.texture_warning_bachi, 350, int(y)+135, ray.WHITE) ray.draw_texture(title_screen.texture_warning_bachi, 350, int(y)+135, ray.WHITE)
if self.resize_animation_1.is_finished: scale = self.resize_animation_1.attribute
scale = self.resize_animation_2.attribute width = title_screen.texture_warning_x_1.width
width = title_screen.texture_warning_x_1.width height = title_screen.texture_warning_x_1.height
height = title_screen.texture_warning_x_1.height x_x = 150 + (width//2) - ((width * scale)//2)
x_x = 150 + (width//2) - ((width * scale)//2) x_y = 200 + (height//2) - ((height * scale)//2)
x_y = 200 + (height//2) - ((height * scale)//2)
fade = ray.fade(ray.WHITE, self.fade_animation_5.attribute)
else:
scale = self.resize_animation_1.attribute
width = title_screen.texture_warning_x_1.width
height = title_screen.texture_warning_x_1.height
x_x = 150 + (width//2) - ((width * scale)//2)
x_y = 200 + (height//2) - ((height * scale)//2)
fade = ray.fade(ray.WHITE, self.fade_animation_4.attribute)
x_source = ray.Rectangle(0, 0, width, height) x_source = ray.Rectangle(0, 0, width, height)
x_dest = ray.Rectangle(x_x, x_y, width*scale, height*scale) x_dest = ray.Rectangle(x_x, x_y, width*scale, height*scale)
ray.draw_texture_pro(title_screen.texture_warning_x_1, x_source, x_dest, ray.Vector2(0,0), 0, fade) ray.draw_texture_pro(title_screen.texture_warning_x_1, x_source, x_dest, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fade_animation_4.attribute))
scale = self.resize_animation_3.attribute scale = self.resize_animation_3.attribute
width = title_screen.texture_warning_bachi_hit.width width = title_screen.texture_warning_bachi_hit.width
@@ -287,10 +271,5 @@ class WarningBoard:
hit_y = 225 + (height//2) - ((height * scale)//2) hit_y = 225 + (height//2) - ((height * scale)//2)
hit_source = ray.Rectangle(0, 0, width, height) hit_source = ray.Rectangle(0, 0, width, height)
hit_dest = ray.Rectangle(hit_x, hit_y, width*scale, height*scale) hit_dest = ray.Rectangle(hit_x, hit_y, width*scale, height*scale)
if self.fade_animation_7.is_finished: ray.draw_texture_pro(title_screen.texture_warning_bachi_hit, hit_source, hit_dest, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fade_animation_7.attribute))
fade = ray.fade(ray.WHITE, self.fade_animation_8.attribute)
else:
fade = ray.fade(ray.WHITE, self.fade_animation_7.attribute)
ray.draw_texture_pro(title_screen.texture_warning_bachi_hit, hit_source, hit_dest, ray.Vector2(0,0), 0, fade)
ray.draw_texture_pro(title_screen.texture_black, self.source_rect, self.dest_rect, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fade_animation_2.attribute)) ray.draw_texture_pro(title_screen.texture_black, self.source_rect, self.dest_rect, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fade_animation_2.attribute))