class NewMapListBlock(b3.parsers.frostbite2.util.MapListBlock): """ Alters MapListBlock class since mapList.list raw data includes playlist information in MOHW Example raw data for MOHW: [ "2" "CustomPL" "3" "MP_03" "CombatMission" "1" "MP_05" "BombSquad" "1" ] """ def append(self, data): """ Parses and appends the maps from raw_data. data : words as received from the Frostbite2 mapList.list command """ # validation if type(data) not in (tuple, list): raise MapListBlockError( "invalid data: expecting data as a tuple or as a list, received '%s' instead" % type(data)) if len(data) < 3: raise MapListBlockError( "invalid data: data should have at least 3 elements. %r", data) try: num_maps = int(data[0]) except ValueError, err: raise MapListBlockError( "invalid data: first element should be a integer, got %r" % data[0], err) try: num_words = int(data[2]) except ValueError, err: raise MapListBlockError( "invalid data: second element should be a integer, got %r" % data[1], err)
def append(self, data): """ Parses and appends the maps from raw_data. data : words as received from the Frostbite2 mapList.list command """ # validation if type(data) not in (tuple, list): raise MapListBlockError( "invalid data: expecting data as a tuple or as a list, received '%s' instead" % type(data)) if len(data) < 3: raise MapListBlockError( "invalid data: data should have at least 3 elements. %r", data) try: num_maps = int(data[0]) except ValueError, err: raise MapListBlockError( "invalid data: first element should be a integer, got %r" % data[0], err)
def append(self, data): """ Parses and appends the maps from raw_data. data : words as received from the Frostbite2 mapList.list command """ # validation if type(data) not in (tuple, list): raise MapListBlockError("invalid data: expecting data as a tuple or as a list, received '%s' instead" % type(data)) if len(data) < 3: raise MapListBlockError("invalid data: data should have at least 3 elements. %r", data) try: num_maps = int(data[0]) except ValueError as err: raise MapListBlockError("invalid data: first element should be a integer, got %r" % data[0], err) try: num_words = int(data[2]) except ValueError as err: raise MapListBlockError("invalid data: second element should be a integer, got %r" % data[1], err) if len(data) != (3 + (num_maps * num_words)): raise MapListBlockError("invalid data: the total number of elements is not coherent with the " "number of maps declared. %s != (2 + %s * %s)" % (len(data), num_maps, num_words)) if num_words < 3: raise MapListBlockError("invalid data. Expecting at least 3 words of data per map") if self._num_words is not None and self._num_words != num_words: raise MapListBlockError("cannot append data: nums_words are different from existing data") # parse data map_data = [] for i in range(num_maps): base_index = 3 + (i * num_words) try: num_rounds = int(data[base_index+2]) except ValueError: raise MapListBlockError("invalid data: %sth element should be a integer, " "got %r" % (base_index + 2, data[base_index + 2])) map_data.append({'name': data[base_index + 0], 'gamemode': data[base_index + 1], 'num_of_rounds': num_rounds}) # append data self._map_data += tuple(map_data) self._num_maps = len(self._map_data) if self._num_words is None: self._num_words = num_words
num_maps = int(data[0]) except ValueError, err: raise MapListBlockError( "invalid data: first element should be a integer, got %r" % data[0], err) try: num_words = int(data[2]) except ValueError, err: raise MapListBlockError( "invalid data: second element should be a integer, got %r" % data[1], err) if len(data) != (3 + (num_maps * num_words)): raise MapListBlockError( "invalid data: the total number of elements is not coherent with the " "number of maps declared. %s != (2 + %s * %s)" % (len(data), num_maps, num_words)) if num_words < 3: raise MapListBlockError( "invalid data. Expecting at least 3 words of data per map") if self._num_words is not None and self._num_words != num_words: raise MapListBlockError( "cannot append data: nums_words are different from existing data" ) # parse data map_data = [] for i in range(num_maps): base_index = 3 + (i * num_words)