def test_2(self): bloc = MapListBlock( ['2', '3', 'map1', 'mode1', '1', 'map2', 'mode2', '2']) self.assertEqual(2, len(bloc)) self.assertEqual('map1', bloc[0]['name']) self.assertEqual('mode1', bloc[0]['gamemode']) self.assertEqual(1, bloc[0]['num_of_rounds']) self.assertEqual('map2', bloc[1]['name']) self.assertEqual('mode2', bloc[1]['gamemode']) self.assertEqual(2, bloc[1]['num_of_rounds']) self.assertEqual("MapListBlock[map1:mode1:1, map2:mode2:2]", repr(bloc)) self.assertEqual(0, len(bloc.getByName('MP_003'))) self.assertEqual(1, len(bloc.getByName('map1'))) self.assertEqual(1, len(bloc.getByName('map2'))) self.assertIn(0, bloc.getByName('map1')) self.assertIn(1, bloc.getByName('map2')) self.assertTrue(bloc.getByName('map1')[0]['gamemode'] == 'mode1') self.assertTrue(bloc.getByName('map2')[1]['gamemode'] == 'mode2') self.assertEqual(0, len(bloc.getByNameAndGamemode('map1', 'mode?'))) self.assertEqual(1, len(bloc.getByNameAndGamemode('map1', 'mode1'))) self.assertEqual(0, len(bloc.getByNameAndGamemode('map2', 'mode?'))) self.assertEqual(1, len(bloc.getByNameAndGamemode('map2', 'mode2'))) self.assertIn(0, bloc.getByNameAndGamemode('map1', 'mode1')) self.assertIn(1, bloc.getByNameAndGamemode('map2', 'mode2'))
def test_1(self): bloc = MapListBlock(['1', '3', 'test','mode', '2']) self.assertEqual(1, len(bloc)) self.assertEqual('test', bloc[0]['name']) self.assertEqual('mode', bloc[0]['gamemode']) self.assertEqual(2, bloc[0]['num_of_rounds']) self.assertEqual("MapListBlock[test:mode:2]", repr(bloc)) self.assertEqual(0, len(bloc.getByName('MP_003'))) self.assertEqual(1, len(bloc.getByName('test')))
def test_1(self): bloc = MapListBlock(['1', '3', 'test', 'mode', '2']) self.assertEqual(1, len(bloc)) self.assertEqual('test', bloc[0]['name']) self.assertEqual('mode', bloc[0]['gamemode']) self.assertEqual(2, bloc[0]['num_of_rounds']) self.assertEqual("MapListBlock[test:mode:2]", repr(bloc)) self.assertEqual(0, len(bloc.getByName('MP_003'))) self.assertEqual(1, len(bloc.getByName('test')))
def test_3(self): bloc = MapListBlock(['3','3', 'map1','mode1','1', 'map2','mode2','2', 'map1','mode2','2']) self.assertEqual(3, len(bloc)) self.assertEqual('map1', bloc[2]['name']) self.assertEqual('mode2', bloc[2]['gamemode']) self.assertEqual(0, len(bloc.getByName('MP_003'))) self.assertEqual(2, len(bloc.getByName('map1'))) self.assertEqual(1, len(bloc.getByName('map2'))) self.assertEqual("MapListBlock[map1:mode1:1, map2:mode2:2, map1:mode2:2]", repr(bloc)) self.assertIn(0, bloc.getByName('map1')) self.assertIn(1, bloc.getByName('map2')) self.assertIn(2, bloc.getByName('map1')) self.assertTrue(bloc.getByName('map1')[0]['gamemode'] == 'mode1') self.assertTrue(bloc.getByName('map1')[2]['gamemode'] == 'mode2') self.assertTrue(bloc.getByName('map2')[1]['gamemode'] == 'mode2') self.assertEqual(0, len(bloc.getByNameAndGamemode('map1', 'mode?'))) self.assertEqual(1, len(bloc.getByNameAndGamemode('map1', 'mode1'))) self.assertEqual(1, len(bloc.getByNameAndGamemode('map1', 'mode2'))) self.assertEqual(0, len(bloc.getByNameAndGamemode('map2', 'mode?'))) self.assertEqual(0, len(bloc.getByNameAndGamemode('map2', 'mode1'))) self.assertEqual(1, len(bloc.getByNameAndGamemode('map2', 'mode2'))) self.assertIn(0, bloc.getByNameAndGamemode('map1', 'mode1')) self.assertIn(1, bloc.getByNameAndGamemode('map2', 'mode2')) self.assertIn(2, bloc.getByNameAndGamemode('map1', 'mode2')) self.assertIn(2, bloc.getByNameGamemodeAndRounds('map1', 'mode2', '2'))
def cmd_setnextmap(self, data, client=None, cmd=None): """\ <mapname> - Set the nextmap (partial map name works) """ if not data: client.message('Invalid or missing data, try !help setnextmap') else: match = self.console.getMapsSoundingLike(data) if len(match) > 1: client.message('do you mean : %s ?' % ', '.join(match)) return if len(match) == 1: map_id = match[0] maplist = MapListBlock(self.console.write(('mapList.list',))) if not len(maplist): # maplist is empty, fix this situation by loading save mapList from disk try: self.console.write(('mapList.load',)) except Exception, err: self.warning(err) maplist = MapListBlock(self.console.write(('mapList.list',))) current_max_rounds = self.console.write(('mapList.getRounds',))[1] if not len(maplist): # maplist is still empty, nextmap will be inserted at index 0 self.console.write(('mapList.add', map_id, self.console.game.gameType, current_max_rounds, 0)) self.console.write(('mapList.setNextMapIndex', 0)) else: current_map_index = int(self.console.write(('mapList.getMapIndices', ))[0]) matching_maps = maplist.getByName(map_id) if not len(matching_maps): # then insert wanted map in rotation list next_map_index = current_map_index + 1 self.console.write(('mapList.add', map_id, self.console.game.gameType, current_max_rounds, next_map_index)) self.console.write(('mapList.setNextMapIndex', next_map_index)) elif len(matching_maps) == 1: # easy case, just set the nextLevelIndex to the index found self.console.write(('mapList.setNextMapIndex', matching_maps.keys()[0])) else: # multiple matches :s matching_indices = matching_maps.keys() # try to find the next indice after the index of the current map indices_after_current = [x for x in matching_indices if x > current_map_index] if len(indices_after_current): next_map_index = indices_after_current[0] else: next_map_index = matching_indices[0] self.console.write(('mapList.setNextMapIndex', next_map_index)) if client: cmd.sayLoudOrPM(client, 'next map set to %s' % self.console.getEasyName(map_id))
def cmd_setnextmap(self, data, client=None, cmd=None): """\ <mapname> - Set the nextmap (partial map name works) """ if not data: client.message('Invalid or missing data, try !help setnextmap') else: match = self.console.getMapsSoundingLike(data) if len(match) > 1: client.message('do you mean : %s ?' % ', '.join(match)) return if len(match) == 1: map_id = match[0] maplist = MapListBlock(self.console.write(('mapList.list', ))) if not len(maplist): # maplist is empty, fix this situation by loading save mapList from disk try: self.console.write(('mapList.load', )) except Exception, err: self.warning(err) maplist = MapListBlock( self.console.write(('mapList.list', ))) current_max_rounds = self.console.write( ('mapList.getRounds', ))[1] if not len(maplist): # maplist is still empty, nextmap will be inserted at index 0 self.console.write( ('mapList.add', map_id, self.console.game.gameType, current_max_rounds, 0)) self.console.write(('mapList.setNextMapIndex', 0)) else: current_map_index = int( self.console.write(('mapList.getMapIndices', ))[0]) matching_maps = maplist.getByName(map_id) if not len(matching_maps): # then insert wanted map in rotation list next_map_index = current_map_index + 1 self.console.write( ('mapList.add', map_id, self.console.game.gameType, current_max_rounds, next_map_index)) self.console.write( ('mapList.setNextMapIndex', next_map_index)) elif len(matching_maps) == 1: # easy case, just set the nextLevelIndex to the index found self.console.write(('mapList.setNextMapIndex', matching_maps.keys()[0])) else: # multiple matches :s matching_indices = matching_maps.keys() # try to find the next indice after the index of the current map indices_after_current = [ x for x in matching_indices if x > current_map_index ] if len(indices_after_current): next_map_index = indices_after_current[0] else: next_map_index = matching_indices[0] self.console.write( ('mapList.setNextMapIndex', next_map_index)) if client: cmd.sayLoudOrPM( client, 'next map set to %s' % self.console.getEasyName(map_id))