Skip to content

Commit

Permalink
Build render fixed in map/unit list. Disband submit correctly. On to …
Browse files Browse the repository at this point in the history
…1.0!
  • Loading branch information
spamguy committed Apr 14, 2017
1 parent 939e16f commit 05e8508
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ angular.module('gametoolsprovincelistitem.component')
case 'Hold': return 'holds';
case 'Convoy': return 'convoys';
case 'Disband': return 'disbands';
case 'Build':
if (order[2] === 'Army')
return 'builds an army';
else
return 'builds a fleet';
default: return '';
}
}

function renderOrderTarget() {
if (!order || order.length < 3)
if (!order || order.length < 3 || order[1] === 'Build')
return '';
return order[2].toUpperCase();
}
Expand Down
2 changes: 1 addition & 1 deletion client/app/components/map/map.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.active
{
color: yellow;
md-icon.active svg
svg
{
fill: yellow;
}
Expand Down
29 changes: 20 additions & 9 deletions client/app/components/map/map.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,26 @@
<md-icon md-svg-icon="convoy" ng-class="{'active': $ctrl.service.getCurrentAction() === 'Convoy' }"></md-icon>
<md-tooltip>Convoy</md-tooltip>
</md-button>
<md-button ng-if="$ctrl.service.userCanPerformAction('Adjustment', 'Build', 'Army')" ng-click="$ctrl.service.setCurrentAction('Build-Army')" aria-label="Build Army" hide-sm hide-xs>
+1 Army
</md-button>
<md-button ng-if="$ctrl.service.userCanPerformAction('Adjustment', 'Build', 'Fleet')" ng-click="$ctrl.service.setCurrentAction('Build-Fleet')" aria-label="Build Fleet" hide-sm hide-xs>
+1 Fleet
</md-button>
<md-button ng-if="$ctrl.service.userCanPerformAction('Adjustment', 'Disband') || $ctrl.service.userCanPerformAction('Retreat')" ng-click="$ctrl.service.setCurrentAction('Disband')" aria-label="Disband" hide-sm hide-xs>
Disband
</md-button>
<md-button
ng-class="{'active': $ctrl.service.getCurrentAction() === 'Build-Army' }"
ng-if="$ctrl.service.userCanPerformAction('Adjustment', 'Build', 'Army')"
ng-click="$ctrl.service.setCurrentAction('Build-Army')"
aria-label="Build Army"
hide-sm
hide-xs>+1 Army</md-button>
<md-button
ng-class="{'active': $ctrl.service.getCurrentAction() === 'Build-Fleet' }"
ng-if="$ctrl.service.userCanPerformAction('Adjustment', 'Build', 'Fleet')"
ng-click="$ctrl.service.setCurrentAction('Build-Fleet')"
aria-label="Build Fleet"
hide-sm
hide-xs>+1 Fleet</md-button>
<md-button
ng-class="{'active': $ctrl.service.getCurrentAction() === 'Disband' }"
ng-if="$ctrl.service.userCanPerformAction('Adjustment', 'Disband') || $ctrl.service.userCanPerformAction('Retreat')"
ng-click="$ctrl.service.setCurrentAction('Disband')"
aria-label="Disband"
hide-sm hide-xs>Disband</md-button>
</div>
</md-toolbar>

Expand Down
35 changes: 28 additions & 7 deletions client/app/services/map/map.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ angular.module('mapService', ['gameService', 'userService', 'variantService'])
_ordinal = 1,
_options = { },
service = function(data) {
var powerOfCurrentPlayer = gameService.getCurrentUserInGame(data.game);
var powerOfCurrentPlayer = gameService.getCurrentUserInGame(data.game),
currentPhase,
o = 0;

this.variant = data.variant;
this.game = data.game;
Expand All @@ -23,6 +25,22 @@ angular.module('mapService', ['gameService', 'userService', 'variantService'])
powerOfCurrentPlayer = powerOfCurrentPlayer.Nation;
_.pull(this.variant.Nations, powerOfCurrentPlayer);
this.variant.Nations.unshift(powerOfCurrentPlayer);

// Build commands need to create dummy units in order for them to show up as orders.
currentPhase = this.getCurrentPhase();
if (currentPhase && !currentPhase.Resolved && currentPhase.Type === 'Adjustment') {
for (; o < this.orders.length; o++) {
if (this.orders[o].Properties.Parts[1] === 'Build') {
currentPhase.Units.push({
Province: this.orders[o].Properties.Parts[0],
Unit: {
Type: this.orders[o].Properties.Parts[2],
Nation: this.orders[o].Properties.Nation
}
});
}
}
}
};

service.prototype.getCurrentPhase = getCurrentPhase;
Expand Down Expand Up @@ -134,7 +152,7 @@ angular.module('mapService', ['gameService', 'userService', 'variantService'])
function generateArc(source, target) {
var sourceProvince = variantService.getProvinceInVariant(this.variant, source),
targetProvince = variantService.getProvinceInVariant(this.variant, target),
LINK_UNIT_PADDING = 16,
LINK_UNIT_PADDING = 19,
dx = targetProvince.x - sourceProvince.x,
dy = targetProvince.y - sourceProvince.y,
dr = Math.sqrt(dx * dx + dy * dy),
Expand Down Expand Up @@ -224,7 +242,7 @@ angular.module('mapService', ['gameService', 'userService', 'variantService'])
order = buildBuildOrder(_clickedProvinces.pop());
break;
case 'Disband':
order = buildDisbandOrder();
order = buildDisbandOrder(_clickedProvinces.pop());
break;
default:
console.warn('Order type \'' + getCurrentAction() + '\' not recognised');
Expand Down Expand Up @@ -355,15 +373,17 @@ angular.module('mapService', ['gameService', 'userService', 'variantService'])
return null;

var source = _clickedProvinces.shift(),
sourceComponents = source.split('/'),
target = _clickedProvinces.shift(),
sourceProvince = variantService.getProvinceInVariant(variant, source);
sourceProvince = variantService.getProvinceInVariant(variant, sourceComponents[0]),
subprovince = sourceComponents[1] || '';

// Source can't move to itself. Treat as hold.
if (source === target)
if (sourceComponents[0] === target)
return buildDefaultOrder(source);

// Discern between Move and MoveViaConvoy by examining graph edges.
if (!sourceProvince.Subs[''].Edges[target])
if (!sourceProvince.Subs[subprovince].Edges[target])
return [source, 'MoveViaConvoy', target];

return [source, 'Move', target];
Expand Down Expand Up @@ -412,6 +432,7 @@ angular.module('mapService', ['gameService', 'userService', 'variantService'])
return [province, 'Build', buildParts[1]];
}

function buildDisbandOrder() {
function buildDisbandOrder(id) {
return [id, 'Disband'];
}
}]);
2 changes: 1 addition & 1 deletion variants
Submodule variants updated from 0e729b to 8f4a5c

0 comments on commit 05e8508

Please sign in to comment.