Ejemplo n.º 1
0
def _record_as_person_info_from(record: StructRecord) -> str:
    assert isinstance(record, StructRecord)

    info = assertion.is_instance(record.note, SceneDataInfo)
    data = "、".join(info.data)

    return f"[P: {data}]"
Ejemplo n.º 2
0
def _record_as_stage_info_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, StageInfo)

    head = info.index
    stage = info.stage
    subject = info.subject
    outline = info.outline
    out_subject = ''

    if StageInfoType.DRAW is info.type:
        subject = f"({subject})" if subject else ''
    elif StageInfoType.PUT is info.type:
        subject = f"[{subject}]"
    elif StageInfoType.RID is info.type:
        out_subject = f"[{subject}]"
        subject = ''
    elif StageInfoType.NONE is info.type:
        head = stage = subject = outline = '----'
    else:
        return None

    _head = just_string_of(str(head), 4)
    _stage = just_string_of(stage, 16)
    _subject = just_string_of(subject, 16)
    _outline = just_string_of(outline, 48)
    _out_subject = just_string_of(out_subject, 16)

    return f"| {_head} | {_stage} | {_subject} | {_outline} | {_out_subject} |"
Ejemplo n.º 3
0
def _base_stage_status_data_from(infos_data: InfosData) -> list:
    assert isinstance(infos_data, InfosData)

    _PROC = f"{PROC}: base stage data"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    tmp = []
    index = 0
    stage = 'None'

    for record in infos_data.get_data():
        assert isinstance(record, InfoRecord)
        if InfoType.ACTION is record.type:
            ret = _record_as_stage_info_from(index, stage, record)
            if ret:
                tmp.append(ret)
        elif InfoType.TITLE_SCENE is record.type:
            index += 1
        elif InfoType.SCENE_HEAD is record.type:
            info = assertion.is_instance(record.note, SceneInfo)
            stage = info.stage
        else:
            continue

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))

    return tmp
Ejemplo n.º 4
0
def _record_as_stage_state_info_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, StageStateInfo)

    head = info.index
    stage = info.stage
    item = info.outline
    view = ''

    if StageStateType.ITEM is info.type:
        item = info.outline
        view = ''
    elif StageStateType.VIEW is info.type:
        item = ''
        view = info.outline
    elif StageStateType.NONE is info.type:
        head = stage = item = view = '----'
    else:
        return None

    _head = just_string_of(str(head), 4)
    _stage = just_string_of(stage, 16)
    _item = just_string_of(item, 16)
    _view = just_string_of(view, 32)

    return f"| {_head} | {_stage} | {_item} | {_view} |"
Ejemplo n.º 5
0
def stage_infos_from(infos_data: InfosData) -> InfosData:
    assert isinstance(infos_data, InfosData)

    logger.debug(msg.PROC_START.format(proc=PROC))

    tmp = []
    index = 0
    current = None

    tmp.append(get_record_as_splitter())
    tmp.append(get_record_as_data_title('STAGE INFOS'))

    for record in infos_data.get_data():
        assert isinstance(record, InfoRecord)
        if InfoType.ACTION is record.type:
            ret = _record_as_stage_info_from(index, current, record)
            if ret:
                tmp.append(ret)
        elif InfoType.TITLE_EPISODE is record.type:
            tmp.append(_get_record_as_splitter())
        elif InfoType.TITLE_SCENE is record.type:
            index += 1
        elif InfoType.SCENE_HEAD is record.type:
            info = assertion.is_instance(record.note, SceneInfo)
            current = info.stage
        else:
            continue

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))

    return InfosData(tmp)
Ejemplo n.º 6
0
def _record_as_knowledge_info_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, KnowledgeInfo)

    head = info.index
    subject = info.subject
    outline = info.outline
    old_know = ''

    if KnowledgeInfoType.EXPLAIN is info.type:
        subject = f"{subject}"
        outline = f"※{outline}"
    elif KnowledgeInfoType.KNOW is info.type:
        subject = f"{subject}"
    elif KnowledgeInfoType.KNOWN is info.type:
        subject = f"{subject}"
        old_know = f"({outline})"
        outline = ''
    elif KnowledgeInfoType.REMEMBER is info.type:
        subject = f"{subject}"
        old_know = f"〜{outline}"
        outline = ''
    elif KnowledgeInfoType.NONE is info.type:
        head = subject = outline = old_know = '----'
    else:
        return None

    _head = just_string_of(str(head), 4)
    _subject = just_string_of(subject, 16)
    _outline = just_string_of(outline, 32)
    _old_know = just_string_of(old_know, 32)

    return f"| {_head} | {_subject} | {_outline} | {_old_know} |"
