mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
Fix the dreaded font reloading bug
This commit is contained in:
@@ -3,6 +3,8 @@ from enum import IntEnum
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pyray as ray
|
||||
|
||||
from libs.config import Config
|
||||
|
||||
class PlayerNum(IntEnum):
|
||||
@@ -137,6 +139,8 @@ class GlobalData:
|
||||
session_data (list[SessionData]): Session data for both players.
|
||||
"""
|
||||
songs_played: int = 0
|
||||
font: ray.Font = ray.get_font_default()
|
||||
font_codepoints = set()
|
||||
config: Config = field(default_factory=dict)
|
||||
song_hashes: dict[str, list[dict]] = field(default_factory=lambda: dict()) #Hash to path
|
||||
song_paths: dict[Path, str] = field(default_factory=lambda: dict()) #path to hash
|
||||
|
||||
@@ -203,6 +203,17 @@ class OutlinedText:
|
||||
return n.hexdigest()
|
||||
|
||||
def _load_font_for_text(self, text: str) -> ray.Font:
|
||||
reload_font = False
|
||||
for character in text:
|
||||
if character not in global_data.font_codepoints:
|
||||
global_data.font_codepoints.add(character)
|
||||
reload_font = True
|
||||
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))
|
||||
logger.info(f"Reloaded font with {len(global_data.font_codepoints)} codepoints")
|
||||
return global_data.font
|
||||
codepoint_count = ray.ffi.new('int *', 0)
|
||||
unique_codepoints = set(text)
|
||||
codepoints = ray.load_codepoints(''.join(unique_codepoints), codepoint_count)
|
||||
|
||||
Reference in New Issue
Block a user