示例#1
0
def source_loop_mode():
    from pprint import pprint
    from rocketleaguereplayanalysis.data.data_loader import get_data

    print('===== Entering Loop Mode =====')
    print('To exit, type exit.')
    user_input2 = input('Press Enter to Continue > ')
    parsed_user_input2 = user_input2.split(' ')

    data = get_data()

    if parsed_user_input2 != 'exit':
        for i, frame in enumerate(data['Frames']):
            if parsed_user_input2 != 'exit':
                for j, update in enumerate(frame['ActorUpdates']):
                    print('=====')
                    print('Frame:', i)
                    print('Time:', frame['Time'])
                    print('Actor:', update['Id'])

                    print('=====')

                    pprint(update)

                    user_input2 = input('Press Enter to Continue > ')
                    parsed_user_input2 = user_input2.split(' ')

                    if parsed_user_input2 == 'exit':
                        return
            else:
                return
    else:
        return
示例#2
0
def parse_player_info():
    from rocketleaguereplayanalysis.data.data_loader import get_data

    global player_info, team0, team1

    player_info = {}

    for i in range(0, len(get_data())):
        for update in get_data()['Frames'][i]['ActorUpdates']:
            if 'ClassName' in update and update['ClassName'] == \
                    'TAGame.PRI_TA':
                player_id = update['Id']

                if player_id not in player_info:
                    player_info[player_id] = {}
                if 'Engine.PlayerReplicationInfo:PlayerName' in update.keys():
                    player_info[player_id]['name'] = \
                        update['Engine.PlayerReplicationInfo:PlayerName']
                if 'TAGame.PRI_TA:ClientLoadouts' in update.keys():
                    player_info[player_id]['items'] = \
                        update['TAGame.PRI_TA:ClientLoadouts']
                if 'Engine.PlayerReplicationInfo:Team' in update.keys():
                    player_info[player_id]['team'] = \
                        update['Engine.PlayerReplicationInfo:Team']['ActorId']
                if 'TAGame.PRI_TA:TotalXP' in update.keys():
                    player_info[player_id]['xp'] = \
                        update['TAGame.PRI_TA:TotalXP']
                    player_info[player_id]['xp_level'] = \
                        get_xp_level(update['TAGame.PRI_TA:TotalXP'])
                    player_info[player_id]['xp_title'] = \
                        get_xp_title(player_info[player_id]['xp_level'])
            elif 'ClassName' in update and update['ClassName'] == \
                    'TAGame.Team_Soccar_TA':
                if update['TypeName'] == 'Archetypes.Teams.Team0':
                    team0 = update['Id']
                elif update['TypeName'] == 'Archetypes.Teams.Team1':
                    team1 = update['Id']
                else:
                    print('wat? Teams don\'t seem to make sense...')
                    print('Found Team 0 (Usually Blue):  ', team0)
                    print('Found Team 1 (Usually Orange):', team1)
                    print('Weird Team:                   ', update['Id'])
def parse_actor_data():
    global actor_data
    from rocketleaguereplayanalysis.data.data_loader import get_data

    for frame in get_data()['Frames']:
        for update in frame['ActorUpdates']:

            actor_id = update['Id']

            if actor_id not in actor_data.keys():
                actor_data[actor_id] = []

            if 'ClassName' in update.keys():
                if update['ClassName'] not in actor_data[actor_id]:
                    actor_data[actor_id].append(update['ClassName'])
