Repository: nagisc007/storybuilder

Issue:
Need to fix: action output with japanese spaces
日本語の時にはスペースを「全角」で適用する
===

**Description**
actionでのoutput時に半角だと折角そろえたものがずれているので、そこを読み取って調整する。


Comments:

Patch:
diff --git a/builder/tools.py b/builder/tools.py
index c36e60b..1c8ebbe 100644
--- a/builder/tools.py
+++ b/builder/tools.py
@@ -99,21 +99,33 @@ def _story_converted_as_action_in_group(group: ActionGroup, level: int, is_debug
         if isinstance(a, ActionGroup):
             tmp.extend(_story_converted_as_action_in_group(a, level + 1, is_debug))
         else:
-            tmp.append(_action_str_by_type(a, level, is_debug))
+            tmp.append(_action_str_by_type(a, group.lang, level, is_debug))
     return tmp
 
 
-def _action_str_by_type(act: Action, level: int, is_debug: bool) -> str:
+def _action_str_by_type(act: Action, lang: LangType, level: int, is_debug: bool) -> str:
     if act.act_type == ActType.ACT:
-        return "{:8}:{:8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or not act.note else act.note)
+        if lang == LangType.JPN:
+            return "{:　8}{:　8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or not act.note else act.note)
+        else:
+            return "{:8}:{:8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or not act.note else act.note)
     elif act.act_type == ActType.EXPLAIN:
-        return "{:8}:{:8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or not act.note else act.note)
+        if lang == LangType.JPN:
+            return "{:　8}:{:　8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or not act.note else act.note)
+        else:
+            return "{:8}:{:8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or not act.note else act.note)
     elif act.act_type == ActType.TAG:
         return _action_str_by_tag(act, level)
     elif act.act_type == ActType.TELL:
-        return "{:8}:{:8}:「{}」:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or act.note else act.note)
+        if lang == LangType.JPN:
+            return "{:　8}:{:　8}:「{}」:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or act.note else act.note)
+        else:
+            return "{:8}:{:8}:「{}」:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or act.note else act.note)
     elif act.act_type == ActType.TEST and is_debug:
-        return "> {:8}:{:8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or act.note else act.note)
+        if lang == LangType.JPN:
+            return "> {:　8}:{:　8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or act.note else act.note)
+        else:
+            return "> {:8}:{:8}:{}:{}".format(act.subject.name, behavior_str_of(act.behavior), act.action, "" if act.note == "nothing" or act.note else act.note)
     else:
         return ""
 
@@ -142,9 +154,9 @@ def _story_converted_as_description_in_group(group: ActionGroup, level: int, is_
 
 def _description_str_by_type(act: Action, lang: LangType, level: int, is_debug: bool) -> str:
     if act.act_type in (ActType.ACT, ActType.EXPLAIN):
-        return "{}{}{}".format("　" if lang == LangType.JPN else " ", act.description, "。" if lang == LangType.JPN else ".")
+        return "{}{}{}".format(_paragraphtop_by_lang(lang), act.description, _period_by_lang(lang))
     elif act.act_type == ActType.TELL:
-        return "{}{}{}".format("「" if lang == LangType.JPN else '"', act.description, "」" if lang == LangType.JPN else '"')
+        return "{}{}{}".format(_double_quatation_by_lang(lang), act.description, _double_quatation_by_lang(lang, False))
     elif act.act_type == ActType.TAG:
         return _description_str_by_tag(act, level, is_debug)
     elif act.act_type == ActType.TEST and is_debug:
@@ -161,3 +173,20 @@ def _description_str_by_tag(act: Action, level: int, is_debug: bool) -> str:
     else:
         return ""
 
+def _period_by_lang(lang: LangType) -> str:
+    return "。" if lang == LangType.JPN else ". "
+
+
+def _comma_by_lang(lang: LangType) -> str:
+    return "、" if lang == LangType.JPN else ", "
+
+
+def _paragraphtop_by_lang(lang: LangType) -> str:
+    return "　" if lang == LangType.JPN else " "
+
+
+def _double_quatation_by_lang(lang: LangType, is_top: bool=True) -> str:
+    if is_top:
+        return "「" if lang == LangType.JPN else ' "'
+    else:
+        return "」" if lang == LangType.JPN else '" '


Test patch:
diff --git a/tests/test_tools.py b/tests/test_tools.py
index 6722214..837b1f2 100644
--- a/tests/test_tools.py
+++ b/tests/test_tools.py
@@ -84,15 +84,15 @@ class BasicMethodTest(unittest.TestCase):
     def test__story_converted_as_description(self):
         self.assertEqual(tools._story_converted_as_description(self.story, False),
                 ["# Taro and Hanako",
-                    " a cute girl come in.",
-                    '"Nice to meet you"',
-                    '"I\'m not fine"'])
+                    " a cute girl come in. ",
+                    ' "Nice to meet you" ',
+                    ' "I\'m not fine" '])
 
 
     def test__story_converted_as_description_in_group(self):
         self.assertEqual(tools._story_converted_as_description_in_group(self.story, 1, False),
                 ["# Taro and Hanako",
-                    " a cute girl come in.",
-                    '"Nice to meet you"',
-                    '"I\'m not fine"'])
+                    " a cute girl come in. ",
+                    ' "Nice to meet you" ',
+                    ' "I\'m not fine" '])