aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Paquette <pcpaquette@gmail.com>2019-09-09 18:05:10 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-09-10 09:09:25 -0400
commita954a00d263750c279dbb2c0a9ae85707022bcd7 (patch)
tree3ca755350a4d7a417814e2c07bc9adbe011e2980
parent1606653546958fd6d621809ab3cfdc8c5e7b8494 (diff)
Added ability to specify a custom SVG path in the renderer
- This could be used for instance to change the colours on the map.
-rw-r--r--diplomacy/engine/renderer.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/diplomacy/engine/renderer.py b/diplomacy/engine/renderer.py
index 01fe209..1c92886 100644
--- a/diplomacy/engine/renderer.py
+++ b/diplomacy/engine/renderer.py
@@ -38,19 +38,23 @@ def _attr(node_element, attr_name):
class Renderer():
""" Renderer object responsible for rendering a game state to svg """
- def __init__(self, game):
+ def __init__(self, game, svg_path=None):
""" Constructor
:param game: The instantiated game object to render
+ :param svg_path: Optional. Can be set to the full path of a custom SVG to use for rendering the map.
:type game: diplomacy.Game
"""
self.game = game
self.metadata = {}
self.xml_map = None
- self.xml_map_path = os.path.join(settings.PACKAGE_DIR, 'maps', 'svg', self.game.map.name + '.svg')
+
+ # If no SVG path provided, we default to the one in the maps folder
+ if not svg_path:
+ svg_path = os.path.join(settings.PACKAGE_DIR, 'maps', 'svg', self.game.map.name + '.svg')
# Loading XML
- if os.path.exists(self.xml_map_path):
- self.xml_map = minidom.parse(self.xml_map_path).toxml()
+ if os.path.exists(svg_path):
+ self.xml_map = minidom.parse(svg_path).toxml()
self._load_metadata()
def norm_order(self, order):