Beispiel #1
0
def run_file(args, timelist):
    """Runs a timeline against a specified file"""
    state = {
        "file": True,
        "last_entry": False,
        "last_sync_position": 0,
        "last_jump": 0,
        "branch": 1,
        "timeline_stopped": True,
    }
    started = False
    encounter_sets = []

    with args.file as file:
        # If searching for encounters, divert and find start/end first.
        if args.search_fights:
            encounter_sets = e_tools.find_fights_in_file(file)
            # If all we want to do is list encounters, stop here and give to the user.
            if args.search_fights < 0:
                return e_tools.list_fights_in_file(args, encounter_sets)
        start_time, end_time = e_tools.choose_fight_times(args, encounter_sets)
        # Scan the file until the start timestamp
        for line in file:

            # Scan the file until the start timestamp
            if not started and line[14:26] != start_time:
                continue

            if line[14:26] == end_time:
                break

            # We're at the start of the encounter now.
            if not started:
                started = True
                state["last_sync_timestamp"] = e_tools.parse_event_time(line)

            state = check_event(line, timelist, state)
    if not started:
        raise Exception("Fight start not found")
def parse_file(args):
    """Reads a file specified by arguments, and returns an entry list"""

    entries = []
    started = False
    encounter_sets = []
    with args.file as file:
        # If searching for encounters, divert and find start/end first.
        if args.search_fights:
            encounter_sets = e_tools.find_fights_in_file(file)
            # If all we want to do is list encounters, stop here and give to the user.
            if args.search_fights < 0:
                return e_tools.list_fights_in_file(args, encounter_sets)
        start_time, end_time = e_tools.choose_fight_times(args, encounter_sets)
        # Scan the file until the start timestamp
        for line in file:

            if not started and start_time != line[14:26]:
                continue

            if end_time == line[14:26]:
                break

            # We're at the start of the encounter now.
            if not started:
                started = True
                last_ability_time = e_tools.parse_event_time(line)

            # We cull non-useful lines before potentially more expensive operations.
            if not line[0:2] in ["00", "21", "22", "34"]:
                continue

            line_fields = line.split("|")

            # If it's a zone seal, we want to make a special entry.
            if e_tools.is_zone_seal(line_fields):
                entry = make_entry(
                    {
                        "line_type": "zone_seal",
                        "time": e_tools.parse_event_time(line),
                        "zone_message": line_fields[4].split(" will be sealed off")[0],
                    }
                )
                entries.append(entry)
                continue

            # We're looking for enemy casts or enemies becoming targetable/untargetable.
            # These lines will start with 21, 22, or 34, and have an NPC ID (400#####)
            # If none of these apply, skip the line

            if not line[0:2] in ["21", "22", "34"] or not line[37:40] == "400":
                continue

            # We aren't including targetable lines unless the user explicitly says to.
            if line[0:2] == "34" and not line_fields[3] in args.include_targetable:
                continue
            # At this point, we have a combat line for the timeline.
            entry = make_entry(
                {
                    "line_type": line_fields[0],
                    "time": e_tools.parse_event_time(line),
                    "combatant": line_fields[3],
                }
            )
            if line[0:2] in ["21", "22"]:
                entry["ability_id"] = line_fields[4]
                entry["ability_name"] = line_fields[5]

            # Unknown abilities should be hidden sync lines by default.
            if line_fields[5].startswith(("Unknown_", "unknown_")):
                entry["ability_name"] = "--sync--"
            else:
                entry["targetable"] = (
                    "--targetable--" if line_fields[6] == "01" else "--untargetable--"
                )
            entries.append(entry)

    if not started:
        raise Exception("Fight start not found")

    return entries, last_ability_time