mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
Fix the dreaded font reloading bug
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
from pathlib import Path
|
||||
import pyray as ray
|
||||
|
||||
from libs.screen import Screen
|
||||
from libs.texture import tex
|
||||
|
||||
|
||||
class DevScreen(Screen):
|
||||
def on_screen_start(self):
|
||||
super().on_screen_start()
|
||||
self.text = ".⁉ゃん座組ス5れへデ7?x事音ょ野ダHズパに相村束虹神狂'Uqはたt朗♢弥ウち”作Wシら黒さドカモ金章よ方りj沙べ口ぃご歌!こ制みわ険時行×ワ獣ぺ阿啓R哀肉乱終鼓ツ,0かVしでw?2⒒悟マ乙ィの女アラA疾浄u+も’グ怒[ャロ冒陽ね路想ベ#ト醜ペ!太悪χキn初あKン〜<原Qハ1s旅をガ分ビNゼ玄沢≠食@フ拝テM豚幻濤ま人腹世P愴)っピやナJ社びB一6c畑譚]gてd~曲花Oくkル第◇校*⒓森・バコ談ヤ急め愛プ重ー勝DE:Zチ東二じ車>ブ刑ミ+X:焼おyつλ♪オい憎aFe竜そ大84得渉/◆ソC番、l†レ悲暴う胸るG“ゆS転fゅとセo「風輔@双zr―-vノケp‼b…響3メ罪 クL自(Iイタニムき夜幽T&楽m学走ジ島h田i美心Yボサッリュひ寅9」達"
|
||||
unique_codepoints = set(self.text)
|
||||
codepoint_count = ray.ffi.new('int *', 0)
|
||||
unique_string = ''.join(unique_codepoints)
|
||||
codepoints = ray.load_codepoints(unique_string, codepoint_count)
|
||||
self.font = ray.load_font_ex(str(Path('Graphics/Modified-DFPKanteiryu-XB.ttf')), 40, codepoints, len(unique_codepoints))
|
||||
|
||||
def on_screen_end(self, next_screen: str):
|
||||
return super().on_screen_end(next_screen)
|
||||
@@ -14,4 +22,5 @@ class DevScreen(Screen):
|
||||
super().update()
|
||||
|
||||
def draw(self):
|
||||
ray.draw_rectangle(0, 0, 1280, 720, ray.GREEN)
|
||||
ray.draw_rectangle(0, 0, tex.screen_width, tex.screen_height, ray.GREEN)
|
||||
ray.draw_text_ex(self.font, "幽玄ノ乱", ray.Vector2(tex.screen_width//2, tex.screen_height//2), 60, 20, ray.BLACK)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
import threading
|
||||
|
||||
import pyray as ray
|
||||
@@ -43,6 +44,22 @@ class LoadScreen(Screen):
|
||||
self.songs_loaded = True
|
||||
logger.info("Song hashes loaded")
|
||||
|
||||
def _load_font(self):
|
||||
for hash in global_data.song_hashes:
|
||||
song_entry = global_data.song_hashes[hash]
|
||||
for song in song_entry:
|
||||
titles = song.get('title', dict())
|
||||
subtitles = song.get('subtitle', dict())
|
||||
for title in titles.values():
|
||||
for character in title:
|
||||
global_data.font_codepoints.add(character)
|
||||
for subtitle in subtitles.values():
|
||||
for character in subtitle:
|
||||
global_data.font_codepoints.add(character)
|
||||
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))
|
||||
|
||||
def _load_navigator(self):
|
||||
"""Background thread function to load navigator"""
|
||||
self.navigator.initialize(global_data.config["paths"]["tja_path"])
|
||||
@@ -70,6 +87,7 @@ class LoadScreen(Screen):
|
||||
super().update()
|
||||
|
||||
if self.songs_loaded and not self.navigator_started:
|
||||
self._load_font()
|
||||
self.navigator_thread = threading.Thread(target=self._load_navigator)
|
||||
self.navigator_thread.daemon = True
|
||||
self.navigator_thread.start()
|
||||
|
||||
Reference in New Issue
Block a user