马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 Ag2S 于 2020-5-9 13:51 编辑
复制以下代码,保存为py文件,放到游戏的game目录的上层目录,运行(需要安装python)。
[RenPy] 纯文本查看 复制代码 #!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import re
def getFontsList():
fs=[]
fs.append('DejaVuSans.ttf')
dirpath='game'
for root,dirs,files in os.walk(dirpath):
for file in files:
if((file.endswith('.ttf') or file.endswith('.otf')) and 'tl' not in root):
fs.append(os.path.join(root,file).replace('\\','/').replace('game/',''))
return fs
def getSourceFiles():
fs=[]
dirpath='game'
for root,dirs,files in os.walk(dirpath):
for file in files:
if(file.endswith('.rpy') and 'tl' not in root):
fs.append(os.path.join(root,file).replace('\\','/'))
return fs
def getStylesName(files):
styles=[]
styles.append('default')
for name in files:
lines=open(name,mode='r',encoding='utf-8').readlines( )
for line in lines:
b1= re.search('style (.*):', line)
if(b1):
name=b1.group(1)
b2=' ' not in name
if(b2):
#print(name)
styles.append(name)
styles=list(set(styles))
return styles
def genratePatch(fonts,styles,path):
patch=open('patch.rpy',mode='w',encoding='utf-8')
patch.write('##汉化Patch由Ag2S20150909制作\n')
patch.write('##This chinese Patch made by Ag2S20150909\n')
##python初始化
patch.write('init 200 python:\n')
patch.write(" config.language='chinese'\n")
patch.write(" if config.language=='chinese':\n")
for f in fonts:
patch.write(" config.font_replacement_map[\"%s\", True, True] = (\"%s\", True, True)\n" %(f,path))
patch.write(" config.font_replacement_map[\"%s\", False, False] = (\"%s\", False, False)\n" %(f,path))
patch.write(" config.font_replacement_map[\"%s\", True, False] = (\"%s\", True, False)\n" %(f,path))
patch.write(" config.font_replacement_map[\"%s\", False,True] = (\"%s\", False,True)\n" %(f,path))
for st in styles:
patch.write('translate chinese style %s:\n font "%s"\n' %(st,path))
patch.write('\ntranslate chinese python:\n')
patch.write(' gui.button_text_font = "%s"\n' %(path))
patch.write(' gui.glyph_font = "%s"\n' %(path))
patch.write(' gui.interface_text_font = "%s"\n' %(path))
patch.write(' gui.text_font = "%s"\n' %(path))
patch.write(' gui.name_text_font = "%s"\n' %(path))
##中文字体的相对路径
path='tl/chinese/patch/Alibaba-PuHuiTi-Regular.ttf'
files=getSourceFiles()
styles=getStylesName(files)
fonts=getFontsList()
genratePatch(fonts,styles,path)
|