Skip to content

Commit

Permalink
Merge pull request #44 from HaruhiFanClub/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LJxFFFF authored Aug 14, 2021
2 parents b54b2ab + 5f007e1 commit 7e7cb07
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 59 deletions.
6 changes: 5 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@
- 0.1.1
- fix [立绘回收 #20](https://github.com/HaruhiFanClub/Excel2RpyScript/issues/20)
- fix [Nvl模式与adv模式的切换 #19](https://github.com/HaruhiFanClub/Excel2RpyScript/issues/19)
- 去掉Exe文件的外部依赖
- 去掉Exe文件的外部依赖

- 0.2.4
- fix 条件选择在最后一行时无法读取
- 支持对话框头像
7 changes: 4 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class Application(Application_ui):
def __init__(self, master=None):
Application_ui.__init__(self, master)

def convert(self, output_dir, res, role_name_mapping):
def convert(self, output_dir, res, role_name_mapping, role_side_character_mapping):
try:
RpyFileWriter.write_file(output_dir, res, role_name_mapping)
RpyFileWriter.write_file(output_dir, res, role_name_mapping, role_side_character_mapping)
except FileNotFoundError:
raise SaveFileException("保存目录不存在")

Expand Down Expand Up @@ -137,8 +137,9 @@ def ConvertButton_Cmd(self, event=None):
parser = Parser(path)
conveter = Converter(parser)
convert_results = conveter.generate_rpy_elements()
print(conveter.side_characters)
for res in convert_results:
self.convert(self.saveAddr.get(), res, conveter.role_name_mapping)
self.convert(self.saveAddr.get(), res, conveter.role_name_mapping, conveter.side_characters)
except ConvertException as err:
success_flag = False
showerror("转换错误", err.msg)
Expand Down
2 changes: 1 addition & 1 deletion const/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

CURRENT_VERSION = "v0.2.3"
CURRENT_VERSION = "v0.2.4"
1 change: 1 addition & 0 deletions const/converter_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'special': 26,
'voice': 27,
'menu': 28,
'side_character': 29,
}

# 元素映射
Expand Down
2 changes: 1 addition & 1 deletion const/parser_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
EXCEL_PARSE_START_ROW = 7

# excel解析列数
EXCEL_PARSE_START_COL = 29
EXCEL_PARSE_START_COL = 30
Binary file modified dist/Excel2RpyScript.exe
Binary file not shown.
21 changes: 16 additions & 5 deletions handler/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
'sound', # 音效
'transition', # 转场
'voice', # 语音
'menu' # 条件跳转
'menu', # 条件跳转
'side_character' # 头像
])


Expand All @@ -36,6 +37,7 @@ def __init__(self, parser):
self.current_mode = 'nvl'
self.current_role = Role("narrator_nvl", "None")
self.characters = list()
self.side_characters = dict()

def add_role(self, name):
role = self.role_name_mapping.get(name)
Expand Down Expand Up @@ -95,6 +97,7 @@ def convert(self):
transition=self._converter_transition(),
voice=self._converter_voice(),
menu=self._converter_menu(),
side_character=self._converter_side_character(),
)

def _converter_mode(self):
Expand Down Expand Up @@ -122,7 +125,7 @@ def _converter_role(self):

def _converter_text(self):
# 文本
text = self.row[ElementColNumMapping.get('text')].replace("\n", "\\n")
text = str(self.row[ElementColNumMapping.get('text')]).replace("\n", "\\n")
if not text:
return None
replace_index_char = []
Expand Down Expand Up @@ -154,7 +157,7 @@ def _converter_background(self):

def _converter_character(self):
# 立绘
character_str = self.row[ElementColNumMapping.get('character')].strip()
character_str = str(self.row[ElementColNumMapping.get('character')]).strip()
if not character_str:
return []
characters = []
Expand Down Expand Up @@ -196,7 +199,7 @@ def _converter_change_page(self):
return Command("nvl clear")

