Read a map of a given name, and return a GameMap.
(map_name)
| 166 | |
| 167 | |
| 168 | def get_map(map_name): |
| 169 | ''' |
| 170 | Read a map of a given name, and return a GameMap. |
| 171 | ''' |
| 172 | |
| 173 | try: |
| 174 | with open(map_name) as f: |
| 175 | contents = f.read() |
| 176 | print("Loading map " + map_name) |
| 177 | if map_name.endswith('.bc18map'): |
| 178 | return bc.GameMap.from_json(contents) |
| 179 | elif map_name.endswith('.bc18t'): |
| 180 | return bc.GameMap.parse_text_map(contents) |
| 181 | except Exception as e: |
| 182 | if 'testmap' not in map_name: |
| 183 | print('failed to load map:', e) |
| 184 | try: |
| 185 | with open('/player/' + map_name) as f: |
| 186 | contents = f.read() |
| 187 | print("Loading map " + map_name) |
| 188 | if map_name.endswith('.bc18map'): |
| 189 | return bc.GameMap.from_json(contents) |
| 190 | elif map_name.endswith('.bc18t'): |
| 191 | return bc.GameMap.parse_text_map(contents) |
| 192 | except Exception as e: |
| 193 | if 'testmap' not in map_name: |
| 194 | print('failed to load map:', e) |
| 195 | try: |
| 196 | with open('/player/' + map_name) as f: |
| 197 | contents = f.read() |
| 198 | print("Loading map " + map_name) |
| 199 | if map_name.endswith('.bc18map'): |
| 200 | return bc.GameMap.from_json(contents) |
| 201 | elif map_name.endswith('.bc18t'): |
| 202 | return bc.GameMap.parse_text_map(contents) |
| 203 | except Exception as e: |
| 204 | print("Loading test map...") |
| 205 | return bc.GameMap.test_map() |
| 206 | |
| 207 | def create_game(args): |
| 208 | ''' |
nothing calls this directly
no test coverage detected