From 2c674a2191e91fd6f53cd556322a97f47aaaf8d1 Mon Sep 17 00:00:00 2001 From: exane Date: Fri, 3 Jul 2015 09:46:27 +0200 Subject: [PATCH] fix card clinching --- client/js/client.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client/js/client.js b/client/js/client.js index 5b39ff1..93c3a1e 100644 --- a/client/js/client.js +++ b/client/js/client.js @@ -181,7 +181,7 @@ let SideView = Backbone.View.extend({ } //calculateCardMargin($field.find(".card"), 351, 70, cards.length); - this.battleView.calculateMargin(this.$el.find(".field-close")); + this.battleView.calculateMargin($field.find(".field-close")); }, renderRangeField: function(){ if(!this.field.ranged) return; @@ -210,7 +210,7 @@ let SideView = Backbone.View.extend({ } //calculateCardMargin($field.find(".card"), 351, 70, cards.length); - this.battleView.calculateMargin(this.$el.find(".field-range")); + this.battleView.calculateMargin($field.find(".field-range")); }, renderSiegeField: function(){ if(!this.field.siege) return; @@ -239,7 +239,7 @@ let SideView = Backbone.View.extend({ } //calculateCardMargin($field.find(".card"), 351, 70, cards.length); - this.battleView.calculateMargin(this.$el.find(".field-siege")); + this.battleView.calculateMargin($field.find(".field-siege")); }, renderWeatherField: function(){ if(!this.field.weather) return; @@ -247,6 +247,7 @@ let SideView = Backbone.View.extend({ let cards = this.field.weather.cards; $weatherField.html(this.templateCards(cards)); + this.battleView.calculateMargin($weatherField, 0); return this; } /*, @@ -582,11 +583,12 @@ let BattleView = Backbone.View.extend({ } })*/ }, - calculateMargin: function($container/*, totalWidth, cardWidth, n*/){ + calculateMargin: function($container, minSize){ + minSize = typeof minSize === "number" && minSize >= 0 ? minSize : 6; var n = $container.children().size(); let w = $container.width(), c = $container.find(".card").outerWidth() + 3; let res; - if(n < 6) + if(n < minSize) res = 0; else { res = -((w - c) / (n - 1) - c) + 1