mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30: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}"
|
||||
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():
|
||||
"""Create the scores database if it doesn't exist
|
||||
The migration will eventually be removed"""
|
||||
"""Create the scores database if it doesn't exist"""
|
||||
with sqlite3.connect('scores.db') as con:
|
||||
cursor = con.cursor()
|
||||
create_table_query = '''
|
||||
@@ -102,13 +137,6 @@ def create_song_db():
|
||||
con.commit()
|
||||
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():
|
||||
force_dedicated_gpu()
|
||||
global_data.config = get_config()
|
||||
@@ -117,9 +145,11 @@ def main():
|
||||
plain_formatter = logging.Formatter('[%(levelname)s] %(name)s: %(message)s')
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setFormatter(colored_formatter)
|
||||
console_handler = DedupHandler(console_handler)
|
||||
|
||||
file_handler = logging.FileHandler("latest.log")
|
||||
file_handler.setFormatter(plain_formatter)
|
||||
file_handler = DedupHandler(file_handler)
|
||||
logging.basicConfig(
|
||||
level=log_level,
|
||||
handlers=[console_handler, file_handler]
|
||||
|
||||
@@ -76,8 +76,6 @@ hitsound = 1.0
|
||||
attract_mode = 1.0
|
||||
|
||||
[video]
|
||||
screen_width = 1280
|
||||
screen_height = 720
|
||||
fullscreen = false
|
||||
borderless = false
|
||||
target_fps = -1
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import sys
|
||||
import cffi
|
||||
import platform
|
||||
import logging
|
||||
|
||||
@@ -399,7 +399,6 @@ class YellowBox:
|
||||
if not self.tja:
|
||||
return
|
||||
offset = tex.skin_config['yb_diff_offset'].x
|
||||
print(song_box.scores)
|
||||
for diff in self.tja.metadata.course_data:
|
||||
if diff >= Difficulty.URA:
|
||||
continue
|
||||
|
||||
@@ -161,6 +161,7 @@ class OutlinedText:
|
||||
self.text = text
|
||||
self.hash = self._hash_text(text, font_size, color, vertical)
|
||||
self.outline_thickness = outline_thickness * global_tex.screen_scale
|
||||
self.vertical = vertical
|
||||
if self.hash in text_cache:
|
||||
self.texture = ray.load_texture(f'cache/image/{self.hash}.png')
|
||||
else:
|
||||
@@ -428,7 +429,11 @@ class OutlinedText:
|
||||
final_color = ray.fade(color, fade)
|
||||
else:
|
||||
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:
|
||||
ray.begin_shader_mode(self.shader)
|
||||
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
|
||||
if self.branch_condition == 'p':
|
||||
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)
|
||||
if self.branch_indicator is not None and self.branch_indicator.difficulty != 'expert':
|
||||
if self.branch_indicator.difficulty == 'master':
|
||||
@@ -930,8 +932,6 @@ class Player:
|
||||
self.branch_m.pop(0)
|
||||
if self.branch_e:
|
||||
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
|
||||
|
||||
def update(self, ms_from_start: float, current_time: float, background: Optional[Background]):
|
||||
|
||||
Reference in New Issue
Block a user