def __init__(self, **options): self.reset() self.configure(**options) self.logger = log_utils.get_logger(self.__class__) if self.options.get('register_defaults',None): self.register_defaults()
def __init__(self, file_object, filename=None, **options): self.opt = utils.AttributeDict(options) self.logger = log_utils.get_logger(self.__class__) self.filename = filename or getattr(file_object,'name','Unavailable') file_object.seek(0) self.filehash = hashlib.sha256(file_object.read()).hexdigest() file_object.seek(0)
def SelectionTracker(replay): debug = replay.opt.debug logger = log_utils.get_logger(SelectionTracker) for person in replay.entities: # TODO: A more robust person interface might be nice person.selection_errors = 0 player_selections = GameState(PlayerSelection()) for event in person.events: error = False if event.name == 'SelectionEvent': selections = player_selections[event.frame] control_group = selections[event.control_group].copy() error = not control_group.deselect(event.mask_type, event.mask_data) control_group.select(event.new_units) selections[event.control_group] = control_group if debug: logger.info("[{0}] {1} selected {2} units: {3}".format(Length(seconds=event.second), person.name, len(selections[0x0A].objects), selections[0x0A])) elif event.name == 'SetToHotkeyEvent': selections = player_selections[event.frame] selections[event.control_group] = selections[0x0A].copy() if debug: logger.info("[{0}] {1} set hotkey {2} to current selection".format(Length(seconds=event.second), person.name, event.hotkey)) elif event.name == 'AddToHotkeyEvent': selections = player_selections[event.frame] control_group = selections[event.control_group].copy() error = not control_group.deselect(event.mask_type, event.mask_data) control_group.select(selections[0x0A].objects) selections[event.control_group] = control_group if debug: logger.info("[{0}] {1} added current selection to hotkey {2}".format(Length(seconds=event.second), person.name, event.hotkey)) elif event.name == 'GetFromHotkeyEvent': selections = player_selections[event.frame] control_group = selections[event.control_group].copy() error = not control_group.deselect(event.mask_type, event.mask_data) selections[0xA] = control_group if debug: logger.info("[{0}] {1} retrieved hotkey {2}, {3} units: {4}".format(Length(seconds=event.second), person.name, event.control_group, len(selections[0x0A].objects), selections[0x0A])) else: continue # TODO: The event level interface here should be improved # Possibly use 'added' and 'removed' unit lists as well event.selected = selections[0x0A].objects if error: person.selection_errors += 1 if debug: logger.warn("Error detected in deselection mode {0}.".format(event.mask_type)) person.selection = player_selections # Not a real lock, so don't change it! person.selection.locked = True return replay
def SelectionTracker(replay): debug = replay.opt['debug'] logger = log_utils.get_logger(SelectionTracker) for person in replay.entities: # TODO: A more robust person interface might be nice person.selection_errors = 0 player_selections = GameState(PlayerSelection()) for event in person.events: error = False if event.name == 'SelectionEvent': selections = player_selections[event.frame] control_group = selections[event.control_group].copy() error = not control_group.deselect(event.mask_type, event.mask_data) control_group.select(event.new_units) selections[event.control_group] = control_group if debug: logger.info("[{0}] {1} selected {2} units: {3}".format(Length(seconds=event.second), person.name, len(selections[0x0A].objects), selections[0x0A])) elif event.name == 'SetControlGroupEvent': selections = player_selections[event.frame] selections[event.control_group] = selections[0x0A].copy() if debug: logger.info("[{0}] {1} set hotkey {2} to current selection".format(Length(seconds=event.second), person.name, event.hotkey)) elif event.name == 'AddToControlGroupEvent': selections = player_selections[event.frame] control_group = selections[event.control_group].copy() error = not control_group.deselect(event.mask_type, event.mask_data) control_group.select(selections[0x0A].objects) selections[event.control_group] = control_group if debug: logger.info("[{0}] {1} added current selection to hotkey {2}".format(Length(seconds=event.second), person.name, event.hotkey)) elif event.name == 'GetControlGroupEvent': selections = player_selections[event.frame] control_group = selections[event.control_group].copy() error = not control_group.deselect(event.mask_type, event.mask_data) selections[0xA] = control_group if debug: logger.info("[{0}] {1} retrieved hotkey {2}, {3} units: {4}".format(Length(seconds=event.second), person.name, event.control_group, len(selections[0x0A].objects), selections[0x0A])) else: continue # TODO: The event level interface here should be improved # Possibly use 'added' and 'removed' unit lists as well event.selected = selections[0x0A].objects if error: person.selection_errors += 1 if debug: logger.warn("Error detected in deselection mode {0}.".format(event.mask_type)) person.selection = player_selections # Not a real lock, so don't change it! person.selection.locked = True return replay
def __init__(self, file_object, filename=None, factory=None, **options): self.factory = factory self.opt = utils.AttributeDict(options) self.logger = log_utils.get_logger(self.__class__) self.filename = filename or getattr(file_object, 'name', 'Unavailable') if hasattr(file_object, 'seek'): file_object.seek(0) self.filehash = hashlib.sha256(file_object.read()).hexdigest() file_object.seek(0)
def __init__(self, file_object, filename=None, factory=None, **options): self.factory = factory self.opt = utils.AttributeDict(options) self.logger = log_utils.get_logger(self.__class__) self.filename = filename or getattr(file_object, "name", "Unavailable") if hasattr(file_object, "seek"): file_object.seek(0) self.filehash = hashlib.sha256(file_object.read()).hexdigest() file_object.seek(0)
def SelectionTracker(replay): debug = replay.opt.debug logger = log_utils.get_logger(SelectionTracker) for person in replay.people: # TODO: A more robust person interface might be nice person.selection_errors = 0 player_selection = GameState(PlayerSelection()) for event in person.selection_events: if debug: logger.debug("Event bytes: "+event.bytes.encode("hex")) error = False selection = player_selection[event.frame] if isinstance(event, SelectionEvent): selection[event.bank] = selection[event.bank].copy() error = not selection[event.bank].deselect(*event.deselect) selection[event.bank].select(event.objects) if debug: logger.info("[{0}] {1} selected {2} units: {3}".format(Length(seconds=event.second),person.name,len(selection[0x0A].objects),selection[0x0A])) elif isinstance(event, GetFromHotkeyEvent): # For some reason they leave the hotkey buffer unmodified so make a copy selection[0x0A] = selection[event.hotkey].copy() error = not selection[0x0A].deselect(*event.deselect) if debug: logger.info("[{0}] {1} retrieved hotkey {2}, {3} units: {4}".format(Length(seconds=event.second),person.name,event.hotkey,len(selection[0x0A].objects),selection[0x0A])) elif isinstance(event, SetToHotkeyEvent): # Make a copy to decouple the hotkey from primary selection selection[event.hotkey] = selection[0x0A].copy() if debug: logger.info("[{0}] {1} set hotkey {2} to current selection".format(Length(seconds=event.second),person.name,event.hotkey)) elif isinstance(event, AddToHotkeyEvent): selection[event.hotkey] = selection[event.hotkey].copy() error = not selection[event.hotkey].deselect(*event.deselect) selection[event.hotkey].select(selection[0x0A].objects) if debug: logger.info("[{0}] {1} added current selection to hotkey {2}".format(Length(seconds=event.second),person.name,event.hotkey)) # TODO: The event level interface here should be improved # Possibly use 'added' and 'removed' unit lists as well event.selected = selection[0x0A].objects if error: person.selection_errors += 1 if debug: logger.warn("Error detected in deselection mode {0}.".format(event.deselect[0])) person.selection = player_selection # Not a real lock, so don't change it! person.selection.locked = True return replay
def SelectionTracker(replay): debug = replay.opt.debug logger = log_utils.get_logger(SelectionTracker) for person in replay.people: # TODO: A more robust person interface might be nice person.selection_errors = 0 player_selection = GameState(PlayerSelection()) for event in person.selection_events: if debug: logger.debug("Event bytes: " + event.bytes.encode("hex")) error = False selection = player_selection[event.frame] if isinstance(event, SelectionEvent): selection[event.bank] = selection[event.bank].copy() error = not selection[event.bank].deselect(*event.deselect) selection[event.bank].select(event.objects) if debug: logger.info("[{0}] {1} selected {2} units: {3}".format( Length(seconds=event.second), person.name, len(selection[0x0A].objects), selection[0x0A])) elif isinstance(event, GetFromHotkeyEvent): # For some reason they leave the hotkey buffer unmodified so make a copy selection[0x0A] = selection[event.hotkey].copy() error = not selection[0x0A].deselect(*event.deselect) if debug: logger.info( "[{0}] {1} retrieved hotkey {2}, {3} units: {4}". format(Length(seconds=event.second), person.name, event.hotkey, len(selection[0x0A].objects), selection[0x0A])) elif isinstance(event, SetToHotkeyEvent): # Make a copy to decouple the hotkey from primary selection selection[event.hotkey] = selection[0x0A].copy() if debug: logger.info( "[{0}] {1} set hotkey {2} to current selection".format( Length(seconds=event.second), person.name, event.hotkey)) elif isinstance(event, AddToHotkeyEvent): selection[event.hotkey] = selection[event.hotkey].copy() error = not selection[event.hotkey].deselect(*event.deselect) selection[event.hotkey].select(selection[0x0A].objects) if debug: logger.info( "[{0}] {1} added current selection to hotkey {2}". format(Length(seconds=event.second), person.name, event.hotkey)) # TODO: The event level interface here should be improved # Possibly use 'added' and 'removed' unit lists as well event.selected = selection[0x0A].objects if error: person.selection_errors += 1 if debug: logger.warn( "Error detected in deselection mode {0}.".format( event.deselect[0])) person.selection = player_selection # Not a real lock, so don't change it! person.selection.locked = True return replay
def __init__(self): self.logger = log_utils.get_logger(self.__class__)
def __init__(self, *new_objects): self.logger = log_utils.get_logger(UnitSelection) self.objects = list() self.select(new_objects)
def logger(self): if not hasattr(self, "_logger"): self._logger = log_utils.get_logger(self.__class__) return self._logger