How to use the sc2reader.utils.Length function in sc2reader

To help you get started, we’ve selected a few sc2reader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GraylinKim / sc2reader / sc2reader / engine / plugins / gameheart.py View on Github external
if event.name == 'UnitBornEvent' and event.control_pid and event.unit_type_name in self.PRIMARY_BUILDINGS:
                # In normal replays, starting units are born on frame zero.
                if event.frame == 0:
                    yield PluginExit(self, code=0, details=dict())
                    return
                else:
                    start_frame = event.frame
                    actual_players[event.control_pid] = self.PRIMARY_BUILDINGS[event.unit_type_name]

        self.fix_entities(replay, actual_players)
        self.fix_events(replay, start_frame)

        replay.frames -= start_frame
        replay.game_length = Length(seconds=replay.frames / 16)
        replay.real_type = get_real_type(replay.teams)
        replay.real_length = Length(seconds=int(replay.game_length.seconds/GAME_SPEED_FACTOR[replay.speed]))
        replay.start_time = datetime.utcfromtimestamp(replay.unix_timestamp-replay.real_length.seconds)
github GraylinKim / sc2reader / sc2reader / engine / plugins / gameheart.py View on Github external
if start_frame != -1 and event.frame > start_frame + 5:  # fuzz it a little
                break
            if event.name == 'UnitBornEvent' and event.control_pid and event.unit_type_name in self.PRIMARY_BUILDINGS:
                # In normal replays, starting units are born on frame zero.
                if event.frame == 0:
                    yield PluginExit(self, code=0, details=dict())
                    return
                else:
                    start_frame = event.frame
                    actual_players[event.control_pid] = self.PRIMARY_BUILDINGS[event.unit_type_name]

        self.fix_entities(replay, actual_players)
        self.fix_events(replay, start_frame)

        replay.frames -= start_frame
        replay.game_length = Length(seconds=replay.frames / 16)
        replay.real_type = get_real_type(replay.teams)
        replay.real_length = Length(seconds=int(replay.game_length.seconds/GAME_SPEED_FACTOR[replay.speed]))
        replay.start_time = datetime.utcfromtimestamp(replay.unix_timestamp-replay.real_length.seconds)
github GraylinKim / sc2reader / sc2reader / events / message.py View on Github external
def _str_prefix(self):
        player_name = self.player.name if getattr(self, 'pid', 16) != 16 else "Global"
        return "{0}\t{1:<15} ".format(Length(seconds=int(self.frame / 16)), player_name)
github GraylinKim / sc2reader / sc2reader / engine / plugins / context.py View on Github external
def load_tracker_controller(self, event, replay):
        if event.control_pid in replay.entity:
            event.unit_controller = replay.entity[event.control_pid]
        elif event.control_pid != 0:
            self.logger.error("Bad control_pid ({0}) for event {1} at {2} [{3}].".format(event.control_pid, event.__class__, Length(seconds=event.second), event.frame))
github GraylinKim / sc2reader / sc2reader / resources.py View on Github external
def load_game_events(self):
        # Copy the events over
        # TODO: the events need to be fixed both on the reader and processor side
        if 'replay.game.events' not in self.raw_data:
            return

        self.game_events = self.raw_data['replay.game.events']
        self.events = sorted(self.events+self.game_events, key=lambda e: e.frame)

        # hideous hack for HotS 2.0.0.23925, see https://github.com/GraylinKim/sc2reader/issues/87
        if self.base_build == 23925 and self.events and self.events[-1].frame > self.frames:
            self.frames = self.events[-1].frame
            self.length = utils.Length(seconds=int(self.frames/self.game_fps))
github GraylinKim / sc2reader / sc2reader / engine / plugins / context.py View on Github external
def load_message_game_player(self, event, replay):
        if replay.versions[1] == 1 or (replay.versions[1] == 2 and replay.build < 24247):
            if event.pid in replay.entity:
                event.player = replay.entity[event.pid]
                event.player.events.append(event)
            elif event.pid != 16:
                self.logger.error("Bad pid ({0}) for event {1} at {2} [{3}].".format(event.pid, event.__class__, Length(seconds=event.second), event.frame))
            else:
                pass  # This is a global event

        else:  # Now event.pid is actually a user id for human entities
            if event.pid < len(replay.humans):
                event.player = replay.human[event.pid]
                event.player.events.append(event)
            elif event.pid != 16:
                self.logger.error("Bad pid ({0}) for event {1} at {2} [{3}].".format(event.pid, event.__class__, Length(seconds=event.second), event.frame))
            else:
                pass  # This is a global event
github GraylinKim / sc2reader / sc2reader / engine / plugins / context.py View on Github external
def load_tracker_upkeeper(self, event, replay):
        if event.upkeep_pid in replay.entity:
            event.unit_upkeeper = replay.entity[event.upkeep_pid]
        elif event.upkeep_pid != 0:
            self.logger.error("Bad upkeep_pid ({0}) for event {1} at {2} [{3}].".format(event.upkeep_pid, event.__class__, Length(seconds=event.second), event.frame))
github GraylinKim / sc2reader / sc2reader / resources.py View on Github external
# Since the underlying traceback isn't important to most people, don't expose it in python2 anymore
        if load_level >= 0:
            self.load_level = 0
            try:
                self.archive = mpyq.MPQArchive(replay_file, listfile=False)
            except Exception as e:
                raise exceptions.MPQError("Unable to construct the MPQArchive", e)

            header_content = self.archive.header['user_data_header']['content']
            header_data = BitPackedDecoder(header_content).read_struct()
            self.versions = list(header_data[1].values())
            self.frames = header_data[3]
            self.build = self.versions[4]
            self.base_build = self.versions[5]
            self.release_string = "{0}.{1}.{2}.{3}".format(*self.versions[1:5])
            self.game_length = utils.Length(seconds=self.frames/16)
            self.length = self.real_length = utils.Length(seconds=int(self.frames/self.game_fps))

        # Load basic details if requested
        if load_level >= 1:
            self.load_level = 1
            for data_file in ['replay.initData', 'replay.details', 'replay.attributes.events']:
                self._read_data(data_file, self._get_reader(data_file))
            self.load_details()
            self.datapack = self._get_datapack()

            # Can only be effective if map data has been loaded
            if options.get('load_map', False):
                self.load_map()

        # Load players if requested
        if load_level >= 2: