<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/controllers/worlds_controller.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -130,6 +130,15 @@ class GamesController &lt; ApplicationController
     end
   end
 
+  def borders
+    world = Game.find(params[:id]).world
+    respond_to do |format|
+      format.js do
+        render :json =&gt; world.borders.to_json
+      end
+    end
+  end
+
   def players
     game = Game.find(params[:id])
     respond_to do |format|</diff>
      <filename>app/controllers/games_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,23 +29,6 @@ class Country &lt; ActiveRecord::Base
     %Q(#{id} [color=&quot;#{colour}&quot;,style=filled,label=&quot;#{name}&quot;];)
   end
 
-  def to_js
-      text = %Q[countries[#{id}] = paper.circle(#{x_position}, #{y_position}, #{(Math::log(armies.to_f) + 1) * 10});\n]
-      text &lt;&lt; unhighlight
-      text &lt;&lt; %Q[var attr = {&quot;font&quot;: '12px &quot;Verdana&quot;', opacity: 0.8};\narmies[#{id}] = paper.text(#{x_position}, #{y_position - 20}, &quot;#{name}&quot;).attr(attr).attr(&quot;fill&quot;, &quot;#0f0&quot;);\n]
-      text &lt;&lt; %Q[var attr = {&quot;font&quot;: '20px &quot;Verdana&quot;', opacity: 0.8};\narmies[#{id}] = paper.text(#{x_position}, #{y_position + 7}, &quot;#{armies}&quot;).attr(attr).attr(&quot;fill&quot;, &quot;#fff&quot;);\n]
-      text
-  end
-
-  def highlight
-    %Q[countries[#{id}].attr(&quot;fill&quot;, &quot;#000&quot;);\n countries[#{id}].attr(&quot;stroke&quot;, &quot;#f00&quot;);\n countries[#{id}].attr(&quot;stroke-width&quot;, &quot;20&quot;);\n]
-  end
-
-  def unhighlight
-    %Q[countries[#{id}].attr(&quot;fill&quot;, &quot;#000&quot;);\n countries[#{id}].attr(&quot;stroke&quot;, &quot;##{game_player.colour.hex}&quot;);\n countries[#{id}].attr(&quot;stroke-width&quot;, &quot;20&quot;).attr(&quot;id&quot;, &quot;#{id}&quot;);\n]
-  end
-
-
   def attack(target, attacker_dice = 1, target_dice = 1)
     strengths = battle_strengths(attacker_dice, target)
     logger.info &quot;battle_strengths [#{strengths}]&quot;</diff>
      <filename>app/models/country.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,18 +30,6 @@ class World &lt; ActiveRecord::Base
     #TODO award_bonuses game_player
   end
 
-  def to_js
-    text = %Q[function draw_map() {paper = Raphael(&quot;holder&quot;, 1150, 600);\n]
-    #countries.collect { |c| c.neighbours }.flatten.each_with_index do |n,i|
-    #  text &lt;&lt; n.to_js(i)
-    #end
-    countries.each_with_index do |c, i|
-      text &lt;&lt; c.to_js
-    end
-    text &lt;&lt; '}'
-    text
-  end
-
   def generate_regions(options = {}, country_options = {})
     options[:min] ||= 2
     options[:max] ||= 4
@@ -61,6 +49,10 @@ class World &lt; ActiveRecord::Base
     `dot -Tsvg -Gsize=800,600 -o#{out} #{File.join(RAILS_ROOT, 'tmp', id.to_s)}.dot` unless RAILS_ENV == 'testing'
   end
 
+  def borders
+    regions.collect { |r| r.borders }.flatten
+  end
+
   protected
 
   def countries</diff>
      <filename>app/models/world.rb</filename>
    </modified>
    <modified>
      <diff>@@ -25,6 +25,7 @@ ActionController::Routing::Routes.draw do |map|
       }
 
   map.connect 'countries/:id', :controller =&gt; 'countries', :action =&gt; 'show'
+  map.connect 'borders/:id', :controller =&gt; 'worlds', :action =&gt; 'borders'
 
   # Sample resource route with options:
   #   map.resources :products, :member =&gt; { :short =&gt; :get, :toggle =&gt; :post }, :collection =&gt; { :sold =&gt; :get }</diff>
      <filename>config/routes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,12 +13,63 @@ function Map(target) {
   // Target div
   this.target = target;
 
-  // save the players so we can draw the countries with the correct colours
+  // Save the players so we can draw the countries with the correct colours
   this.players = {};
 
   // countries
   this.countries = {};
 
+  // borders
+  this.borders = {};
+
+  // setup the players so we can use the colours when we draw the map and connectors
+  this.setPlayers = function(players) {
+    for (var i = 0, ii = players.length; i &lt; ii; i++) {
+      this.players[players[i].game_player.id] = players[i].game_player;
+    }
+  };
+
+  // draw one country on the map
+  this.drawCountry = function(country_json) {
+    var country = country_json.country;
+    var country_id = country.id;
+    $(&quot;g:contains('&quot;+country.name+&quot;')&quot;).remove();
+    var colour = this.players[country.game_player_id].colour.hex;
+    var y = Math.round(country.y_position),
+        x = Math.round(country.x_position);
+    var radius = this.settings.countryRadius + this.settings.countryIncRadius * country.armies;
+    this.countries[country_id] = country;
+    var group = this.map.group();
+    group.circle(x, y, radius).attr({fill:'#'+colour, stroke: &quot;#fff&quot;, strokewidth: 2});
+    group.text(x, y+radius+10, country.name + ' (' + country.armies + ')').attr(this.hoverLabelStyle).show();
+  };
+
+  // Draw all the countries
+  this.drawCountries = function(countries) {
+    for (var i = 0, ii = countries.length; i &lt; ii; i++) {
+      this.drawCountry(countries[i]);
+    }
+  };
+
+  // draw one border on the map
+  this.drawBorder = function(border_json) {
+    var border = border_json.neighbour;
+    var from = this.countries[border.country_id];
+    var to = this.countries[border.neighbour_id];
+    //$(&quot;g:contains('&quot;+border.name+&quot;')&quot;).remove();
+    //var colour = this.players[border.game_player_id].colour.hex;
+    this.borders[border.id] = border;
+    var group = this.map.group();
+    group.path({stroke: &quot;#ddd&quot;}).moveTo(from.x_position, from.y_position).lineTo(to.x_position, to.y_position);
+  };
+
+  // Draw all the borders
+  this.drawBorders = function(borders) {
+    for (var i = 0, ii = borders.length; i &lt; ii; i++) {
+      this.drawBorder(borders[i]);
+    }
+  };
+
   this.settings = $.extend({
       // Dimensions
     width: 1000,
@@ -57,37 +108,6 @@ function Map(target) {
   }, (arguments[3] || {}) );
 
 
-  this.map = Raphael(target, this.settings.width, this.settings.height);
-
-  // setup the players so we can use the colours when we draw the map and connectors
-  this.setPlayers = function(players) {
-    for (var i = 0, ii = players.length; i &lt; ii; i++) {
-      this.players[players[i].game_player.id] = players[i].game_player;
-    }
-  };
-
-  // plot one country on the map
-  this.plotCountry = function(country_json) {
-    var country = country_json.country;
-    var country_id = country.id;
-    $(&quot;g:contains('&quot;+country.name+&quot;')&quot;).remove();
-    var colour = this.players[country.game_player_id].colour.colour.hex;
-    var y = Math.round(this.settings.height - this.settings.bottomGutter - country.y_position),
-        x = Math.round(this.settings.leftGutter + country.x_position);
-    var radius = this.settings.countryRadius + this.settings.countryIncRadius * country.armies;
-    this.countries[country_id] = this.map.group();
-    var group = this.countries[country_id];
-    group.circle(x, y, radius).attr({fill:'#'+colour, stroke: &quot;#fff&quot;, strokewidth: 2});
-    group.text(x, y+radius+10, country.name + ' (' + country.armies + ')').attr(this.hoverLabelStyle).show();
-  };
-
-  // Plot all the countries
-  this.plot = function(countries) {
-    for (var i = 0, ii = countries.length; i &lt; ii; i++) {
-      this.plotCountry(countries[i]);
-    }
-  };
-
   this.setStyleDefaults = function() {
     // X and Y axis labels and captions default to global style if not provided
     // - X Axis Labels
@@ -171,6 +191,7 @@ function Map(target) {
     }
   };
 
+  this.map = Raphael(target, this.settings.width, this.settings.height);
   this.setStyleDefaults();
   this.setPenColor();
 }</diff>
      <filename>public/javascripts/map.js</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@ function allocate_armies(game_id,game_player_id) {
   $.post(&quot;/games/allocate_armies&quot;,{game_id: game_id, game_player_id: game_player_id, country_id: $('#country_id').val(), armies: $('#armies').val(),authenticity_token: global_token}, function(data) {
       $(&quot;#out&quot;).html(data);
       });
-  plot_map();
+  draw_country($('#country_id').val());
 }
 
 function pass_turn(game_id,game_player_id) {
@@ -21,8 +21,8 @@ function attack(game_id,game_player_id,attacker_country_id, target_country_id,ar
   $.post(&quot;/games/attack&quot;,{game_id: game_id, game_player_id: game_player_id, attacker_country_id: attacker_country_id, target_country_id: target_country_id, armies: armies,authenticity_token: global_token}, function(data) {
       $(&quot;#out&quot;).html(data);
       });
-  plot_country(attacker_country_id);
-  plot_country(target_country_id);
+  draw_country(attacker_country_id);
+  draw_country(target_country_id);
 }
 
 function draw_svg (game_id) {
@@ -31,12 +31,25 @@ function draw_svg (game_id) {
 
 var map;
 
-function plot_country(country_id) {
-  $.getJSON(&quot;/countries/&quot; + country_id, function(data) { map.plotCountry(data)} );
+// draw one country on the map
+function draw_country(country_id) {
+  $.getJSON(&quot;/countries/&quot; + country_id, function(data) { map.drawCountry(data)} );
 }
 
-function plot_map() {
-  $.getJSON(&quot;/games/&quot; + game_id + &quot;/countries&quot;, function(data) { map.plot(data)} );
+// draw all the countries
+function draw_map() {
+  draw_countries();
+  draw_borders();
+}
+
+// draw all the countries
+function draw_borders() {
+  $.getJSON(&quot;/borders/&quot; + game_id, function(data) { map.drawBorders(data)} );
+}
+
+// draw all the countries
+function draw_countries() {
+  $.getJSON(&quot;/games/&quot; + game_id + &quot;/countries&quot;, function(data) { map.drawCountries(data)} );
 }
 
 function set_players() {
@@ -47,6 +60,6 @@ $(document).ready(function() {
 
     map = new Map(&quot;map_holder&quot;);
     set_players();
-    plot_map();
+    draw_map();
 
 });</diff>
      <filename>public/javascripts/risk.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c4ab2140b901b4841a096445907d774ee223479d</id>
    </parent>
  </parents>
  <author>
    <name>Martin Stannard</name>
    <email>mstannard@gmail.com</email>
  </author>
  <url>http://github.com/martinstannard/risque/commit/55e258ceb72f9f0c4693488ba3c6b95aec72fa0a</url>
  <id>55e258ceb72f9f0c4693488ba3c6b95aec72fa0a</id>
  <committed-date>2008-12-21T15:40:52-08:00</committed-date>
  <authored-date>2008-12-21T15:40:52-08:00</authored-date>
  <message>added borders - need to fix z-order</message>
  <tree>1cb53d92664c1780187c94489745de35d0cab7ed</tree>
  <committer>
    <name>Martin Stannard</name>
    <email>mstannard@gmail.com</email>
  </committer>
</commit>