def _converter_voice(self):
voice_str = self.row[ElementColNumMapping.get('voice')].strip()
voice_str = str(self.row[ElementColNumMapping.get('voice')]).strip()
if not voice_str:
return None
if voice_str.split(" ")[-1] == "sustain":
Expand All @@ -210,7 +213,7 @@ def _converter_menu(self):
menu = self.row[ElementColNumMapping.get('menu')]
if not menu:
return None
text = self.row[ElementColNumMapping.get('text')].replace("\n", "\\n")
text = str(self.row[ElementColNumMapping.get('text')]).replace("\n", "\\n")
if not text:
return None
replace_index_char = []
Expand All @@ -224,3 +227,11 @@ def _converter_menu(self):
new_text_list[idx] = ReplaceCharacterMapping.get(char)
text = ''.join(new_text_list)
return Menu(label=text, target=menu)

def _converter_side_character(self):
# 对话框头像
character_str = str(self.row[ElementColNumMapping.get('side_character')]).strip()
if not character_str:
return None
self.converter.side_characters[self.converter.current_role.pronoun] = character_str
return None
9 changes: 8 additions & 1 deletion handler/writer.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
MENU_TEMPLATE = " \"{label}\":\n jump {target}\n"
SIDE_CHARACTER_TEMPLATE = "image side {role_name} = \"{path}\"\n"


class RpyFileWriter(object):

@classmethod
def write_file(cls, output_dir, res, role_name_mapping):
def write_file(cls, output_dir, res, role_name_mapping, role_side_character_mapping):
output_path = output_dir + "/" + res.label + '.rpy'
with open(output_path, 'w', encoding='utf-8') as f:
for k, v in role_name_mapping.items():
f.write(v.render() + "\n")
f.write("define narrator_nvl = Character(None, kind=nvl)\n")
f.write("define narrator_adv = Character(None, kind=adv)\n")
f.write("define config.voice_filename_format = \"audio/{filename}\"\n")
for k, v in role_side_character_mapping.items():
f.write(SIDE_CHARACTER_TEMPLATE.format(role_name=k, path=v))
f.write("\nlabel {}:\n".format(res.label))
last_voice = None
current_menus = []
Expand Down Expand Up @@ -46,3 +49,7 @@ def write_file(cls, output_dir, res, role_name_mapping):
if rpy_element.change_page:
f.write(rpy_element.change_page.render() + '\n')
last_voice = rpy_element.voice
if current_menus:
# fix menu在最后一行
f.write("menu:\n" + "\n".join(
[MENU_TEMPLATE.format(label=m.label, target=m.target) for m in current_menus]))
4 changes: 2 additions & 2 deletions model/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from corelib.exception import RenderException
from model import RpyElement

ROLE_TEMPLATE = "define {name} = Character('{role}', color=\"{color}\")" # 角色模板
ROLE_TEMPLATE = "define {name} = Character('{role}', color=\"{color}\", image=\"{side_character}\")" # 角色模板


# 对话
Expand Down Expand Up @@ -55,7 +55,7 @@ def __init__(self, pronoun, name, color=None):
def render(self):
if not self.name:
return ""
return ROLE_TEMPLATE.format(name=self.pronoun, role=self.name, color=self.color)
return ROLE_TEMPLATE.format(name=self.pronoun, role=self.name, color=self.color, side_character=self.pronoun)


# 图像
Expand Down
17 changes: 12 additions & 5 deletions test/Sheet2.rpy
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
define role1 = Character('春日', color="#c8c8ff")
define role2 = Character('阿虚', color="#c8c8ff")
define role1 = Character('aaa', color="#c8c8ff", image="role1")
define role2 = Character('aaabv', color="#c8c8ff", image="role2")
define role3 = Character('阿虚', color="#c8c8ff", image="role3")
define role4 = Character('春日', color="#c8c8ff", image="role4")
define role5 = Character('春日bbbb', color="#c8c8ff", image="role5")
define narrator_nvl = Character(None, kind=nvl)
define narrator_adv = Character(None, kind=adv)
define config.voice_filename_format = "audio/{filename}"
image side role1 = "images/haruhi 1.png"

