def _to_item(cls, record: InfoRecord) -> str: assert isinstance(record, InfoRecord) info = assertion.is_instance(record.note, ItemInfo) level = str(record.level) index = str(record.index) subject = record.subject have = info.have return cls._conv_item(level, index, subject, have)
def _to_person(cls, record: InfoRecord) -> str: assert isinstance(record, InfoRecord) info = assertion.is_instance(record.note, PersonInfo) level = str(record.level) index = str(record.index) subject = record.subject outline = record.outline return cls._conv_person(level, index, subject, info.type, outline)
def reorder_data_from(cls, data: list) -> list: assert isinstance(data, list) tmp = [] cache = [] persons = [] objects = [] is_lighting = False is_int = False is_start_spin = False for record in data: assert isinstance(record, StructRecord) if RecordType.TITLE is record.type: tmp.append(record) elif RecordType.SPIN is record.type: tmp.append(record) info = assertion.is_instance(record.note, SpinInfo) is_int = info.location == 'INT' is_start_spin = True elif RecordType.SCENE_END is record.type: if not is_start_spin: continue oret = cls._conv_object_pack(objects) if oret: tmp.append(oret) pret = cls._conv_person_pack(persons) if pret: tmp.append(pret) if not is_lighting: tmp.append(cls._get_default_light(is_int)) tmp.extend(copy.deepcopy(cache)) tmp.append(record) # reset objects = [] persons = [] cache = [] is_lighting = False is_int = False is_start_spin = False elif RecordType.OBJECT is record.type: objects.append(record) elif RecordType.PERSON is record.type: persons.append(record) elif RecordType.LIGHT is record.type: is_lighting = True cache.append(record) else: cache.append(record) logger.debug( msg.PROC_MESSAGE.format(proc=f"reorder struct data: {PROC}")) return tmp
def __init__(self, type: ActType, subject: str, outline: str, descs: list = None, note: str = None): self.type = assertion.is_instance(type, ActType) self.subject = assertion.is_str(subject) self.outline = assertion.is_str(outline) self.descs = assertion.is_list(descs) if descs else [] self.note = assertion.is_str(note) if note else ''
def _to_flag(cls, record: InfoRecord) -> str: assert isinstance(record, InfoRecord) info = assertion.is_instance(record.note, FlagInfo) level = str(record.level) index = str(record.index) subject = record.subject foreshadow = info.foreshadow payoff = info.payoff return cls._conv_flag(level, index, subject, foreshadow, payoff)
def _to_flag(record: StructRecord) -> str: assert isinstance(record, StructRecord) act = assertion.is_instance(record.act, ActType) category = record.act.to_category() subject = record.subject outline = record.outline indent = get_indent(2) if ActType.FORESHADOW is act: return f"<{subject}>={outline}" else: return f"<{subject}>〜{outline}"
def _to_spin(record: StructRecord) -> str: assert isinstance(record, StructRecord) info = assertion.is_instance(record.note, SpinInfo) camera = info.subject stage = info.stage location = info.location year = info.year date = info.date time = info.time clock = info.clock return f"○{stage}/{location}({time}/{clock}) - {date}/{year} - [{camera}]"
def inherited( self, type: ActType = None, subject: str = None, outline: str = None, descs: list = None, note: str = None, ) -> Action: return Action( assertion.is_instance(type, ActType) if type else self.type, assertion.is_str(subject) if subject else self.subject, assertion.is_str(outline) if outline else self.outline, assertion.is_list(descs) if descs else self.descs, assertion.is_str(note) if note else self.note, )
def _conv_spin(record: ScriptRecord, tags: dict) -> ScriptRecord: assert isinstance(record, ScriptRecord) assert isinstance(tags, dict) info = assertion.is_instance(record.note, SpinInfo) return ScriptRecord( record.type, record.subject, record.descs, SpinInfo( translate_tags_str(info.subject, tags, True, None), translate_tags_str(info.stage, tags, True, None), translate_tags_str(info.year, tags, True, None), translate_tags_str(info.date, tags, True, None), translate_tags_str(info.time, tags, True, None), info.clock, ))
def _conv_person(record: InfoRecord, callings: dict, tags: dict) -> InfoRecord: assert isinstance(record, InfoRecord) assert isinstance(callings, dict) assert isinstance(tags, dict) info = assertion.is_instance(record.note, PersonInfo) subject = record.subject outline = record.outline if record.subject in callings: calling = callings[record.subject] outline = translate_tags_str(outline, calling) return InfoRecord(record.type, record.level, record.index, translate_tags_str(subject, tags, True, None), translate_tags_str(outline, tags), info)
def _to_transision(cls, record: InfoRecord) -> str: assert isinstance(record, InfoRecord) info = assertion.is_instance(record.note, TransitionInfo) level = str(record.level) index = str(record.index) title = info.title stage = info.stage time = info.time clock = info.clock date = info.date year = info.year camera = info.camera return cls._conv_transition(level, index, title, stage, time, clock, date, year, camera)
def _conv_item(record: InfoRecord, callings: dict, tags: dict) -> InfoRecord: assert isinstance(record, InfoRecord) assert isinstance(callings, dict) assert isinstance(tags, dict) info = assertion.is_instance(record.note, ItemInfo) subject = record.subject outline = record.outline have = info.have if record.subject in callings: calling = callings[record.subject] outline = translate_tags_str(outline, calling) have = translate_tags_str(have, calling) return InfoRecord(record.type, record.level, record.index, translate_tags_str(subject, tags), translate_tags_str(outline, tags), ItemInfo(translate_tags_str(have, tags), ))
def _conv_transition(record: InfoRecord, tags: dict) -> InfoRecord: assert isinstance(record, InfoRecord) assert isinstance(tags, dict) info = assertion.is_instance(record.note, TransitionInfo) return InfoRecord( record.type, record.level, record.index, record.subject, record.outline, TransitionInfo( translate_tags_str(info.title, tags), translate_tags_str(info.camera, tags, True, None), translate_tags_str(info.stage, tags, True, None), info.location, translate_tags_str(info.year, tags), translate_tags_str(info.date, tags), translate_tags_str(info.time, tags, True, None), info.clock, ))
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 _to_act(record: StructRecord) -> str: assert isinstance(record, StructRecord) act = assertion.is_instance(record.act, ActType) subject = record.subject if record.subject else '――' category = act.to_category() outline = record.outline if record.outline else '――' indent = get_indent(2) if act in DIALOGUE_ACTS: _outline = f"「{outline}」" if ActType.VOICE is act: _outline = f"({category})『{outline}』" return f"{subject}{_outline}" elif act in DOING_ACTS: return f"{indent}〔{category}〕[{subject}]{outline}" elif act in DRAW_ACTS: return f"{indent}@({category})[{subject}]{outline}" elif act in FLAG_ACTS: return f"{indent}!({category})[{subject}]{outline}" elif act in STATE_ACTS: return f"{indent}%({category})[{subject}]={outline}" elif act in THINKING_ACTS: return f"{indent}({category})[{subject}]{outline}" elif act in SELECT_ACTS: if ActType.CHOICE is act: return f"{indent}!({category})[{subject}]={outline}" else: assert ActType.SELECTION is act selects = outline.replace(' ', '').split(',') _selects = '/'.join(selects) return f'{indent}?({category})[{subject}]={_selects}' elif act in TIME_ACTS: return f"[XII] {outline}" else: logger.warning( msg.ERR_FAIL_INVALID_DATA_WITH_DATA.format( data=f"act type in format: {PROC}"), act) return None
def _conv_flag(record: InfoRecord, callings: dict, tags: dict) -> InfoRecord: assert isinstance(record, InfoRecord) assert isinstance(callings, dict) assert isinstance(tags, dict) info = assertion.is_instance(record.note, FlagInfo) subject = record.subject outline = record.outline foreshadow = info.foreshadow payoff = info.payoff if subject in callings: calling = callings[record.subject] subject = calling['S'] outline = translate_tags_str(outline, calling) foreshadow = translate_tags_str(foreshadow, calling) payoff = translate_tags_str(payoff, calling) return InfoRecord( record.type, record.level, record.index, translate_tags_str(subject, tags), translate_tags_str(outline, tags), FlagInfo(translate_tags_str(foreshadow, tags), translate_tags_str(payoff, tags)))
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 __init__(self, type: InstType, args: list = None, note: str = None): self.type = assertion.is_instance(type, InstType) self.args = assertion.is_list(args) if args else [] self.note = assertion.is_str(note) if note else ''
def _to_spin(record: ScriptRecord) -> str: assert isinstance(record, ScriptRecord) info = assertion.is_instance(record.note, SpinInfo) return f"○{info.stage}({info.time})"
def test_assertion_is_instance(x, t): assert is_instance(x, t), f"Expected a type {t} value: {x}"
def append(self, key: str, val: Rubi): self.data[key] = assertion.is_instance(val, Rubi)