Ejemplo n.º 7
0
def _record_as_flag_info_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, FlagInfo)

    head = ''
    subject_a = ''
    flag = ''
    subject_b = ''
    deflag = ''

    if FlagType.FLAG is info.type:
        head = info.index
        subject_a = info.subject
        flag = info.flag
    elif FlagType.DEFLAG is info.type:
        head = info.index
        subject_b = info.subject
        deflag = info.flag
    else:
        head = subject_a = flag = subject_b = deflag = '----'

    _head = just_string_of(str(head), 4)
    _subject_a = just_string_of(subject_a, 16)
    _flag = just_string_of(flag, 32)
    _subject_b = just_string_of(subject_b, 16)
    _deflag = just_string_of(deflag, 32)

    return f"| {_head} | {_subject_a} | {_flag} | {_subject_b} | {_deflag} |"
Ejemplo n.º 8
0
def _record_as_item_info_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, ItemInfo)

    head = info.index
    subject = info.subject
    outline = info.outline
    out_subject = ''

    if ItemInfoType.HAVE is info.type:
        subject = f"({subject})[{outline}]"
    elif ItemInfoType.DISCARD is info.type:
        out_subject = f"({subject})[{outline}]"
        subject = ''
    elif ItemInfoType.NONE is info.type:
        head = subject = outline = out_subject = '----'
    else:
        return None

    _head = just_string_of(str(head), 4)
    _subject = just_string_of(subject, 32)
    _out_subject = just_string_of(out_subject, 32)

    return f"| {_head} | {_subject} | {_out_subject} |"
Ejemplo n.º 9
0
def _record_as_person_state_info_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, PersonStateInfo)

    head = info.index
    subject = info.subject
    outline = info.outline
    skin = state = pinfo = ''

    if PersonStateType.INFO is info.type:
        pinfo = outline
    elif PersonStateType.SKIN is info.type:
        skin = outline
    elif PersonStateType.STATE is info.type:
        state = outline
    elif PersonStateType.NONE is info.type:
        head = skin = state = pinfo = '----'
    else:
        return None

    _head = just_string_of(str(head), 4)
    _subject = just_string_of(subject, 16)
    _skin = just_string_of(skin, 16)
    _state = just_string_of(state, 16)
    _pinfo = just_string_of(pinfo, 32)

    return f"| {_head} | {_subject} | {_skin} | {_state} | {_pinfo} |"
Ejemplo n.º 10
0
def _record_as_title_from(record: StoryRecord) -> ActionRecord:
    assert isinstance(record, StoryRecord)

    elm = assertion.is_instance(record.type, ElmType)

    # NOTE: ここは他にも何か情報入れる場合、追加
    return ActionRecord(
        ActType.DATA,
        DATA_TITLE_TABLE[elm],
        elm_title_of(record),
    )
Ejemplo n.º 11
0
def _record_as_transition_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, SceneInfo)

    camera = just_string_of(info.camera, 16)
    stage = just_string_of(info.stage, 16)
    year = just_string_of(info.year, 8)
    date = just_string_of(info.date, 8)
    time = just_string_of(info.time, 8)

    return f"| {stage} | {time} | {date} | {year} | {camera} |"
Ejemplo n.º 12
0
def _record_as_scene_data_from(record: StructRecord) -> str:
    assert isinstance(record, StructRecord)

    info = assertion.is_instance(record.note, SceneInfo)

    camera = info.camera
    stage = info.stage
    year = info.year
    date = info.date
    time = info.time

    return f"○{stage}({time})- {date}/{year} 【{camera}】"
