Skip to content

Commit

Permalink
changed selectCard to selectEntity and made players targetable, r…
Browse files Browse the repository at this point in the history
…emoved `isTargetable` method for cards
  • Loading branch information
Zomis committed Aug 23, 2015
1 parent 7e69765 commit 335bace
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
17 changes: 9 additions & 8 deletions src/game_board/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ function GameboardController(CardshifterServerAPI, $scope, $timeout, $rootScope,
$scope.cancelAction();
}

$scope.selectCard = function(card) {
$scope.selectEntity = function(entity) {
if (!$scope.doingAction) {
return;
}
var selected = $scope.selected;
var index = selected.indexOf(card);
var index = selected.indexOf(entity);

if(index === -1) { // select
selected.push(card);
card.selected = true;
selected.push(entity);
entity.selected = true;
} else { // de-select
selected.splice(index, 1);
card.selected = false;
entity.selected = false;
}
}

Expand Down Expand Up @@ -222,9 +225,7 @@ function GameboardController(CardshifterServerAPI, $scope, $timeout, $rootScope,
*/
function storeCard(card) {
var destinationZone = findZone(card.zone);
card.isTargetable = function() {
return $scope.targets.indexOf(card.id) !== -1;
}

try {
if(destinationZone.known) {
destinationZone.entities[card.id] = card;
Expand Down
11 changes: 7 additions & 4 deletions src/game_board/game_board.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
<div>
<div ng-repeat="(type, info) in playerInfos" class="player"
ng-class="{'player-user': info == playerInfos.user, 'player-opponent': info != playerInfos.user}">
<h1><u>{{info.name}}</u></h1>
<h1 ng-click="selectEntity(info)"
ng-class="{'selected': info.selected, 'targetable': doingAction && targets.indexOf(info.id) !== -1}">
<u>{{info.name}}</u>
</h1>

<!-- Player properties -->
<div class="properties">
Expand All @@ -33,14 +36,14 @@ <h3>{{zoneName}}</h3>
<ul>
<li ng-repeat="(id, card) in zoneInfo.entities">
<div class="card"
ng-class="{'selected': card.selected, 'targetable': card.isTargetable()}">
ng-class="{'selected': card.selected, 'targetable': doingAction && targets.indexOf(card.id) !== -1}">
<!-- For target required actions -->
<a href ng-click="selectCard(card)" ng-show="card.isTargetable() && doingAction">
<a href ng-click="selectEntity(card)" ng-show="doingAction && targets.indexOf(card.id) !== -1">
{{card.properties.name}}
</a>

<!-- For non-target-required actions -->
<div ng-hide="card.isTargetable() && doingAction">
<div ng-hide="doingAction && targets.indexOf(card.id) !== -1">
<p>
{{card.properties.name}}
</p>
Expand Down

0 comments on commit 335bace

Please sign in to comment.