aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/engine/map.py
diff options
context:
space:
mode:
authorPhilip Paquette <pcpaquette@gmail.com>2019-09-09 17:57:09 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-09-10 09:09:25 -0400
commit1606653546958fd6d621809ab3cfdc8c5e7b8494 (patch)
treefe779b03267cd99cecab9812a03aefe5068d1ad3 /diplomacy/engine/map.py
parent55c1b225e22a5ce2da1c405fee99ea4315541962 (diff)
Added ability to load a custom map by specifying the path to a '.map' file
Diffstat (limited to 'diplomacy/engine/map.py')
-rw-r--r--diplomacy/engine/map.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/diplomacy/engine/map.py b/diplomacy/engine/map.py
index 13d430b..65bcdfa 100644
--- a/diplomacy/engine/map.py
+++ b/diplomacy/engine/map.py
@@ -74,8 +74,8 @@ class Map():
e.g. {'MAO': 'WATER', 'SER': 'LAND', 'SYR': 'COAST', 'MOS': 'LAND', 'VEN': 'COAST', ... }
- locs: List of 3 letter locations (With coasts)
e.g. ['ADR', 'AEG', 'ALB', 'ANK', 'APU', 'ARM', 'BAL', 'BAR', 'BEL', 'BER', ... ]
- - name: Name of the map
- e.g. 'standard'
+ - name: Name of the map (or full path to a custom map file)
+ e.g. 'standard' or '/some/path/to/file.map'
- own_word: Dict to indicate the word used to refer to people living in each power's country
e.g. {'RUSSIA': 'RUSSIAN', 'FRANCE': 'FRENCH', 'UNOWNED': 'UNOWNED', 'TURKEY': 'TURKISH', ... }
- owns: List that indicates which power have a OWNS or CENTERS line
@@ -128,7 +128,7 @@ class Map():
def __init__(self, name='standard', use_cache=True):
""" Constructor function
- :param name: Name of the map to load
+ :param name: Name of the map to load (or full path to a custom map file)
:param use_cache: Boolean flag to indicate we want a blank object that doesn't use cache
"""
if name in MAP_CACHE:
@@ -302,8 +302,13 @@ class Map():
# Otherwise file_name is the file handler
power = 0
if file_name is None:
- file_name = '{}.map'.format(self.name)
- file_path = os.path.join(settings.PACKAGE_DIR, 'maps', file_name)
+ file_name = '{}.map'.format(self.name) if not self.name.endswith('.map') else self.name
+
+ # If file_name is a path to a custom map, we use that path, otherwise, we check in the maps folder
+ if os.path.exists(file_name):
+ file_path = file_name
+ else:
+ file_path = os.path.join(settings.PACKAGE_DIR, 'maps', file_name)
# Checking if file exists:
found_map = 1 if os.path.exists(file_path) else 0