mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
fix scarlet police crash
This commit is contained in:
48
PyTaiko.py
48
PyTaiko.py
@@ -78,9 +78,44 @@ class ColoredFormatter(logging.Formatter):
|
|||||||
record.levelname = f"{log_color}{record.levelname}{self.RESET}"
|
record.levelname = f"{log_color}{record.levelname}{self.RESET}"
|
||||||
return super().format(record)
|
return super().format(record)
|
||||||
|
|
||||||
|
class DedupHandler(logging.Handler):
|
||||||
|
def __init__(self, handler, show_count=True):
|
||||||
|
super().__init__()
|
||||||
|
self.handler = handler
|
||||||
|
self.last_log = None
|
||||||
|
self.duplicate_count = 0
|
||||||
|
self.show_count = show_count
|
||||||
|
|
||||||
|
def emit(self, record):
|
||||||
|
current_log = (record.levelno, record.name, record.getMessage())
|
||||||
|
|
||||||
|
if current_log == self.last_log:
|
||||||
|
self.duplicate_count += 1
|
||||||
|
else:
|
||||||
|
if self.duplicate_count > 0 and self.show_count:
|
||||||
|
dup_record = logging.LogRecord(
|
||||||
|
record.name, logging.INFO, "", 0,
|
||||||
|
f"(previous message repeated {self.duplicate_count} time{'s' if self.duplicate_count > 1 else ''})",
|
||||||
|
(), None
|
||||||
|
)
|
||||||
|
self.handler.emit(dup_record)
|
||||||
|
|
||||||
|
self.handler.emit(record)
|
||||||
|
self.last_log = current_log
|
||||||
|
self.duplicate_count = 0
|
||||||
|
|
||||||
|
def setFormatter(self, fmt):
|
||||||
|
self.handler.setFormatter(fmt)
|
||||||
|
|
||||||
|
def handle_exception(exc_type, exc_value, exc_traceback):
|
||||||
|
"""Log uncaught exceptions"""
|
||||||
|
if issubclass(exc_type, KeyboardInterrupt):
|
||||||
|
sys.__excepthook__(exc_type, exc_value, exc_traceback)
|
||||||
|
return
|
||||||
|
logger.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
|
||||||
|
|
||||||
def create_song_db():
|
def create_song_db():
|
||||||
"""Create the scores database if it doesn't exist
|
"""Create the scores database if it doesn't exist"""
|
||||||
The migration will eventually be removed"""
|
|
||||||
with sqlite3.connect('scores.db') as con:
|
with sqlite3.connect('scores.db') as con:
|
||||||
cursor = con.cursor()
|
cursor = con.cursor()
|
||||||
create_table_query = '''
|
create_table_query = '''
|
||||||
@@ -102,13 +137,6 @@ def create_song_db():
|
|||||||
con.commit()
|
con.commit()
|
||||||
logger.info("Scores database created successfully")
|
logger.info("Scores database created successfully")
|
||||||
|
|
||||||
def handle_exception(exc_type, exc_value, exc_traceback):
|
|
||||||
"""Log uncaught exceptions"""
|
|
||||||
if issubclass(exc_type, KeyboardInterrupt):
|
|
||||||
sys.__excepthook__(exc_type, exc_value, exc_traceback)
|
|
||||||
return
|
|
||||||
logger.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
force_dedicated_gpu()
|
force_dedicated_gpu()
|
||||||
global_data.config = get_config()
|
global_data.config = get_config()
|
||||||
@@ -117,9 +145,11 @@ def main():
|
|||||||
plain_formatter = logging.Formatter('[%(levelname)s] %(name)s: %(message)s')
|
plain_formatter = logging.Formatter('[%(levelname)s] %(name)s: %(message)s')
|
||||||
console_handler = logging.StreamHandler()
|
console_handler = logging.StreamHandler()
|
||||||
console_handler.setFormatter(colored_formatter)
|
console_handler.setFormatter(colored_formatter)
|
||||||
|
console_handler = DedupHandler(console_handler)
|
||||||
|
|
||||||
file_handler = logging.FileHandler("latest.log")
|
file_handler = logging.FileHandler("latest.log")
|
||||||
file_handler.setFormatter(plain_formatter)
|
file_handler.setFormatter(plain_formatter)
|
||||||
|
file_handler = DedupHandler(file_handler)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=log_level,
|
level=log_level,
|
||||||
handlers=[console_handler, file_handler]
|
handlers=[console_handler, file_handler]
|
||||||
|
|||||||
@@ -76,8 +76,6 @@ hitsound = 1.0
|
|||||||
attract_mode = 1.0
|
attract_mode = 1.0
|
||||||
|
|
||||||
[video]
|
[video]
|
||||||
screen_width = 1280
|
|
||||||
screen_height = 720
|
|
||||||
fullscreen = false
|
fullscreen = false
|
||||||
borderless = false
|
borderless = false
|
||||||
target_fps = -1
|
target_fps = -1
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import sys
|
|
||||||
import cffi
|
import cffi
|
||||||
import platform
|
import platform
|
||||||
import logging
|
import logging
|
||||||
|
|||||||
@@ -399,7 +399,6 @@ class YellowBox:
|
|||||||
if not self.tja:
|
if not self.tja:
|
||||||
return
|
return
|
||||||
offset = tex.skin_config['yb_diff_offset'].x
|
offset = tex.skin_config['yb_diff_offset'].x
|
||||||
print(song_box.scores)
|
|
||||||
for diff in self.tja.metadata.course_data:
|
for diff in self.tja.metadata.course_data:
|
||||||
if diff >= Difficulty.URA:
|
if diff >= Difficulty.URA:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ class OutlinedText:
|
|||||||
self.text = text
|
self.text = text
|
||||||
self.hash = self._hash_text(text, font_size, color, vertical)
|
self.hash = self._hash_text(text, font_size, color, vertical)
|
||||||
self.outline_thickness = outline_thickness * global_tex.screen_scale
|
self.outline_thickness = outline_thickness * global_tex.screen_scale
|
||||||
|
self.vertical = vertical
|
||||||
if self.hash in text_cache:
|
if self.hash in text_cache:
|
||||||
self.texture = ray.load_texture(f'cache/image/{self.hash}.png')
|
self.texture = ray.load_texture(f'cache/image/{self.hash}.png')
|
||||||
else:
|
else:
|
||||||
@@ -428,7 +429,11 @@ class OutlinedText:
|
|||||||
final_color = ray.fade(color, fade)
|
final_color = ray.fade(color, fade)
|
||||||
else:
|
else:
|
||||||
final_color = color
|
final_color = color
|
||||||
dest_rect = ray.Rectangle(x, y+((10 * global_tex.screen_scale)-10), self.texture.width+x2, self.texture.height+y2)
|
if not self.vertical:
|
||||||
|
offset = (10 * global_tex.screen_scale)-10
|
||||||
|
else:
|
||||||
|
offset = 0
|
||||||
|
dest_rect = ray.Rectangle(x, y+offset, self.texture.width+x2, self.texture.height+y2)
|
||||||
if self.outline_thickness > 0:
|
if self.outline_thickness > 0:
|
||||||
ray.begin_shader_mode(self.shader)
|
ray.begin_shader_mode(self.shader)
|
||||||
ray.draw_texture_pro(self.texture, self.default_src, dest_rect, origin, rotation, final_color)
|
ray.draw_texture_pro(self.texture, self.default_src, dest_rect, origin, rotation, final_color)
|
||||||
|
|||||||
@@ -903,7 +903,9 @@ class Player:
|
|||||||
self.is_branch = False
|
self.is_branch = False
|
||||||
if self.branch_condition == 'p':
|
if self.branch_condition == 'p':
|
||||||
self.branch_condition_count = max(min((self.branch_condition_count/total_notes)*100, 100), 0)
|
self.branch_condition_count = max(min((self.branch_condition_count/total_notes)*100, 100), 0)
|
||||||
if self.branch_condition_count >= e_req and self.branch_condition_count < m_req:
|
if self.branch_indicator is not None:
|
||||||
|
logger.info(f"Branch set to {self.branch_indicator.difficulty} based on conditions {self.branch_condition_count}, {e_req, m_req}")
|
||||||
|
if self.branch_condition_count >= e_req and self.branch_condition_count < m_req and e_req >= 0:
|
||||||
self.merge_branch_section(self.branch_e.pop(0), current_ms)
|
self.merge_branch_section(self.branch_e.pop(0), current_ms)
|
||||||
if self.branch_indicator is not None and self.branch_indicator.difficulty != 'expert':
|
if self.branch_indicator is not None and self.branch_indicator.difficulty != 'expert':
|
||||||
if self.branch_indicator.difficulty == 'master':
|
if self.branch_indicator.difficulty == 'master':
|
||||||
@@ -930,8 +932,6 @@ class Player:
|
|||||||
self.branch_m.pop(0)
|
self.branch_m.pop(0)
|
||||||
if self.branch_e:
|
if self.branch_e:
|
||||||
self.branch_e.pop(0)
|
self.branch_e.pop(0)
|
||||||
if self.branch_indicator is not None:
|
|
||||||
logger.info(f"Branch set to {self.branch_indicator.difficulty} based on conditions {self.branch_condition_count}, {e_req, m_req}")
|
|
||||||
self.branch_condition_count = 0
|
self.branch_condition_count = 0
|
||||||
|
|
||||||
def update(self, ms_from_start: float, current_time: float, background: Optional[Background]):
|
def update(self, ms_from_start: float, current_time: float, background: Optional[Background]):
|
||||||
|
|||||||
Reference in New Issue
Block a user