def char_counts_from(type: BuildType, data: list, columns: int, rows: int) -> list: assert isinstance(type, BuildType) assert isinstance(data, list) assert isinstance(columns, int) assert isinstance(rows, int) logger.debug(msg.PROC_START.format(proc=PROC)) counts = CharCounter.counts_data_from(type, data, columns, rows) if not counts: logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"'{type}' char counts data: {PROC}")) return None formatted = Formatter.format_data(type, counts) if not formatted: logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"format '{type}' counts data: {PROC}")) return None logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return formatted
def build_contents(story_data: StoryData, tags: dict) -> OutputsData: assert isinstance(story_data, StoryData) assert isinstance(tags, dict) logger.debug(msg.PROC_START.format(proc=PROC)) tmp = [] for record in story_data.get_data(): assert isinstance(record, BaseCode) if isinstance(record, SceneInfo): ret = Converter.to_content_record(record) if ret: tmp.append(ret) else: continue formatted = Formatter.format_data(tmp) if not formatted: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"format data: {PROC}")) return None translated = translate_tags_text_list(formatted, tags) logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return OutputsData(translated)
def build_base_info(cls, args: Namespace, outputs_data: dict) -> bool: assert isinstance(args, Namespace) assert isinstance(outputs_data, dict) tmp = OutputsData(['BASE INFO\n===\n\n']) columns, rows = _get_columns_and_rows() for type, outputs in outputs_data.items(): if Checker.has(args, type) and outputs: assert isinstance(outputs, OutputsData) ret = char_counts_from(type, outputs.get_data(), columns, rows) if ret: tmp += OutputsData(ret) if not tmp or tmp.is_empty(): logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"base info data: {PROC}")) return False if not Outputter.output_data(_get_build_path('base'), tmp): logger.error( msg.ERR_FAIL_CANNOT_WRITE_DATA.format( data=f"base info data: {PROC}")) return False logger.debug( msg.PROC_MESSAGE.format(proc=f"ouputted base infos: {PROC}")) return True
def run(self) -> int: logger.debug(msg.PROC_START.format(proc=PROC)) args = get_commandline_arguments() if not args: logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"command line args: {PROC}")) return os.EX_NOINPUT if BuildChecker.has_build_cmd_of(args, BuildType.BUILD): if not build_project(args): logger.debug( msg.ERR_FAIL_SUBPROCESS.format( proc=f"build project: {PROC}")) return os.EX_SOFTWARE elif BuildChecker.has_build_cmd_of(args, BuildType.INIT): if not init_project(): logger.debug( msg.ERR_FAIL_SUBPROCESS.format( proc=f"init project: {PROC}")) return os.EX_SOFTWARE else: logger.warning( msg.ERR_FAIL_INVALID_DATA_WITH_DATA.format( data=f"build command: {PROC}"), args.cmd) return os.EX_NOINPUT logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return os.EX_OK
def nametags_from(assets: AssetsDB) -> dict: assert isinstance(assets, AssetsDB) logger.debug(msg.PROC_START.format(proc=PROC)) config = yaml.safe_load(read_file(FILE_CONFIG)) if not config: logger.error(msg.ERR_FAIL_MISSING_DATA.format(data=f"config file: {PROC}")) return {} mob_num = config[ELM_CONFIG][ELM_MOBS] tmp = {} for key, val in assets.data.items(): assert isinstance(key, str) assert isinstance(val, SObject) if isinstance(val, Person): if not Converter.person_names_of(tmp, val): logger.warning( msg.ERR_FAIL_INVALID_DATA.format( data=f"person '{val.tag}' name: {PROC}")) elif isinstance(val, Stage): if not Converter.stage_names_of(tmp, val): logger.warning( msg.ERR_FAIL_INVALID_DATA.format( data=f"stage '{val.tag}' name: {PROC}")) elif isinstance(val, Item): if not Converter.item_name_of(tmp, val): logger.warning( msg.ERR_FAIL_INVALID_DATA.format( data=f"item '{val.tag}' name: {PROC}")) elif isinstance(val, NameTag): if NameTagType.MOB is val.type: if not Converter.mob_name_of(tmp, val, mob_num): logger.warning( msg.ERR_FAIL_INVALID_DATA.format( data=f"mob names: {PROC}")) elif NameTagType.TIME is val.type: if not Converter.time_name_of(tmp, val): logger.warning( msg.ERR_FAIL_INVALID_DATA.format( data=f"time names: {PROC}")) elif NameTagType.WORD is val.type: if not Converter.word_name_of(tmp, val): logger.warning( msg.ERR_FAIL_INVALID_DATA.format( data=f"word names: {PROC}")) else: continue elif isinstance(val, Rubi): continue else: continue logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return tmp
def call_scene(level: int, tag: str, scenes: ScenesDB) -> list: assert isinstance(level, int) assert isinstance(tag, str) assert isinstance(scenes, ScenesDB) if not scenes.has(tag): logger.warning( msg.ERR_FAIL_MISSING_DATA_WITH_DATA.format( data=f"call tag: {PROC}"), tag) return [] tmp = [] scode = assertion.is_instance(scenes.get(tag), SceneCode) tmp.append(Converter.conv_scene_info_from(level, scode)) for obj in scode.data: if isinstance(obj, Action): tmp.append(obj) elif isinstance(obj, Instruction): if InstType.CALL is obj.type: call_tag = obj.args[0] # TODO: 親タグも取得して相互呼び出しを禁止する if tag == call_tag: logger.error( msg.ERR_FAIL_MUSTBE_WITH_DATA.format( data=f"not self calling: {PROC}"), tag) raise ValueError('invalid self calling', tag) ret = call_scene(level + 1, obj.args[0], scenes) if ret: tmp.extend(ret) else: tmp.append(obj) else: logger.warning( msg.ERR_FAIL_INVALID_DATA_WITH_DATA.format( data=f"scene code object: {PROC}"), obj) continue tmp.append(_get_scene_end(scode)) return tmp
def build_plot(story_data: StoryData, tags: dict) -> OutputsData: assert isinstance(story_data, StoryData) assert isinstance(tags, dict) logger.debug(msg.PROC_START.format(proc=PROC)) plots = Converter.plots_data_from(story_data) if not plots: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"plots data: {PROC}")) return None reordered = Converter.reorder_plots(plots) if not reordered: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"reordered plots: {PROC}")) return None formatted = Formatter.format_data(reordered) if not formatted: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"formatted plots: {PROC}")) return None translated = translate_tags_text_list(formatted, dict_sorted(tags, True)) logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return OutputsData(translated)
def get_commandline_arguments() -> Namespace: logger.debug(msg.PROC_START.format(proc=PROC)) parser = assertion.is_instance(_init_commandline_parser(), ArgumentParser) if not parser: logger.error(msg.ERR_FAIL_CANNOT_CREATE_DATA.format(data=f"parser: {PROC}")) return None if not _set_parser_options(parser): logger.warning(msg.ERR_FAIL_CANNOT_CREATE_DATA.format(data=f"arg parser options: {PROC}")) return None args = parser.parse_args() if not args: logger.error(msg.ERR_FAIL_MISSING_DATA.format(data=f"args: {PROC}")) return None logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return args
def build_project(args: Namespace) -> bool: assert isinstance(args, Namespace) logger.debug(msg.PROC_START.format(proc=PROC)) assets = get_assets_db() if not assets or assets.is_empty(): logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"assets db: {PROC}")) return False builds = { BuildType.OUTLINE: None, BuildType.PLOT: None, BuildType.SCRIPT: None, BuildType.NOVEL: None, BuildType.STRUCT: None, } if not _check_and_create_build_dir(): logger.error( msg.ERR_FAIL_CANNOT_CREATE_DATA.format( data=f"build directory: {PROC}")) return False srcs = get_srcs_db() if not srcs or srcs.is_empty(): logger.error(msg.ERR_FAIL_MISSING_DATA.format(data=f"srcs db: {PROC}")) return False scenes = scenes_db_from(srcs) if not scenes or scenes.is_empty(): logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"scenes db: {PROC}")) return False codes = compile_codes(scenes, assets) if not codes: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"story data: {PROC}")) return False logger.debug(msg.MSG_UNIMPLEMENT_PROC.format(proc=PROC)) nametags = nametags_from(assets) callings = callingtags_from(assets) is_comment = args.comment contents = build_contents(codes, nametags) if not contents: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"contents data: {PROC}")) return False if Checker.has(args, BuildType.OUTLINE): outputs = build_outline(codes, nametags) if not outputs or outputs.is_empty(): logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"outline output data: {PROC}")) return False builds[BuildType.OUTLINE] = outputs if not Outputter.output_data(_get_build_path('outline'), contents.cloned() + outputs): logger.error( msg.ERR_FAIL_CANNOT_WRITE_DATA.format( data=f"output outline data: {PROC}")) return False if Checker.has(args, BuildType.PLOT): outputs = build_plot(codes, nametags) if not outputs or outputs.is_empty(): logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"plot output data: {PROC}")) return False builds[BuildType.PLOT] = outputs if not Outputter.output_data(_get_build_path('plot'), contents.cloned() + outputs): logger.error( msg.ERR_FAIL_CANNOT_WRITE_DATA.format( data=f"output plot data: {PROC}")) return False if Checker.has(args, BuildType.STRUCT): outputs = build_struct(codes, nametags, callings, is_comment) if not outputs or outputs.is_empty(): logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"struct output data: {PROC}")) return False builds[BuildType.STRUCT] = outputs if not Outputter.output_data(_get_build_path('struct'), contents.cloned() + outputs): logger.error( msg.ERR_FAIL_CANNOT_WRITE_DATA.format( data=f"output struct data: {PROC}")) return False if Checker.has(args, BuildType.SCRIPT): outputs = build_script(codes, nametags, callings, is_comment) if not outputs or outputs.is_empty(): logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"script output data: {PROC}")) return False builds[BuildType.SCRIPT] = outputs if not Outputter.output_data(_get_build_path('script'), contents.cloned() + outputs): logger.error( msg.ERR_FAIL_CANNOT_WRITE_DATA.format( data=f"output script data: {PROC}")) return False if Checker.has(args, BuildType.NOVEL): outputs = build_novel(codes, nametags, callings, is_comment) if not outputs or outputs.is_empty(): logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"novel output data: {PROC}")) return False builds[BuildType.NOVEL] = outputs if not Outputter.output_data(_get_build_path('novel'), contents.cloned() + outputs): logger.error( msg.ERR_FAIL_CANNOT_WRITE_DATA.format( data=f"output novel data: {PROC}")) return False if args.rubi: outputs_rubi = outputs.cloned() rubis = rubitags_from(assets) updated_rubi = apply_rubi_in_novel_data(outputs_rubi, rubis) if not Outputter.output_data(_get_build_path('novel_rubi'), contents.cloned() + updated_rubi): logger.error( msg.ERR_FAIL_CANNOT_WRITE_DATA.format( data=f"output novel with rubi data: {PROC}")) return False if Checker.has(args, BuildType.INFO): outputs = build_info(codes, nametags, callings) if not outputs or outputs.is_empty(): logger.debug( msg.ERR_FAIL_MISSING_DATA.format( data=f"info output data: {PROC}")) return False if not Outputter.output_data(_get_build_path('info'), outputs): logger.error( msg.ERR_FAIL_CANNOT_WRITE_DATA.format( data=f"output info data: {PROC}")) return False if not BaseInfoBuilder.build_base_info(args, builds): logger.error( msg.ERR_FAIL_SUBPROCESS.format(proc=f"base info outputs: {PROC}")) return False logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return True
def compile_codes(scenes: ScenesDB, assets: AssetsDB) -> StoryData: assert isinstance(scenes, ScenesDB) assert isinstance(assets, AssetsDB) logger.debug(msg.PROC_START.format(proc=PROC)) config = yaml.safe_load(read_file(FILE_CONFIG)) if not config: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"config file: {PROC}")) return None entry = config[ELM_CONFIG][ELM_ENTRY] if not scenes.has(entry): logger.error( msg.ERR_FAIL_MISSING_DATA_WITH_DATA.format( data=f"entry point: {PROC}"), entry) return None data = call_scene(0, entry, scenes) if not data: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"story data: {PROC}")) return None tags = nametags_from(assets) if not tags: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"name tags: {PROC}")) return None tags_sorted = dict_sorted(tags) # NOTE: current tags unused timeclocks = timeclocks_from(assets) if not timeclocks: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"time clocks tags: {PROC}")) return None updated_alias = apply_alias(data) if not updated_alias: logger.error( msg.ERR_FAIL_MISSING_DATA.format(data=f"apply alias data: {PROC}")) return None updated_timeclock = apply_scene_time_to_clock(updated_alias, timeclocks) if not updated_timeclock: logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"apply time clock data: {PROC}")) return None updated_same_info = apply_scene_info_same(updated_timeclock) if not updated_same_info: logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"apply same info data: {PROC}")) return None updated_same_acts = apply_scene_action_same(updated_same_info) if not updated_same_acts: logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"apply same act data: {PROC}")) return None # if date and year refine by next updated_next = apply_scene_info_next(updated_same_acts) if not updated_next: logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"apply next date time: {PROC}")) return None # apply inst updated_inst = apply_instructions(updated_next) if not updated_inst: logger.error( msg.ERR_FAIL_MISSING_DATA.format( data=f"apply instruction data: {PROC}")) return None # tag convert # TODO: ここで一回タグ変換するか?いなか? logger.debug( msg.MSG_UNIMPLEMENT_PROC.format(proc=f"tag convert phase: {PROC}")) logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return StoryData(updated_inst)