示例#4
0
def data_explorer_cli():
    from pprint import pprint
    from rocketleaguereplayanalysis.data.data_loader import get_data
    from rocketleaguereplayanalysis.data.actor_data import get_actor_data
    from rocketleaguereplayanalysis.data.object_numbers import \
        get_player_info, team0, team1
    from rocketleaguereplayanalysis.parser.frames import get_frames

    print()

    print('Now entering raw data explorer CLI.')
    print("""
    Help:
    
    To see keys for data point:             `keys [key...]`
    To see data for data point:             `data [key...]`
    To see actor data:                      `actor_data`
    To see player info:                     `player_info`
    To see pressure info:                   `pressure_info`
    To see possession info:                 `possession_info`
    To enter source frame loop mode:        `source_loop_mode`
    To enter parsed data frame loop mode:   `data_loop_mode`
    To exit:                                `exit`
    """)

    cont = True

    data = get_data()

    while cont:
        user_input = input('> ').split(' ')

        parsed_input = []
        for in_string in user_input:
            try:
                parsed_input.append(int(in_string))
            except:
                parsed_input.append(in_string)

        if parsed_input[0] == 'keys':
            try:
                show_data = data
                for key in parsed_input[1:]:
                    if key != '':
                        show_data = show_data[key]
                pprint(show_data.keys())
            except KeyError:
                print('Key is not in data')
            except AttributeError:
                print('Key does not have any subkeys')
        elif parsed_input[0] == 'data':
            try:
                show_data = data
                for key in parsed_input[1:]:
                    if key != '':
                        show_data = show_data[key]
                pprint(show_data)
            except KeyError:
                print('Key is not in data')
            except AttributeError:
                print('Key does not have any subkeys')
        elif parsed_input[0] == 'actor_data':
            pprint(get_actor_data())
        elif parsed_input[0] == 'player_info':
            pprint(get_player_info())
        elif parsed_input[0] == 'pressure_info':
            print('Blue:\t', get_frames()[-1]['pressure'][team0])
            print('Orange:\t', get_frames()[-1]['pressue'][team1])
        elif parsed_input[0] == 'possession_info':
            print('Blue:\t', get_frames()[-1]['possession'][team0])
            print('Orange:\t', get_frames()[-1]['possession'][team1])
        elif parsed_input[0] == 'source_loop_mode':
            source_loop_mode()
        elif parsed_input[0] == 'data_loop_mode':
            data_loop_mode()
        elif parsed_input[0] == 'exit':
            cont = False
        else:
            print('Command Not Recognized.')
            print('User Input:  ', user_input)
            print('Parsed Input:', parsed_input)