label Sheet2:
play music "audio/19.mp3"
hide haruhi 1
hide kyon 5
show haruhi 1 at left
show kyon 1 at right
scene bg34
with dissolve
voice "images/test1.jpg"
narrator_nvl "\"sheet2 喂,你们知道肾上腺素这种东西吗?\""
narrator_nvl "\"没错,就是那种当人遭遇某种突如其来的刺激时才会分泌,可以使人呼吸加快、心跳加速、瞳孔放大,激发身体潜能好应对可能发生的事情的那种激素。\""
narrator_nvl "\"如果现在我的身上有那么一个用来测量这种激素浓度的仪器,那么上面的数字恐怕一定是在不断地飙升的吧——\""
Expand Down Expand Up @@ -41,7 +47,8 @@ hide kyon 5
show haruhi 3 at left
show kyon 5 at center
stop music
role1 "\"啊! \""
voice "images/test1.jpg"
role2 "\"啊! \""
hide haruhi 3
hide kyon 5
show haruhi 3 at left
Expand All @@ -56,14 +63,14 @@ hide kyon 4
show haruhi 1 at left
show kyon 4 at center
with dissolve
role2 "\"你没事吧?!春日。 \""
role3 "\"你没事吧?!春日。 \""
hide haruhi 1
hide kyon 4
show haruhi 2 at center
narrator_adv "\"借着手机屏幕的亮光,我勉强看清了她的表情——涨红了脸,流露出一股由惊慌、不满和似乎是害羞的情绪所组成的复杂表情。看样子她也快到极限了。 \""
hide haruhi 2
show haruhi 6 at center
role1 "\"没,没事。\""
role4 "\"没,没事。\""
hide haruhi 6
hide haruhi 1
narrator_adv "\"只是不小心被石头绊了一下,\想不\%到竟\"\"差点\'\'{{[[去。\""
14 changes: 9 additions & 5 deletions test/Sheet3.rpy
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
define role1 = Character('春日', color="#c8c8ff")
define role2 = Character('阿虚', color="#c8c8ff")
define role1 = Character('aaa', color="#c8c8ff", image="role1")
define role2 = Character('aaabv', color="#c8c8ff", image="role2")
define role3 = Character('阿虚', color="#c8c8ff", image="role3")
define role4 = Character('春日', color="#c8c8ff", image="role4")
define role5 = Character('春日bbbb', color="#c8c8ff", image="role5")
define narrator_nvl = Character(None, kind=nvl)
define narrator_adv = Character(None, kind=adv)
define config.voice_filename_format = "audio/{filename}"
image side role1 = "images/haruhi 1.png"

label Sheet3:
play music "audio/19.mp3"
Expand Down Expand Up @@ -41,7 +45,7 @@ hide kyon 5
show haruhi 3 at left
show kyon 5 at center
stop music
role1 "\"啊! \""
role5 "\"啊! \""
hide haruhi 3
hide kyon 5
show haruhi 3 at left
Expand All @@ -56,14 +60,14 @@ hide kyon 4
show haruhi 1 at left
show kyon 4 at center
with dissolve
role2 "\"你没事吧?!春日。 \""
role3 "\"你没事吧?!春日。 \""
hide haruhi 1
hide kyon 4
show haruhi 2 at center
narrator_adv "\"借着手机屏幕的亮光,我勉强看清了她的表情——涨红了脸,流露出一股由惊慌、不满和似乎是害羞的情绪所组成的复杂表情。看样子她也快到极限了。 \""
hide haruhi 2
show haruhi 6 at center
role1 "\"没,没事。\""
role4 "\"没,没事。\""
hide haruhi 6
hide haruhi 1
narrator_adv "\"只是不小心被石头绊了一下,\想不\%到竟\"\"差点\'\'{{[[去。\""
46 changes: 11 additions & 35 deletions test/start.rpy
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
define role1 = Character('春日', color="#c8c8ff")
define role2 = Character('阿虚', color="#c8c8ff")
define role1 = Character('aaa', color="#c8c8ff", image="role1")
define role2 = Character('aaabv', color="#c8c8ff", image="role2")
define role3 = Character('阿虚', color="#c8c8ff", image="role3")
define role4 = Character('春日', color="#c8c8ff", image="role4")
define role5 = Character('春日bbbb', color="#c8c8ff", image="role5")
define narrator_nvl = Character(None, kind=nvl)
define narrator_adv = Character(None, kind=adv)
define config.voice_filename_format = "audio/{filename}"
image side role1 = "images/haruhi 1.png"

