def build_script(story_data: StoryData, tags: dict, callings: dict, is_comment: bool) -> OutputsData: assert isinstance(story_data, StoryData) assert isinstance(tags, dict) assert isinstance(callings, dict) assert isinstance(is_comment, bool) logger.debug(msg.PROC_START.format(proc=PROC)) scripts = Converter.scripts_data_from(story_data) if not scripts: return None updated_tags = TagConverter.conv_callings_and_tags(scripts, dict_sorted(tags, True), callings) if not updated_tags: return None formatted = Formatter.format_data(updated_tags, is_comment) if not formatted: return None translated = translate_tags_text_list(formatted, dict_sorted(tags, True)) logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return OutputsData(translated)
def conv_callings_and_tags(cls, data: list, tags: dict, callings: dict) -> list: assert isinstance(data, list) assert isinstance(tags, dict) assert isinstance(callings, dict) tmp = [] _tags = dict_sorted(tags) for record in data: assert isinstance(record, StructRecord) if RecordType.SPIN is record.type: tmp.append(cls._conv_spin(record, _tags)) elif record.type in [ RecordType.ACT, RecordType.OBJECT, RecordType.PERSON ]: tmp.append(cls._conv_act(record, _tags, callings)) else: tmp.append(record) logger.debug( msg.PROC_MESSAGE.format( proc=f"tag converted structs data: {PROC}")) return tmp
def apply_alias(data: list) -> list: assert isinstance(data, list) # TODO: 現在はそのシーンのみでAlias置換を行っているが、レベルが深くなっても維持するように変更する tmp = [] alias = {} for record in data: assert isinstance(record, BaseCode) if isinstance(record, SceneInfo): tmp.append(record) elif isinstance(record, SceneEnd): tmp.append(record) alias = {} elif isinstance(record, Instruction) and InstType.ALIAS is record.type: tokens = assertion.is_list(record.args) alias[tokens[0]] = tokens[2] elif isinstance(record, Action): ret = TagConv.apply_alias_to_action(record, dict_sorted(alias, True)) tmp.append(ret) else: tmp.append(record) logger.debug( msg.PROC_MESSAGE.format(proc=f"completed apply alias: {PROC}")) 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 _conv_desc(record: ScriptRecord, callings: dict) -> ScriptRecord: assert isinstance(record, ScriptRecord) assert isinstance(callings, dict) if record.subject in callings: calling = dict_sorted(callings[record.subject], True) return ScriptRecord( record.type, calling['S'], [translate_tags_str(d, calling) for d in record.descs], record.note) else: return record
def _conv_act(record: StructRecord, tags: dict, callings: dict) -> StructRecord: assert isinstance(record, StructRecord) assert isinstance(tags, dict) assert isinstance(callings, dict) if record.subject in callings: calling = dict_sorted(callings[record.subject], True) return StructRecord(record.type, record.act, calling['S'], translate_tags_str(record.outline, calling), record.note) elif record.subject in tags: return StructRecord( record.type, record.act, translate_tags_str(record.subject, tags, True, None), record.outline, record.note) else: return record
def build_outline(story_data: StoryData, tags: dict) -> OutputsData: assert isinstance(story_data, StoryData) assert isinstance(tags, dict) logger.debug(msg.PROC_START.format(proc=PROC)) outlines = Converter.outlines_data_from(story_data) if not outlines: return None reordered = Converter.reorder_outlines(outlines) if not reordered: return None formatted = Formatter.format_data(reordered) if not formatted: return None translated = translate_tags_text_list(formatted, dict_sorted(tags, True)) logger.debug(msg.PROC_SUCCESS.format(proc=PROC)) return OutputsData(translated)
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)