Ejemplo n.º 13
0
def _content_record_of(record: StoryRecord, index: int) -> ContentRecord:
    assert isinstance(record, StoryRecord)
    assert isinstance(index, int)

    elm = assertion.is_instance(record.type, ElmType)

    if not str(TITLE_ELMS[elm]) in record.data:
        logger.warning(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"content record in {PROC}"))
        return None

    title = record.data[str(TITLE_ELMS[elm])]

    return ContentRecord(elm, title, index)
Ejemplo n.º 14
0
def _update_tags_scene_head_record(record: InfoRecord, tags: dict) -> InfoRecord:
    assert isinstance(record, InfoRecord)
    assert isinstance(tags, dict)

    info = assertion.is_instance(record.note, SceneInfo)
    _info = SceneInfo()
    _info.camera = translate_tags_str(info.camera, tags, True, None)
    _info.stage = translate_tags_str(info.stage, tags, True, None)
    _info.year = translate_tags_str(str(info.year), tags, True, None)
    _info.date = translate_tags_str(str(info.date), tags, True, None)
    _info.time = translate_tags_str(str(info.time), tags, True, None)

    return InfoRecord(
            record.type,
            record.act,
            record.subject,
            record.outline,
            _info)
Ejemplo n.º 15
0
def _update_tags_scene_data_record(record: StructRecord,
                                   tags: dict) -> StructRecord:
    assert isinstance(record, StructRecord)
    assert isinstance(tags, dict)

    info = assertion.is_instance(record.note, SceneInfo)
    updated = SceneInfo()

    updated.camera = translate_tags_str(info.camera, tags, True, None)
    updated.stage = translate_tags_str(info.stage, tags, True, None)
    updated.year = translate_tags_str(str(info.year), tags, True, None)
    updated.date = translate_tags_str(str(info.date), tags, True, None)
    updated.time = translate_tags_str(str(info.time), tags, True, None)

    return StructRecord(record.type, record.act,
                        translate_tags_str(record.subject, tags, True, None),
                        translate_tags_str(record.outline, tags, True, None),
                        updated)
Ejemplo n.º 16
0
def get_commandline_arguments() -> Namespace:
    logger.debug(msg.PROC_START.format(proc=PROC))

    parser = assertion.is_instance(_init_commandline_parser(), ArgumentParser)

    if not parser:
        return None

    if not _set_parser_options(parser):
        logger.warning(msg.ERR_FAIL_SET_DATA.format(data='arg parser options'))
        return None

    args = parser.parse_args()

    if not args:
        return None

    logger.debug(msg.PROC_DONE.format(proc=PROC))
    return args
Ejemplo n.º 17
0
def _record_as_fashion_info_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, FashionInfo)

    head = info.index
    subject = info.subject
    outline = info.outline

    if head < 0:
        head = subject = outline = '----'
    else:
        outline = f"[{outline}]"

    _head = just_string_of(str(head), 4)
    _subject = just_string_of(subject, 16)
    _outline = just_string_of(outline, 32)

    return f"| {_head} | {_subject} | {_outline} |"
Ejemplo n.º 18
0
def story_data_from(args: Namespace) -> StoryData:
    assert isinstance(args, Namespace)

    logger.debug(msg.PROC_START.format(proc=PROC))

    order_data = read_yaml_data(read_file(filepath_of(ElmType.ORDER, '')))

    if not order_data:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(data=f"order data in {PROC}"))
        return None

    elmpart = assertion.is_instance(
        _get_elm_part(args.part if args.part else ""), ElmPart)

    serialized = assertion.is_list(
        serialized_filenames_from_order(
            order_data,
            elmpart.chapter[0],
            elmpart.chapter[1],
            elmpart.episode[0],
            elmpart.episode[1],
            elmpart.scene[0],
            elmpart.scene[1],
        ))

    if not serialized:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(
                data=f"serialized data in {PROC}"))
        return None

    story_data_base = _conv_story_data_from(serialized)
    if not story_data_base:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(
                data=f"story data base in {PROC}"))
        return None

    updated = update_story_data_if_same_or_next_tag(StoryData(story_data_base))

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return updated
Ejemplo n.º 19
0
def _conv_plot_record(record: StoryRecord) -> PlotRecord:
    assert isinstance(record, StoryRecord)

    elm = assertion.is_instance(record.type, ElmType)
    if not is_enable_the_elm(elm, ENABLE_ELMS):
        logger.warning(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"element type in {PROC}"))
        return None

    title = assertion.is_str(elm_title_of(record))
    setup = assertion.is_str(_elm_setup_of(record))
    tp1st = assertion.is_str(_elm_tp1st_of(record))
    develop = assertion.is_str(_elm_develop_of(record))
    tp2nd = assertion.is_str(_elm_tp2nd_of(record))
    climax = assertion.is_str(_elm_climax_of(record))
    resolve = assertion.is_str(_elm_resolve_of(record))

    return PlotRecord(elm, title, setup, tp1st, develop, tp2nd, climax,
                      resolve)
