Skip to content

Commit

Permalink
<fix> fix replace font error in newer version of renpy
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymousException committed Jun 6, 2024
1 parent 2638f16 commit 45075f1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/font_style_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ translate {tl_name} python:
gui.headline_text_font = FontGroup().add(font_path, 0x2E80, 0xffff).add(font_path, 0x0000, 0xffff)

font_path = "{font_path}"
#replace defined font
change_font(font_path)
20 changes: 2 additions & 18 deletions src/renpy_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,10 @@ def ExtractStyleFontListFromFile(p):

return d


def ExtractDefinedFontListFromFile(p):
f = io.open(p, 'r+', encoding='utf-8')
_read = f.read()
f.close()
return ExtractDefineList(_read)

# ExtractDefinedFontListFromFile(f'F:\Games\RenPy\MilkyTouch-Finale.Official-pc\game\screens.rpy')


def ExtractStyleFontListFromDirectory(p):
if (p[len(p) - 1] != '/' and p[len(p) - 1] != '\\'):
p = p + '/'
ret_d = dict()
ret_set = set()
paths = os.walk(p, topdown=False)
for path, dir_lst, file_lst in paths:
for file_name in file_lst:
Expand All @@ -141,10 +130,9 @@ def ExtractStyleFontListFromDirectory(p):
continue
# print(i)
d = ExtractStyleFontListFromFile(i)
ret_set = ret_set | ExtractDefinedFontListFromFile(i)
if len(d) > 0:
ret_d.update(d)
return ret_d, ret_set
return ret_d


def ExtractFontContent(data):
Expand All @@ -168,10 +156,7 @@ def GenGuiFontsOriginal(p, tl_name, font_path):
f.close()
if (pythonBeginLine in _read):
appendMode = True
result, defined_set = ExtractStyleFontListFromDirectory(p)
defined_contents = ''
for defined in defined_set:
defined_contents = defined_contents + f' {defined} = gui.text_font\n'
result = ExtractStyleFontListFromDirectory(p)
if (appendMode):
f = io.open(guiPath, 'a+', encoding='utf-8')
for key, value in result.items():
Expand Down Expand Up @@ -214,7 +199,6 @@ def GenGuiFontsOriginal(p, tl_name, font_path):
f.close()
template = template.replace('{tl_name}', tl_name)
template = template.replace('{font_path}', 'fonts/' + font_path)
template = template.replace('#replace defined font', defined_contents)
f = io.open(guiPath, 'w', encoding='utf-8')
header = template
# print(header)
Expand Down

0 comments on commit 45075f1

Please sign in to comment.