def load_frames():
    global frames

    import copy

    from rocketleaguereplayanalysis.data.data_loader import get_data
    from rocketleaguereplayanalysis.data.object_numbers import \
        get_player_info, get_game_event_num, team0, team1
    from rocketleaguereplayanalysis.parser.frame_data import \
        update_game_data, update_car_data, update_player_data, \
        update_ball_data, update_boost_data

    data = get_data()

    current_ball_object = None
    current_car_objects = {}
    current_boost_objects = {}
    player_info = get_player_info()
    game_event_num = get_game_event_num()

    frames = [len(data['Frames'])]
    frames[0] = {
        'time': {
            'replay_time': data['Frames'][0]['Delta'],
            'server_time': data['Frames'][0]['Time'],
            'game_time': 300,
            'game_minutes': int(300 / 60),
            'game_seconds': 300 % 60,
            'replay_delta': data['Frames'][0]['Delta'],
            'server_delta': data['Frames'][0]['Delta'],
            'real_replay_time': 0,
            'real_replay_delta': data['Frames'][0]['Delta']
        },
        'scoreboard': {
            'team0': 0,
            'team1': 0
        },
        'ball': {
            'loc': {
                'x': 0,
                'y': 0,
                'z': 0
            },
            'rot': {
                'x': 0,
                'y': 0,
                'z': 0
            },
            'sleep': True,
            'last_hit': None
        },
        'cars': {}
    }

    for player_id in player_info.keys():
        current_car_objects[player_id] = None
        current_boost_objects[player_id] = []
        frames[0]['cars'][player_id] = {
            'loc': {
                'x': None,
                'y': None,
                'z': None
            },
            'rot': {
                'x': 0,
                'y': 0,
                'z': 0
            },
            'ang_vel': {
                'x': 0,
                'y': 0,
                'z': 0
            },
            'lin_vel': {
                'x': 0,
                'y': 0,
                'z': 0
            },
            'throttle': 0,
            'steer': .5,
            'ping': 0,
            'boost': 85 / 255,
            'boosting': False,
            'sleep': True,
            'drift': False,
            '2nd_cam': False,
            'driving': False,
            'scoreboard': {
                'score': 0,
                'goals': 0,
                'assists': 0,
                'saves': 0,
                'shots': 0
            }
        }

    for i in range(0, len(data['Frames'])):

        if i > 0:
            frames.append(copy.deepcopy(frames[i - 1]))

            server_time = data['Frames'][i]['Time']
            replay_time = (frames[i - 1]['time']['replay_time'] +
                           data['Frames'][i]['Delta'])
            game_time = frames[i - 1]['time']['game_time']
            server_delta = (data['Frames'][i]['Time'] -
                            data['Frames'][i - 1]['Time'])
            replay_delta = data['Frames'][i]['Delta']
        else:
            server_time = data['Frames'][0]['Time']
            replay_time = data['Frames'][0]['Delta']
            game_time = 300
            server_delta = data['Frames'][0]['Delta']
            replay_delta = data['Frames'][0]['Delta']

        if replay_delta == 0:
            # There seems to have been a goal here.
            real_replay_delta = replay_delta
            real_replay_time = (frames[i]['time']['real_replay_time'] +
                                replay_delta)
        else:
            real_replay_delta = server_delta
            real_replay_time = (frames[i]['time']['real_replay_time'] +
                                server_delta)

        frames[i]['time'] = {
            'replay_time': replay_time,
            'server_time': server_time,
            'game_time': game_time,
            'game_minutes': int(game_time / 60),
            'game_seconds': game_time % 60,
            'replay_delta': replay_delta,
            'server_delta': server_delta,
            'real_replay_time': real_replay_time,
            'real_replay_delta': real_replay_delta
        }

        # Check for deleted actors
        for actor_id in data['Frames'][i]['DeletedActorIds']:
            if actor_id == current_ball_object:
                frames[i]['ball'] = {
                    'loc': {
                        'x': 0,
                        'y': 0,
                        'z': 0
                    },
                    'rot': {
                        'x': 0,
                        'y': 0,
                        'z': 0
                    },
                    'sleep': True,
                    'last_hit': None
                }
            else:
                for player_id in current_boost_objects:
                    if actor_id in current_boost_objects[player_id]:
                        current_boost_objects[player_id].remove(actor_id)
                for player_id in current_car_objects:
                    if actor_id == current_car_objects[player_id]:
                        current_car_objects[player_id] = None
                        current_boost_objects[player_id] = []
                        frames[i]['cars'][player_id]['loc'] = \
                            {'x': None, 'y': None, 'z': None}
                        frames[i]['cars'][player_id]['rot'] = \
                            {'x': 0, 'y': 0, 'z': 0}
                        frames[i]['cars'][player_id]['ang_vel'] = \
                            {'x': 0, 'y': 0, 'z': 0}
                        frames[i]['cars'][player_id]['lin_vel'] = \
                            {'x': 0, 'y': 0, 'z': 0}
                        frames[i]['cars'][player_id]['throttle'] = 0
                        frames[i]['cars'][player_id]['steer'] = .5
                        frames[i]['cars'][player_id]['ping'] = 0
                        frames[i]['cars'][player_id]['boost'] = 85 / 255
                        frames[i]['cars'][player_id]['boosting'] = False
                        frames[i]['cars'][player_id]['sleep'] = True
                        frames[i]['cars'][player_id]['drift'] = False
                        frames[i]['cars'][player_id]['2nd_cam'] = False
                        frames[i]['cars'][player_id]['driving'] = False

        for update in data['Frames'][i]['ActorUpdates']:
            actor_id = update['Id']

            # Update ball object number
            if 'ClassName' in update and \
                    ('TAGame.Ball_TA' in update['ClassName']):
                current_ball_object = actor_id

            # Update car numbers
            if 'ClassName' in update and \
                    ('TAGame.Car_TA' in update['ClassName']):
                player = update['Engine.Pawn:PlayerReplicationInfo']['ActorId']
                current_car_objects[player] = update['Id']

            update_boost_data(update, frames, current_car_objects,
                              current_boost_objects, i)

            # Update ball data
            if actor_id == current_ball_object:
                update_ball_data(update, frames, i)
            # Update player info
            elif actor_id in player_info.keys():
                update_player_data(update, frames, i, actor_id)
            # Update game data
            elif actor_id == game_event_num:
                update_game_data(update, frames, i)
            # Update team 0 score
            elif actor_id == team0:
                if 'Engine.TeamInfo:Score' in update:
                    frames[i]['scoreboard']['team0'] = \
                        update['Engine.TeamInfo:Score']
            # Update team 1 score
            elif actor_id == team1:
                if 'Engine.TeamInfo:Score' in update:
                    frames[i]['scoreboard']['team1'] = \
                        update['Engine.TeamInfo:Score']
            else:
                # update car data
                for player_id in current_car_objects:
                    if actor_id == current_car_objects[player_id]:
                        update_car_data(update, frames, i, player_id)

        # Deplete Boost
        for player_id in current_car_objects:
            if frames[i]['cars'][player_id]['boosting']:
                frames[i]['cars'][player_id]['boost'] -= \
                    real_replay_delta * 85 / 255
                frames[i]['cars'][player_id]['boost'] = \
                    max(0, frames[i]['cars'][player_id]['boost'])