label start:
play music "audio/19.mp3"
Expand All @@ -11,7 +15,6 @@ show kyon 1 at right
scene bg34
with dissolve
narrator_nvl "\"喂,你们知道肾上腺素这种东西吗?\""
voice "test"
narrator_nvl "\"没错,就是那种当人遭遇某种突如其来的刺激时才会分泌,可以使人呼吸加快、心跳加速、瞳孔放大,激发身体潜能好应对可能发生的事情的那种激素。\""
narrator_nvl "\"如果现在我的身上有那么一个用来测量这种激素浓度的仪器,那么上面的数字恐怕一定是在不断地飙升的吧——\""
nvl clear
Expand All @@ -29,42 +32,15 @@ with dissolve
narrator_adv "\"包裹在右手上的外套一直摩擦着粗糙的岩壁,回音在隧道里相互叠加不断传递 ,最终汇聚成了一股丝毫都不悦耳、反而让人愈加烦躁的声音。 \""
narrator_adv "\"如果这是一个恐怖游戏的关卡,那么我一定要提名它拿今年科隆游戏展的最佳恐怖游戏配音奖——如果有这个奖项的话。\""
play music "audio/20.mp3"
voice "test"
narrator_adv "\"就在我试图用一些轻松一点的想法冲淡自己的紧张,尽量不让自己在逃出去之前就被自己的肾上腺素毒死之时,我那紧紧握着春日右手的左手,又一次感受到了来自春日那微微地握力。 \""
voice sustain
narrator_adv "\"不仅是我,就连平日里元气十足、坐镇北高文学部部室四处征伐的团长大人,此刻也通过手心里微微渗出的汗滴来委婉地告诉我她的不安。\""
narrator_adv "\"而这时不时传来的、看似微弱但却异常敏感的身体信号,则更是从频率上在暗示着她和我一样不断加重的负面情绪。\""
narrator_adv "\"从刚刚开始,我们就一直拉着手——像是在孤岛那会儿一样,只不过这次面对的,似乎是更加未知的前景。\""
role1 "\"从刚刚开始,我们就一直拉着手——像是在孤岛那会儿一样,只不过这次面对的,似乎是更加未知的前景。\""
narrator_adv "\"我对春日报以相同的回应,也握了握她的手。\""
narrator_adv "\"老实说,我并不怀疑春日这难得的、稳扎稳打的脱险方法,更坚信走出去只是迟早的事情——但不知为什么,不安和焦虑,却顽固地笼罩在我心里这个看似光明的信念上,挥之不去。\""
menu:
"跳转到sheet2":
jump sheet2
"跳转到Sheet2":
jump Sheet2

"跳转到sheet3":
jump sheet3
hide haruhi 3
hide kyon 5
show haruhi 3 at left
show kyon 4 at center
narrator_adv "\"正在我不断地想要用一些较为轻松的想法,在一众消极因素里解救出自己的积极心态时,春日突然发出的叫声,把我的思维拉回了阴暗空旷的隧道里。\""
narrator_adv "\"她的身子迅速地向前扑去,左手也离开了岩壁,挥舞到了半空中——很明显是失去了平衡的缘故,并且由于和我紧握双手的关系,几乎把我也拉到了摔倒的境地。 \""
with Fade(0.1,0.0,0.5,color="#FFFFFF")
narrator_adv "\"我急忙把身体往后倾斜,并借助着右手触碰到的一块突起的岩石,在体重、地心引力和惯性的共同作用下,才勉强把她拉了起来,避免了她磕在隧道的某个地方。\""
play music "audio/22.mp3"
hide haruhi 3
hide kyon 4
show haruhi 1 at left
show kyon 4 at center
with dissolve
role2 "\"你没事吧?!春日。 \""
hide haruhi 1
hide kyon 4
show haruhi 2 at center
narrator_adv "\"借着手机屏幕的亮光,我勉强看清了她的表情——涨红了脸,流露出一股由惊慌、不满和似乎是害羞的情绪所组成的复杂表情。看样子她也快到极限了。 \""
hide haruhi 2
show haruhi 6 at center
role1 "\"没,没事。\""
hide haruhi 6
hide haruhi 1
narrator_adv "\"只是不小心被石头绊了一下,想不到竟然差点摔了下去。\""
"跳转到Sheet3":
jump Sheet3
Binary file modified test/示例表格.xlsx
Binary file not shown.

0 comments on commit 7e7cb07

Please sign in to comment.