Ejemplo n.º 20
0
def _record_of_scene_transition_from(record: InfoRecord,
                                     cache: SceneInfo) -> InfoRecord:
    assert isinstance(record, InfoRecord)
    assert isinstance(cache, SceneInfo)

    def _diff(a: str, b: str) -> str:
        if a != b:
            return '↓'
        else:
            return '…'

    base = assertion.is_instance(record.note, SceneInfo)

    dif = SceneInfo()

    dif.camera = _diff(base.camera, cache.camera)
    dif.stage = _diff(base.stage, cache.stage)
    dif.year = _diff(base.year, cache.year)
    dif.date = _diff(base.date, cache.date)
    dif.time = _diff(base.time, cache.time)

    return InfoRecord(InfoType.SCENE_TRANSITION, ActType.DATA, '', '', dif)
Ejemplo n.º 21
0
def _reorder_each_stages(base_data: list) -> list:
    assert isinstance(base_data, list)

    _PROC = f"{PROC}: reorder stage data"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    tmp = []

    stages = _get_stages_list()

    tmp.append(get_record_as_splitter())
    tmp.append(get_record_as_data_title("STAGE STATUS TRANSITIONS"))

    for stage in stages:
        tmp.append(_get_record_as_data_splitter(ElmType.STAGE))
        for record in base_data:
            assert isinstance(record, InfoRecord)
            info = assertion.is_instance(record.note, StageStateInfo)
            if info.stage == stage:
                tmp.append(record)

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))

    return tmp
Ejemplo n.º 22
0
def _reorder_each_persons(base_data: list) -> list:
    assert isinstance(base_data, list)

    _PROC = f"{PROC}: reorder person data"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    tmp = []

    persons = _get_persons_list()

    tmp.append(get_record_as_splitter())
    tmp.append(get_record_as_data_title("PERSON STATUS TRANSITIONS"))

    for person in persons:
        tmp.append(_get_record_as_data_splitter(ElmType.PERSON))
        for record in base_data:
            assert isinstance(record, InfoRecord)
            info = assertion.is_instance(record.note, PersonStateInfo)
            if info.subject == person:
                tmp.append(record)

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))

    return tmp
Ejemplo n.º 23
0
def _record_as_person_info_from(record: InfoRecord) -> str:
    assert isinstance(record, InfoRecord)

    info = assertion.is_instance(record.note, PersonInfo)

    head = info.index
    info_sub = ''
    subject = info.subject
    outline = info.outline

    if PersonInfoType.BE is info.type:
        info_sub = f"[{subject}]"
    elif PersonInfoType.COME is info.type:
        info_sub = f"in {subject}"
    elif PersonInfoType.GO is info.type:
        info_sub = f"out {subject}"
    else:
        head = info_sub = outline = '----'

    _head = just_string_of(str(head), 4)
    _subject = just_string_of(info_sub, 16)
    _outline = just_string_of(outline, 48)

    return f"| {_head} | {_subject} | {_outline} |"
Ejemplo n.º 24
0
def test_assertion_is_instance(x, t):

    assert is_instance(x, t), f"Expected a type {t} value: {x}"
Ejemplo n.º 25
0
 def __init__(self, data: list, record_cls: Any):
     assert isinstance(data, list)
     self.data = [assertion.is_instance(r, record_cls) for r in data]