aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/engine/renderer.py
diff options
context:
space:
mode:
authorPhilip Paquette <pcpaquette@gmail.com>2019-09-11 17:00:36 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-09-14 18:18:53 -0400
commit8ca9bcfbad2b93e1466f290cf8d7eb82e3bf8146 (patch)
tree9eab9dc7f45ce8dd393bce312ae0f85e325e01d8 /diplomacy/engine/renderer.py
parentabb42dcd4886705d6ba8af27f68ef605218ac67c (diff)
.render() method - Added arg 'output_path' to be able to save img on disk
Diffstat (limited to 'diplomacy/engine/renderer.py')
-rw-r--r--diplomacy/engine/renderer.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/diplomacy/engine/renderer.py b/diplomacy/engine/renderer.py
index e4c6ff3..42a8435 100644
--- a/diplomacy/engine/renderer.py
+++ b/diplomacy/engine/renderer.py
@@ -63,15 +63,17 @@ class Renderer:
self.xml_map = minidom.parse(svg_path).toxml()
self._load_metadata()
- def render(self, incl_orders=True, incl_abbrev=False, output_format='svg'):
+ def render(self, incl_orders=True, incl_abbrev=False, output_format='svg', output_path=None):
""" Renders the current game and returns the XML representation
:param incl_orders: Optional. Flag to indicate we also want to render orders.
:param incl_abbrev: Optional. Flag to indicate we also want to display the provinces abbreviations.
:param output_format: The desired output format. Valid values are: 'svg'
+ :param output_path: Optional. The full path where to save the rendering on disk.
:type incl_orders: bool, optional
:type incl_abbrev: bool, optional
:type output_format: str, optional
+ :type output_path: str | None, optional
:return: The rendered image in the specified format.
"""
# pylint: disable=too-many-branches
@@ -181,8 +183,16 @@ class Renderer:
elif _attr(child_node, 'id') == 'MouseLayer':
svg_node.removeChild(child_node)
+ # Rendering
+ rendered_image = xml_map.toxml()
+
+ # Saving to disk
+ if output_path:
+ with open(output_path, 'w') as output_file:
+ output_file.write(rendered_image)
+
# Returning
- return xml_map.toxml()
+ return rendered_image
def _load_metadata(self):
""" Loads meta-data embedded in the XML map and clears unused nodes """