def _correct(val: SCode):
     if val.cmd in SCmd.get_dialogue_actions():
         return 2
     elif val.cmd in SCmd.get_normal_actions():
         return 1
     else:
         return 0
Example #2
0
 def _collect_plot_title(self, src: ContainerLike) -> list:
     tmp = []
     for child in src.children:
         if isinstance(child, (Chapter, Episode, Scene, Material)):
             tmp.extend(self._collect_plot_title(child))
         elif isinstance(child, SCode):
             if child.cmd in SCmd.get_plot_structs():
                 tmp.append(child.option)
     return list(set(tmp))
Example #3
0
 def _updated_plot_info_internal(self, src: (Chapter, Episode, Scene, Material, SCode),
         title: str) -> list:
     if isinstance(src, (Chapter, Episode, Scene, Material)):
         tmp = []
         for child in src.children:
             ret = self._updated_plot_info_internal(child, title)
             if ret:
                 tmp.extend(ret)
         return tmp
     elif isinstance(src, SCode):
         if src.cmd in SCmd.get_plot_structs() and src.option == title:
             return [src]
     else:
         LOG.error('Invalid value in updated_plot_info_internal: {src}')
         return []
Example #4
0
    def _has_invalid_symbol(self, src: CodeList) -> Tuple[list, bool]:
        tmp = []
        invalids = []
        checker = Checker()

        for child in assertion.is_instance(src, CodeList).data:
            assertion.is_instance(child, SCode)
            if child.cmd in SCmd.get_all_actions():
                for line in child.script:
                    if checker.has_tag_symbol(line):
                        invalids.append(line)
                tmp.append(child)
            else:
                # NOTE: それ以外をどうするか。ここはスルーか
                tmp.append(child)
        if invalids:
            return (invalids, False)
        else:
            return (CodeList(*tmp), True)
 def manupaper_rows_of(self,
                       src: ContainerLike,
                       columns: int,
                       is_contain_plot: bool = False) -> int:
     if isinstance(src, (Story, Chapter, Episode)):
         return sum(
             self.manupaper_rows_of(child, columns)
             for child in src.children)
     elif isinstance(src, Scene):
         checker = Checker()
         ret = []
         tmp = 0
         for child in src.children:
             if assertion.is_instance(child,
                                      SCode).cmd in SCmd.get_all_actions():
                 if checker.is_empty_script(child, is_contain_plot):
                     if tmp:
                         ret.append(int_ceil(tmp, columns))
                         tmp = 0
                     continue
                 if is_contain_plot:
                     tmp += self.total_characters_of(child)
                 else:
                     tmp += self.description_characters_of(child)
             elif child.cmd in SCmd.get_end_of_containers():
                 continue
             elif child.cmd in SCmd.get_informations():
                 continue
             elif child.cmd in SCmd.get_scene_controls():
                 continue
             elif child.cmd in SCmd.get_plot_infos():
                 if is_contain_plot:
                     tmp += self.total_characters_of(child)
             elif child.cmd in SCmd.get_tags():
                 if child.cmd is SCmd.TAG_BR:
                     tmp = 1
                 elif child.cmd is SCmd.TAG_SYMBOL:
                     tmp = 2
                 else:
                     tmp = 0
             if not checker.has_then(child):
                 ret.append(int_ceil(tmp, columns))
                 tmp = 0
         if tmp:
             ret.append(int_ceil(tmp, columns))
         return sum(ret)
     elif isinstance(src, SCode):
         # actions
         if assertion.is_instance(src, SCode).cmd in SCmd.get_all_actions():
             chars = self.total_characters_of(
                 src
             ) if is_contain_plot else self.description_characters_of(src)
             return int_ceil(chars + 2, columns)
         # then
         elif src.cmd is SCmd.THEN:
             return 0
         # container break
         elif src.cmd in SCmd.get_end_of_containers():
             return 0
         # tag
         elif src.cmd in SCmd.get_tags():
             if src.cmd is SCmd.TAG_BR:
                 return 1
             elif src.cmd is SCmd.TAG_SYMBOL:
                 return 2
             else:
                 return 0
         # info
         elif src.cmd in SCmd.get_informations():
             return 0
         # scene control
         elif src.cmd in SCmd.get_scene_controls():
             return 0
         # plot control
         elif src.cmd in SCmd.get_plot_infos():
             return int_ceil(self.total_characters_of(src), columns)
         else:
             msg = f'Invalid SCmd: {code.cmd}'
             LOG.critical(msg)
         return 0
     elif isinstance(src, Material):
         return 0
     elif isinstance(src, (list, tuple)):
         return sum(self.manupaper_rows_of(child, columns) for child in src)
     else:
         msg = 'Error'
         LOG.critical(msg)
         return 0
 def _validate_scode(val: SCode):
     return val.cmd in SCmd.get_all_actions()
 def _validate_scode(val: SCode):
     return not val.cmd in SCmd.get_informations()
    def _conv_to_plot(self, src: CodeList, is_data: bool) -> RawData:
        LOG.info('COMP: conv_to_plot start')

        conv = Converter()
        tmp = []
        is_added = False
        head_info = ''
        in_material = False
        ch_num = ep_num = sc_num = 1

        for code in assertion.is_instance(src, CodeList).data:
            assertion.is_instance(code, SCode)
            # actions
            if code.cmd in SCmd.get_normal_actions():
                continue
            elif code.cmd in SCmd.get_dialogue_actions():
                continue
            # then
            elif code.cmd is SCmd.THEN:
                continue
            # container break
            elif code.cmd in SCmd.get_end_of_containers():
                if code.cmd is SCmd.END_CHAPTER:
                    tmp.append('\n')
                elif code.cmd is SCmd.END_MATERIAL:
                    tmp.append('\n')
                    in_material = False
                else:
                    continue
            elif code.cmd in SCmd.get_head_of_containers():
                if code.cmd is SCmd.HEAD_MATERIAL:
                    in_material = True
                continue
            # tags
            elif code.cmd in SCmd.get_tags():
                ret, (ch_num, ep_num, sc_num) = self._conv_from_tag(
                    code, head_info, (ch_num, ep_num, sc_num), True,
                    not is_data, is_data, in_material)
                if ret:
                    if code.cmd is SCmd.TAG_TITLE and not ret.startswith('#'):
                        tmp.append('\n')
                    tmp.append(FormatTag.SYMBOL_HEAD if code.cmd is SCmd.
                               TAG_SYMBOL else FormatTag.TAG_HEAD)
                    tmp.append(ret)
            # info
            elif code.cmd in SCmd.get_informations():
                if code.cmd is SCmd.INFO_DATA:
                    if isinstance(code.script[0], HeaderInfo):
                        head_info = self._get_headinfo(
                            code) + ' | T:' + self._get_headinfo_total(code)
                    elif isinstance(code.script[0], SceneInfo):
                        # NOTE: 場所情報はカット
                        continue
                    elif isinstance(code.script[0], PlotInfo):
                        tmp.append(self._get_plotinfo(code))
                    else:
                        tmp.append("".join(code.script))
                elif code.cmd is SCmd.INFO_CONTENT:
                    tmp.append(self._get_storyinfo(code))
                elif code.cmd is SCmd.INFO_STORY and is_data:
                    title = code.script[0]['title']
                    tmp.append(self._get_storydata(code))
                continue
            # scene control
            elif code.cmd in SCmd.get_scene_controls():
                continue
            # plot control
            elif code.cmd in SCmd.get_plot_infos():
                ret = self._conv_from_plotinfo(code)
                if ret:
                    tmp.append(ret)
                    is_added = True
            # others
            else:
                LOG.error(f'Unknown SCmd!: {code.cmd}')
            if is_added:
                is_added = False
                tmp.append('\n')
        return RawData(*tmp)
    def _conv_to_novel(self, src: CodeList, is_comment: bool) -> RawData:
        LOG.info('COMP: conv_to_novel start')

        tmp = []
        checker = Checker()
        conv = Converter()
        is_added = False
        is_then = False
        in_dialogue = False
        desc_head = " "
        head_info = ""
        dial_stock = None
        ch_num = ep_num = sc_num = 1

        for code in assertion.is_instance(src, CodeList).data:
            assertion.is_instance(code, SCode)
            # actions
            if code.cmd in SCmd.get_normal_actions():
                if not checker.is_empty_script(code):
                    if not is_then or in_dialogue:
                        tmp.append(FormatTag.DESCRIPTION_HEAD)
                    in_dialogue = False
                    tmp.append(
                        f'{desc_head}{conv.to_description(conv.script_relieved_symbols(code.script))}'
                    )
                    is_added = True
            elif code.cmd in SCmd.get_dialogue_actions():
                in_dialogue = True
                is_voice = code.cmd is SCmd.VOICE
                script = conv.script_relieved_symbols(code.script)
                if dial_stock:
                    script = dial_stock + script
                    dial_stock = None
                if not is_then:
                    tmp.append(FormatTag.DIALOGUE_HEAD)
                    if is_voice:
                        tmp.append(f'{conv.to_dialogue(script, ("『", "』"))}')
                    else:
                        tmp.append(f'{conv.to_dialogue(script)}')
                else:
                    dial_stock = conv.script_relieved_symbols(code.script)
                is_added = True
            # then
            elif code.cmd is SCmd.THEN:
                is_then = True
            # container break
            elif code.cmd in SCmd.get_end_of_containers():
                tmp.append(self._conv_from_end_container(code))
            elif code.cmd in SCmd.get_head_of_containers():
                # NOTE: materialで何かするならここでinto操作
                continue
            # tag
            elif code.cmd in SCmd.get_tags():
                ret, (ch_num, ep_num, sc_num) = self._conv_from_tag(
                    code, head_info, (ch_num, ep_num, sc_num), is_comment,
                    False, False, False)
                if ret:
                    tmp.append(FormatTag.SYMBOL_HEAD if code.cmd is SCmd.
                               TAG_SYMBOL else FormatTag.TAG_HEAD)
                    tmp.append(ret)
            # info
            elif code.cmd in SCmd.get_informations():
                if code.cmd is SCmd.INFO_DATA:
                    if isinstance(code.script[0], HeaderInfo):
                        head_info = self._get_headinfo(code)
                    elif isinstance(code.script[0], SceneInfo):
                        tmp.append(self._get_sceneinfo(code))
                    elif isinstance(code.script[0], PlotInfo):
                        continue
                    else:
                        tmp.append("".join(code.script))
                elif code.cmd is SCmd.INFO_CONTENT:
                    tmp.append(self._get_storyinfo(code))
                continue
            # scene control
            elif code.cmd in SCmd.get_scene_controls():
                continue
            # plot control
            elif code.cmd in SCmd.get_plot_infos():
                continue
            else:
                msg = f'Unknown SCmd!: {code.cmd}'
                LOG.error(msg)
            if is_added:
                is_added = False
                if not is_then:
                    tmp.append('\n')
                    desc_head = ' '
                else:
                    is_then = False
                    desc_head = ''
        return RawData(*tmp)