# Chariot Extensions for ATITD Maps
# =================================
#
# Adds the ability to render chariot routes on a map image.

package ATITD::Map;

use strict;
use warnings;

# Render the chariot links in the colors specified.
sub render_chariots {
	my ($self, $color, $dim_color) = @_;
	
	for my $chariot ($self->telling->chariots) {
		for my $link ($chariot->links) {
			$self->render_chariot_link($link, $color, $dim_color);
		}
	}
	
	return $self;
}

# Render a single chariot link in the colors specified.
sub render_chariot_link {
	my ($self, $link, $color, $dim_color) = @_;	
	my $from = $self->translate($link->from->coords);
	my $to = $self->translate($link->to->coords);
	
	if ($link->open) {
		# Open both ways: Thick bright line
		if ($link->reciprocal->open) {
			$self->render_line($from, $to, $color, 2);
		}

		# Open one way: Thin bright line with an arrow
		else {
			$self->render_arrow($from, $to, $color, 1);
		}
	}
	elsif (!$link->reciprocal->open) {
		# Not open: Dashed dim line
		$self->render_line($from, $to, $dim_color, -1);
	}
	
	return $self;
}	

1;
